File: dialog.pl

package info (click to toggle)
libgtk2-perl 1%3A1.140-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,808 kB
  • ctags: 609
  • sloc: perl: 14,245; ansic: 118; makefile: 70
file content (159 lines) | stat: -rw-r--r-- 4,917 bytes parent folder | download | duplicates (8)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/perl -w
#
# Dialog and Message Boxes
#
# Dialog widgets are used to pop up a transient window for user feedback.
#

package dialog;

use Glib qw(TRUE FALSE);
use Gtk2;

my $window = undef;
my $entry1 = undef;
my $entry2 = undef;

my $i = 1;

sub message_dialog_clicked {
  my $dialog = Gtk2::MessageDialog->new ($window,
				   [qw/modal destroy-with-parent/],
				   'info',
				   'ok',
				   sprintf "This message box has been popped up the following\nnumber of times:\n\n%d", $i);
  $dialog->run;
  $dialog->destroy;
  $i++;
}

sub interactive_dialog_clicked {
  #my $dialog = Gtk2::Dialog->new_with_buttons ("Interactive Dialog",
  my $dialog = Gtk2::Dialog->new ("Interactive Dialog",
					$window,
					[qw/modal destroy-with-parent/],
					'gtk-ok',
					'ok',
                                        "_Non-stock Button",
                                        'cancel');

  my $hbox = Gtk2::HBox->new (FALSE, 8);
  $hbox->set_border_width (8);
  $dialog->vbox->pack_start ($hbox, FALSE, FALSE, 0);

  my $stock = Gtk2::Image->new_from_stock ('gtk-dialog-question', 'dialog');
  $hbox->pack_start ($stock, FALSE, FALSE, 0);

  my $table = Gtk2::Table->new (2, 2, FALSE);
  $table->set_row_spacings (4);
  $table->set_col_spacings (4);
  $hbox->pack_start ($table, TRUE, TRUE, 0);
  my $label = Gtk2::Label->new_with_mnemonic ("_Entry 1");
  $table->attach_defaults ($label, 0, 1, 0, 1);
  my $local_entry1 = Gtk2::Entry->new;
  $local_entry1->set_text ($entry1->get_text);
  $table->attach_defaults ($local_entry1, 1, 2, 0, 1);
  $label->set_mnemonic_widget ($local_entry1);

  $label = Gtk2::Label->new_with_mnemonic ("E_ntry 2");
  $table->attach_defaults ($label, 0, 1, 1, 2);

  my $local_entry2 = Gtk2::Entry->new;
  $local_entry2->set_text ($entry2->get_text);
  $table->attach_defaults ($local_entry2, 1, 2, 1, 2);
  $label->set_mnemonic_widget ($local_entry2);
  
  $hbox->show_all;
  my $response = $dialog->run;

  if ($response eq 'ok') {
      $entry1->set_text ($local_entry1->get_text);
      $entry2->set_text ($local_entry2->get_text);
  }

  $dialog->destroy;
}

sub do {
  if (!$window) {
      $window = Gtk2::Window->new;
      $window->set_title ("Dialogs");

      $window->signal_connect (destroy => sub { $window = undef; 1 });
      $window->set_border_width (8);

      my $frame = Gtk2::Frame->new ("Dialogs");
      $window->add ($frame);

      my $vbox = Gtk2::VBox->new (FALSE, 8);
      $vbox->set_border_width (8);
      $frame->add ($vbox);

      # Standard message dialog
      my $hbox = Gtk2::HBox->new (FALSE, 8);
      $vbox->pack_start ($hbox, FALSE, FALSE, 0);
      my $button = Gtk2::Button->new_with_mnemonic ("_Message Dialog");
      $button->signal_connect (clicked => \&message_dialog_clicked);
      $hbox->pack_start ($button, FALSE, FALSE, 0);

      $vbox->pack_start (Gtk2::HSeparator->new, FALSE, FALSE, 0);

      # Interactive dialog
      $hbox = Gtk2::HBox->new (FALSE, 8);
      $vbox->pack_start ($hbox, FALSE, FALSE, 0);
      $vbox2 = Gtk2::VBox->new (FALSE, 0);

      $button = Gtk2::Button->new_with_mnemonic ("_Interactive Dialog");
      $button->signal_connect (clicked => \&interactive_dialog_clicked);
      $hbox->pack_start ($vbox2, FALSE, FALSE, 0);
      $vbox2->pack_start ($button, FALSE, FALSE, 0);

      my $table = Gtk2::Table->new (2, 2, FALSE);
      $table->set_row_spacings (4);
      $table->set_col_spacings (4);
      $hbox->pack_start ($table, FALSE, FALSE, 0);

      my $label = Gtk2::Label->new_with_mnemonic ("_Entry 1");
      $table->attach_defaults ($label, 0, 1, 0, 1);

      $entry1 = Gtk2::Entry->new;
      $table->attach_defaults ($entry1, 1, 2, 0, 1);
      $label->set_mnemonic_widget ($entry1);

      $label = Gtk2::Label->new_with_mnemonic ("E_ntry 2");
      
      $table->attach_defaults ($label, 0, 1, 1, 2);

      $entry2 = Gtk2::Entry->new;
      $table->attach_defaults ($entry2, 1, 2, 1, 2);
      $label->set_mnemonic_widget ($entry2);
  }

  if (!$window->visible) {
      $window->show_all;
  } else {    
      $window->destroy;
      $window = undef;
  }

  return $window;
}

1;
__END__
Copyright (C) 2003 by the gtk2-perl team (see the file AUTHORS for the
full list)

This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Library General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option) any
later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.  See the GNU Library General Public License for more
details.

You should have received a copy of the GNU Library General Public License along
with this library; if not, write to the Free Software Foundation, Inc., 59
Temple Place - Suite 330, Boston, MA  02111-1307  USA.