Bladeren bron

*** empty log message ***

Mark Mine 24 jaren geleden
bovenliggende
commit
23c106d86c
1 gewijzigde bestanden met toevoegingen van 26 en 1 verwijderingen
  1. 26 1
      direct/src/gui/DirectDialog.py

+ 26 - 1
direct/src/gui/DirectDialog.py

@@ -20,6 +20,9 @@ class DirectDialog(DirectFrame):
                                  each button.  If value is [] then the
                                  each button.  If value is [] then the
                                  ordinal rank of the button is used as 
                                  ordinal rank of the button is used as 
                                  its value
                                  its value
+            buttonHotKeyList     List of hotkeys to bind to each button.
+                                 Typing hotkey is equivalent to pressing
+                                 the corresponding button.
             buttonSize           4-tuple used to specify custom size for
             buttonSize           4-tuple used to specify custom size for
                                  each button (to make bigger then geom/text
                                  each button (to make bigger then geom/text
                                  for example)
                                  for example)
@@ -51,6 +54,7 @@ class DirectDialog(DirectFrame):
             ('buttonGeomList',    [],            INITOPT),
             ('buttonGeomList',    [],            INITOPT),
             ('buttonImageList',   [],            INITOPT),
             ('buttonImageList',   [],            INITOPT),
             ('buttonValueList',   [],            INITOPT),
             ('buttonValueList',   [],            INITOPT),
+            ('buttonHotKeyList',  [],            INITOPT),
             ('button_borderWidth',(.01,.01),     None),
             ('button_borderWidth',(.01,.01),     None),
             ('button_pad',        (.01,.01),     None),
             ('button_pad',        (.01,.01),     None),
             ('button_relief',     RAISED,        None),
             ('button_relief',     RAISED,        None),
@@ -93,6 +97,12 @@ class DirectDialog(DirectFrame):
                 value = self['buttonValueList'][i]
                 value = self['buttonValueList'][i]
             except IndexError:
             except IndexError:
                 value = i
                 value = i
+            try:
+                print 'HERE'
+                hotKey = self['buttonHotKeyList'][i]
+            except IndexError:
+                print 'THERE'
+                hotKey = None
             button = self.createcomponent(
             button = self.createcomponent(
                 name, (), "button",
                 name, (), "button",
                 DirectButton, (self,),
                 DirectButton, (self,),
@@ -102,6 +112,21 @@ class DirectDialog(DirectFrame):
                 frameSize = self['buttonSize'],
                 frameSize = self['buttonSize'],
                 command = lambda s = self, v = value: s.buttonCommand(v)
                 command = lambda s = self, v = value: s.buttonCommand(v)
                 )
                 )
+            # Add any hot key binding
+            print "HOTKEY", hotKey
+            if hotKey:
+                print 'DOING IT'
+                if ((type(hotKey) == types.ListType) or
+                    (type(hotKey) == types.TupleType)):
+                    print 'NOW'
+                    for key in hotKey:
+                        print 'REALLY'
+                        button.accept(key, self.buttonCommand,
+                                      extraArgs = [value])
+                else:
+                    print 'NOT'
+                    button.accept(hotKey, self.buttonCommand,
+                                extraArgs = [value])
             self.buttonList.append(button)
             self.buttonList.append(button)
         
         
         # Update dialog when everything has been initialised
         # Update dialog when everything has been initialised
@@ -309,4 +334,4 @@ class TTOkCancelDialog(DirectDialog):
         self.defineoptions(kw, optiondefs)
         self.defineoptions(kw, optiondefs)
         DirectDialog.__init__(self, parent)
         DirectDialog.__init__(self, parent)
         self.initialiseoptions(TTOkCancelDialog)
         self.initialiseoptions(TTOkCancelDialog)
-
+        buttons.removeNode()