Ticket #2006: 0001-code-cleanup-as-per-Sascha-s-feedback.patch

File 0001-code-cleanup-as-per-Sascha-s-feedback.patch, 7.9 KB (added by walter, 14 years ago)
  • extensions/cpsection/touchpad/model.py

    From 34e9431889ab0ead43abec2732fd14b972ce71ae Mon Sep 17 00:00:00 2001
    From: Walter Bender <walter@sugarlabs.org>
    Date: Wed, 26 May 2010 19:36:27 -0400
    Subject: [PATCH] code cleanup as per Sascha's feedback
    
    ---
     extensions/cpsection/touchpad/model.py |   18 ++------
     extensions/cpsection/touchpad/view.py  |   75 ++++++++++++--------------------
     2 files changed, 33 insertions(+), 60 deletions(-)
    
    diff --git a/extensions/cpsection/touchpad/model.py b/extensions/cpsection/touchpad/model.py
    index 4e29651..b02b2cc 100644
    a b from gettext import gettext as _ 
    1818from os import system, path, remove
    1919import gconf
    2020
    21 _CAPACITIVE = 0
    22 _RESISTIVE = 1
    2321_flag_path = '/home/olpc/.olpc-pentablet-mode'
    2422_node_path = '/sys/devices/platform/i8042/serio1/ptmode'
    2523
    def get_touchpad(): 
    3129    _file_handle.close()
    3230
    3331    if _text[0] == '1':
    34         return _RESISTIVE
     32        return 'resistive'
    3533    else:
    36         return _CAPACITIVE
     34        return 'capacitive'
    3735
    3836def set_touchpad(touchpad):
    3937    """Set the touchpad mode."""
    40     if touchpad == _CAPACITIVE:
     38    if touchpad == 'capacitive':
    4139        if path.exists(_flag_path):
    4240            remove(_flag_path)
    4341        system("echo 0 > %s" % (_node_path))
    4442    else:
    45         system("touch %s" % (_flag_path))
     43        _file_handle = open(_flag_path, "w")
     44        _file_handle.close()
    4645        system("echo 1 > %s" % (_node_path))
    4746    return
    4847
    49 def print_touchpad():
    50     """Print the future touchpad mode."""
    51     if get_touchpad == _CAPACITIVE:
    52         print _('Touchpad set to finger mode.')
    53     else:
    54         print _('Touchpad set to stylus mode.')
    55 
    5648def get_color_xo():
    5749    """Get xo color"""
    5850    client = gconf.client_get_default()
  • extensions/cpsection/touchpad/view.py

    diff --git a/extensions/cpsection/touchpad/view.py b/extensions/cpsection/touchpad/view.py
    index 19fb686..7339a43 100644
    a b from sugar.graphics import style 
    2424from sugar.graphics.xocolor import XoColor
    2525
    2626from jarabe.controlpanel.sectionview import SectionView
    27 from jarabe.controlpanel.inlinealert import InlineAlert
    28 
    29 _CAPACITIVE = 0
    30 _RESISTIVE = 1
    3127
    3228class TouchpadEventIcon(gtk.EventBox):
    33     """A subclass of the Sugar Event Icon"""
     29    """Clickable icon used for capacitive and resistive buttons""" 
    3430    __gtype_name__ = "SugarEventIcon"
    3531
    3632    def __init__(self, **kwargs):
    class TouchpadEventIcon(gtk.EventBox): 
    4642        self.add(self.icon)
    4743        self.icon.show()
    4844
    49 class TouchpadPicker(TouchpadEventIcon):
    50     """A class for the touchpad selection buttons"""
     45class _TouchpadPicker(TouchpadEventIcon):
     46    """The touchpad selection buttons"""
    5147    __gsignals__ = {
    5248        'touchpad-changed': (gobject.SIGNAL_RUN_FIRST,
    5349                          gobject.TYPE_NONE,
    class TouchpadPicker(TouchpadEventIcon): 
    5854        """Create icons for the touchpad mode buttons."""   
    5955        TouchpadEventIcon.__init__(self)
    6056
    61         if touchpad_mode == _CAPACITIVE:
     57        if touchpad_mode == 'capacitive':
    6258            self.icon.props.icon_name = 'capacitive'
    6359        else:
    6460            self.icon.props.icon_name = 'resistive'
    class TouchpadPicker(TouchpadEventIcon): 
    7066
    7167    def update(self, touchpad, xo_color):
    7268        """Update the button states."""
    73         if self._touchpad_mode == _CAPACITIVE:
     69        if self._touchpad_mode == 'capacitive':
    7470            self.icon.props.icon_name = 'capacitive'
    75             if touchpad == _CAPACITIVE:
     71            if touchpad == 'capacitive':
    7672                self.icon.props.xo_color = xo_color
    7773            else:
    7874                self.icon.props.xo_color = XoColor('#666666,#FFFFFF')
    79         elif self._touchpad_mode == _RESISTIVE:
     75        elif self._touchpad_mode == 'resistive':
    8076            self.icon.props.icon_name = 'resistive'
    81             if touchpad == _RESISTIVE:
     77            if touchpad == 'resistive':
    8278                self.icon.props.xo_color = xo_color
    8379            else:
    8480                self.icon.props.xo_color = XoColor('#666666,#FFFFFF')
    class TouchpadPicker(TouchpadEventIcon): 
    8884        self.emit('touchpad-changed', touchpad_mode)
    8985
    9086class Touchpad(SectionView):
    91     """A class for the touchpad selection panel"""
     87    """The touchpad selection panel"""
    9288
    9389    def __init__(self, model, alerts):
    94         """ Create the touchpad panel."""
     90        """ Create the touchpad selection panel."""
    9591        SectionView.__init__(self)
    9692
    9793        self._model = model
    class Touchpad(SectionView): 
    10298        self.set_spacing(style.DEFAULT_SPACING)
    10399        self._group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
    104100
    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
     101        self._label_box = gtk.HBox(spacing=style.DEFAULT_SPACING)
     102        self._box = gtk.HBox(spacing=style.DEFAULT_SPACING)
    109103
    110104        self._pickers = {
    111                 _CAPACITIVE: TouchpadPicker(_CAPACITIVE),
    112                 _RESISTIVE: TouchpadPicker(_RESISTIVE)}
     105                'capacitive': _TouchpadPicker('capacitive'),
     106                'resistive': _TouchpadPicker('resistive')}
    113107
    114         self._setup_touchpad()
     108        self._setup_widgets()
    115109        self._initial_value = self._model.get_touchpad()
    116110        self._update_pickers(self._initial_value)
    117111
    118112        self.setup()
    119113
    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,
     114    def _setup_widgets(self):               
     115        """Layout the panel: label, buttons"""
     116        label = gtk.Label(_('Click to change your touchpad:'))
     117        label.modify_fg(gtk.STATE_NORMAL,
    124118                              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()
     119        self._group.add_widget(label)
     120        self._label_box.pack_start(label, expand=False)
     121        label.show()
    128122
    129123        for touchpad_mode in sorted(self._pickers.keys()):
    130124            picker = self._pickers[touchpad_mode]
    131125            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)
     126            self._box.pack_start(picker, expand=False)
    141127
    142128        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()
     129        self._center_in_panel.add(self._box)
     130        self.pack_start(self._label_box, False)
     131        self.pack_start(self._center_in_panel, False)     
     132        self._label_box.show()
     133        self._box.show()
    150134        self._center_in_panel.show()
    151135   
    152136    def setup(self):
    class Touchpad(SectionView): 
    161145
    162146    def undo(self):
    163147        """Undo any changes."""
    164         for widget, handler in self._handlers:
    165             widget.disconnect(handler)
    166148        self._model.set_touchpad(self._initial_value)
    167         self._touchpad_alert.hide()       
    168149
    169150    def _update_pickers(self, touchpad):
    170151        """Update the buttons to reflect selection"""