-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
dialog_boxes.pl
140 lines (112 loc) · 4.3 KB
/
dialog_boxes.pl
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
#!/usr/bin/perl
#
# Dialog and Message Boxes
#
# Dialog widgets are used to pop up a transient window for user feedback.
#
# Perl version by Dave M <dave.nerd@gmail.com>
use strict;
use warnings;
use feature 'state';
use Gtk3 '-init';
use Glib 'TRUE', 'FALSE';
my ( $entry1, $entry2 );
my $window = Gtk3::Window->new('toplevel');
$window->set_title('Dialogs');
$window->signal_connect( destroy => sub { Gtk3->main_quit } );
$window->set_border_width(8);
my $icon = 'gtk-logo-rgb.gif';
if ( -e $icon ) {
my $pixbuf = Gtk3::Gdk::Pixbuf->new_from_file($icon);
my $transparent = $pixbuf->add_alpha( TRUE, 0xff, 0xff, 0xff );
$window->set_icon($transparent);
}
my $frame = Gtk3::Frame->new('Dialogs');
$window->add($frame);
my $vbox = Gtk3::Box->new( 'vertical', 8 );
$vbox->set_border_width(8);
$frame->add($vbox);
# Standard message dialog
my $hbox = Gtk3::Box->new( 'horizontal', 8 );
$vbox->pack_start( $hbox, FALSE, FALSE, 0 );
my $button = Gtk3::Button->new_with_mnemonic('_Message Dialog');
$button->signal_connect( clicked => \&message_dialog_clicked );
$hbox->pack_start( $button, FALSE, FALSE, 0 );
$vbox->pack_start( Gtk3::Separator->new('horizontal'), FALSE, FALSE, 0 );
# Interactive dialog
$hbox = Gtk3::Box->new( 'horizontal', 8 );
$vbox->pack_start( $hbox, FALSE, FALSE, 0 );
my $vbox2 = Gtk3::Box->new( 'vertical', 0 );
$button = Gtk3::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 = Gtk3::Grid->new();
$table->set_row_spacing(4);
$table->set_column_spacing(4);
$hbox->pack_start( $table, FALSE, FALSE, 0 );
my $label = Gtk3::Label->new_with_mnemonic('_Entry 1');
$table->attach( $label, 0, 0, 1, 1 );
$entry1 = Gtk3::Entry->new();
$table->attach( $entry1, 1, 0, 1, 1 );
$label->set_mnemonic_widget($entry1);
$label = Gtk3::Label->new_with_mnemonic('E_ntry 2');
$table->attach( $label, 0, 1, 1, 1 );
$entry2 = Gtk3::Entry->new();
$table->attach( $entry2, 1, 1, 1, 1 );
$window->show_all;
Gtk3->main;
sub message_dialog_clicked {
state $i = 1;
# format_secondary_text not implemented yet
my $dialog = Gtk3::MessageDialog->new(
$window,
[qw( modal destroy-with-parent )],
'info',
'ok',
"This messagebox has been popped up the following\n"
. "number of times: $i"
);
$dialog->run;
$dialog->destroy;
$i++;
}
sub interactive_dialog_clicked {
# new_with_buttons not implemented yet
my $dialog = Gtk3::Dialog->new();
$dialog->set_title('Interactive Dialog');
$dialog->set_modal(TRUE);
$dialog->set_destroy_with_parent(TRUE);
$dialog->add_button( 'gtk-ok', 'ok' );
my $hbox = Gtk3::Box->new( 'horizontal', 8 );
$hbox->set_border_width(8);
$dialog->get_content_area()->add($hbox);
my $stock = Gtk3::Image->new_from_stock( 'gtk-dialog-question', 6 );
$hbox->pack_start( $stock, FALSE, FALSE, 0 );
my $table = Gtk3::Grid->new();
$table->set_row_spacing(4);
$table->set_column_spacing(4);
$hbox->pack_start( $table, TRUE, TRUE, 0 );
my $label = Gtk3::Label->new_with_mnemonic('_Entry 1');
$table->attach( $label, 0, 0, 1, 1 );
my $local_entry1 = Gtk3::Entry->new();
$local_entry1->set_text( $entry1->get_text() );
$table->attach( $local_entry1, 1, 0, 1, 1 );
$label->set_mnemonic_widget($local_entry1);
$label = Gtk3::Label->new_with_mnemonic('E_ntry 2');
$table->attach( $label, 0, 1, 1, 1 );
my $local_entry2 = Gtk3::Entry->new();
$local_entry2->set_text( $entry2->get_text() );
$table->attach( $local_entry2, 1, 1, 1, 1 );
$label->set_mnemonic_widget($local_entry2);
$hbox->show_all();
if ( 'ok' eq $dialog->run ) {
$entry1->set_text( $local_entry1->get_text );
$entry2->set_text( $local_entry2->get_text );
}
$dialog->destroy;
}
# 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.