[Dextrose] [PATCH] Globalkey for touchpad device icon

Martin Abente martin.abente.lahaye at gmail.com
Wed Nov 3 17:27:30 EDT 2010


Add a new keyboard shortcut as a globalkey, this will 
toggle the touchpad mode when <Alt + m> is pressed.

Also change DeviceView.palette indentifier for 
DeviceView._palette. Palette was not showing 
because of that.

Dextrose version

---
 extensions/deviceicon/touchpad.py |   14 +++++++++-----
 extensions/globalkey/Makefile.am  |    1 +
 extensions/globalkey/touchpad.py  |   33 +++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 5 deletions(-)
 create mode 100644 extensions/globalkey/touchpad.py

diff --git a/extensions/deviceicon/touchpad.py b/extensions/deviceicon/touchpad.py
index 7f3ecb5..357bdd6 100644
--- a/extensions/deviceicon/touchpad.py
+++ b/extensions/deviceicon/touchpad.py
@@ -37,6 +37,8 @@ FLAG_PATH = '/home/olpc/.olpc-pentablet-mode'
 # NODE_PATH is used to communicate with the touchpad device.
 NODE_PATH = '/sys/devices/platform/i8042/serio1/ptmode'
 
+_view = None
+
 class DeviceView(TrayIcon):
     """ Manage the touchpad mode from the device palette on the Frame. """
 
@@ -55,13 +57,13 @@ class DeviceView(TrayIcon):
 
     def create_palette(self):
         """ On create, set the current mode. """
-        self.palette = ResourcePalette(_('My touchpad'), self.icon)
-        self.palette.set_group_id('frame')
-        return self.palette
+        self._palette = ResourcePalette(_('My touchpad'), self.icon)
+        self._palette.set_group_id('frame')
+        return self._palette
 
     def __button_release_event_cb(self, widget, event):
         """ On button release, switch modes. """
-        self.palette.toggle_mode()
+        self._palette.toggle_mode()
         return True
 
 
@@ -100,8 +102,10 @@ class ResourcePalette(Palette):
 
 def setup(tray):
     """ Touchpad palette only appears when the device exisits. """
+    global _view
     if os.path.exists(NODE_PATH):
-        tray.add_device(DeviceView())
+        _view = DeviceView()
+        tray.add_device(_view)
 
 
 def read_touchpad_mode():
diff --git a/extensions/globalkey/Makefile.am b/extensions/globalkey/Makefile.am
index b44626e..e3aaa8a 100644
--- a/extensions/globalkey/Makefile.am
+++ b/extensions/globalkey/Makefile.am
@@ -4,5 +4,6 @@ sugar_PYTHON = 		\
 	__init__.py	\
 	magnifier.py	\
 	screenshot.py	\
+	touchpad.py	\
 	viewsource.py	\
 	virtualkeyboard.py
diff --git a/extensions/globalkey/touchpad.py b/extensions/globalkey/touchpad.py
new file mode 100644
index 0000000..e36cf80
--- /dev/null
+++ b/extensions/globalkey/touchpad.py
@@ -0,0 +1,33 @@
+# Copyright (C) 2010, Martin Abente
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+import logging
+
+BOUND_KEYS = ['<alt>m']
+touchpad = None
+
+def handle_key_press(key):
+    global touchpad
+    if touchpad is None:
+        try:
+            touchpad = __import__('deviceicon.touchpad', globals(),
+                                   locals(), ['touchpad'])
+        except Exception:
+            logging.error('Could not import touchpad module.')
+            return
+
+    if touchpad._view is not None:
+        touchpad._view._palette.toggle_mode()
-- 
1.7.1



More information about the Dextrose mailing list