Pierre Hjälm wrote:
Wouldn't the easiest way be to intercept text change event
and just check if the value still is a valid number and if
not just change the value back to the latest "sane" value?warning, pseudoish code below...
def OnTextChange(self,evt):
try:
int(self.GetValue())
self.oldval=self.GetValue()
except:
self.SetValue(self.oldval)
# hmm... we must stop the usual texthandling, does this work?
evt.SetString("")
Hmm... This would achieve *a* result, but not necessarily what
the user wants from a GUI perspective; if they select
the entire value, and then hit delete, a more appropriate
response might be to replace the value with "0", and then
select it so the next keystroke replaces the 0, thus producing
a more natural numeric meaning of "delete."
Anyway, in light of the lack of responses to my original
question "has this been done (well) before/is it available?",
I will assume (alas) "no." I have a working class that does
{G,S}etValue() with naturals, complete with event generation,
etc, but it's not as general as I'd like it to be (eg. it
doesn't handle negative integers). I will try to polish it
up sometime this year before submission to Robin for the
library.
/Will Sadkin
Parlance Corporation