[pygtk] Change state of a button
Frédéric
frederic.mantegazza at gbiloba.org
Sun Jul 13 17:00:35 WST 2008
On samedi 12 juillet 2008, Casey McGinty wrote:
> > On vendredi 11 juillet 2008, Casey McGinty wrote:
> > > So you want to see the button go in and then out, like in real time?
> > > I don't think you can do this with a gtk.Button. Maybe you could rig
> > > a gtk.ToggleButton to emulate the button press. I would think that
> > > if you change the button state from active, to inactive, without
> > > adding any delay, it will happen too fast for you you to see it on
> > > the screen.
> >
> > The problem if I use a ToggleButton is that I will have to press it
> > twice to release it; and I don't want to, as it will drive a panoramic
> > head; it can be dangerous if the motor stay on...
>
> What if you make the callback logic in the Togglebutton to unset the
> ToggleButton after it is set? Then it should behave like a standard
> button. I've never done this, but I would think that this could be done
> easily.
Ok, I finally made it work with a ToggleButton. First, lets say that I use
the 'pressed' and 'released' events, the first to start a motor move, the
second to stop the motor move. I do no need the 'clicked' event.
Here is what I did:
1) I binded the 'pressed' and 'released' events of the toggle button.
2) I binded the 'pressed' and 'released' events of the associated key.
3) In the key 'pressed' callback, I call set_active(True) on the button; in
the key 'released' callback, I call set_active(False) on the button. This
way, the button state follow the key state.
4) Then, as I use a ToggleButton, clicking on the button with the mouse
toggle it, which I don't want. So, in the 'released' callback of the
button, I just call set_active(False) on itself; this way, as soon as I
release the button, it go back in inactive state.
I did the same with a button used with 'clicked' callback.
Hope it can be usefull for other people.
Thanks you very much for you help!
--
Frédéric
http://www.gbiloba.org
More information about the pygtk
mailing list