]> mj.ucw.cz Git - moe.git/blob - submit/gtktest.pl
e09a8cca0ce9ab753eac9c6aa1a9be3300f39c20
[moe.git] / submit / gtktest.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Gtk2 -init;
7
8 sub timer {
9         print STDERR "Brum!\n";
10         return 1;
11 }
12 Glib::Timeout->add(5000, \&timer);
13
14 my $cursor = Gtk2::Gdk::Cursor->new('watch');
15
16 my $window = Gtk2::Window->new ('toplevel');
17
18 my $b1 = Gtk2::Button->new ('Quit');
19 $b1->signal_connect (clicked => sub { Gtk2->main_quit });
20 my $b2 = Gtk2::Button->new ('Exit');
21 $b2->signal_connect (clicked => sub { Gtk2->main_quit });
22 my $b3 = Gtk2::Button->new ('Apage!');
23 $b3->signal_connect (clicked => sub { Gtk2->main_quit });
24 my $box = Gtk2::HBox->new();
25 $box->pack_start_defaults($b1);
26 $box->pack_start_defaults($b2);
27 $box->pack_start_defaults($b3);
28
29 my $bb = Gtk2::Button->new ('Brum!');
30 $bb->signal_connect (clicked => sub {
31                 my $dialog = Gtk2::MessageDialog->new($window, [qw/modal destroy-with-parent/], 'question', 'ok-cancel', "So what?");
32                 $dialog->set_default_response("ok");
33                 $dialog->signal_connect (response => sub { $_[0]->destroy });
34                 $dialog->show_all;
35         });
36 #$bb->set_sensitive(0);
37
38 my $store = Gtk2::ListStore->new('Glib::Uint', 'Glib::String');
39 for (my $i=0; $i<10; $i++) {
40         my $iter = $store->append;
41         $store->set($iter, 0, $i, 1, "Hey ($i)");
42 }
43
44 my $tree = Gtk2::TreeView->new($store);
45 my $rend = Gtk2::CellRendererText->new;
46 my $col = Gtk2::TreeViewColumn->new_with_attributes("Int", $rend, "text", 0);
47 $tree->append_column($col);
48 $col = Gtk2::TreeViewColumn->new_with_attributes("String", $rend, "text", 1);
49 $tree->append_column($col);
50
51 my $sel = $tree->get_selection;
52 $sel->set_mode('single');
53 $sel->signal_connect(changed => sub {
54         my $iter = $_[0]->get_selected;
55         my $val = $store->get($iter, 0);
56         print "Selected $val\n";
57         });
58
59 my $lay = Gtk2::ScrolledWindow->new;
60 $lay->set_policy("automatic", "automatic");
61 $lay->add($tree);
62
63 my $lab = Gtk2::Label->new;
64 $lab->set_markup("<span size='x-large'>Welcome to the Cave</span>");
65
66 my $bar = Gtk2::Statusbar->new;
67 my $barctx = $bar->get_context_id('xyzzy');
68 $bar->push($barctx, "Ready");
69
70 my $bbox = Gtk2::VBox->new();
71 $bbox->pack_start($lab, 0, 0, 0);
72 $bbox->pack_start($box, 0, 0, 0);
73 $bbox->pack_start($lay, 1, 1, 0);
74 $bbox->pack_start($bb, 0, 0, 0);
75 $bbox->pack_start($bar, 0, 0, 0);
76
77 $window->signal_connect ("delete-event" => sub { Gtk2->main_quit });
78 $window->set_title("Brum");
79 $window->set_wmclass("submit", "Submit");
80 $window->set_default_size(320, 400);
81 $window->add ($bbox);
82 $window->show_all;
83
84 $window->window->set_cursor($cursor);
85 #$window->window->set_cursor(undef);
86
87 Gtk2->main;