Forum: Ruby-Gnome 2 Gtk::ItemFactory, create_items

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
C53e81f5d7c781c6dc3979c4ce888706?d=identicon&s=25 Grant Schoep (matobinder)
on 2012-08-29 00:03
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 <RadioItem>
  Preferences/Color/Green uses Preferences/Color/Red
  Preferences/Color/Blue  uses Preferences/Color/Red

However, on the Preferences/Shape example:
  Preferences/Shape/Square    uses <RadioItem>
  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 = [
    '<Tearoff>', nil, nil, ifactory_cb],
    '<Item>', '<control>N', nil, ifactory_cb],
    '<Item>', '<control>O', nil, ifactory_cb],
    '<Item>', '<control>S', nil, ifactory_cb],
  ['/File/Save _As...',
    '<Item>', nil, nil, ifactory_cb],
  ['/File/sep1', '<Separator>'],
    '<Item>', '<control>Q', nil, ifactory_cb],

  ['/_Preferences/Color/_Red',        '<RadioItem>', nil, nil,
  ['/_Preferences/Color/_Green',      '/Preferences/Color/Red', nil,
nil, ifactory_cb],
  ['/_Preferences/Color/_Blue',       '/Preferences/Color/Red', nil,
nil, ifactory_cb],
  ['/_Preferences/Shape/_Square',     '<RadioItem>', nil, nil,
  ['/_Preferences/Shape/_Rectangle',  '/Preferences/Shape/Square', nil,
nil, ifactory_cb],
  ['/_Preferences/Shape/_Oval',       '/Preferences/Shape/Rectangle',
nil, nil, ifactory_cb],

  ['/_Help', '<LastBranch>'],
  ['/Help/_About', '<Item>', nil, nil, ifactory_cb],
This topic is locked and can not be replied to.