dabo Commit
Revision 6163
Date: 2010-10-25 05:36:20 -0700 (Mon, 25 Oct 2010)
Author: Ed
Trac: http://trac.dabodev.com/changeset/6163
Changed:
U trunk/dabo/ui/uiwx/dKeys.py
U trunk/dabo/ui/uiwx/dPemMixin.py
Log:
Refactored out the code that translates key combination strings like
"Ctrl+Shift+R" into the modifiers and keys from dPemMixin and into dKeys.
Also fixed a docstring error in the BorderStyle property.
Diff:
Modified: trunk/dabo/ui/uiwx/dKeys.py
===================================================================
--- trunk/dabo/ui/uiwx/dKeys.py 2010-10-24 23:53:02 UTC (rev 6162)
+++ trunk/dabo/ui/uiwx/dKeys.py 2010-10-25 12:36:20 UTC (rev 6163)
@@ -242,3 +242,31 @@
"numpad_decimal": key_Numpad_decimal,
"numpad_divide": key_Numpad_divide,
}
+
+
+def resolveKeyCombo(keyCombo, returnFlags=False):
+ """When returnFlags is False (default), this takes a string
representation
+ of keys and modifiers, and returns a 2-tuple, containing the modifier(s)
+ as the first element, and the key as the second.
+
+ If returnFlags is True, a 3-tuple is returned, with the first two
elements the
+ same as above, but with a thrid element that is a numeric value
compatible with
+ what wxPython expects.
+ """
+ if keyCombo.endswith("+"):
+ # Strip off the trailing two characters
+ keys = keyCombo[:-2].split("+")
+ keys.append("+")
+ else:
+ keys = keyCombo.split("+")
+ # The modifier keys, if any, comprise all but the last key in keys
+ mods = [k.lower() for k in keys[:-1]]
+ key = keys[-1]
+ if returnFlags:
+ # Convert the string mods and key into the correct parms for wx:
+ flags = mod_Normal
+ for mod in mods:
+ flags = flags | modifierStrings[mod.lower()]
+ return (mods, key, flags)
+ else:
+ return (mods, key)
Modified: trunk/dabo/ui/uiwx/dPemMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dPemMixin.py 2010-10-24 23:53:02 UTC (rev 6162)
+++ trunk/dabo/ui/uiwx/dPemMixin.py 2010-10-25 12:36:20 UTC (rev 6163)
@@ -735,20 +735,8 @@
# When user presses <ctrl><alt><w>, close the form:
form.bindKey("ctrl+alt+w", form.Close)
"""
- if keyCombo == "+":
- keys = [keyCombo]
- else:
- keys = keyCombo.split("+")
- # The modifier keys, if any, comprise all but the last key in
keys
- mods = keys[:-1]
- key = keys[-1]
+ mods, key, flags = dabo.ui.dKeys.resolveKeyCombo(keyCombo, True)
upMods = [mm.upper() for mm in mods]
-
- # Convert the string mods and key into the correct parms for wx:
- flags = dKeys.mod_Normal
- for mod in mods:
- flags = flags | dKeys.modifierStrings[mod.lower()]
-
try:
keyCode = dKeys.keyStrings[key.lower()]
except KeyError:
@@ -2678,7 +2666,7 @@
"""))
BorderStyle = property(_getBorderStyle, _setBorderStyle, None,
- _("""Specifies the type of border for this window.
(int).
+ _("""Specifies the type of border for this window.
(str).
Possible choices are:
"None"
_______________________________________________
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/[email protected]