dabo Commit
Revision 3459
Date: 2007-10-12 08:52:23 -0700 (Fri, 12 Oct 2007)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/3459

Changed:
A   trunk/dabo/ui/dialogs/HotKeyEditor.py

Log:
Factored the code for selecting a key combination from the prop sheet into its 
own class so that other code can use it, too.


Diff:
Added: trunk/dabo/ui/dialogs/HotKeyEditor.py
===================================================================
--- trunk/dabo/ui/dialogs/HotKeyEditor.py                               (rev 0)
+++ trunk/dabo/ui/dialogs/HotKeyEditor.py       2007-10-12 15:52:23 UTC (rev 
3459)
@@ -0,0 +1,117 @@
+# -*- coding: utf-8 -*-
+import dabo
+import dabo.dEvents as dEvents
+from dabo.ui import dKeys as dKeys
+if __name__ == "__main__":
+       dabo.ui.loadUI("wx")
+from dabo.dLocalize import _
+
+
+class HotKeyEditor(dabo.ui.dOkCancelDialog):
+       def addControls(self):
+               self.Caption = _("HotKey Editor")
+               self._alt = False
+               self._changed = None
+               self._ctrl = False
+               self._keyChar = ""
+               self._keyCode = -1
+               self._keyText = ""
+               self._shift = False
+               self._originalKeyString = None
+
+               sz = self.Sizer
+               sz.append(dabo.ui.dLabel(self, Caption=_("Press the desired key 
combination")),
+                               border=10, halign="center")
+               sz.appendSpacer(10)
+               bsz = dabo.ui.dBorderSizer(self, "v")
+               self.hkLabel = dabo.ui.dLabel(self, Caption=" "*80, 
FontSize=16, FontBold=True)
+               bsz.append1x(self.hkLabel, halign="center", border=10)
+               sz.append(bsz, halign="center")
+               # Pass key events from the OK/Cancel buttons up to the form
+               self.CancelButton.bindEvent(dEvents.KeyUp, self.onKeyUp)
+               self.OKButton.bindEvent(dEvents.KeyUp, self.onKeyUp)
+
+
+       def setKey(self, key):
+               self._originalKeyString = self._keyText = self.hkLabel.Caption 
= key
+
+
+       def onKeyUp(self, evt):
+               self._keyCode = kcd = evt.keyCode
+               if kcd in (306, 307, 308, 396, 400):
+                       # Just the modifier keys being released
+                       return
+               if kcd in (dKeys.key_Tab, dKeys.key_Left, dKeys.key_Right,
+                                       dKeys.key_Up, dKeys.key_Down, 
dKeys.key_Return):
+                       # Navigation keys; ignore
+                       return
+               self._keyChar = kcr = evt.keyChar
+               if 340 <= kcd <= 354:
+                       # Function keys
+                       self._keyChar = kcr = "F%s" % ((kcd-339), )
+               self._ctrl = dabo.ui.isControlDown() or dabo.ui.isCommandDown()
+               self._shift = dabo.ui.isShiftDown()
+               self._alt = dabo.ui.isAltDown()
+               if kcr is not None:
+                       ctlTxt = {True: "Ctrl+", False: ""}[self._ctrl]
+                       shiftTxt = {True: "Shift+", False: ""}[self._shift]
+                       altTxt = {True: "Alt+", False: ""}[self._alt]
+                       self._keyText = ctlTxt + altTxt + shiftTxt + kcr.upper()
+               else:
+                       self._keyText = ""
+                       self._keyChar = ""
+               self.hkLabel.Caption = self._keyText
+               self.layout()
+
+
+       # Property definitions start here
+       def _getAlt(self):
+               return self._alt
+
+
+       def _getChanged(self):
+               orig = self._originalKeyString
+               return orig is not None and (orig != self._keyText)
+
+
+       def _getCtrl(self):
+               return self._ctrl
+
+
+       def _getKeyChar(self):
+               return self._keyChar
+
+
+       def _getKeyCode(self):
+               return self._keyCode
+
+
+       def _getKeyText(self):
+               return self._keyText
+
+
+       def _getShift(self):
+               return self._shift
+
+
+       Alt = property(_getAlt, None, None,
+                       _("Reflects the presence of the Alt key in the selected 
key combo. Default=False.  (bool)"))
+       
+       Changed = property(_getChanged, None, None,
+                       _("Returns True only if the current key is different 
than the starting value. (read-only) (bool)"))
+       
+       Ctrl = property(_getCtrl, None, None,
+                       _("Reflects the presence of the Ctrl key in the 
selected key combo. Default=False. (read-only) (bool)"))
+       
+       KeyChar = property(_getKeyChar, None, None,
+                       _("The non-modifier key in the selected key combo. 
Default="". (read-only) (str)"))
+
+       KeyCode = property(_getKeyCode, None, None,
+                       _("Underlying key code of the key/modifier combo. 
Default=-1 (read-only) (int)"))
+       
+       KeyText = property(_getKeyText, None, None,
+                       _("The displayed text for the key/modifier combo. 
Default="" (read-only) (str)"))
+       
+       Shift = property(_getShift, None, None,
+                       _("Reflects the presence of the Alt key in the selected 
key combo. Default=False. (read-only) (bool)"))
+       


Property changes on: trunk/dabo/ui/dialogs/HotKeyEditor.py
___________________________________________________________________
Name: svn:eol-style
   + native




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/dabo-dev/[EMAIL PROTECTED]

Reply via email to