Ticket #2006: 0001-adding-touchpad-section-to-CP.patch
File 0001-adding-touchpad-section-to-CP.patch, 14.3 KB (added by walter, 13 years ago) |
---|
-
data/icons/Makefile.am
From 96d9a22d2f6d85956a64cfe4c6b92cc3836d7105 Mon Sep 17 00:00:00 2001 From: Walter Bender <walter@sugarlabs.org> Date: Tue, 18 May 2010 15:48:04 -0400 Subject: [PATCH] adding touchpad section to CP --- 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 | 24 ++++ extensions/cpsection/touchpad/model.py | 44 +++++++ extensions/cpsection/touchpad/view.py | 185 +++++++++++++++++++++++++++++ 7 files changed, 297 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/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..b06e550
- + 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 if path.exists('/sys/devices/platform/i8042/serio1/ptmode'): 21 CLASS = 'Touchpad' 22 ICON = 'module-touchpad' 23 TITLE = _('Touchpad') 24 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..5036211
- + 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 20 _CAPACITIVE = 0 21 _RESISTIVE = 1 22 23 def get_touchpad(): 24 """Get the touchpad mode.""" 25 if path.exists('/home/olpc/.olpc-pentablet-mode'): 26 return _RESISTIVE 27 else: 28 return _CAPACITIVE 29 30 def set_touchpad(touchpad): 31 """Set the touchpad mode.""" 32 if touchpad == _CAPACITIVE: 33 system("rm /home/olpc/.olpc-pentablet-mode") 34 else: 35 system("touch /home/olpc/.olpc-pentablet-mode") 36 return 1 37 38 def print_touchpad(): 39 """Print the future touchpad mode.""" 40 if get_touchpad == _CAPACITIVE: 41 print _('Touchpad will be set to finger mode on next reboot.') 42 else: 43 print _('Touchpad will be set to stylus mode on next reboot.') 44 -
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..7b5c3b4
- + 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 25 from jarabe.controlpanel.sectionview import SectionView 26 from jarabe.controlpanel.inlinealert import InlineAlert 27 28 _CAPACITIVE = 0 29 _RESISTIVE = 1 30 31 class TouchpadEventIcon(gtk.EventBox): 32 """A subclass of the Sugar Event Icon""" 33 __gtype_name__ = "SugarEventIcon" 34 35 def __init__(self, **kwargs): 36 """Create an extra-large, clickable icon.""" 37 gtk.EventBox.__init__(self) 38 39 self.icon = Icon(pixel_size = style.XLARGE_ICON_SIZE, **kwargs) 40 41 self.set_visible_window(False) 42 self.set_app_paintable(True) 43 self.set_events(gtk.gdk.BUTTON_PRESS_MASK) 44 45 self.add(self.icon) 46 self.icon.show() 47 48 class TouchpadPicker(TouchpadEventIcon): 49 """A class for the touchpad selection buttons""" 50 __gsignals__ = { 51 'touchpad-changed': (gobject.SIGNAL_RUN_FIRST, 52 gobject.TYPE_NONE, 53 ([object])) 54 } 55 56 def __init__(self, touchpad_mode): 57 """Create icons for the touchpad mode buttons.""" 58 TouchpadEventIcon.__init__(self) 59 60 if touchpad_mode == _CAPACITIVE: 61 self.icon.props.icon_name = 'capacitive-off' 62 else: 63 self.icon.props.icon_name = 'resistive-off' 64 self._touchpad_mode = touchpad_mode 65 66 self.icon.props.pixel_size = style.XLARGE_ICON_SIZE 67 68 self.connect('button_press_event', self.__pressed_cb, touchpad_mode) 69 70 def update(self, touchpad): 71 """Update the button states.""" 72 if self._touchpad_mode == _CAPACITIVE: 73 if touchpad == _CAPACITIVE: 74 self.icon.props.icon_name = 'capacitive-on' 75 else: 76 self.icon.props.icon_name = 'capacitive-off' 77 elif self._touchpad_mode == _RESISTIVE: 78 if touchpad == _RESISTIVE: 79 self.icon.props.icon_name = 'resistive-on' 80 else: 81 self.icon.props.icon_name = 'resistive-off' 82 83 def __pressed_cb(self, button, event, touchpad_mode): 84 """Callback for button click.""" 85 self.emit('touchpad-changed', touchpad_mode) 86 87 class Touchpad(SectionView): 88 """A class for the touchpad selection panel""" 89 90 def __init__(self, model, alerts): 91 """ Create the touchpad panel.""" 92 SectionView.__init__(self) 93 94 self._model = model 95 self.restart_alerts = alerts 96 self._handlers = [] 97 98 self.set_border_width(style.DEFAULT_SPACING * 2) 99 self.set_spacing(style.DEFAULT_SPACING) 100 self._group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) 101 102 self._touchpad_label = gtk.HBox(spacing=style.DEFAULT_SPACING) 103 self._touchpad_box = gtk.HBox(spacing=style.DEFAULT_SPACING) 104 self._touchpad_alert_box = gtk.HBox(spacing=style.DEFAULT_SPACING) 105 self._touchpad_alert = None 106 107 self._pickers = { 108 _CAPACITIVE: TouchpadPicker(_CAPACITIVE), 109 _RESISTIVE: TouchpadPicker(_RESISTIVE)} 110 111 self._setup_touchpad() 112 initial_touchpad = self._model.get_touchpad() 113 self._update_pickers(initial_touchpad) 114 115 self.setup() 116 117 def _setup_touchpad(self): 118 """Layout the panel: label, buttons, alert""" 119 label_touchpad = gtk.Label(_('Click to change your touchpad:')) 120 label_touchpad.modify_fg(gtk.STATE_NORMAL, 121 style.COLOR_SELECTION_GREY.get_gdk_color()) 122 self._group.add_widget(label_touchpad) 123 self._touchpad_label.pack_start(label_touchpad, expand=False) 124 label_touchpad.show() 125 126 for touchpad_mode in sorted(self._pickers.keys()): 127 picker = self._pickers[touchpad_mode] 128 picker.show() 129 self._touchpad_box.pack_start(picker, expand=False) 130 131 label_touchpad_error = gtk.Label() 132 self._group.add_widget(label_touchpad_error) 133 self._touchpad_alert_box.pack_start(label_touchpad_error, expand=False) 134 label_touchpad_error.show() 135 136 self._touchpad_alert = InlineAlert() 137 self._touchpad_alert_box.pack_start(self._touchpad_alert) 138 if 'color' in self.restart_alerts: 139 self._touchpad_alert.props.msg = self.restart_msg 140 self._touchpad_alert.show() 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.undo() 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) 173 174 def __touchpad_changed_cb(self, touchpadpicker, touchpad): 175 """Callback for mode change.""" 176 self._model.set_touchpad(touchpad) 177 self.needs_restart = True 178 self._touchpad_alert.props.msg = self.restart_msg 179 self.restart_alerts.append('touchpad') 180 181 self._touchpad_alert.show() 182 183 self._update_pickers(touchpad) 184 185 return False