# Button depressing

**URL:** <https://www.ruby-forum.com/t/button-depressing/61767>\
**Category:** Ruby-Gnome 2\
**Created:** [May 26, 2006, 11:55pm UTC](https://www.ruby-forum.com/t/button-depressing/61767 "2006-05-26T23:55:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [May 26, 2006, 11:55pm UTC](https://www.ruby-forum.com/t/button-depressing/61767/1 "2006-05-26T23:55:36Z")

</div>

Hi,

I’m rewriting a Xlib graphical application in Gtk. There’s four  
different states (run, hold, reset, shutdown) that the application be  
be in. The state that the application is in is determined by another  
application, but the user of the graphical application can request a  
different “state”.

Here’s a picture of what the buttons for changing the state look like.  
[http://img87.imageshack.us/img87/9717/buttons2mv.png](http://img87.imageshack.us/img87/9717/buttons2mv.png) The application  
is in “reset” mode currently. Notice how the reset button is  
depressed.

I’m struggling how to reproduce that look in Gtk. I initially tried  
toggle and radio buttons, but I couldn’t figure out how to tell a  
button to be active / toggled without generating a “toggled” event,  
which would tell the application to send a request to change the  
state.

Any ideas? I’m guessing I have two solutions. One is to figure out  
how to get a normal button to look “depressed” like it does in the  
picture. The other solution is to figure out how to be able to tell a  
toggle button to be toggled without that button emitting a toggled  
event (which would tell the application to change state, when the user  
hasn’t requested a state change).

Thanks,  
Joe

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [May 27, 2006, 12:41am UTC](https://www.ruby-forum.com/t/button-depressing/61767/2 "2006-05-27T00:41:28Z")

</div>

On Fri, May 26, 2006 at 02:54:03PM -0700, Joe Van D. wrote:

> event (which would tell the application to change state, when the user  
> hasn’t requested a state change).

You can use the “released signal” of the button for this. You just need  
to  
ensure that you check the actual state of the button in the callback (As  
a  
release outside of the button’s area won’t actually toggle it).

## Sjoerd

The speed of anything depends on the flow of everything.

* * *

All the advantages of Linux Managed Hosting–Without the Cost and Risk!  
Fully trained technicians. The highest number of Red Hat certifications  
in  
the hosting industry. Fanatical Support. Click to learn more  
[http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642](http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642)

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [May 27, 2006, 7:13am UTC](https://www.ruby-forum.com/t/button-depressing/61767/3 "2006-05-27T07:13:43Z")

</div>

On Fri, 2006-05-26 at 14:54 -0700, Joe Van D. wrote:

> is in “reset” mode currently. Notice how the reset button is  
> picture. The other solution is to figure out how to be able to tell a  
> toggle button to be toggled without that button emitting a toggled  
> event (which would tell the application to change state, when the user  
> hasn’t requested a state change).

all you seem to be doing is changing the colors. and no, GTK has no  
method of making a button appear “pressed” without going through the  
code path for an actual press. i just use a separate variable called  
something like in\_my\_special\_context. the handler for the button  
click/press/release events simply checks to see if this is true, and  
returns true without doing anything. you set the var to true when you  
programmatically toggle the button, then back to false afterwards.

* * *

All the advantages of Linux Managed Hosting–Without the Cost and Risk!  
Fully trained technicians. The highest number of Red Hat certifications  
in  
the hosting industry. Fanatical Support. Click to learn more  
[http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642](http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642)

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [May 27, 2006, 7:13am UTC](https://www.ruby-forum.com/t/button-depressing/61767/4 "2006-05-27T07:13:43Z")

</div>

Paul Davis wrote:

> > 
> 
> method of making a button appear “pressed” without going through the  
> code path for an actual press. i just use a separate variable called  
> something like in\_my\_special\_context. the handler for the button  
> click/press/release events simply checks to see if this is true, and  
> returns true without doing anything. you set the var to true when you  
> programmatically toggle the button, then back to false afterwards.

Note also you can use g\_signal\_handler\_block\_by\_func() for this  
purpose.

Cheers,  
-Tristan

* * *

All the advantages of Linux Managed Hosting–Without the Cost and Risk!  
Fully trained technicians. The highest number of Red Hat certifications  
in  
the hosting industry. Fanatical Support. Click to learn more  
[http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642](http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642)

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [May 27, 2006, 1:54pm UTC](https://www.ruby-forum.com/t/button-depressing/61767/5 "2006-05-27T13:54:54Z")

</div>

On Fri, 2006-05-26 at 14:54 -0700, Joe Van D. wrote:

> is in “reset” mode currently. Notice how the reset button is  
> depressed.
> 
> I’m struggling how to reproduce that look in Gtk. I initially tried  
> toggle and radio buttons, but I couldn’t figure out how to tell a  
> button to be active / toggled without generating a “toggled” event,

It’s up to you whether to handle that signal. With a bool you can stop  
yourself from handling it.

> which would tell the application to send a request to change the  
> state.
> 
> Any ideas? I’m guessing I have two solutions. One is to figure out  
> how to get a normal button to look “depressed” like it does in the  
> picture. The other solution is to figure out how to be able to tell a  
> toggle button to be toggled without that button emitting a toggled  
> event (which would tell the application to change state, when the user  
> hasn’t requested a state change).

–  
Murray Cumming  
removed\_email\_address@domain.invalid  
[www.murrayc.com](http://www.murrayc.com)  
[www.openismus.com](http://www.openismus.com)

* * *

All the advantages of Linux Managed Hosting–Without the Cost and Risk!  
Fully trained technicians. The highest number of Red Hat certifications  
in  
the hosting industry. Fanatical Support. Click to learn more  
[http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642](http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642)

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [May 27, 2006, 7:13am UTC](https://www.ruby-forum.com/t/button-depressing/61767/6 "2006-05-27T07:13:43Z")

</div>

On Fri, 2006-05-26 at 20:42 -0400, Tristan Van Berkom wrote:

> > 
> 
> Note also you can use g\_signal\_handler\_block\_by\_func() for this  
> purpose.

not from gtkmm, at least not very conveniently.

–p

* * *

All the advantages of Linux Managed Hosting–Without the Cost and Risk!  
Fully trained technicians. The highest number of Red Hat certifications  
in  
the hosting industry. Fanatical Support. Click to learn more  
[http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642](http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642)
