HP_21.pm untested

filter: Statementstmt 0.0% 0 / 187 Branchbran 0.0% 0 / 54 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 15 totaltotal 0.0% 0 / 275 CC 28 SCAR 24.1
CC
28
Cov
0%
Populate
20.0
chssqrt
12.0
clxclr
12.0
CRAP 11.1
1 $Tk::Calculator::RPN::HP_21::VERSION = '1.2';
2  
3 package Tk::Calculator::RPN::HP_21;
4  
5 use Tk::widgets qw/SlideSwitch/;
6 use Tk::Calculator::RPN::HP;
7 use base qw/Tk::Calculator::RPN::HP/;
8 use strict;
9  
10 our $HELP;
11  
12 sub ClassInit {
13  
14 my ($class, $mw) = @_;
15  
16 $HELP = $class->build_help_window($mw);
17 $class->SUPER::ClassInit($mw);
18  
19 } # end ClassInit
20  
21 sub build_button_rows {
22  
23 my ($self, $parent, $button_descriptions) = @_;
24  
25 foreach my $row (@$button_descriptions) {
26 my $frame = $parent->Frame;
27 foreach my $buttons (@$row) {
28 my ($p1, $p2, $color, $func) = @$buttons;
29  
30 $frame->Tk::Calculator::RPN::HP::Key2_21(
31 -butl => $p1,
32 -botl => $p2,
33 -background => $color,
34 -command => $func,
35 );
36 }
37 $frame->pack(qw/-side top -expand 1 -fill both/);
38 $self->{PB}->set($self->{PB_PERCENT} += 10) if $self->{PB};
39 }
40  
41 } # end build_button_rows
42  
43 sub Populate {
44  
45 my ($self, $args) = @_;
46  
47 $self->optionAdd('*background' => $GRAY_LIGHTER);
48 $self->{ONOFF} = 1; # 1 IFF calculator on (1 initially)
49 $self->{RCFILE} = $^O eq "MSWin32" ?
50 'C:\.hp\hp21' : "$ENV{HOME}/.hp/hp21";
51  
52 # The LED display.
53  
54 my $frame0 = $self->Frame;
55 $frame0->Frame(
56 -background => 'black',
57 -height => 7,
58 )->pack(qw/-expand 1 -fill x -padx 10/);
59 $frame0->pack(qw/-padx 5 -pady 5 -fill both -expand 1/)->pack;
60 $frame0->Label(
61 -background => 'black',
62 -width => 25,
63 -foreground => 'red',
64 -font => ['arial', 14, 'bold'],
65 -textvariable => \$self->{XV},
66 -anchor => 'w',
67 )->pack(qw/-expand 1 -fill x -padx 10/);
68 $frame0->Frame(
69 -background => 'black',
70 -height => 7,
71 )->pack(qw/-expand 1 -fill x -padx 10/);
72  
73 # The two SlideSwitches.
74  
75 my $frame1 = $self->Frame(qw/-relief sunken -bd 2/)->pack;
76 $frame1->pack(qw/-fill both -expand 1/);
77 my $font = ['courier', 10, 'bold'];
78 my $sl1 = $frame1->SlideSwitch(
79 -bg => $GRAY_LIGHTER,
80 -orient => 'horizontal',
81 -command => [$self => 'on'],
82 -llabel =>
83 [-text => 'OFF', -fg => 'black', -bg => $GRAY_LIGHTER, -font => $font],
84 -rlabel =>
85 [-text => 'ON', -fg => 'black', -bg => $GRAY_LIGHTER, -font => $font],
86 -troughcolor => $GRAY_LIGHTER,
87 )->pack(qw/-side left -expand 1/);
88  
89 $self->build_help_button($frame1, $HELP)->pack(qw/-side left/);
90  
91 my $sl2 = $frame1->SlideSwitch(
92 -bg => $GRAY_LIGHTER,
93 -orient => 'horizontal',
94 -llabel =>
95 [-text => 'DEG', -fg => 'black', -bg => $GRAY_LIGHTER, -font => $font],
96 -rlabel =>
97 [-text => 'RAD', -fg => 'black', -bg => $GRAY_LIGHTER, -font => $font],
98 -troughcolor => $GRAY_LIGHTER,
99 -variable => \$self->{MODE},
100 )->pack(qw/-side right -expand 1/);
101  
102 $self->{PB}->set($self->{PB_PERCENT} += 10) if $self->{PB};
103
104 # Build all the button rows.
105  
106 my $frame2 = $self->Frame(qw/-relief sunken -bd 4/)->pack;
107  
108 build_button_rows $self, $frame2, [
109 [
110 ['1/x', 'y**x', $GRAY, [$self => 'rpexp']],
111 ['SIN', 'SIN-1', $GRAY, [$self => 'sinasin']],
112 ['COS', 'COS-1', $GRAY, [$self => 'cosacos']],
113 ['TAN', 'TAN-1', $GRAY, [$self => 'tanatan']],
114 ['g', '', $BLUE, [$self => 'g']],
115 ],
116 [
117 [$SWAP, '>R', $GRAY, [$self => 'swapxy']],
118 [$ROLD, '>P', $GRAY, [$self => 'roll_stack']],
119 ['e**x', 'LN', $GRAY, [$self => 'exln']],
120 ['STO', 'LOG', $GRAY, [$self => 'stolog']],
121 ['RCL', '10**x', $GRAY, [$self => 'rclt2x']],
122 ],
123 [
124 ['ENTER ^', '', $GRAY, [$self => 'enter']],
125 ['CHS', 'SQRT', $GRAY, [$self => 'chssqrt']],
126 ['EEX', $PI, $GRAY, [$self => 'eexpi']],
127 ['CLx', 'CLR', $GRAY, [$self => 'clxclr']],
128 ],
129 [
130 ['-', 'M-', 'tan', [$self => 'math3', $SB, undef, undef]],
131 ['7', '', 'tan', [$self => 'key', 7]],
132 ['8', '', 'tan', [$self => 'key', 8]],
133 ['9', '', 'tan', [$self => 'key', 9]],
134 ],
135 [
136 ['+', 'M+', 'tan', [$self => 'math3', $AD, undef, undef]],
137 ['4', '', 'tan', [$self => 'key', 4]],
138 ['5', '', 'tan', [$self => 'key', 5]],
139 ['6', '', 'tan', [$self => 'key', 6]],
140 ],
141 [
142 ['x', 'Mx', 'tan', [$self => 'math3', $ML, undef, undef]],
143 ['1', '', 'tan', [$self => 'key', 1]],
144 ['2', '', 'tan', [$self => 'key', 2]],
145 ['3', '', 'tan', [$self => 'key', 3]],
146 ],
147 [
148 ['/', 'M/', 'tan', [$self => 'math3', $DV, undef, undef]],
149 ['0', '', 'tan', [$self => 'key', 0]],
150 ['.', '', 'tan', [$self => 'key', '.']],
151 ['DSP', '', 'tan', [$self => 'err']],
152 ],
153 ];
154  
155 # The Quit Button and HP logo.
156  
157 my $frame3 = $self->Frame->pack;
158 $font = ['courier', 10, 'bold'];
159 my $hp = $frame3->Button(
160 -text => ' hp ',
161 -font => $font,
162 -relief => 'raised',
163 -command => sub {
164 $self->{ONOFF} = 1;
165 $self->on;
166 &Tk::exit;
167 },
168 );
169 $hp->pack(qw/-side left -expand 1 -fill both -pady 10/);
170 $hp->bind('<Enter>' => sub {$_[0]->configure(-text => 'Quit')});
171 $hp->bind('<Leave>' => sub {$_[0]->configure(-text => ' hp ')});
172 $frame3->Label(
173 -text => ' H E W L E T T . P A C K A R D 21',
174 -font => $font,
175 -foreground => $SILVER,
176 -background => $GRAY_LIGHTER,
177 )->pack(qw/-side left -expand 0/);
178  
179 $self->set_keypad_bindings;
180
181 $self->{PB}->set($self->{PB_PERCENT} = 90) if $self->{PB};
182
183 } # end Populate
184  
185 # Function key processors.
186  
187 sub chssqrt {
188  
189 my ($self) = @_;
190  
191 return unless $self->{ONOFF};
192 if ($self->{G_PRESSED}) { # sqrt
193 $self->math($SQ);
194 } else { # chs
195 $self->chs;
196 }
197  
198 } # end chssqrt
199  
200 sub clxclr {
201  
202 my ($self) = @_;
203  
204 return unless $self->{ONOFF};
205 if ($self->{G_PRESSED}) { # clr
206 $self->clr;
207 } else { # clx
208 $self->clx;
209 }
210  
211 } # end clxclr
212  
213 sub cosacos {
214  
215 my ($self) = @_;
216  
217 return unless $self->{ONOFF};
218 if ($self->{G_PRESSED}) {
219 $self->trig_math($AC);
220 } else {
221 $self->trig_math($CO);
222 }
223  
224 } # end cosacos
225  
226 sub eexpi {
227  
228 my ($self) = @_;
229  
230 return unless $self->{ONOFF};
231 if ($self->{G_PRESSED}) {
232 $self->pi;
233 } else {
234 $self->err;
235 }
236  
237 } # end eexpi
238  
239 sub exln {
240  
241 my ($self) = @_;
242  
243 return unless $self->{ONOFF};
244 my $f = $self->{G_PRESSED} ? $LN : $EX;
245 $self->math($f);
246  
247 } # end exln
248  
249 sub on {
250  
251 my ($self, $val) = @_;
252  
253 return unless defined $val;
254 $self->clr;
255 $self->SUPER::on($val);
256  
257 } # end on
258  
259 sub rclt2x {
260  
261 my ($self) = @_;
262  
263 return unless $self->{ONOFF};
264 if ($self->{G_PRESSED}) {
265 $self->math($TX);
266 } else {
267 $self->err;
268 }
269  
270 } # end rclt2x
271  
272 sub rpexp {
273  
274 my ($self) = @_;
275  
276 return unless $self->{ONOFF};
277 if ($self->{G_PRESSED}) {
278 $self->math3(undef, undef, $YX);
279 } else {
280 $self->math($RP);
281 }
282  
283 } # end rpexp
284  
285 sub roll_stack {
286  
287 my ($self) = @_;
288  
289 return unless $self->{ONOFF};
290 if ($self->{G_PRESSED}) {
291 $self->bell;
292 } else {
293 $self->roll_down;
294 }
295  
296 } # end rollstack
297  
298 sub sinasin {
299  
300 my ($self) = @_;
301  
302 return unless $self->{ONOFF};
303 if ($self->{G_PRESSED}) {
304 $self->trig_math($AS);
305 } else {
306 $self->trig_math($SI);
307 }
308  
309 } # end sinasin
310  
311 sub stolog {
312  
313 my ($self) = @_;
314  
315 return unless $self->{ONOFF};
316 if ($self->{G_PRESSED}) {
317 $self->math($LG);
318 } else {
319 $self->err;
320 }
321  
322 } # end stolog
323  
324 sub tanatan {
325  
326 my ($self) = @_;
327  
328 return unless $self->{ONOFF};
329 if ($self->{G_PRESSED}) {
330 $self->trig_math($AT);
331 } else {
332 $self->trig_math($TA);
333 }
334  
335 } # end tanatan
336  
337 1;
338  
339 =head1 AUTHOR
340  
341 sol0@Lehigh.EDU
342  
343 Copyright (C) 2001 - 2007, Steve Lidie. All rights reserved.
344  
345 This program is free software; you can redistribute it and/or
346 modify it under the same terms as Perl itself.
347  
348 =head1 KEYWORDS
349  
350 calculator, HP, RPN, HP 21
351  
352 =cut