#!/usr/bin/perl -w #TITLE: ItemFactory #REQUIRES: Gtk use Gtk; init Gtk; $win = new Gtk::Window; $accel = new Gtk::AccelGroup; $accel->attach($win); $factory = new Gtk::ItemFactory('Gtk::MenuBar', '
', $accel); $factory->create_items({ path => '/_File', type => '', }, { path => '/_File/tearoff1', type => '', }, { path => '/_File/_Hello', accelerator => 'H', action => 2, callback => [sub { my ($widget, $action, @args) = @_; print "Hello world! action=$action, args=(@args)\n" }, 17, 42], }, { path => '/_File/E_xit', accelerator => 'X', callback => sub {Gtk->exit(0)} }); sub foo_callback { my ($widget, $action, @args) = @_; print "Foo! action=$action, args=(@args)\n"; } $factory->create_item(['/_Menu/tearoff1', undef, 0, '']); $factory->create_item(['/_Menu/foo _1', undef, 1, undef], \&foo_callback, 1, 2, 3); $factory->create_item(['/_Menu/foo _2', undef, 2, undef, \&foo_callback]); $factory->create_items({ path => '/_Help', type => '', }, { path => '/_Help/tearoff1', type => '', }, ['/_Help/_About', 'A', 0, undef, sub {print "Just a test\n"}]); $menubar = $factory->get_widget('
'); $menubar->show; $win->add($menubar); $win->show; $win->signal_connect('delete_event', sub {Gtk->exit(0)}); main Gtk;