Robin Dunn wrote:
Stef Mientki wrote:
hello,
I think I miss the "OnChange" event heavily ....
... I've a slider,
... when the user moves the slider, I want "something" to happen,
and of course that works.Now I change the slider value by code, ...
... the visual presentation changes nicely,
... but as the slider has only an EVT_SLIDER event
... which isn't fired,
... "something" is not happening.As a workaround I copied the code for doing "something",
to the code where I change the slider value by code,
but I hate redundancy.And probably this problem not only occurs with the slider,
but with a lot of other controls.There are exceptions to this, mainly for historical reasons, but the standard in wxWidgets is that a change to the widget done programamtically should not generate a changed event, only changes done by the user through the UI should. One of the reasons for this is that in those cases that do cause an event there are lots more questions like, "How can I tell when an event happens because of a programmatic change and not some user action?" than there are the opposite kinds of questions for the other widgets.
So it's a choice, ...
... in the previous language I used,
every control had an OnChange event,
and in less than 5% of the cases I really wanted to know if an event
came from the program or from the user
(in which case you can easily detect that by a flag) ...
... so if it's the right choice
btw I don't plead for another choice,
standardization is far more important than the right choice !
So is there an elegant workaround ?
Factor the code out of the event handler and into a new method, and then call that method from both the event handler and also the place in your code where you change the value.
def OnSomeEvent(self, evt):
self.DoSomething()def DoSomething(self):
something()
something_else()def SomeOtherMethod(self):
self.widget.SetValue(1234)
self.DoSomething()
thanks Robin,
I'll do it that way.
cheers,
Stef
Het UMC St Radboud staat geregistreerd bij de Kamer van Koophandel in het handelsregister onder nummer 41055629.
The Radboud University Nijmegen Medical Centre is listed in the Commercial Register of the Chamber of Commerce under file number 41055629.