diff options
author | Martin Abente <martin.abente.lahaye@gmail.com> | 2010-11-03 21:27:30 (GMT) |
---|---|---|
committer | Anish Mangal <anish@activitycentral.com> | 2012-02-01 12:33:29 (GMT) |
commit | 324d69f8e0e0d2e701d7a5410c9964995a89713b (patch) | |
tree | 119aebf1420e312497341ada56837d2c6c8d2286 | |
parent | 49fc3c2226ff40f774f4101102d0520836bf732d (diff) |
Globalkey for touchpad device icon
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
-rw-r--r-- | extensions/deviceicon/touchpad.py | 16 | ||||
-rw-r--r-- | extensions/globalkey/Makefile.am | 1 | ||||
-rw-r--r-- | extensions/globalkey/touchpad.py | 33 |
3 files changed, 44 insertions, 6 deletions
diff --git a/extensions/deviceicon/touchpad.py b/extensions/deviceicon/touchpad.py index 6773afc..ba02037 100644 --- a/extensions/deviceicon/touchpad.py +++ b/extensions/deviceicon/touchpad.py @@ -45,6 +45,8 @@ STATUS_ICON = { # 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. """ @@ -66,14 +68,14 @@ class DeviceView(TrayIcon): """ Create a palette for this icon; called by the Sugar framework when a palette needs to be displayed. """ label = glib.markup_escape_text(_('My touchpad')) - self.palette = ResourcePalette(label, self.icon) - self.palette.set_group_id('frame') - return self.palette + self._palette = ResourcePalette(label, self.icon) + self._palette.set_group_id('frame') + return self._palette def __button_release_event_cb(self, widget, event): """ Callback for button release event; used to invoke touchpad-mode change. """ - self.palette.toggle_mode() + self._palette.toggle_mode() return True @@ -111,10 +113,12 @@ class ResourcePalette(Palette): def setup(tray): - """ Initialize the devic icon; called by the shell when initializing the + """ Initialize the device icon; called by the shell when initializing the Frame. """ + global _view if os.path.exists(NODE_PATH): - tray.add_device(DeviceView()) + _view = DeviceView() + tray.add_device(_view) _write_touchpad_mode(TOUCHPAD_MODE_CAPACITIVE) 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..eeaba40 --- /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() |