Mercurial > my-enso-commands
comparison my-enso-commands.py @ 3:9767abfe290b
Added more service-oriented commands.
| author | Atul Varma <varmaa@toolness.com> |
|---|---|
| date | Sun, 18 May 2008 00:44:02 -0700 |
| parents | c28ae8f664ba |
| children | 56d44190362e |
comparison
equal
deleted
inserted
replaced
| 2:c28ae8f664ba | 3:9767abfe290b |
|---|---|
| 8 import urllib | 8 import urllib |
| 9 import threading | 9 import threading |
| 10 import logging | 10 import logging |
| 11 from StringIO import StringIO | 11 from StringIO import StringIO |
| 12 | 12 |
| 13 def cmd_define(ensoapi): | 13 def _do_service(ensoapi, serviceName): |
| 14 import AppKit | 14 import AppKit |
| 15 | |
| 16 serviceName = "Look Up in Dictionary" | |
| 17 | 15 |
| 18 text = ensoapi.get_selection().get("text", "").strip() | 16 text = ensoapi.get_selection().get("text", "").strip() |
| 19 | 17 |
| 20 if not text: | 18 if not text: |
| 21 ensoapi.display_message("No text selection!") | 19 ensoapi.display_message("No text selection!") |
| 31 | 29 |
| 32 if not AppKit.NSPerformService( serviceName, pb ): | 30 if not AppKit.NSPerformService( serviceName, pb ): |
| 33 raise Exception( "Failed to perform service." ) | 31 raise Exception( "Failed to perform service." ) |
| 34 finally: | 32 finally: |
| 35 pass | 33 pass |
| 34 | |
| 35 def cmd_define(ensoapi): | |
| 36 _do_service(ensoapi, "Look Up in Dictionary") | |
| 37 | |
| 38 def cmd_speak(ensoapi): | |
| 39 _do_service(ensoapi, "Speech/Start Speaking Text") | |
| 40 | |
| 41 def cmd_summarize(ensoapi): | |
| 42 _do_service(ensoapi, "Summarize") | |
| 43 | |
| 44 def cmd_spotlight(ensoapi): | |
| 45 _do_service(ensoapi, "Spotlight") | |
| 36 | 46 |
| 37 def cmd_count_lines(ensoapi): | 47 def cmd_count_lines(ensoapi): |
| 38 seldict = ensoapi.get_selection() | 48 seldict = ensoapi.get_selection() |
| 39 ensoapi.display_message( "Selection is %s lines." % | 49 ensoapi.display_message( "Selection is %s lines." % |
| 40 len(seldict.get("text","").splitlines()) ) | 50 len(seldict.get("text","").splitlines()) ) |
