wx.SpinCtrl min/max range trim silently?

Bogdan Valentin Neacsa wrote:

Hello,

I have a SpinCtrl created like:

self.entry = SpinStepCtrl(self.parent, -1)
self.entry.SetRange(cfg_min, cfg_max)

This works as expected and from the spin up/down arrows I cannot enter
any bigger value. However if I type in the text field I can enter a
value as big / low as I want. This is part of a lager panel that gets
submitted when an ok button is pressed,

self.ok_button.Bind(wx.EVT_BUTTON, self.onOk)

Now when this gets processed the GetValue() will automatically trim it
to be in the interval silently. I would like some way to either: have
some kind of onChange event that can detect that the value is
larger/lower than min/max and also correct it in the UI so the user can
immediately see it has been trimmed, or somehow later get the
'non-trimmed' value so I can process that myself and raise and
exception. How can I achieve any of those cases?

I think that it emits the EVT_TEXT event so you could catch changes in a handler for that event and change the value yourself. It could also make sense to use a validator for it.

···

--
Robin Dunn
Software Craftsman

Thank you for the input. I’ve tried using EVT_TEXT and getting inputed text from event.String . This seems to work fine on Windows, however on Ubuntu event.String seems to always be an empty string. Is there any other way I can get the input from that SpinCtrl?

joi, 14 martie 2013, 18:57:55 UTC+2, Robin Dunn a scris:

···

I think that it emits the EVT_TEXT event so you could catch changes in a
handler for that event and change the value yourself. It could also
make sense to use a validator for it.


Robin Dunn
Software Craftsman
http://wxPython.org