@@ -26,12 +26,12 @@ def __init__(self,parent,title,action,currentKeySequences):
2626 self .result = ''
2727 self .keyString = StringVar (self )
2828 self .keyString .set ('' )
29- self .keyCtrl = StringVar ( self )
30- self .keyCtrl . set ( '' )
31- self .keyAlt = StringVar ( self )
32- self . keyAlt . set ( '' )
33- self . keyShift = StringVar ( self )
34- self .keyShift . set ( '' )
29+ self .SetModifiersForPlatform ( )
30+ self .modifier_vars = []
31+ for modifier in self .modifiers :
32+ variable = StringVar ( self )
33+ variable . set ( '' )
34+ self .modifier_vars . append ( variable )
3535 self .CreateWidgets ()
3636 self .LoadFinalKeyList ()
3737 self .withdraw () #hide while setting geometry
@@ -74,18 +74,16 @@ def CreateWidgets(self):
7474 labelKeysBasic = Label (self .frameKeySeqBasic ,justify = LEFT ,
7575 textvariable = self .keyString ,relief = GROOVE ,borderwidth = 2 )
7676 labelKeysBasic .pack (ipadx = 5 ,ipady = 5 ,fill = X )
77- checkCtrl = Checkbutton (self .frameControlsBasic ,
77+ self .modifier_checkbuttons = {}
78+ column = 0
79+ for modifier , variable in zip (self .modifiers , self .modifier_vars ):
80+ label = self .modifier_label .get (modifier , modifier )
81+ check = Checkbutton (self .frameControlsBasic ,
7882 command = self .BuildKeyString ,
79- text = 'Ctrl' ,variable = self .keyCtrl ,onvalue = 'Control' ,offvalue = '' )
80- checkCtrl .grid (row = 0 ,column = 0 ,padx = 2 ,sticky = W )
81- checkAlt = Checkbutton (self .frameControlsBasic ,
82- command = self .BuildKeyString ,
83- text = 'Alt' ,variable = self .keyAlt ,onvalue = 'Alt' ,offvalue = '' )
84- checkAlt .grid (row = 0 ,column = 1 ,padx = 2 ,sticky = W )
85- checkShift = Checkbutton (self .frameControlsBasic ,
86- command = self .BuildKeyString ,
87- text = 'Shift' ,variable = self .keyShift ,onvalue = 'Shift' ,offvalue = '' )
88- checkShift .grid (row = 0 ,column = 3 ,padx = 2 ,sticky = W )
83+ text = label ,variable = variable ,onvalue = modifier ,offvalue = '' )
84+ check .grid (row = 0 ,column = column ,padx = 2 ,sticky = W )
85+ self .modifier_checkbuttons [modifier ] = check
86+ column += 1
8987 labelFnAdvice = Label (self .frameControlsBasic ,justify = LEFT ,
9088 text = "Select the desired modifier\n " +
9189 "keys above, and final key\n " +
@@ -119,6 +117,21 @@ def CreateWidgets(self):
119117 "separated by a space, eg., <Alt-v> <Meta-v>." )
120118 labelHelpAdvanced .grid (row = 0 ,column = 0 ,sticky = NSEW )
121119
120+ def SetModifiersForPlatform (self ):
121+ """Determine list of names of key modifiers for this platform.
122+
123+ The names are used to build Tk bindings -- it doesn't matter if the
124+ keyboard has these keys, it matters if Tk understands them. The
125+ order is also important: key binding equality depends on it, so
126+ config-keys.def must use the same ordering.
127+ """
128+ import sys
129+ if sys .platform == 'darwin' and sys .executable .count ('.app' ):
130+ self .modifiers = ['Shift' , 'Control' , 'Option' , 'Command' ]
131+ else :
132+ self .modifiers = ['Control' , 'Alt' , 'Shift' ]
133+ self .modifier_label = {'Control' : 'Ctrl' }
134+
122135 def ToggleLevel (self ):
123136 if self .buttonLevel .cget ('text' )[:8 ]== 'Advanced' :
124137 self .ClearKeySeq ()
@@ -152,22 +165,15 @@ def BuildKeyString(self):
152165 self .keyString .set (keyStr )
153166
154167 def GetModifiers (self ):
155- modList = []
156- ctrl = self .keyCtrl .get ()
157- alt = self .keyAlt .get ()
158- shift = self .keyShift .get ()
159- if ctrl : modList .append (ctrl )
160- if alt : modList .append (alt )
161- if shift : modList .append (shift )
162- return modList
168+ modList = [variable .get () for variable in self .modifier_vars ]
169+ return filter (None , modList )
163170
164171 def ClearKeySeq (self ):
165172 self .listKeysFinal .select_clear (0 ,END )
166173 self .listKeysFinal .yview (MOVETO , '0.0' )
167- self .keyCtrl .set ('' )
168- self .keyAlt .set ('' ),
169- self .keyShift .set ('' )
170- self .keyString .set ('' )
174+ for variable in self .modifier_vars :
175+ variable .set ('' )
176+ self .keyString .set ('' )
171177
172178 def LoadFinalKeyList (self ):
173179 #these tuples are also available for use in validity checks
0 commit comments