Changeset 167:db7becb14f9e


Ignore:
Timestamp:
05/11/12 17:27:04 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Added code to reconcile the hotkeys if they are equal

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/gui/prefs.py

    r166 r167  
    1515class Hotkey(gtk.HBox):
    1616    """A widget to handle a hotkey."""
     17
     18    # Constant to denote that the status of the Ctrl modifier is changed
     19    CHANGED_CTRL = 1
     20   
     21    # Constant to denote that the status of the Shift modifier is changed
     22    CHANGED_SHIFT = 2
     23   
     24    # Constant to denote that the value of the key is changed
     25    CHANGED_KEY = 3
     26   
    1727    def __init__(self, labelText, tooltips):
    1828        """Construct the hotkey widget.
     
    3545        self._ctrl = gtk.CheckButton("Ctrl")
    3646        self._ctrl.set_tooltip_text(tooltips[1])
     47        self._ctrl.connect("toggled", self._ctrlToggled)
    3748        self.pack_start(self._ctrl, False, False, 4)
    3849           
    3950        self._shift = gtk.CheckButton("Shift")
    4051        self._shift.set_tooltip_text(tooltips[2])
     52        self._shift.connect("toggled", self._shiftToggled)
    4153        self.pack_start(self._shift, False, False, 4)
    4254
     
    5062        self._hotkey.add_attribute(cell, 'text', 0)
    5163        self._hotkey.set_tooltip_text(tooltips[0])
     64        self._hotkey.connect("changed", self._keyChanged)
    5265        self.pack_start(self._hotkey, False, False, 4)
    5366
    5467        self._setting = False
    5568
    56     def set(self, hotkey):
    57         """Set the hotkey widget from the given hotkey."""
     69    @property
     70    def ctrl(self):
     71        """Get whether the Ctrl modifier is selected."""
     72        return self._ctrl.get_active()
     73
     74    @ctrl.setter
     75    def ctrl(self, ctrl):
     76        """Get whether the Ctrl modifier is selected."""
    5877        self._setting = True
    59 
    60         self._ctrl.set_active(hotkey.ctrl)
    61         self._shift.set_active(hotkey.shift)
     78        self._ctrl.set_active(ctrl)
     79        self._setting = False
     80
     81    @property
     82    def shift(self):
     83        """Get whether the Shift modifier is selected."""
     84        return self._shift.get_active()
     85
     86    @shift.setter
     87    def shift(self, shift):
     88        """Get whether the Shift modifier is selected."""
     89        self._setting = True
     90        self._shift.set_active(shift)
     91        self._setting = False
     92
     93    @property
     94    def key(self):
     95        """Get the value of the key."""
     96        return self._hotkeyModel.get_value(self._hotkey.get_active_iter(), 0)
     97
     98    @key.setter
     99    def key(self, key):
     100        """Set the value of the key."""
     101        self._setting = True
    62102
    63103        hotkeyModel = self._hotkeyModel
    64104        iter = hotkeyModel.get_iter_first()
    65105        while iter is not None and \
    66               hotkeyModel.get_value(iter, 0)!=hotkey.key:
     106              hotkeyModel.get_value(iter, 0)!=key:
    67107            iter = hotkeyModel.iter_next(iter)
    68108
     
    71111
    72112        self._hotkey.set_active_iter(iter)           
    73        
     113
    74114        self._setting = False
     115
     116    def set(self, hotkey):
     117        """Set the hotkey widget from the given hotkey."""
     118        self.ctrl = hotkey.ctrl
     119        self.shift = hotkey.shift
     120        self.key = hotkey.key
    75121
    76122    def get(self):
     
    79125        key = self._hotkeyModel.get_value(self._hotkey.get_active_iter(), 0)
    80126
    81         return config.Hotkey(ctrl = self._ctrl.get_active(),
    82                              shift = self._shift.get_active(),
    83                              key = key)
     127        return config.Hotkey(ctrl = self.ctrl, shift = self.shift,
     128                             key = self.key)
     129
     130    def _ctrlToggled(self, checkButton):
     131        """Called when the status of the Ctrl modifier has changed."""
     132        if not self._setting:
     133            self.emit("hotkey-changed", Hotkey.CHANGED_CTRL)
     134
     135    def _shiftToggled(self, checkButton):
     136        """Called when the status of the Shift modifier has changed."""
     137        if not self._setting:
     138            self.emit("hotkey-changed", Hotkey.CHANGED_SHIFT)
     139
     140    def _keyChanged(self, comboBox):
     141        """Called when the value of the key has changed."""
     142        if not self._setting:
     143            self.emit("hotkey-changed", Hotkey.CHANGED_KEY)
     144
     145    def __eq__(self, other):
     146        """Determine if the two hotkeys are equal."""
     147        return self.ctrl==other.ctrl and self.shift==other.shift and \
     148               self.key==other.key
     149
     150#------------------------------------------------------------------------------
     151
     152gobject.signal_new("hotkey-changed", Hotkey, gobject.SIGNAL_RUN_FIRST,
     153                   None, (int,))
    84154
    85155#------------------------------------------------------------------------------
     
    512582        self._enableChecklistsToggled(self._enableChecklists)
    513583
     584        self._pilotHotkey.connect("hotkey-changed", self._reconcileHotkeys,
     585                                  self._checklistHotkey)
     586        self._checklistHotkey.connect("hotkey-changed", self._reconcileHotkeys,
     587                                      self._pilotHotkey)
     588
    514589        return mainAlignment
    515590
     
    519594        self._pilotControlsSounds.set_sensitive(active)
    520595        self._pilotHotkey.set_sensitive(active)
     596        if active and self._checklistHotkey.get_sensitive():
     597            self._reconcileHotkeys(self._checklistHotkey, Hotkey.CHANGED_SHIFT,
     598                                   self._pilotHotkey)
    521599        #self._approachCallOuts.set_sensitive(active)
    522600        self._speedbrakeAtTD.set_sensitive(active)
     
    526604        active = button.get_active()
    527605        self._checklistHotkey.set_sensitive(active)
     606        if active and self._pilotHotkey.get_sensitive():
     607            self._reconcileHotkeys(self._pilotHotkey, Hotkey.CHANGED_SHIFT,
     608                                   self._checklistHotkey)
     609
     610    def _reconcileHotkeys(self, changedHotkey, what, otherHotkey):
     611        """Reconcile the given hotkeys so that they are different.
     612
     613        changedHotkey is the hotkey that has changed. what is one of the
     614        Hotkey.CHANGED_XXX constants denoting what has changed. otherHotkey is
     615        the other hotkey that must be reconciled.
     616
     617        If the other hotkey is not sensitive or is not equal to the changed
     618        one, nothing happens.
     619
     620        Otherwise, if the status of the Ctrl modifier has changed, the status
     621        of the Ctrl modifier on the other hotkey will be negated. Similarly, if
     622        the Shift modifier has changed. If the key has changed, the Shift
     623        modifier is negated in the other hotkey."""
     624        if otherHotkey.get_sensitive() and changedHotkey==otherHotkey:
     625            if what==Hotkey.CHANGED_CTRL:
     626                otherHotkey.ctrl = not changedHotkey.ctrl
     627            elif what==Hotkey.CHANGED_SHIFT or what==Hotkey.CHANGED_KEY:
     628                otherHotkey.shift = not changedHotkey.shift
    528629
    529630    def _buildAdvanced(self):
     
    588689        """Called when the update URL is changed."""
    589690        self._setOKButtonSensitivity()
     691
Note: See TracChangeset for help on using the changeset viewer.