wxNumCtrl?

RE: [wxPython-users] wxNumCtrl?
Pierre Hjälm wrote:

[…]

This is my attempt at an integer control:

class IntInput(wxTextCtrl):

[…]

My version is a little more sophisticated than yours,

in that it tries to help the user out as they type.

For instance, if the current value of my control is 0 and you

either select the value or place the cursor at the front of

the control, and then type ‘-’, the control replaces the value

with -1, with the 1 selected, so that it will be replaced

with the next digit; this way you can just type ‘-234’ and

have a legal integer value after each keystroke, and the

number becomes “what the user expects.”

Similarly, if you select the entire contents and “delete”

it, then my control replaces the value with zero, as

a reasonable meaning of “delete” in an integer entry control.

It also allow you to replace leading digits with 0, producing

the appropriate resulting value, making this action behave

like “delete”.

It now handles cuts and pastes properly too, and also

supports bounds checking/limiting as a part of its validation,

recoloring the text as appropriate if bounds are set but the

control is not limiting the values entered. (This is a very

handy feature that eliminates a lot of otherwise necessary

external coding.)

I must give Pierre thanks for his insights re: paste; I hadn’t

considered this issue yet when he brought it up. I also must

thank him for the idiom of

if result_text in ["","-"]:

(This simplified a bit of my code and made it more readable.)

I will be submitting my control and a demo for it to Robin today.

However, if anyone else wants to review them, I’d also be happy to

post them here.

/Will Sadkin

Parlance Corporation

Will Sadkin <wsadkin@nameconnector.com> writes:

> Pierre Hjälm wrote:
> > [...]
> >This is my attempt at an integer control:
> >
> > class IntInput(wxTextCtrl):
> [...]
>
> My version is a little more sophisticated than yours,
> in that it tries to help the user out as they type.
>
...
>
> I must give Pierre thanks for his insights re: paste; I hadn't
> considered this issue yet when he brought it up. I also must
> thank him for the idiom of
>
> if result_text in ["","-"]:
>
> (This simplified a bit of my code and made it more readable.)
>
Glad to be of help :slight_smile:

I don't have the same goals with the control as you do, so it's not
surprising that my code didn't work for you. For one, even though
it's an integer-only control, I do want people to be able to leave
it blank. And I also believe that the control shouldn't be _too_
intelligent and change the text automagically while you are editing
it (well, at least not in ways that may not be obvious). But, that's
me, and I already have my control done. It handles bort integers, floats,
dates, text and what not, and is not especially complicated.

I in turn must thank you for pointing me at the wxCallAfter function,
it made the code much clearer.

···

--
  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