wxNumCtrl?

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

Will Sadkin <wsadkin@nameconnector.com> writes:

>
> 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.
>
Of course it's been done. It's just that my input class is very large
and integrated into my framework so it's really nothing I can share.
Btw, it is not done the way I described above, although I do use
the integer (or float) cast try/except to check that the input is a
valid number.
The hard problem is dealing with pasting (I just discard any entries
not done via the keyboard, not nice, but it works).

If you really, really (please don't :slight_smile: want to, I could probably make
a more general class out of it.

···

--
  Pierre Hjälm, Systems Administrator
  Department of Information Science, Uppsala University, Sweden
  email:pierre.hjalm@dis.uu.se phone:+46-(0)18-4711044 fax:+46-(0)18-554422