Browse Source

Added failedCommand option that lets us register a callback for when the user attempts to submit a disabled DirectEntry field. This lets us give feedback by flashing the field a different color, etc.

M. Ian Graham 18 years ago
parent
commit
656bc2105f
2 changed files with 10 additions and 0 deletions
  1. 9 0
      direct/src/gui/DirectEntry.py
  2. 1 0
      direct/src/gui/DirectGuiGlobals.py

+ 9 - 0
direct/src/gui/DirectEntry.py

@@ -53,6 +53,9 @@ class DirectEntry(DirectFrame):
             # Command to be called on hitting Enter
             # Command to be called on hitting Enter
             ('command',        None,              None),
             ('command',        None,              None),
             ('extraArgs',      [],                None),
             ('extraArgs',      [],                None),
+            # Command to be called when enter is hit but we fail to submit
+            ('failedCommand',  None,              None),
+            ('failedExtraArgs',[],                None),
             # commands to be called when focus is gained or lost
             # commands to be called when focus is gained or lost
             ('focusInCommand', None,              None),
             ('focusInCommand', None,              None),
             ('focusInExtraArgs', [],              None),
             ('focusInExtraArgs', [],              None),
@@ -94,6 +97,7 @@ class DirectEntry(DirectFrame):
 
 
         # Bind command function
         # Bind command function
         self.bind(DGG.ACCEPT, self.commandFunc)
         self.bind(DGG.ACCEPT, self.commandFunc)
+        self.bind(DGG.ACCEPTFAILED, self.failedCommandFunc)
 
 
         self.accept(self.guiItem.getFocusInEvent(), self.focusInCommandFunc)
         self.accept(self.guiItem.getFocusInEvent(), self.focusInCommandFunc)
         self.accept(self.guiItem.getFocusOutEvent(), self.focusOutCommandFunc)
         self.accept(self.guiItem.getFocusOutEvent(), self.focusOutCommandFunc)
@@ -149,6 +153,11 @@ class DirectEntry(DirectFrame):
             # Pass any extra args to command
             # Pass any extra args to command
             apply(self['command'], [self.get()] + self['extraArgs'])
             apply(self['command'], [self.get()] + self['extraArgs'])
 
 
+    def failedCommandFunc(self, event):
+        if self['failedCommand']:
+            # Pass any extra args
+            apply(self['failedCommand'], [self.get()] + self['failedExtraArgs'])
+
     def focusInCommandFunc(self):
     def focusInCommandFunc(self):
         if self['focusInCommand']:
         if self['focusInCommand']:
             apply(self['focusInCommand'], self['focusInExtraArgs'])
             apply(self['focusInCommand'], self['focusInExtraArgs'])

+ 1 - 0
direct/src/gui/DirectGuiGlobals.py

@@ -70,6 +70,7 @@ B3RELEASE = PGButton.getReleasePrefix() + MouseButton.three().getName() + '-'
 # For DirectEntry widgets
 # For DirectEntry widgets
 OVERFLOW = PGEntry.getOverflowPrefix()
 OVERFLOW = PGEntry.getOverflowPrefix()
 ACCEPT = PGEntry.getAcceptPrefix() + KeyboardButton.enter().getName() + '-'
 ACCEPT = PGEntry.getAcceptPrefix() + KeyboardButton.enter().getName() + '-'
+ACCEPTFAILED = PGEntry.getAcceptFailedPrefix() + KeyboardButton.enter().getName() + '-'
 TYPE = PGEntry.getTypePrefix()
 TYPE = PGEntry.getTypePrefix()
 ERASE = PGEntry.getErasePrefix()
 ERASE = PGEntry.getErasePrefix()
 # For DirectSlider and DirectScrollBar widgets
 # For DirectSlider and DirectScrollBar widgets