Reputation: 4180
Let's say I have a ToggleButton with an id 'btn_toggle'. If I do this from code:
self.ids['btn_toggle'].dispatch('on_press')
then the on_press event is fired, and the bound event handlers are called. Everything is fine, except that the button is not toggled at all. The toggle button group is not updated. Is this a bug, or should I use a different event for this?
Upvotes: 0
Views: 235
Reputation: 5947
The on_press
event and the state
property of the button are less linked than you think, in fact, they can change/be triggered pretty much independently.
If you want to change the state of the button, you just do that self.ids.btn_toggle.state = 'down'
, but it won't automatically create an on_press
event (that is directly triggered by the click), so if that's what you want, you still need to do it.
Basically, in a ToggleButton
, on_press
means that the user clicked the button, if the button was already down, it won't change its state, until the user releases the touch (and then you get an on_release
event, as well as an on_state
event), if the button was not down, you get both an on_press
and an on_state
event, and you get an on_release
event (only) when the user releases the touch.
It might be that you actually want to react to on_state
instead of on_press
, if what interests you is the state of the button, not of the touch on the button.
Upvotes: 1