File: testif.pl

package info (click to toggle)
libgtk-perl 0.7009-12
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,956 kB
  • ctags: 2,260
  • sloc: perl: 13,998; xml: 9,919; ansic: 2,894; makefile: 64; cpp: 45
file content (57 lines) | stat: -rw-r--r-- 1,554 bytes parent folder | download | duplicates (4)
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
#!/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', '<main>', $accel);

$factory->create_items({ path	     =>  '/_File',
			 type	     =>  '<Branch>',
		       },
		       { path	     =>  '/_File/tearoff1',
			 type	     =>  '<Tearoff>',
		       },
		       { path	     =>  '/_File/_Hello',
			 accelerator =>  '<control>H',
			 action      =>  2,
			 callback    =>  [sub {
					      my ($widget, $action, @args) = @_;
					      print "Hello world! action=$action, args=(@args)\n"
					  }, 17, 42],
		       },
		       { path	     =>  '/_File/E_xit',
			 accelerator =>  '<control>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, '<Tearoff>']);
$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	     => '<LastBranch>',
		       },
		       { path	     =>  '/_Help/tearoff1',
			 type	     =>  '<Tearoff>',
		       },
		       ['/_Help/_About', '<control>A', 0, undef, sub {print "Just a test\n"}]);

$menubar = $factory->get_widget('<main>');
$menubar->show;
$win->add($menubar);
$win->show;
$win->signal_connect('delete_event', sub {Gtk->exit(0)});
main Gtk;