def initialize
register_stock_icons
super('Application Window')
table = Gtk::Table.new(1, 4, false)
add(table)
accel_group = Gtk::AccelGroup.new
add_accel_group(accel_group)
item_factory = Gtk::ItemFactory.new(Gtk::ItemFactory::TYPE_MENU_BAR,
'<main>', accel_group)
menuitem_cb = proc do |data, widget|
dialog = Gtk::MessageDialog.new(self,
Gtk::Dialog::DESTROY_WITH_PARENT,
Gtk::MessageDialog::INFO,
Gtk::MessageDialog::BUTTONS_CLOSE,
"You selected or toggled the menu item \"#{Gtk::ItemFactory.path_from_widget(widget)}\"")
dialog.signal_connect('response') do |widget, data|
widget.destroy
end
dialog.show
end
menu_items = [
["/_File"],
["/_File/_New",
"<StockItem>", "<control>N", Gtk::Stock::NEW, menuitem_cb],
["/_File/_Open",
"<StockItem>", "<control>O", Gtk::Stock::OPEN, menuitem_cb],
["/File/_Save",
"<StockItem>", "<control>S", Gtk::Stock::SAVE, menuitem_cb],
["/File/Save _As...",
"<StockItem>", nil, Gtk::Stock::SAVE, menuitem_cb],
["/File/sep1",
"<Separator>", nil, nil, menuitem_cb],
["/File/Quit",
"<StockItem>", "<control>Q", Gtk::Stock::QUIT, menuitem_cb],
["/_Preferences"],
["/_Preferences/_Color"],
["/_Preferences/Color/_Red",
"<RadioItem>", nil, nil, menuitem_cb],
["/_Preferences/Color/_Green",
"/Preferences/Color/Red", nil, nil, menuitem_cb],
["/_Preferences/Color/_Blue",
"/Preferences/Color/Red", nil, nil, menuitem_cb],
["/Preferences/_Shape"],
["/Preferences/Shape/_Square",
"<RadioItem>", nil, nil, menuitem_cb],
["/Preferences/Shape/_Rectangle",
"/Preferences/Shape/Square", nil, nil, menuitem_cb],
["/Preferences/Shape/_Oval",
"/Preferences/Shape/Square", nil, nil, menuitem_cb],
["/_Help"],
["/Help/_About", "<Item>", nil, nil, Proc.new{about_cb}],
]
item_factory.create_items(menu_items)
table.attach(item_factory.get_widget('<main>'),
0, 1, 0, 1,
Gtk::EXPAND | Gtk::FILL, 0,
0, 0)
toolbar = Gtk::Toolbar.new
toolbar.append(Gtk::Stock::OPEN,
"This is a demo button with an 'open' icon"
) do toolbar_cb end
toolbar.append(Gtk::Stock::QUIT,
"This is a demo button with an 'quit' icon"
) do toolbar_cb end
toolbar.append_space
toolbar.append(:demo_gtk_logo,
"This is a demo button with an 'gtk' icon"
) do toolbar_cb end
table.attach(toolbar,
0, 1, 1, 2,
Gtk::EXPAND | Gtk::FILL, 0,
0, 0)
sw = Gtk::ScrolledWindow.new
sw.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
sw.shadow_type = Gtk::SHADOW_IN
table.attach(sw,
0, 1, 2, 3,
Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL,
0, 0)
set_default_size(200, 200)
contents = Gtk::TextView.new
sw.add(contents)
statusbar = Gtk::Statusbar.new
table.attach(statusbar,
0, 1, 3, 4,
Gtk::EXPAND | Gtk::FILL, 0,
0, 0)
buffer = contents.buffer
buffer.signal_connect('changed') do |buffer|
update_statusbar(buffer, statusbar)
end
buffer.signal_connect('mark_set') do |buffer, iter, mark|
update_statusbar(buffer, statusbar)
end
end