1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
# Copyright (c) 2003-2005 Ruby-GNOME2 Project Team
# This program is licenced under the same licence as Ruby-GNOME2.
#
# $Id: item_factory.rb,v 1.4 2005/02/12 23:02:43 kzys Exp $
=begin
= Item Factory
The Gtk::ItemFactory object allows the easy creation of menus
from an array of descriptions of menu items.
=end
require 'common'
module Demo
class ItemFactory < BasicWindow
def initialize
super('Item Factory')
accel_group = Gtk::AccelGroup.new
item_factory = Gtk::ItemFactory.new(Gtk::ItemFactory::TYPE_MENU_BAR,
'<main>', accel_group)
add_accel_group(accel_group)
set_border_width(0)
ifactory_cb = proc do |data, widget|
puts "ItemFactory: activated \"#{Gtk::ItemFactory.path_from_widget(widget)}\""
end
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)
item_factory.get_item('/Preferences/Shape/Oval').set_active(true)
box1 = Gtk::VBox.new(false, 0)
add(box1)
box1.pack_start(item_factory.get_widget('<main>'), false, false, 0)
label = Gtk::Label.new("Type\n<alt>\nto start")
label.set_size_request(200, 200)
label.set_alignment(0.5, 0.5)
box1.pack_start(label, true, true, 0)
separator = Gtk::HSeparator.new
box1.pack_start(separator)
box2 = Gtk::VBox.new(false, 10)
box2.set_border_width(10)
box1.pack_start(box2, false, true, 0)
button = Gtk::Button.new('close')
# TODO: Need signal_connect_swapped?
button.signal_connect('clicked') do
quit
end
box2.pack_start(button, true, true, 0)
button.set_flags(Gtk::Widget::CAN_DEFAULT)
button.grab_default
end
end
end
|