| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#! /usr/bin/env perl |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Tk::Panel; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
81561
|
use 5.014000; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
39
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
30
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
37
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use vars qw(@ISA $VERSION); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
158
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
598
|
use Tk; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Carp; |
|
13
|
|
|
|
|
|
|
require Tk::Widget; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '1.5'; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Construct Tk::Widget 'Panel'; |
|
18
|
|
|
|
|
|
|
use base qw(Tk::Derived Tk::Frame); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub debug {}; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Class initialisation function. |
|
23
|
|
|
|
|
|
|
# Called exactly once for each MainWindow widget tree, just |
|
24
|
|
|
|
|
|
|
# before the first widget is created. |
|
25
|
|
|
|
|
|
|
sub ClassInit |
|
26
|
|
|
|
|
|
|
{ |
|
27
|
|
|
|
|
|
|
debug "args: @_\n"; |
|
28
|
|
|
|
|
|
|
# nothing. |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Constructor. Uses new inherited from base class |
|
32
|
|
|
|
|
|
|
sub Populate |
|
33
|
|
|
|
|
|
|
{ |
|
34
|
|
|
|
|
|
|
debug "args: @_\n"; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $self = shift; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$self->SUPER::Populate(@_); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Create 2 more frames, boundary with groove, and inside. |
|
41
|
|
|
|
|
|
|
$self->{boundary} = $self->Component('Frame', 'boundary'); |
|
42
|
|
|
|
|
|
|
$self->{inside} = $self->Component('Frame', 'inside'); |
|
43
|
|
|
|
|
|
|
# Create the title widgets. |
|
44
|
|
|
|
|
|
|
$self->{label} = $self->Component('Label', 'label'); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$self->{check} = $self->Component('Checkbutton', 'check', |
|
47
|
|
|
|
|
|
|
-variable => \$self->{Configure}->{'-show'}, |
|
48
|
|
|
|
|
|
|
-command => [ 'refresh', $self ], |
|
49
|
|
|
|
|
|
|
); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
#debug "boundary: $self->{boundary}\n"; |
|
52
|
|
|
|
|
|
|
#debug "inside: $self->{inside}\n"; |
|
53
|
|
|
|
|
|
|
#debug "check: $self->{check}\n"; |
|
54
|
|
|
|
|
|
|
#debug "label: $self->{label}\n"; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Set up extra configuration |
|
57
|
|
|
|
|
|
|
$self->ConfigSpecs( |
|
58
|
|
|
|
|
|
|
'-relief' => [$self->{boundary},'relief','Relief','groove'], |
|
59
|
|
|
|
|
|
|
'-border' => [$self->{boundary},'borderwidth','BorderWidth', 3], |
|
60
|
|
|
|
|
|
|
'-background' => [['SELF','DESCENDANTS'],undef,undef, undef], |
|
61
|
|
|
|
|
|
|
'-foreground' => [['SELF','DESCENDANTS'],undef,undef, undef], |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
'-margin' => ['PASSIVE','margin','Margin', 10], |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
'-text' => [ |
|
66
|
|
|
|
|
|
|
[$self->{check}, $self->{label}], |
|
67
|
|
|
|
|
|
|
'text','Text', ''], |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
'-show' => ['PASSIVE','','', 1], |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
'-flatheight' => ['PASSIVE','','', 'standard'], |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
'-state' => [$self->{check},'','', 'active'], |
|
74
|
|
|
|
|
|
|
'-toggle' => ['PASSIVE','','', 1], |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
'-fg' => '-foreground', |
|
77
|
|
|
|
|
|
|
'-bg' => '-background', |
|
78
|
|
|
|
|
|
|
); |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Where to create children. |
|
81
|
|
|
|
|
|
|
$self->Delegates('Construct' => $self->{inside}); |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$self; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# DoWhenIdle seems to be replaced by afterIdle in Tk800.018. |
|
87
|
|
|
|
|
|
|
sub afterIdle { &DoWhenIdle; } |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
;## Update the widget when you get a chance. |
|
90
|
|
|
|
|
|
|
sub DoWhenIdle |
|
91
|
|
|
|
|
|
|
{ |
|
92
|
|
|
|
|
|
|
debug "args: @_\n"; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $self = shift; |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
$self->refresh(); |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub refresh |
|
100
|
|
|
|
|
|
|
{ |
|
101
|
|
|
|
|
|
|
debug "args: @_\n"; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $self = shift; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
local ($_); |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# ------------- display the title. --------------- |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Choose which title widget is on and which is off. |
|
110
|
|
|
|
|
|
|
my ($on, $off) = $self->cget('-toggle') ? |
|
111
|
|
|
|
|
|
|
qw(check label) : |
|
112
|
|
|
|
|
|
|
qw(label check) ; |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# Turn off the one we don't want. |
|
115
|
|
|
|
|
|
|
$self->{$off}->placeForget(); |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# position the one we do want to see. |
|
118
|
|
|
|
|
|
|
my $h = $self->{$on}->ReqHeight; |
|
119
|
|
|
|
|
|
|
my $b = $self->cget('-border'); |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
debug "label height $h\n"; |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
$self->{$on}->place( |
|
124
|
|
|
|
|
|
|
'-in' => $self->{boundary}, |
|
125
|
|
|
|
|
|
|
'-relx' => 0.05, |
|
126
|
|
|
|
|
|
|
'-y' => -0.5 * $h - 0.5*$b, |
|
127
|
|
|
|
|
|
|
); |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# If there is no real title and its the label that |
|
130
|
|
|
|
|
|
|
# requested then don't show it. Otherwise a gap |
|
131
|
|
|
|
|
|
|
# appears in the boundary. |
|
132
|
|
|
|
|
|
|
$self->{label}->placeForget() |
|
133
|
|
|
|
|
|
|
if ($self->cget('-text') eq '' && $on eq 'label'); |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# ---------- Set the margins. ----------------- |
|
136
|
|
|
|
|
|
|
my $m = $self->cget('-margin'); |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my @config = ( |
|
139
|
|
|
|
|
|
|
-padx => $m, |
|
140
|
|
|
|
|
|
|
-pady => $m, |
|
141
|
|
|
|
|
|
|
-fill => "both", |
|
142
|
|
|
|
|
|
|
-expand => "y", |
|
143
|
|
|
|
|
|
|
); |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
$self->{boundary}->pack(@config); |
|
146
|
|
|
|
|
|
|
$self->{inside}->pack(-in=>$self->{boundary}, @config); |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# ---------------------------------------------- |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
unless ($self->cget('-show')) |
|
151
|
|
|
|
|
|
|
{ |
|
152
|
|
|
|
|
|
|
debug "inside hidden.\n"; |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# what is the closed height. |
|
155
|
|
|
|
|
|
|
my $ht = $self->cget('-flatheight'); |
|
156
|
|
|
|
|
|
|
$ht = $self->{$on}->ReqHeight if ($ht eq 'standard'); |
|
157
|
|
|
|
|
|
|
$ht = $self->cget('-border') if ($ht eq 'flat'); |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
croak "Option '-flatheight' must be a number, 'flat' or 'standard' (not '$ht').\n" |
|
160
|
|
|
|
|
|
|
unless ($ht =~ /^\d+$/); |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# We need to known the width so that we can set it |
|
163
|
|
|
|
|
|
|
# after hiding the inside so that the width |
|
164
|
|
|
|
|
|
|
# doesn't jump. |
|
165
|
|
|
|
|
|
|
my $wt = $self->{boundary}->Width; |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# collapse the boundary. |
|
168
|
|
|
|
|
|
|
$self->{boundary}->configure( |
|
169
|
|
|
|
|
|
|
'-height' => $ht, |
|
170
|
|
|
|
|
|
|
'-width' => $wt, |
|
171
|
|
|
|
|
|
|
); |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# hide the inside. |
|
174
|
|
|
|
|
|
|
$self->{inside}->packForget(); |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# overload these. |
|
179
|
|
|
|
|
|
|
sub gridColumnconfigure |
|
180
|
|
|
|
|
|
|
{ |
|
181
|
|
|
|
|
|
|
(shift)->{'inside'}->gridColumnconfigure(@_); |
|
182
|
|
|
|
|
|
|
} |
|
183
|
|
|
|
|
|
|
sub gridRowconfigure |
|
184
|
|
|
|
|
|
|
{ |
|
185
|
|
|
|
|
|
|
(shift)->{'inside'}->gridRowconfigure(@_); |
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
;# Called as the widget is destroyed. |
|
189
|
|
|
|
|
|
|
sub OnDestroy |
|
190
|
|
|
|
|
|
|
{ |
|
191
|
|
|
|
|
|
|
debug "args: @_\n"; |
|
192
|
|
|
|
|
|
|
} |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
;###################################################################### |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub test |
|
197
|
|
|
|
|
|
|
{ |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
#use Tk; |
|
200
|
|
|
|
|
|
|
#use Tk::Panel; |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
eval 'sub Panel::debug { |
|
203
|
|
|
|
|
|
|
my ($package, $filename, $line, |
|
204
|
|
|
|
|
|
|
$subroutine, $hasargs, $wantargs) = caller(1); |
|
205
|
|
|
|
|
|
|
print STDERR "$subroutine: "; |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
if (@_) {print STDERR @_; } |
|
208
|
|
|
|
|
|
|
else {print "Debug $filename line $line.\n";} |
|
209
|
|
|
|
|
|
|
}; '; |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
# colours. |
|
212
|
|
|
|
|
|
|
my $lightgreen = '#90ee90'; |
|
213
|
|
|
|
|
|
|
my $lightblue = '#9090ee'; |
|
214
|
|
|
|
|
|
|
my $darkred = '#8b0000'; |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
# ---- Main Window ----------------------------- |
|
217
|
|
|
|
|
|
|
my $top = MainWindow->new(); |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
#-------------- Top panel. ----------------------- |
|
220
|
|
|
|
|
|
|
my $g = $top->Panel('-text' => 'hello', '-fg'=>'red')->pack( |
|
221
|
|
|
|
|
|
|
-expand=>'yes', -fill=>'x', |
|
222
|
|
|
|
|
|
|
); |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
my @pack = ('-side'=>'left'); |
|
225
|
|
|
|
|
|
|
$top->after(10000, [ 'configure', $g, '-margin' => 20 ]); |
|
226
|
|
|
|
|
|
|
$top->after(20000, [ 'configure', $g, '-text' => 'Top panel' ]); |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
# pack everything inside the inner frame. |
|
229
|
|
|
|
|
|
|
$b = $g->Button( |
|
230
|
|
|
|
|
|
|
-text => 'Exit', |
|
231
|
|
|
|
|
|
|
-command => sub {exit;}, |
|
232
|
|
|
|
|
|
|
)->pack(@pack); |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
$b = $g->Button(-text=>'hello', -command => [ 'configure', $g, '-text', 'hello'] )->pack(@pack); |
|
235
|
|
|
|
|
|
|
$b = $g->Button(-text=>'goodbye', -command => [ 'configure', $g, '-text', 'goodbye'] )->pack(@pack); |
|
236
|
|
|
|
|
|
|
$b = $g->Button('-text'=>'no label', -command => [ 'configure', $g, '-text', ''] )->pack(@pack); |
|
237
|
|
|
|
|
|
|
$b = $g->Button(-text=>'boo', -command => [ 'configure', $g, '-text', 'boo'] )->pack(@pack); |
|
238
|
|
|
|
|
|
|
$g->Button( |
|
239
|
|
|
|
|
|
|
-text => "toggle", |
|
240
|
|
|
|
|
|
|
-command => sub { |
|
241
|
|
|
|
|
|
|
$g->configure('-toggle'=>!$g->cget('-toggle')); |
|
242
|
|
|
|
|
|
|
}, |
|
243
|
|
|
|
|
|
|
)->pack(); |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
#-------------- bottom panel. ----------------------- |
|
247
|
|
|
|
|
|
|
my $h = $top->Panel( |
|
248
|
|
|
|
|
|
|
-fg => $darkred, |
|
249
|
|
|
|
|
|
|
-bg => $lightblue, |
|
250
|
|
|
|
|
|
|
-text => 'bottom panel', |
|
251
|
|
|
|
|
|
|
-toggle => 0, |
|
252
|
|
|
|
|
|
|
-flatheight => 'flat', |
|
253
|
|
|
|
|
|
|
)->pack(); |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
$b = $h->Button( |
|
256
|
|
|
|
|
|
|
-text => "double margin", |
|
257
|
|
|
|
|
|
|
-command => sub { $h->configure('-margin'=>$h->cget('-margin')*2); }, |
|
258
|
|
|
|
|
|
|
)->pack(); |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
$b = $h->Button( |
|
261
|
|
|
|
|
|
|
-text => "halve margin", |
|
262
|
|
|
|
|
|
|
-command => sub { $h->configure('-margin'=>$h->cget('-margin')/2); }, |
|
263
|
|
|
|
|
|
|
)->pack(); |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
$b = $h->Button( |
|
266
|
|
|
|
|
|
|
-text => "double border", |
|
267
|
|
|
|
|
|
|
-command => sub { $h->configure('-border'=>$h->cget('-border')*2); }, |
|
268
|
|
|
|
|
|
|
)->pack(); |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
$b = $h->Button( |
|
271
|
|
|
|
|
|
|
-text => "halve border", |
|
272
|
|
|
|
|
|
|
-command => sub { $h->configure('-border'=>$h->cget('-border')/2); }, |
|
273
|
|
|
|
|
|
|
)->pack(); |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
$b = $h->Button( |
|
276
|
|
|
|
|
|
|
-text => "toggle", |
|
277
|
|
|
|
|
|
|
-command => sub { |
|
278
|
|
|
|
|
|
|
$h->configure('-toggle'=>!$h->cget('-toggle')); |
|
279
|
|
|
|
|
|
|
}, |
|
280
|
|
|
|
|
|
|
)->pack(); |
|
281
|
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
$b = $h->Button( |
|
283
|
|
|
|
|
|
|
-text => "disable", |
|
284
|
|
|
|
|
|
|
-command => sub { $h->configure('-state'=>'disabled');}, |
|
285
|
|
|
|
|
|
|
)->pack(); |
|
286
|
|
|
|
|
|
|
$b = $h->Button( |
|
287
|
|
|
|
|
|
|
-text => "active", |
|
288
|
|
|
|
|
|
|
-command => sub { $h->configure('-state'=>'active');}, |
|
289
|
|
|
|
|
|
|
)->pack(); |
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
$b = $h->Button( |
|
292
|
|
|
|
|
|
|
-text => "unpack", |
|
293
|
|
|
|
|
|
|
-command => sub { |
|
294
|
|
|
|
|
|
|
$h->configure('-show'=>0); |
|
295
|
|
|
|
|
|
|
$h->after(3000, [ 'configure', $h, '-show' => 1]); |
|
296
|
|
|
|
|
|
|
}, |
|
297
|
|
|
|
|
|
|
)->pack(); |
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
# Start demonstration. |
|
300
|
|
|
|
|
|
|
MainLoop; |
|
301
|
|
|
|
|
|
|
} |
|
302
|
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
&test if ($0 eq __FILE__); |
|
304
|
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
1; |
|
306
|
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
__END__ |