line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gtk2::Ex::Dialogs; |
2
|
|
|
|
|
|
|
############################################################################### |
3
|
|
|
|
|
|
|
# Gtk2::Ex::Dialogs - Useful tools for Gnome2/Gtk2 Perl GUI design. |
4
|
|
|
|
|
|
|
# Copyright (C) 2005 Open Door Software Inc. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# This library is free software; you can redistribute it and/or |
7
|
|
|
|
|
|
|
# modify it under the terms of the GNU Lesser General Public |
8
|
|
|
|
|
|
|
# License as published by the Free Software Foundation; either |
9
|
|
|
|
|
|
|
# version 2.1 of the License, or (at your option) any later version. |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# This library is distributed in the hope that it will be useful, |
12
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14
|
|
|
|
|
|
|
# Lesser General Public License for more details. |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# You should have received a copy of the GNU Lesser General Public |
17
|
|
|
|
|
|
|
# License along with this library; if not, write to the Free Software |
18
|
|
|
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19
|
|
|
|
|
|
|
############################################################################### |
20
|
1
|
|
|
1
|
|
28221
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
BEGIN { |
23
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
104
|
|
24
|
1
|
|
|
1
|
|
6
|
use constant FALSE => 0; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
91
|
|
25
|
1
|
|
|
1
|
|
1498
|
use Gtk2::Ex::Dialogs::Message; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use Gtk2::Ex::Dialogs::ErrorMsg; |
27
|
|
|
|
|
|
|
use Gtk2::Ex::Dialogs::Question; |
28
|
|
|
|
|
|
|
use Gtk2::Ex::Dialogs::ChooseFile; |
29
|
|
|
|
|
|
|
use Gtk2::Ex::Dialogs::ChoosePreviewFile; |
30
|
|
|
|
|
|
|
use Gtk2::Ex::Dialogs::ChooseDirectory; |
31
|
|
|
|
|
|
|
use vars qw( $VERSION $parent_window $title $icon $text |
32
|
|
|
|
|
|
|
$destroy_with_parent $modal $no_separator |
33
|
|
|
|
|
|
|
$default_yes $must_exist $AUTOLOAD ); |
34
|
|
|
|
|
|
|
$VERSION = '0.11'; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub import { |
38
|
|
|
|
|
|
|
my $class = shift(); |
39
|
|
|
|
|
|
|
my $cfg = undef; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
if ( @_ % 2 == 0 ) { |
42
|
|
|
|
|
|
|
$cfg = { @_ }; |
43
|
|
|
|
|
|
|
} elsif ( @_ % 2 >= 1 ) { |
44
|
|
|
|
|
|
|
croak( $class . " class received an uneven argument list." ); |
45
|
|
|
|
|
|
|
} else { |
46
|
|
|
|
|
|
|
$cfg = {}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::title = |
50
|
|
|
|
|
|
|
$cfg->{title} || ''; |
51
|
|
|
|
|
|
|
Gtk2::Ex::Dialogs->set_title( $Gtk2::Ex::Dialogs::title ); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::text = |
54
|
|
|
|
|
|
|
$cfg->{text} || ''; |
55
|
|
|
|
|
|
|
Gtk2::Ex::Dialogs->set_text( $Gtk2::Ex::Dialogs::text ); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::icon = |
58
|
|
|
|
|
|
|
$cfg->{icon} || ''; |
59
|
|
|
|
|
|
|
Gtk2::Ex::Dialogs->set_icon( $Gtk2::Ex::Dialogs::icon ); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::modal = |
62
|
|
|
|
|
|
|
$cfg->{modal} || FALSE; |
63
|
|
|
|
|
|
|
Gtk2::Ex::Dialogs->set_modal( $Gtk2::Ex::Dialogs::modal ); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::no_separator = |
66
|
|
|
|
|
|
|
$cfg->{no_separator} || FALSE; |
67
|
|
|
|
|
|
|
Gtk2::Ex::Dialogs->set_no_separator( $Gtk2::Ex::Dialogs::no_separator ); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::parent_window = |
70
|
|
|
|
|
|
|
$cfg->{parent_window} || undef; |
71
|
|
|
|
|
|
|
Gtk2::Ex::Dialogs->set_parent_window( $Gtk2::Ex::Dialogs::parent_window ); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::destroy_with_parent = |
74
|
|
|
|
|
|
|
$cfg->{destroy_with_parent} || FALSE; |
75
|
|
|
|
|
|
|
Gtk2::Ex::Dialogs->set_destroy_with_parent( $Gtk2::Ex::Dialogs::destroy_with_parent ); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::default_yes = |
78
|
|
|
|
|
|
|
$cfg->{"default_yes"} || FALSE; |
79
|
|
|
|
|
|
|
Gtk2::Ex::Dialogs->set_default_yes( $Gtk2::Ex::Dialogs::default_yes ); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::must_exist = |
82
|
|
|
|
|
|
|
$cfg->{must_exist} || FALSE; |
83
|
|
|
|
|
|
|
Gtk2::Ex::Dialogs->set_must_exist( $Gtk2::Ex::Dialogs::must_exist ); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub AUTOLOAD { |
88
|
|
|
|
|
|
|
my $class = $_[0]; |
89
|
|
|
|
|
|
|
my $value = $_[1]; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $method = $AUTOLOAD; |
92
|
|
|
|
|
|
|
$method =~ s!^\Q$class\E\:\:!!; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
if ( $method eq 'set_title' ) { |
95
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::title = $value; |
96
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ChooseDirectory::title = $value; |
97
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ChooseFile::title = $value; |
98
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ChoosePreviewFile::title = $value; |
99
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ErrorMsg::title = $value; |
100
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::Message::title = $value; |
101
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::Question::title = $value; |
102
|
|
|
|
|
|
|
} elsif ( $method eq 'set_text' ) { |
103
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::text = $value; |
104
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ErrorMsg::text = $value; |
105
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::Message::text = $value; |
106
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::Question::text = $value; |
107
|
|
|
|
|
|
|
} elsif ( $method eq 'set_icon' ) { |
108
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::icon = $value; |
109
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ErrorMsg::icon = $value; |
110
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::Message::icon = $value; |
111
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::Question::icon = $value; |
112
|
|
|
|
|
|
|
} elsif ( $method eq 'set_modal' ) { |
113
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::modal = $value; |
114
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ChooseDirectory::modal = $value; |
115
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ChooseFile::modal = $value; |
116
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ChoosePreviewFile::modal = $value; |
117
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ErrorMsg::modal = $value; |
118
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::Message::modal = $value; |
119
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::Question::modal = $value; |
120
|
|
|
|
|
|
|
} elsif ( $method eq 'set_no_separator' ) { |
121
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::no_separator = $value; |
122
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ErrorMsg::no_separator = $value; |
123
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::Message::no_separator = $value; |
124
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::Question::no_separator = $value; |
125
|
|
|
|
|
|
|
} elsif ( $method eq 'set_parent_window' ) { |
126
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::parent_window = $value; |
127
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ChooseDirectory::parent_window = $value; |
128
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ChooseFile::parent_window = $value; |
129
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ChoosePreviewFile::parent_window = $value; |
130
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ErrorMsg::parent_window = $value; |
131
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::Message::parent_window = $value; |
132
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::Question::parent_window = $value; |
133
|
|
|
|
|
|
|
} elsif ( $method eq 'set_destroy_with_parent' ) { |
134
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::destroy_with_parent = $value; |
135
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ChooseDirectory::destroy_with_parent = $value; |
136
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ChooseFile::destroy_with_parent = $value; |
137
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ChoosePreviewFile::destroy_with_parent = $value; |
138
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ErrorMsg::destroy_with_parent = $value; |
139
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::Message::destroy_with_parent = $value; |
140
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::Question::destroy_with_parent = $value; |
141
|
|
|
|
|
|
|
} elsif ( $method eq 'set_default_yes' ) { |
142
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::default_yes = $value; |
143
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::Question::default_yes = $value; |
144
|
|
|
|
|
|
|
} elsif ( $method eq 'set_must_exist' ) { |
145
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::must_exist = $value; |
146
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ChooseDirectory::must_exist = $value; |
147
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ChooseFile::must_exist = $value; |
148
|
|
|
|
|
|
|
$Gtk2::Ex::Dialogs::ChoosePreviewFile::must_exist = $value; |
149
|
|
|
|
|
|
|
} else { |
150
|
|
|
|
|
|
|
croak( $class . " does not have a method called " . $AUTOLOAD . "()." ); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
return( $value ); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 NAME |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Gtk2::Ex::Dialogs - Useful tools for Gnome2/Gtk2 Perl GUI design. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 SYNOPSIS |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
use Gtk2::Ex::Dialogs ( destroy_with_parent => TRUE, |
163
|
|
|
|
|
|
|
modal => TRUE, |
164
|
|
|
|
|
|
|
no_separator => FALSE ); |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# do some stuff like creating your app's main $window then, |
167
|
|
|
|
|
|
|
# to ensure that all messages use the right parent, set it: |
168
|
|
|
|
|
|
|
Gtk2::Ex::Dialogs->set_parent_window( $window ); |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# now popup a new dialog |
171
|
|
|
|
|
|
|
my $r = ask Gtk2::Ex::Dialogs::Question ( "Is Perl only hacker's glue?" ); |
172
|
|
|
|
|
|
|
if ( $r ) { |
173
|
|
|
|
|
|
|
# end-user thinks so |
174
|
|
|
|
|
|
|
} else { |
175
|
|
|
|
|
|
|
# end-user does not think so |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# now popup a new dialog ( blocking the main loop if there is one ) |
179
|
|
|
|
|
|
|
new_and_run |
180
|
|
|
|
|
|
|
Gtk2::Ex::Dialogs::Message ( title => "Dialog Title", |
181
|
|
|
|
|
|
|
text => "This is a simple message" ); |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# now popup a new dialog ( blocking the main loop if there is one ) |
184
|
|
|
|
|
|
|
new_and_run |
185
|
|
|
|
|
|
|
Gtk2::Ex::Dialogs::ErrorMsg ( "Simple error message." ); |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 DESCRIPTION |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
This module provides the Gtk2::Ex::Dialogs::Message, Gtk2::Ex::Dialogs::ErrorMsg and |
190
|
|
|
|
|
|
|
Gtk2::Ex::Dialogs::Question classes to the main application while setting the initial |
191
|
|
|
|
|
|
|
defaults to those specified upon using Gtk2::Ex::Dialogs. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 OPTIONS |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Gtk2::Ex::Dialogs supports the following options: |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=over |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item B => STRING |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
The title of the dialog window. Defaults to an empty string. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item B => STRING |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
The text to be displayed. This is the core purpose of the module and is the |
206
|
|
|
|
|
|
|
only mandatory argument. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item B => /path/to/image || stock-id || Gtk2::Gdk::Pixbuf || Gtk2::Image |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
The dialog-sized image to place to the left of the text. Note: there are five |
211
|
|
|
|
|
|
|
aliased stock-ids which correspond to the five gtk-dialog-* ids, "warning", |
212
|
|
|
|
|
|
|
"question", "info", "error" and "authentication". Defaults to the stock-id |
213
|
|
|
|
|
|
|
"gtk-dialog-question". |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item B => Gtk2::Window |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Reference to the main application window. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=item B => BOOL |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
When the B is destroyed, what do we do? Defaults to FALSE. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item B => BOOL |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Does this message make the B freeze while the message exists. |
226
|
|
|
|
|
|
|
Defaults to FALSE. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=item B => BOOL |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Draw the horizontal separator between the content area and the button area |
231
|
|
|
|
|
|
|
below. Defaults to FALSE. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=item B => BOOL |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Autofocus on the "YES" button. Defaults to FALSE. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=item B => BOOL |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
The end-user must supply a path to an existing file or directory. Should the |
240
|
|
|
|
|
|
|
end-user provide a non-existant path, the dialog will be respawned until an |
241
|
|
|
|
|
|
|
existing file is chosen. Defaults to FALSE. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=back |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 FUNCTIONS |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
This module provides a "set_" function for all options that takes a signle |
248
|
|
|
|
|
|
|
argument that is then used as the default for all three modules |
249
|
|
|
|
|
|
|
Gtk2::Ex::Dialogs::Message, Gtk2::Ex::Dialogs::ErrorMsg and Gtk2::Ex::Dialogs::Question. For clarity, |
250
|
|
|
|
|
|
|
the function names are as follows: |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=over |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=item Gtk2::Ex::Dialogs->set_title |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=item Gtk2::Ex::Dialogs->set_text |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=item Gtk2::Ex::Dialogs->set_icon |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=item Gtk2::Ex::Dialogs->set_modal |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=item Gtk2::Ex::Dialogs->set_parent_window |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=item Gtk2::Ex::Dialogs->set_destroy_with_parent |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=item Gtk2::Ex::Dialogs->set_default_yes |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=item Gtk2::Ex::Dialogs->set_must_exist |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=back |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=cut |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
1; |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
__END__ |