]> mj.ucw.cz Git - moe.git/blob - submit/gtktest.pl
MOP: New template for home directories (KDE config etc.)
[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 $box->set_border_width(5);
29
30 my $bb = Gtk2::Button->new ('Brum!');
31 $bb->signal_connect (clicked => sub {
32                 my $dialog = Gtk2::MessageDialog->new($window, [qw/modal destroy-with-parent/], 'question', 'ok-cancel', "So what?");
33                 $dialog->set_default_response("ok");
34                 $dialog->signal_connect (response => sub { $_[0]->destroy });
35                 $dialog->show_all;
36         });
37 #$bb->set_sensitive(0);
38
39 my $store = Gtk2::ListStore->new('Glib::Uint', 'Glib::String');
40 for (my $i=0; $i<10; $i++) {
41         my $iter = $store->append;
42         $store->set($iter, 0, $i, 1, "Hey ($i)");
43 }
44
45 my $tree = Gtk2::TreeView->new($store);
46 my $rend = Gtk2::CellRendererText->new;
47 my $col = Gtk2::TreeViewColumn->new_with_attributes("Int", $rend, "text", 0);
48 $tree->append_column($col);
49 $col = Gtk2::TreeViewColumn->new_with_attributes("String", $rend, "text", 1);
50 $tree->append_column($col);
51 $tree->set_headers_visible(0);
52
53 my $lay = Gtk2::ScrolledWindow->new;
54 $lay->set_policy("automatic", "automatic");
55 $lay->add($tree);
56 $lay->set_border_width(5);
57
58 my $frame = Gtk2::Frame->new("A list");
59 $frame->add($lay);
60
61 my $sel = $tree->get_selection;
62 $sel->set_mode('single');
63 $sel->signal_connect(changed => sub {
64         my $iter = $_[0]->get_selected;
65         my $val = $store->get($iter, 0);
66         print "Selected $val\n";
67         });
68
69 my $lab = Gtk2::Label->new;
70 $lab->set_markup("<span size='x-large'>Welcome to the Cave</span>");
71
72 my $bar = Gtk2::Statusbar->new;
73 my $barctx = $bar->get_context_id('xyzzy');
74 $bar->push($barctx, "Ready");
75
76 my $bbox = Gtk2::VBox->new();
77 $bbox->pack_start($lab, 0, 0, 0);
78 $bbox->pack_start($box, 0, 0, 0);
79 $bbox->pack_start($frame, 1, 1, 0);
80 $bbox->pack_start($bb, 0, 0, 0);
81 $bbox->pack_start($bar, 0, 0, 0);
82
83 $window->signal_connect ("delete-event" => sub { Gtk2->main_quit });
84 $window->set_title("Brum");
85 $window->set_wmclass("submit", "Submit");
86 $window->set_default_size(320, 400);
87 $window->add ($bbox);
88 $window->show_all;
89
90 #$window->window->set_cursor($cursor);
91 #$window->window->set_cursor(undef);
92
93 Gtk2->main;