# Hopefully trivial question regarding UIManager & Menu items

**URL:** <https://www.ruby-forum.com/t/hopefully-trivial-question-regarding-uimanager-menu-items/150625>\
**Category:** Ruby-Gnome 2\
**Created:** [October 10, 2008, 3:34pm UTC](https://www.ruby-forum.com/t/hopefully-trivial-question-regarding-uimanager-menu-items/150625 "2008-10-10T15:34:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_SSTownley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@Andrew\_SSTownley](https://www.ruby-forum.com/u/Andrew_SSTownley)\
**Post date:** [October 10, 2008, 3:34pm UTC](https://www.ruby-forum.com/t/hopefully-trivial-question-regarding-uimanager-menu-items/150625/1 "2008-10-10T15:34:43Z")

</div>

Hi,

I’m playing around with the new (to me) UIManager class to build  
application menus, and I was wondering how you can access each of the  
menu items to add a handler for the “selected” signal.

If I have to walk the menu items after getting the top-level menus with  
uimanager[“/MenuBar”], that’s fine, but I’m actually not sure which  
methods I’m supposed to use to traverse the children. Using

uimanager[…].each

doesn’t seem to give me the menu items as I would expect. I get things  
like:

#\<Gtk::ImageMenuItem:0x7fe166e4abc0 ptr=0xc500c0\>  
#\<Gtk::AccelLabel:0x7fe166e4a878 ptr=0xd37130\>  
#\<Gtk::Image:0x7fe166e4a800 ptr=0xc50170\>

What I’m actually trying to do is add a selected handler to each menu  
item so that I can update the status bar with additional information.  
Anyone with a better idea on how to do this (code would be nice! :),  
please feel free to adjust my thinking.

I don’t seem to find any examples for this anywhere. I know I could do  
it if I added the menu items manually, but I’m trying to use the new  
tools (and the merge stuff will be handy for my app too).

Thanks in advance,

## ast

Andrew S. Townley [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://atownley.org](http://atownley.org)

---

<div class="post-metadata">

**Author:** ![Andrew\_SSTownley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@Andrew\_SSTownley](https://www.ruby-forum.com/u/Andrew_SSTownley)\
**Post date:** [October 11, 2008, 11:59am UTC](https://www.ruby-forum.com/t/hopefully-trivial-question-regarding-uimanager-menu-items/150625/2 "2008-10-11T11:59:31Z")

</div>

Ok,

I’ve discovered the signal in the UIManager, “connect-proxy”, that I  
need to access. I missed it when I was looking before, sorry.

However, now that I’m trying to use this signal, I don’t understand  
what’s happening.

Normally, you’d do something like this:

@uimanager.signal\_connect(“connect-proxy”) do |uimanager, action, proxy|  
proxy.signal\_connect(“select”) do |item|  
set\_status\_text(action.tooltip)  
end  
end

However, when I try this, I get messages like:

example.rb:101: warning: GRClosure invoking callback: already destroyed

each time the “select” signal is fired.

I’ve tried making the block to “connect-proxy” an external block, but I  
still get half as many messages.

Based on the way you need to connect signals, I don’t see how this is  
really supposed to work if the internal proc objects are already  
destroyed. Is this because they’re doubly nested?

$ ruby -v  
ruby 1.8.6 (2007-09-24 patchlevel 111) [x86\_64-linux]

Any advice on the correct way to do this would be most appreciated.

BTW: is there a way to get a bundle of the ruby-gnome2 documentation  
for off-line use (without building the whole project from scratch)?

Cheers,

ast

On Fri, 2008-10-10 at 00:01 +0100, Andrew S. Townley wrote:

> uimanager[…].each  
> Anyone with a better idea on how to do this (code would be nice! :),  
> please feel free to adjust my thinking.
> 
> I don’t seem to find any examples for this anywhere. I know I could do  
> it if I added the menu items manually, but I’m trying to use the new  
> tools (and the merge stuff will be handy for my app too).
> 
> Thanks in advance,
> 
> ast  
> –  
> Andrew S. Townley [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [http://atownley.org](http://atownley.org)

---

<div class="post-metadata">

**Author:** ![Andrew\_SSTownley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@Andrew\_SSTownley](https://www.ruby-forum.com/u/Andrew_SSTownley)\
**Post date:** [October 18, 2008, 8:30am UTC](https://www.ruby-forum.com/t/hopefully-trivial-question-regarding-uimanager-menu-items/150625/3 "2008-10-18T08:30:35Z")

</div>

Hi,

In [1223718947.23429.17.camel@linna](mailto:1223718947.23429.17.camel@linna)  
“[ruby-gnome2-devel-en] Additional info Re: Hopefully trivial question  
regarding UIManager & Menu items” on Sat, 11 Oct 2008 10:55:47 +0100,  
“Andrew S. Townley” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> example.rb:101: warning: GRClosure invoking callback: already destroyed
> 
> each time the “select” signal is fired.

Thanks for reporting.  
I’ve fixed it in trunk.

Workaround:  
proxies = []  
@uimanager.signal\_connect(“connect-proxy”) do |uimanager, action,  
proxy|  
proxies \<\< proxy  
proxy.signal\_connect(“select”) do |item|  
set\_status\_text(action.tooltip)  
end  
end

> BTW: is there a way to get a bundle of the ruby-gnome2 documentation  
> for off-line use (without building the whole project from scratch)?

You can get it as RD format:  
% svn co

> **[Ruby-GNOME 2](https://sourceforge.net/projects/ruby-gnome2/)**
>
> Download Ruby-GNOME 2 for free. This project is a set of Ruby language bindings for the various application development libraries included with the GNOME/GTK+ environment. This project is for GTK+2.0 or later.

You can see it by rbbr:  
[http://ruby-gnome2.sourceforge.jp/hiki.cgi?rbbr](http://ruby-gnome2.sourceforge.jp/hiki.cgi?rbbr)

Put RD formatted documentation to rbbr’s data  
dir. (e.g. /usr/share/rbbr/rd/, /usr/local/share/rbbr/rd/  
and so on)

## Thanks,

kou
