[Idle-dev] CVS: idle keybindingDialog.py,1.8,1.9

Tony Lownds tonylownds@users.sourceforge.net
Sat, 28 Sep 2002 17:23:11 -0700


Update of /cvsroot/idlefork/idle
In directory usw-pr-cvs1:/tmp/cvs-serv812

Modified Files:
	keybindingDialog.py 
Log Message:
Mac users now see correct modifiers in the Key Binding Entry window.

Index: keybindingDialog.py
===================================================================
RCS file: /cvsroot/idlefork/idle/keybindingDialog.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** keybindingDialog.py	6 Jun 2002 00:44:16 -0000	1.8
--- keybindingDialog.py	29 Sep 2002 00:23:08 -0000	1.9
***************
*** 27,36 ****
          self.keyString=StringVar(self)
          self.keyString.set('')
!         self.keyCtrl=StringVar(self)
!         self.keyCtrl.set('')
!         self.keyAlt=StringVar(self)
!         self.keyAlt.set('')
!         self.keyShift=StringVar(self)
!         self.keyShift.set('')
          self.CreateWidgets()
          self.LoadFinalKeyList()
--- 27,36 ----
          self.keyString=StringVar(self)
          self.keyString.set('')
!         self.SetModifiersForPlatform()
!         self.modifier_vars = []
!         for modifier in self.modifiers:
!             variable = StringVar(self)
!             variable.set('')
!             self.modifier_vars.append(variable)
          self.CreateWidgets()
          self.LoadFinalKeyList()
***************
*** 75,90 ****
                  textvariable=self.keyString,relief=GROOVE,borderwidth=2)
          labelKeysBasic.pack(ipadx=5,ipady=5,fill=X)
!         checkCtrl=Checkbutton(self.frameControlsBasic,
                  command=self.BuildKeyString,
!                 text='Ctrl',variable=self.keyCtrl,onvalue='Control',offvalue='')
!         checkCtrl.grid(row=0,column=0,padx=2,sticky=W)
!         checkAlt=Checkbutton(self.frameControlsBasic,
!                 command=self.BuildKeyString,
!                 text='Alt',variable=self.keyAlt,onvalue='Alt',offvalue='')
!         checkAlt.grid(row=0,column=1,padx=2,sticky=W)
!         checkShift=Checkbutton(self.frameControlsBasic,
!                 command=self.BuildKeyString,
!                 text='Shift',variable=self.keyShift,onvalue='Shift',offvalue='')
!         checkShift.grid(row=0,column=3,padx=2,sticky=W)
          labelFnAdvice=Label(self.frameControlsBasic,justify=LEFT,
                  text="Select the desired modifier\n"+
--- 75,88 ----
                  textvariable=self.keyString,relief=GROOVE,borderwidth=2)
          labelKeysBasic.pack(ipadx=5,ipady=5,fill=X)
!         self.modifier_checkbuttons = {}
!         column = 0
!         for modifier, variable in zip(self.modifiers, self.modifier_vars):
!             label = self.modifier_label.get(modifier, modifier)
!             check=Checkbutton(self.frameControlsBasic,
                  command=self.BuildKeyString,
!                 text=label,variable=variable,onvalue=modifier,offvalue='')
!             check.grid(row=0,column=column,padx=2,sticky=W)
!             self.modifier_checkbuttons[modifier] = check
!             column += 1
          labelFnAdvice=Label(self.frameControlsBasic,justify=LEFT,
                  text="Select the desired modifier\n"+
***************
*** 120,123 ****
--- 118,136 ----
          labelHelpAdvanced.grid(row=0,column=0,sticky=NSEW)
  
+     def SetModifiersForPlatform(self):
+         """Determine list of names of key modifiers for this platform.
+ 
+         The names are used to build Tk bindings -- it doesn't matter if the
+         keyboard has these keys, it matters if Tk understands them. The
+         order is also important: key binding equality depends on it, so
+         config-keys.def must use the same ordering.
+         """
+         import sys
+         if sys.platform == 'darwin' and sys.executable.count('.app'):
+             self.modifiers = ['Shift', 'Control', 'Option', 'Command']
+         else:
+             self.modifiers = ['Control', 'Alt', 'Shift']
+         self.modifier_label = {'Control': 'Ctrl'}
+ 
      def ToggleLevel(self):
          if  self.buttonLevel.cget('text')[:8]=='Advanced':
***************
*** 153,172 ****
          
      def GetModifiers(self):
!         modList=[]
!         ctrl=self.keyCtrl.get()
!         alt=self.keyAlt.get()
!         shift=self.keyShift.get()
!         if ctrl: modList.append(ctrl)
!         if alt: modList.append(alt)
!         if shift: modList.append(shift)
!         return modList
  
      def ClearKeySeq(self):
          self.listKeysFinal.select_clear(0,END)
          self.listKeysFinal.yview(MOVETO, '0.0')
!         self.keyCtrl.set('')
!         self.keyAlt.set(''),
!         self.keyShift.set('')
!         self.keyString.set('')    
      
      def LoadFinalKeyList(self):
--- 166,178 ----
          
      def GetModifiers(self):
!         modList = [variable.get() for variable in self.modifier_vars]
!         return filter(None, modList)
  
      def ClearKeySeq(self):
          self.listKeysFinal.select_clear(0,END)
          self.listKeysFinal.yview(MOVETO, '0.0')
!         for variable in self.modifier_vars:
!             variable.set('')
!         self.keyString.set('')
      
      def LoadFinalKeyList(self):