From 55864fa3f65bab1bc780881c0ff22b002095393a Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 09 Nov 2007 09:24:30 +0000 Subject: Add support for the espeak service --- (limited to 'shell/view') 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 = { 'Escape' : 'close_window', 'q' : 'close_window', '0xDC' : 'open_search', - 'o' : 'open_search' + 'o' : 'open_search', + '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() -- cgit v0.9.1