diff options
author | Marco Pesenti Gritti <mpg@redhat.com> | 2007-11-09 09:24:30 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <mpg@redhat.com> | 2007-11-09 09:24:30 (GMT) |
commit | 55864fa3f65bab1bc780881c0ff22b002095393a (patch) | |
tree | 7221ef33afb92fbed7656b26df574083af7fbe32 /shell/view | |
parent | be8669317d629d14639b0313c4b9179263db4522 (diff) |
Add support for the espeak service
Diffstat (limited to 'shell/view')
-rw-r--r-- | shell/view/keyhandler.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/shell/view/keyhandler.py b/shell/view/keyhandler.py index a34d0d1..cb572f4 100644 --- a/shell/view/keyhandler.py +++ b/shell/view/keyhandler.py @@ -59,13 +59,18 @@ _actions_table = { '<ctrl>Escape' : 'close_window', '<ctrl>q' : 'close_window', '0xDC' : 'open_search', - '<ctrl>o' : 'open_search' + '<ctrl>o' : 'open_search', + '<alt>s' : 'say_text' } J_DBUS_SERVICE = 'org.laptop.Journal' J_DBUS_PATH = '/org/laptop/Journal' J_DBUS_INTERFACE = 'org.laptop.Journal' +SPEECH_DBUS_SERVICE = 'org.laptop.Speech' +SPEECH_DBUS_PATH = '/org/laptop/Speech' +SPEECH_DBUS_INTERFACE = 'org.laptop.Speech' + class KeyHandler(object): def __init__(self, shell): self._shell = shell @@ -73,6 +78,7 @@ class KeyHandler(object): self._key_pressed = None self._keycode_pressed = 0 self._keystate_pressed = 0 + self._speech_proxy = None self._key_grabber = KeyGrabber() self._key_grabber.connect('key-pressed', @@ -110,6 +116,26 @@ class KeyHandler(object): else: hw_manager.set_display_mode(hardwaremanager.COLOR_MODE) + def _get_speech_proxy(self): + if self._speech_proxy is None: + bus = dbus.SessionBus() + speech_obj = bus.get_object(SPEECH_DBUS_SERVICE, SPEECH_DBUS_PATH) + self._speech_proxy = dbus.Interface(speech_obj, SPEECH_DBUS_INTERFACE) + return self._speech_proxy + + def _on_speech_err(self, ex): + logging.error("An error occurred with the ESpeak service: %r" % (ex, )) + + def _primary_selection_cb(self, clipboard, text, user_data): + logging.debug('KeyHandler._primary_selection_cb: %r' % text) + if text: + self._get_speech_proxy().SayText(text, reply_handler=lambda: None, \ + error_handler=self._on_speech_err) + + def handle_say_text(self): + clipboard = gtk.clipboard_get(selection="PRIMARY") + clipboard.request_text(self._primary_selection_cb) + def handle_previous_window(self): self._shell.activate_previous_activity() |