Changeset 167:db7becb14f9e for src/mlx/gui
- Timestamp:
- 05/11/12 17:27:04 (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/gui/prefs.py
r166 r167 15 15 class Hotkey(gtk.HBox): 16 16 """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 17 27 def __init__(self, labelText, tooltips): 18 28 """Construct the hotkey widget. … … 35 45 self._ctrl = gtk.CheckButton("Ctrl") 36 46 self._ctrl.set_tooltip_text(tooltips[1]) 47 self._ctrl.connect("toggled", self._ctrlToggled) 37 48 self.pack_start(self._ctrl, False, False, 4) 38 49 39 50 self._shift = gtk.CheckButton("Shift") 40 51 self._shift.set_tooltip_text(tooltips[2]) 52 self._shift.connect("toggled", self._shiftToggled) 41 53 self.pack_start(self._shift, False, False, 4) 42 54 … … 50 62 self._hotkey.add_attribute(cell, 'text', 0) 51 63 self._hotkey.set_tooltip_text(tooltips[0]) 64 self._hotkey.connect("changed", self._keyChanged) 52 65 self.pack_start(self._hotkey, False, False, 4) 53 66 54 67 self._setting = False 55 68 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.""" 58 77 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 62 102 63 103 hotkeyModel = self._hotkeyModel 64 104 iter = hotkeyModel.get_iter_first() 65 105 while iter is not None and \ 66 hotkeyModel.get_value(iter, 0)!= hotkey.key:106 hotkeyModel.get_value(iter, 0)!=key: 67 107 iter = hotkeyModel.iter_next(iter) 68 108 … … 71 111 72 112 self._hotkey.set_active_iter(iter) 73 113 74 114 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 75 121 76 122 def get(self): … … 79 125 key = self._hotkeyModel.get_value(self._hotkey.get_active_iter(), 0) 80 126 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 152 gobject.signal_new("hotkey-changed", Hotkey, gobject.SIGNAL_RUN_FIRST, 153 None, (int,)) 84 154 85 155 #------------------------------------------------------------------------------ … … 512 582 self._enableChecklistsToggled(self._enableChecklists) 513 583 584 self._pilotHotkey.connect("hotkey-changed", self._reconcileHotkeys, 585 self._checklistHotkey) 586 self._checklistHotkey.connect("hotkey-changed", self._reconcileHotkeys, 587 self._pilotHotkey) 588 514 589 return mainAlignment 515 590 … … 519 594 self._pilotControlsSounds.set_sensitive(active) 520 595 self._pilotHotkey.set_sensitive(active) 596 if active and self._checklistHotkey.get_sensitive(): 597 self._reconcileHotkeys(self._checklistHotkey, Hotkey.CHANGED_SHIFT, 598 self._pilotHotkey) 521 599 #self._approachCallOuts.set_sensitive(active) 522 600 self._speedbrakeAtTD.set_sensitive(active) … … 526 604 active = button.get_active() 527 605 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 528 629 529 630 def _buildAdvanced(self): … … 588 689 """Called when the update URL is changed.""" 589 690 self._setOKButtonSensitivity() 691
Note:
See TracChangeset
for help on using the changeset viewer.