# Gtk::ItemFactory, create\_items

**URL:** <https://www.ruby-forum.com/t/gtk-itemfactory-create-items/222454>\
**Category:** Ruby-Gnome 2\
**Created:** [August 29, 2012, 12:03am UTC](https://www.ruby-forum.com/t/gtk-itemfactory-create-items/222454 "2012-08-29T00:03:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [August 29, 2012, 12:03am UTC](https://www.ruby-forum.com/t/gtk-itemfactory-create-items/222454/1 "2012-08-29T00:03:16Z")

</div>

First off, I’m not having a problem here, other that tying to understand  
how something is actually working.

I was writing a new GUI the other day, and was looking at a chunk of  
code I generally just cut and paste into a new app and reuse part of it.  
It is for the GtkItemFactory for the TYPE\_MENU\_BAR at the top of my App.  
I started wondering exactly how it was working, I looked at the example  
application that ships with Ruby/Gnome2, item\_factory.rb and it brought  
up a question.

I have a question on that. I’m looking at where it is building the  
menu\_items array to pass to create\_items. My question is on the second  
argument, the item\_type arg. This is in the case when it is a type  
.

In the Preferences/Color example:  
Preferences/Color/Red uses   
Preferences/Color/Green uses Preferences/Color/Red  
Preferences/Color/Blue uses Preferences/Color/Red

However, on the Preferences/Shape example:  
Preferences/Shape/Square uses   
Preferences/Shape/Rectangle uses Preferences/Shape/Square  
Preferences/Shape/Oval uses Preferences/Shape/Rectangle

So for the color, both subsequent ones “attach” to the Red.  
But in the Shape example, subsequent ones “attach” to the previous one.

Either way, I don’t seem to see a difference in the how it looks. I just  
noticed that alot of my stuff has it mixed up like this too. I never  
noticed it before. Wondering what this is really suppose to be. The  
documentation on Ruby/Gnome2 for class Gtk::ItemFactory says the  
following on item\_type

“item\_type: GtkItemType?. A simple item when nil is given. If it is set  
path, it is for a radio item to link against”

Here is an extract of the code, it is probably easier to just look at  
the actual item\_factory.rb file in the samples area.

menu\_items = [  
[’/\_File’],  
[’/File/tearoff1’,  
‘’, nil, nil, ifactory\_cb],  
[’/File/\_New’,  
‘’, ‘N’, nil, ifactory\_cb],  
[’/File/\_Open’,  
‘’, ‘O’, nil, ifactory\_cb],  
[’/File/\_Save’,  
‘’, ‘S’, nil, ifactory\_cb],  
[’/File/Save \_As…’,  
‘’, nil, nil, ifactory\_cb],  
[’/File/sep1’, ‘’],  
[’/File/\_Quit’,  
‘’, ‘Q’, nil, ifactory\_cb],

[’/\_Preferences’],  
[’/\_Preferences/\_Color’],  
[’/\_Preferences/Color/\_Red’, ‘’, nil, nil,  
ifactory\_cb],  
[’/\_Preferences/Color/\_Green’, ‘/Preferences/Color/Red’, nil,  
nil, ifactory\_cb],  
[’/\_Preferences/Color/\_Blue’, ‘/Preferences/Color/Red’, nil,  
nil, ifactory\_cb],  
[’/\_Preferences/\_Shape’],  
[’/\_Preferences/Shape/\_Square’, ‘’, nil, nil,  
ifactory\_cb],  
[’/\_Preferences/Shape/\_Rectangle’, ‘/Preferences/Shape/Square’, nil,  
nil, ifactory\_cb],  
[’/\_Preferences/Shape/\_Oval’, ‘/Preferences/Shape/Rectangle’,  
nil, nil, ifactory\_cb],

[’/\_Help’, ‘’],  
[’/Help/\_About’, ‘’, nil, nil, ifactory\_cb],  
]  
item\_factory.create\_items(menu\_items)
