Debian Codegraph @

Debconf/Element/Gnome.pm

raw
1 #!/usr/bin/perl
2
3 =head1 NAME
4
5 Debconf::Element::Gnome - gnome UI element
6
7 =cut
8
9 package Debconf::Element::Gnome;
10 use warnings;
11 use strict;
12 use utf8;
13 use Gtk3;
14 use Debconf::Gettext;
15 use Debconf::Encoding qw(to_Unicode);
16 use base qw(Debconf::Element);
17
18 =head1 DESCRIPTION
19
20 This is a type of Element used by the gnome FrontEnd. It contains a hbox,
21 into which the gnome UI element and any associated lables, help buttons,
22 etc, are packaged.
23
24 =head1 FIELDS
25
26 =over 4
27
28 =item hbox
29
30 This is the hbox that holds all the widgets for this element.
31
32 =back
33
34 =head1 METHODS
35
36 =over 4
37
38 =item init
39
40 Sets up the hbox.
41
42 =cut
43
44 sub init {
45 my $this=shift;
46
47 $this->hbox(Gtk3::VBox->new(0, 10));
48
49 $this->hline1(Gtk3::HBox->new(0, 10));
50 $this->hline1->show;
51 $this->line1(Gtk3::VBox->new(0, 10));
52 $this->line1->show;
53 $this->line1->pack_end ($this->hline1, 1, 1, 0);
54
55 $this->hline2(Gtk3::HBox->new(0, 10));
56 $this->hline2->show;
57 $this->line2(Gtk3::VBox->new(0, 10));
58 $this->line2->show;
59 $this->line2->pack_end ($this->hline2, 1, 1, 0);
60
61 $this->vbox(Gtk3::VBox->new(0, 5));
62 $this->vbox->pack_start($this->line1, 0, 0, 0);
63 $this->vbox->pack_start($this->line2, 1, 1, 0);
64 $this->vbox->show;
65
66 $this->hbox->pack_start($this->vbox, 1, 1, 0);
67 $this->hbox->show;
68
69 # default is not to be expanded or to filled
70 $this->fill(0);
71 $this->expand(0);
72 $this->multiline(0);
73 }
74
75 =item addwidget
76
77 Packs the passed widget into the hbox.
78
79 =cut
80
81 sub addwidget {
82 my $this=shift;
83 my $widget=shift;
84
85 if ($this->multiline == 0) {
86 $this->hline1->pack_start($widget, 1, 1, 0);
87 }
88 else {
89 $this->hline2->pack_start($widget, 1, 1, 0);
90 }
91 }
92
93 =item adddescription
94
95 Packs a label containing the short description into the hbox.
96
97 =cut
98
99 sub adddescription {
100 my $this=shift;
101 my $description=to_Unicode($this->question->description);
102
103 my $label=Gtk3::Label->new($description);
104 $label->show;
105 $this->line1->pack_start($label, 0, 0, 0);
106 }
107
108 =item addbutton
109
110 Packs a button into the first line of the hbox. The button is added
111 at the end of the box.
112
113 =cut
114
115 sub addbutton {
116 my $this=shift;
117 my $text = shift;
118 my $callback = shift;
119
120 my $button = Gtk3::Button->new_with_mnemonic(to_Unicode($text));
121 $button->show;
122 $button->signal_connect("clicked", $callback);
123
124 my $vbox = Gtk3::VBox->new(0, 0);
125 $vbox->show;
126 $vbox->pack_start($button, 1, 0, 0);
127 $this->hline1->pack_end($vbox, 0, 0, 0);
128 }
129
130 =item create_message_dialog
131
132 This is needed because Gtk3::MessageDialog has a much
133 worse behavior than the other Gtk3:: perl widgets when
134 it comes to an UTF-8 locale.
135
136 (This was originally written for Gtk2; is it still true for Gtk3?)
137
138 =cut
139
140 sub create_message_dialog {
141 my $this = shift;
142 my $type = shift;
143 my $title = shift;
144 my $text = shift;
145
146 my $dialog =
147 Gtk3::Dialog->new_with_buttons(to_Unicode($title), undef,
148 "modal", "gtk-close", "close");
149 $dialog->set_border_width(3);
150
151 my $hbox = Gtk3::HBox->new(0);
152 $dialog->get_content_area->pack_start($hbox, 1, 1, 5);
153 $hbox->show;
154
155 my $alignment = Gtk3::Alignment->new(0.5, 0.0, 1.0, 0.0);
156 $hbox->pack_start($alignment, 1, 1, 3);
157 $alignment->show;
158
159 my $image = Gtk3::Image->new_from_stock($type, "dialog");
160 $alignment->add($image);
161 $image->show;
162
163 my $label = Gtk3::Label->new(to_Unicode($text));
164 $label->set_line_wrap(1);
165 $hbox->pack_start($label, 1, 1, 2);
166 $label->show;
167
168 $dialog->run;
169 $dialog->destroy;
170 }
171
172 =item addhelp
173
174 Packs a help button into the hbox. The button is omitted if there is no
175 extended description to display as help.
176
177 =cut
178
179 sub addhelp {
180 my $this=shift;
181
182 my $help=$this->question->extended_description;
183 return unless length $help;
184
185 $this->addbutton(gettext("_Help"), sub {
186 $this->create_message_dialog("gtk-dialog-info",
187 gettext("Help"),
188 to_Unicode($help));
189 });
190
191 if (defined $this->tip ){
192 $this->tip->set_tooltip_text(to_Unicode($help));
193 }
194 }
195
196 =item value
197
198 Return the value the user entered.
199
200 Defaults to returning nothing.
201
202 =cut
203
204 sub value {
205 my $this=shift;
206
207 return '';
208 }
209
210 =back
211
212 =head1 AUTHOR
213
214 Eric Gillespie <[email protected]>
215 Gustavo Noronha Silva <[email protected]>
216
217 =cut
218
219 1