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.

This commit is contained in:
M. Ian Graham 2007-07-19 00:44:56 +00:00
parent 4429b66c8d
commit 656bc2105f
2 changed files with 10 additions and 0 deletions

View File

@ -53,6 +53,9 @@ class DirectEntry(DirectFrame):
# Command to be called on hitting Enter
('command', None, 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
('focusInCommand', None, None),
('focusInExtraArgs', [], None),
@ -94,6 +97,7 @@ class DirectEntry(DirectFrame):
# Bind command function
self.bind(DGG.ACCEPT, self.commandFunc)
self.bind(DGG.ACCEPTFAILED, self.failedCommandFunc)
self.accept(self.guiItem.getFocusInEvent(), self.focusInCommandFunc)
self.accept(self.guiItem.getFocusOutEvent(), self.focusOutCommandFunc)
@ -149,6 +153,11 @@ class DirectEntry(DirectFrame):
# Pass any extra args to command
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):
if self['focusInCommand']:
apply(self['focusInCommand'], self['focusInExtraArgs'])

View File

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