Ticket #2006: 0001-touchpad-section-for-control-panel.patch
File 0001-touchpad-section-for-control-panel.patch, 15.2 KB (added by walter, 13 years ago) |
---|
-
configure.ac
From e0fb7ebf21d2f13ffd4adbb7aebb77f742370350 Mon Sep 17 00:00:00 2001 From: Walter Bender <walter@sugarlabs.org> Date: Thu, 20 May 2010 14:55:55 -0400 Subject: [PATCH] touchpad section for control panel --- configure.ac | 1 + data/icons/Makefile.am | 1 + data/icons/module-touchpad.svg | 36 ++++++ extensions/cpsection/Makefile.am | 2 +- extensions/cpsection/touchpad/Makefile.am | 6 + extensions/cpsection/touchpad/__init__.py | 25 ++++ extensions/cpsection/touchpad/model.py | 59 ++++++++++ extensions/cpsection/touchpad/view.py | 178 +++++++++++++++++++++++++++++ 8 files changed, 307 insertions(+), 1 deletions(-) create mode 100644 data/icons/module-touchpad.svg create mode 100644 extensions/cpsection/touchpad/Makefile.am create mode 100644 extensions/cpsection/touchpad/__init__.py create mode 100644 extensions/cpsection/touchpad/model.py create mode 100644 extensions/cpsection/touchpad/view.py diff --git a/configure.ac b/configure.ac index 4f60892..e7d1c73 100644
a b extensions/cpsection/modemconfiguration/Makefile 59 59 extensions/cpsection/Makefile 60 60 extensions/cpsection/network/Makefile 61 61 extensions/cpsection/power/Makefile 62 extensions/cpsection/touchpad/Makefile 62 63 extensions/cpsection/updater/backends/Makefile 63 64 extensions/cpsection/updater/Makefile 64 65 extensions/deviceicon/Makefile -
data/icons/Makefile.am
diff --git a/data/icons/Makefile.am b/data/icons/Makefile.am index a35643a..b65b34e 100644
a b sugar_DATA = \ 10 10 module-modemconfiguration.svg \ 11 11 module-network.svg \ 12 12 module-power.svg \ 13 module-touchpad.svg \ 13 14 module-updater.svg 14 15 15 16 EXTRA_DIST = $(sugar_DATA) -
new file data/icons/module-touchpad.svg
diff --git a/data/icons/module-touchpad.svg b/data/icons/module-touchpad.svg new file mode 100644 index 0000000..5794fd7
- + 1 <?xml version="1.0" encoding="UTF-8" standalone="no"?> 2 <!-- Created with Inkscape (http://www.inkscape.org/) --> 3 4 <svg 5 xmlns:svg="http://www.w3.org/2000/svg" 6 xmlns="http://www.w3.org/2000/svg" 7 version="1.1" 8 width="55" 9 height="55" 10 viewBox="0 0 55 55" 11 id="Layer_1" 12 xml:space="preserve"><defs 13 id="defs2829" /> 14 <g 15 transform="translate(0,-3.9)" 16 id="g2817"> 17 </g> 18 19 20 21 <g 22 transform="translate(0,4.3506441)" 23 id="g2928"><g 24 transform="translate(0,-20)" 25 id="g2819"> 26 <path 27 d="m 2.934,28.664 0,18.209 49.391,0 0,-18.209 -49.391,0 z M 36,45.833 l -17,0 0,-16.129 17,0 0,16.129 z" 28 id="path2821" 29 style="fill:#ffffff;stroke:#666666;stroke-width:2" /> 30 </g><path 31 d="m 46.742465,3.78755 -5.095999,6.747499 -1.044001,1.3585 -1.7375,4.133 c -0.023,0.052 -0.009,0.1115 0.0345,0.1475 0.0445,0.036 0.1055,0.042 0.1535,0.01 l 3.913,-2.5185 c 0.0055,-0.004 0.0055,-0.0135 0.011,-0.0215 0.0325,-0.0245 0.071,-0.046 0.098,-0.081 0.0015,-10e-4 0.017,-0.0205 0.017,-0.0245 l 0.9155,-1.1355 2.7345,-3.527 4.005501,-5.164499 c 0.011,-0.0115 0.0745,-0.1015 0.0745,-0.1015 0.048,-0.0805 0.074,-0.1725 0.074,-0.278 0,-0.0305 0,-0.059 -0.006,-0.088 -0.0435,-0.3815 -0.357501,-0.841 -0.819501,-1.2065 -0.4615,-0.364 -0.9845,-0.5615 -1.364,-0.517 -0.163,0.021 -0.3945,0.1875 -0.3945,0.1875 l -1.5695,2.0795 z" 32 id="path2823" 33 style="fill:#ffffff;stroke:#666666;stroke-width:1.5" /><path 34 d="m 22.817123,44.784359 c 0,0 -3.23492,-8.766448 -3.243008,-9.837791 -0.0135,-1.797291 -2.398098,-2.342156 -2.398098,-2.342156 0,0 -0.621319,-2.249376 0,-2.770053 0.656117,-0.549837 2.934483,-0.629824 3.735004,0.330634 l 2.413094,2.895211 0,-12.75 c 0,0 0.888891,-1.589214 1.643962,-1.454545 0.745806,0.133019 1.356038,1.454545 1.356038,1.454545 l 0,10.5 0,-4.5 c 0,0 0.947828,-0.746067 1.5,-0.75 0.552172,-0.0039 1.5,0.75 1.5,0.75 l 0,4.5 0,-3.75 c 0,0 0.675747,-0.758712 1.5,-0.75 0.824253,0.0087 1.5,0.568182 1.5,0.568182 l 0,3.931818 0,-3 c 0,0 0.857274,-0.33549 1.5,-0.375 0.526597,-0.03237 1.448303,0.97351 1.5,1.575 0.220672,2.567514 0.969363,5.350927 0.823983,7.574377 -0.100086,1.53071 -0.67874,8.199778 -2.212713,8.199778 l -11.118262,0 z" 35 id="path2825" 36 style="fill:#ffffff;stroke:#666666;stroke-width:1.5" /></g></svg> 37 No newline at end of file -
extensions/cpsection/Makefile.am
diff --git a/extensions/cpsection/Makefile.am b/extensions/cpsection/Makefile.am index a92b5dd..4cf1718 100644
a b 1 1 SUBDIRS = aboutme aboutcomputer datetime frame keyboard language \ 2 modemconfiguration network power updater2 modemconfiguration network power touchpad updater 3 3 4 4 sugardir = $(pkgdatadir)/extensions/cpsection 5 5 sugar_PYTHON = __init__.py -
new file extensions/cpsection/touchpad/Makefile.am
diff --git a/extensions/cpsection/touchpad/Makefile.am b/extensions/cpsection/touchpad/Makefile.am new file mode 100644 index 0000000..fd83e2f
- + 1 sugardir = $(pkgdatadir)/extensions/cpsection/touchpad 2 3 sugar_PYTHON = \ 4 __init__.py \ 5 model.py \ 6 view.py -
new file extensions/cpsection/touchpad/__init__.py
diff --git a/extensions/cpsection/touchpad/__init__.py b/extensions/cpsection/touchpad/__init__.py new file mode 100644 index 0000000..95c1af8
- + 1 # Copyright (C) 2008, OLPC 2 # 3 # This program is free software; you can redistribute it and/or modify 4 # it under the terms of the GNU General Public License as published by 5 # the Free Software Foundation; either version 2 of the License, or 6 # (at your option) any later version. 7 # 8 # This program is distributed in the hope that it will be useful, 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # GNU General Public License for more details. 12 # 13 # You should have received a copy of the GNU General Public License 14 # along with this program; if not, write to the Free Software 15 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 17 from gettext import gettext as _ 18 from os import path 19 20 # Only include this Control Panel section if on OLPC XO-1.0 CL1 hardware. 21 if path.exists('/sys/devices/platform/i8042/serio1/ptmode'): 22 CLASS = 'Touchpad' 23 ICON = 'module-touchpad' 24 TITLE = _('Touchpad') 25 KEYWORDS = ['touchpad'] -
new file extensions/cpsection/touchpad/model.py
diff --git a/extensions/cpsection/touchpad/model.py b/extensions/cpsection/touchpad/model.py new file mode 100644 index 0000000..77eefa4
- + 1 # Copyright (C) 2010, Walter Bender, Sugar Labs 2 # 3 # This program is free software; you can redistribute it and/or modify 4 # it under the terms of the GNU General Public License as published by 5 # the Free Software Foundation; either version 2 of the License, or 6 # (at your option) any later version. 7 # 8 # This program is distributed in the hope that it will be useful, 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # GNU General Public License for more details. 12 # 13 # You should have received a copy of the GNU General Public License 14 # along with this program; if not, write to the Free Software 15 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 16 # 17 from gettext import gettext as _ 18 from os import system, path 19 import gconf 20 21 _CAPACITIVE = 0 22 _RESISTIVE = 1 23 _flag_path = '/home/olpc/.olpc-pentablet-mode' 24 _node_path = '/sys/devices/platform/i8042/serio1/ptmode' 25 26 def get_touchpad(): 27 """Get the touchpad mode.""" 28 29 _file_handle = open(_node_path, "r") 30 _text = _file_handle.read() 31 _file_handle.close() 32 33 if _text[0] == '1': 34 return _RESISTIVE 35 else: 36 return _CAPACITIVE 37 38 def set_touchpad(touchpad): 39 """Set the touchpad mode.""" 40 if touchpad == _CAPACITIVE: 41 system("rm %s" % (_flag_path)) 42 system("echo 0 > %s" % (_node_path)) 43 else: 44 system("touch %s" % (_flag_path)) 45 system("echo 1 > %s" % (_node_path)) 46 return 47 48 def print_touchpad(): 49 """Print the future touchpad mode.""" 50 if get_touchpad == _CAPACITIVE: 51 print _('Touchpad set to finger mode.') 52 else: 53 print _('Touchpad set to stylus mode.') 54 55 def get_color_xo(): 56 """Get xo color""" 57 client = gconf.client_get_default() 58 return client.get_string("/desktop/sugar/user/color") 59 -
new file extensions/cpsection/touchpad/view.py
diff --git a/extensions/cpsection/touchpad/view.py b/extensions/cpsection/touchpad/view.py new file mode 100644 index 0000000..19fb686
- + 1 # Copyright (C) 2008, OLPC 2 # Copyright (C) 2010, Walter Bender, Sugar Labs 3 # 4 # This program is free software; you can redistribute it and/or modify 5 # it under the terms of the GNU General Public License as published by 6 # the Free Software Foundation; either version 2 of the License, or 7 # (at your option) any later version. 8 # 9 # This program is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with this program; if not, write to the Free Software 16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 18 import gtk 19 import gobject 20 from gettext import gettext as _ 21 22 from sugar.graphics.icon import Icon 23 from sugar.graphics import style 24 from sugar.graphics.xocolor import XoColor 25 26 from jarabe.controlpanel.sectionview import SectionView 27 from jarabe.controlpanel.inlinealert import InlineAlert 28 29 _CAPACITIVE = 0 30 _RESISTIVE = 1 31 32 class TouchpadEventIcon(gtk.EventBox): 33 """A subclass of the Sugar Event Icon""" 34 __gtype_name__ = "SugarEventIcon" 35 36 def __init__(self, **kwargs): 37 """Create an extra-large, clickable icon.""" 38 gtk.EventBox.__init__(self) 39 40 self.icon = Icon(pixel_size = style.XLARGE_ICON_SIZE, **kwargs) 41 42 self.set_visible_window(False) 43 self.set_app_paintable(True) 44 self.set_events(gtk.gdk.BUTTON_PRESS_MASK) 45 46 self.add(self.icon) 47 self.icon.show() 48 49 class TouchpadPicker(TouchpadEventIcon): 50 """A class for the touchpad selection buttons""" 51 __gsignals__ = { 52 'touchpad-changed': (gobject.SIGNAL_RUN_FIRST, 53 gobject.TYPE_NONE, 54 ([object])) 55 } 56 57 def __init__(self, touchpad_mode): 58 """Create icons for the touchpad mode buttons.""" 59 TouchpadEventIcon.__init__(self) 60 61 if touchpad_mode == _CAPACITIVE: 62 self.icon.props.icon_name = 'capacitive' 63 else: 64 self.icon.props.icon_name = 'resistive' 65 self._touchpad_mode = touchpad_mode 66 67 self.icon.props.pixel_size = style.XLARGE_ICON_SIZE 68 69 self.connect('button_press_event', self.__pressed_cb, touchpad_mode) 70 71 def update(self, touchpad, xo_color): 72 """Update the button states.""" 73 if self._touchpad_mode == _CAPACITIVE: 74 self.icon.props.icon_name = 'capacitive' 75 if touchpad == _CAPACITIVE: 76 self.icon.props.xo_color = xo_color 77 else: 78 self.icon.props.xo_color = XoColor('#666666,#FFFFFF') 79 elif self._touchpad_mode == _RESISTIVE: 80 self.icon.props.icon_name = 'resistive' 81 if touchpad == _RESISTIVE: 82 self.icon.props.xo_color = xo_color 83 else: 84 self.icon.props.xo_color = XoColor('#666666,#FFFFFF') 85 86 def __pressed_cb(self, button, event, touchpad_mode): 87 """Callback for button click.""" 88 self.emit('touchpad-changed', touchpad_mode) 89 90 class Touchpad(SectionView): 91 """A class for the touchpad selection panel""" 92 93 def __init__(self, model, alerts): 94 """ Create the touchpad panel.""" 95 SectionView.__init__(self) 96 97 self._model = model 98 self._color = XoColor(self._model.get_color_xo()) 99 self._handlers = [] 100 101 self.set_border_width(style.DEFAULT_SPACING * 2) 102 self.set_spacing(style.DEFAULT_SPACING) 103 self._group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) 104 105 self._touchpad_label = gtk.HBox(spacing=style.DEFAULT_SPACING) 106 self._touchpad_box = gtk.HBox(spacing=style.DEFAULT_SPACING) 107 self._touchpad_alert_box = gtk.HBox(spacing=style.DEFAULT_SPACING) 108 self._touchpad_alert = None 109 110 self._pickers = { 111 _CAPACITIVE: TouchpadPicker(_CAPACITIVE), 112 _RESISTIVE: TouchpadPicker(_RESISTIVE)} 113 114 self._setup_touchpad() 115 self._initial_value = self._model.get_touchpad() 116 self._update_pickers(self._initial_value) 117 118 self.setup() 119 120 def _setup_touchpad(self): 121 """Layout the panel: label, buttons, alert""" 122 label_touchpad = gtk.Label(_('Click to change your touchpad:')) 123 label_touchpad.modify_fg(gtk.STATE_NORMAL, 124 style.COLOR_SELECTION_GREY.get_gdk_color()) 125 self._group.add_widget(label_touchpad) 126 self._touchpad_label.pack_start(label_touchpad, expand=False) 127 label_touchpad.show() 128 129 for touchpad_mode in sorted(self._pickers.keys()): 130 picker = self._pickers[touchpad_mode] 131 picker.show() 132 self._touchpad_box.pack_start(picker, expand=False) 133 134 label_touchpad_error = gtk.Label() 135 self._group.add_widget(label_touchpad_error) 136 self._touchpad_alert_box.pack_start(label_touchpad_error, expand=False) 137 label_touchpad_error.show() 138 139 self._touchpad_alert = InlineAlert() 140 self._touchpad_alert_box.pack_start(self._touchpad_alert) 141 142 self._center_in_panel = gtk.Alignment(0.5) 143 self._center_in_panel.add(self._touchpad_box) 144 self.pack_start(self._touchpad_label, False) 145 self.pack_start(self._center_in_panel, False) 146 self.pack_start(self._touchpad_alert_box, False) 147 self._touchpad_label.show() 148 self._touchpad_box.show() 149 self._touchpad_alert_box.show() 150 self._center_in_panel.show() 151 152 def setup(self): 153 """Set up the buttons.""" 154 self.needs_restart = False 155 156 def connect(widget, signal, callback): 157 self._handlers.append((widget, widget.connect(signal, callback))) 158 159 for picker in self._pickers.values(): 160 connect(picker, 'touchpad-changed', self.__touchpad_changed_cb) 161 162 def undo(self): 163 """Undo any changes.""" 164 for widget, handler in self._handlers: 165 widget.disconnect(handler) 166 self._model.set_touchpad(self._initial_value) 167 self._touchpad_alert.hide() 168 169 def _update_pickers(self, touchpad): 170 """Update the buttons to reflect selection""" 171 for picker in self._pickers.values(): 172 picker.update(touchpad, self._color) 173 174 def __touchpad_changed_cb(self, touchpadpicker, touchpad): 175 """Callback for mode change -- no restart alert is needed.""" 176 self._model.set_touchpad(touchpad) 177 self._update_pickers(touchpad) 178 return False