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

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
<RadioItem>.

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 = [
  ['/_File'],
  ['/File/tearoff1',
    '<Tearoff>', nil, nil, ifactory_cb],
  ['/File/_New',
    '<Item>', '<control>N', nil, ifactory_cb],
  ['/File/_Open',
    '<Item>', '<control>O', nil, ifactory_cb],
  ['/File/_Save',
    '<Item>', '<control>S', nil, ifactory_cb],
  ['/File/Save _As...',
    '<Item>', nil, nil, ifactory_cb],
  ['/File/sep1', '<Separator>'],
  ['/File/_Quit',
    '<Item>', '<control>Q', nil, ifactory_cb],

  ['/_Preferences'],
  ['/_Preferences/_Color'],
  ['/_Preferences/Color/_Red',        '<RadioItem>', 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',     '<RadioItem>', 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', '<LastBranch>'],
  ['/Help/_About', '<Item>', nil, nil, ifactory_cb],
]
item_factory.create_items(menu_items)
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.