Change state of a button

View: New views
3 Messages — Rating Filter:   Alert me  

Change state of a button

by Frédéric Mantegazza-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I have some key binding which do the same things as some buttons do. So,
when pressing the key, I would like to see the corresponding button
pressed, as if I did it with the mouse.

I tried to call button.pressed(), but it only emits the signal.

Is it possible to change the state of the button? I didn't find the
methods for that...
_______________________________________________
pygtk mailing list   pygtk@...
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Parent Message unknown Re: Change state of a button

by pcmcg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Jul 11, 2008 at 1:37 AM, Frédéric <frederic.mantegazza@...> wrote:

I would like to see the corresponding button
pressed, as if I did it with the mouse.


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.


_______________________________________________
pygtk mailing list   pygtk@...
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Parent Message unknown Re: Change state of a button

by Frédéric Mantegazza-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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
_______________________________________________
pygtk mailing list   pygtk@...
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
LightInTheBox - Buy quality products at wholesale price