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