line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package UI::Various::Radio; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Author, Copyright and License: see end of file |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
UI::Various::Radio - general radio button widget of L |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use UI::Various; |
12
|
|
|
|
|
|
|
my $main = UI::Various::main(); |
13
|
|
|
|
|
|
|
my $variable = 0; |
14
|
|
|
|
|
|
|
$main->window(... |
15
|
|
|
|
|
|
|
UI::Various::Radio->new(buttons => {1 => 'One', |
16
|
|
|
|
|
|
|
2 => 'Two', |
17
|
|
|
|
|
|
|
3 => 'Three'}), |
18
|
|
|
|
|
|
|
...); |
19
|
|
|
|
|
|
|
$main->mainloop(); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 ABSTRACT |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
This module defines the general radio button widget of an application using |
24
|
|
|
|
|
|
|
L. The radio buttons are vertically aligned. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Note that the limitation to the vertical orientation comes from |
27
|
|
|
|
|
|
|
L. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Besides the common attributes inherited from C the |
32
|
|
|
|
|
|
|
C widget knows only two additional attributes: |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Note that the possible values for the variable are C<0> or C<1>, which will |
35
|
|
|
|
|
|
|
be changed according Perl's standard true/false conversions. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 Attributes |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
######################################################################### |
44
|
|
|
|
|
|
|
|
45
|
8
|
|
|
8
|
|
93
|
use v5.14; |
|
8
|
|
|
|
|
23
|
|
46
|
8
|
|
|
8
|
|
38
|
use strictures; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
35
|
|
47
|
8
|
|
|
8
|
|
1139
|
no indirect 'fatal'; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
33
|
|
48
|
8
|
|
|
8
|
|
446
|
no multidimensional; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
33
|
|
49
|
8
|
|
|
8
|
|
214
|
use warnings 'once'; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
395
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
our $VERSION = '0.24'; |
52
|
|
|
|
|
|
|
|
53
|
8
|
|
|
8
|
|
44
|
use UI::Various::core; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
44
|
|
54
|
8
|
|
|
8
|
|
49
|
use UI::Various::widget; |
|
8
|
|
|
|
|
45
|
|
|
8
|
|
|
|
|
461
|
|
55
|
8
|
|
|
8
|
|
34
|
BEGIN { require 'UI/Various/' . UI::Various::core::using() . '/Radio.pm'; } |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
require Exporter; |
58
|
|
|
|
|
|
|
our @ISA = qw(UI::Various::widget); |
59
|
|
|
|
|
|
|
our @EXPORT_OK = qw(); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
######################################################################### |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item buttons [rw, fixed] |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
an ARRAY with pairs of key values and corresponding displayed texts of the |
66
|
|
|
|
|
|
|
radio buttons, e.g.: |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
[ 1 => 'red', 2 => 'green', 3 => 'blue' ] |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
(looks like a HASH, but is technically an ARRAY as its sequence is important) |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub buttons($;$) |
75
|
|
|
|
|
|
|
{ |
76
|
|
|
|
|
|
|
local $_ = |
77
|
|
|
|
|
|
|
access |
78
|
|
|
|
|
|
|
('buttons', |
79
|
|
|
|
|
|
|
sub{ |
80
|
7
|
100
|
|
7
|
|
27
|
unless (ref($_) eq 'ARRAY') |
81
|
|
|
|
|
|
|
{ |
82
|
1
|
|
|
|
|
4
|
error('_1_attribute_must_be_a_2_reference', 'buttons', 'ARRAY'); |
83
|
1
|
|
|
|
|
6
|
return undef; |
84
|
|
|
|
|
|
|
} |
85
|
6
|
100
|
|
|
|
7
|
if (0 == @{$_}) |
|
6
|
|
|
|
|
13
|
|
86
|
|
|
|
|
|
|
{ |
87
|
1
|
|
|
|
|
4
|
error('_1_may_not_be_empty', 'buttons'); |
88
|
1
|
|
|
|
|
5
|
return undef; |
89
|
|
|
|
|
|
|
} |
90
|
5
|
100
|
|
|
|
9
|
unless (0 == @{$_} % 2) |
|
5
|
|
|
|
|
12
|
|
91
|
|
|
|
|
|
|
{ |
92
|
1
|
|
|
|
|
2
|
error('odd_number_of_parameters_in_initialisation_list_of__1', |
93
|
|
|
|
|
|
|
'buttons'); |
94
|
1
|
|
|
|
|
4
|
return undef; |
95
|
|
|
|
|
|
|
} |
96
|
4
|
|
|
|
|
6
|
my ($self) = @_; |
97
|
4
|
|
|
|
|
7
|
my @keys = (); |
98
|
4
|
|
|
|
|
5
|
my @values = (); |
99
|
4
|
|
|
|
|
5
|
foreach my $i (0..$#{$_}) |
|
4
|
|
|
|
|
11
|
|
100
|
|
|
|
|
|
|
{ |
101
|
34
|
100
|
|
|
|
47
|
if (0 == $i % 2) |
102
|
17
|
|
|
|
|
24
|
{ push @keys, $_->[$i]; } |
103
|
|
|
|
|
|
|
else |
104
|
17
|
|
|
|
|
21
|
{ push @values, $_->[$i]; } |
105
|
|
|
|
|
|
|
} |
106
|
4
|
|
|
|
|
36
|
my %hash = @$_; |
107
|
4
|
|
|
|
|
11
|
$self->{_button_hash} = \%hash; |
108
|
4
|
|
|
|
|
11
|
$self->{_button_keys} = \@keys; |
109
|
4
|
|
|
|
|
18
|
$self->{_button_values} = \@values; |
110
|
|
|
|
|
|
|
}, |
111
|
7
|
|
|
7
|
1
|
55
|
@_); |
112
|
7
|
|
|
|
|
60
|
_init_var(@_); |
113
|
7
|
|
|
|
|
19
|
return $_; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item var [rw, recommended] |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
a variable reference for the radio buttons |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
The variable will be set to one of the key values of C
|
121
|
|
|
|
|
|
|
fixed>> when it is selected. Note that if it's initial value is defined to |
122
|
|
|
|
|
|
|
something not being an existing key value of that ARRAY, it will be set to |
123
|
|
|
|
|
|
|
C. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub var($;$) |
128
|
|
|
|
|
|
|
{ |
129
|
9
|
|
|
9
|
1
|
25
|
local $_ = access_varref('var', @_); |
130
|
9
|
|
|
|
|
21
|
_init_var(@_); |
131
|
9
|
|
|
|
|
20
|
return $_; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# need special initialisation function as initialisation sequence is |
135
|
|
|
|
|
|
|
# undefined: |
136
|
|
|
|
|
|
|
sub _init_var($;@) |
137
|
|
|
|
|
|
|
{ |
138
|
18
|
|
|
18
|
|
1361
|
my ($self) = @_; |
139
|
|
|
|
|
|
|
return unless ($self->isa(__PACKAGE__) and |
140
|
|
|
|
|
|
|
defined $self->{buttons} and |
141
|
|
|
|
|
|
|
defined $self->{var} and |
142
|
18
|
100
|
100
|
|
|
218
|
defined ${$self->{var}}); |
|
11
|
|
100
|
|
|
28
|
|
|
|
|
100
|
|
|
|
|
143
|
|
|
|
|
|
|
# direct access to avoid recursion: |
144
|
10
|
100
|
|
|
|
15
|
defined $self->{_button_hash}{${$self->{var}}} or ${$self->{var}} = undef; |
|
4
|
|
|
|
|
7
|
|
|
10
|
|
|
|
|
23
|
|
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
######################################################################### |
148
|
|
|
|
|
|
|
# |
149
|
|
|
|
|
|
|
# internal constants and data: |
150
|
|
|
|
|
|
|
|
151
|
8
|
|
|
|
|
628
|
use constant ALLOWED_PARAMETERS => |
152
|
8
|
|
|
8
|
|
50
|
(UI::Various::widget::COMMON_PARAMETERS, qw(buttons var)); |
|
8
|
|
|
|
|
14
|
|
153
|
8
|
|
|
8
|
|
49
|
use constant DEFAULT_ATTRIBUTES => (var => dummy_varref()); |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
41
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
######################################################################### |
156
|
|
|
|
|
|
|
######################################################################### |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=back |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 METHODS |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Besides the accessors (attributes) described above and by |
163
|
|
|
|
|
|
|
L and the methods |
164
|
|
|
|
|
|
|
inherited from L only the |
165
|
|
|
|
|
|
|
constructor is provided by the C class itself: |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
######################################################################### |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 B - constructor |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
see L
|
174
|
|
|
|
|
|
|
constructor for UI elements> |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub new($;\[@$]) |
181
|
|
|
|
|
|
|
{ |
182
|
8
|
|
|
8
|
1
|
3003
|
debug(3, __PACKAGE__, '::new'); |
183
|
8
|
|
|
|
|
54
|
local $_ = construct({ DEFAULT_ATTRIBUTES }, |
184
|
|
|
|
|
|
|
'^(?:' . join('|', ALLOWED_PARAMETERS) . ')$', |
185
|
|
|
|
|
|
|
@_); |
186
|
8
|
100
|
|
|
|
28
|
unless (defined $_->{buttons}) |
187
|
|
|
|
|
|
|
{ |
188
|
4
|
|
|
|
|
10
|
error('mandatory_parameter__1_is_missing', 'buttons'); |
189
|
4
|
|
|
|
|
23
|
return undef; |
190
|
|
|
|
|
|
|
} |
191
|
4
|
|
|
|
|
10
|
return $_; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
1; |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
######################################################################### |
197
|
|
|
|
|
|
|
######################################################################### |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 SEE ALSO |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
L |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 LICENSE |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Copyright (C) Thomas Dorner. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it |
208
|
|
|
|
|
|
|
under the same terms as Perl itself. See LICENSE file for more details. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 AUTHOR |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Thomas Dorner Edorner (at) cpan (dot) orgE |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=cut |