blib/lib/Tk/WaitBoxFixed.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 ##########################################
2 ##########################################
3 ## ##
4 ## WaitBoxFixed - a reusable Tk-widget ##
5 ## Wait Dialog ##
6 ## ##
7 ## Version 1.6 ##
8 ## ##
9 ## Brent B. Powers (B2Pi) ##
10 ## Powers@B2Pi.com ##
11 ## ##
12 ##########################################
13 ##########################################
14  
15 ###############################################################################
16 ###############################################################################
17 ## WaitBoxFixed
18 ## Object Oriented Wait Dialog for TkPerl
19 ## (Apologies to John Stoffel and Stephen O. Lidie)
20 ##
21 ## Changes:
22 ## Ver 1.1 Changed show to Show, unshow to unShow, and general
23 ## cleanup for perl5.002 gamma
24 ## Ver 1.2 Changed to general distribution, add VERSION and Version
25 ## Ver 1.3 Added -takefocus param, on suggestion of Ben Hochstedler
26 ## <benh@med.ge.com>, some other stuff
27 ## Ver 1.4 Cavac: Added some fixes
28 ## Ver 1.5 Cavac: Added some fixes
29 ## Ver 1.6 Cavac, ASB: fixes and cleanup of POD
30 ## Ver 1.7 Cavac, added use warnings, increased kwalitee
31 ## Ver 1.8 Cavac and Alex Becker, Updated documentation
32 ##
33 ###############################################################################
34 ###############################################################################
35  
36 package Tk::WaitBoxFixed;
37  
38 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 0 ▶use Tk::Toplevel;
Subroutine BEGIN: called CC=1 SCAR=2.6
41  
42 @Tk::WaitBoxFixed::ISA = qw (Tk::Toplevel);
43  
44 Tk::Widget->Construct('WaitBoxFixed');
45  
46 $Tk::WaitBoxFixed::VERSION = '1.8';
47  
48 ### A couple of convenience variables
49 my(@wd_fullpack) = (-expand => 1, -fill => 'both');
50 my(@wd_packtop) = (-side => 'top');
51 my(@wd_packleft) = (-side => 'left');
52  
53 sub Populate {
54 ### Wait box constructor. Uses new inherited from base class
55 my($cw, $wdtop, $fm, $bitmap, $txt1, $uframe, $txt2);
56 $cw = shift;
57 $cw->SUPER::Populate(@_);
58  
59 ## Create the toplevel window
60 $cw->withdraw;
61 $cw->protocol('WM_DELETE_WINDOW' => sub {});
62  
63 # See http://cpanratings.perl.org/dist/Tk-WaitBox
64 #$cw->transient($cw->toplevel);
65  
66 ### Set up the status
67 $cw->{Shown} = 0;
68  
69 ### Set up the cancel button and text
70 $cw->{cancelroutine} = undef if !defined($cw->{cancelroutine});
71 $cw->{canceltext} = 'Cancel' if !defined($cw->{canceltext});
72  
73 ### OK, create the dialog
74 ### Start with the upper frame (which contains two messages)
75 ## And maybe more....
76 $wdtop = $cw->Frame->pack(@wd_fullpack, @wd_packtop);
77  
78 $fm = $wdtop->Frame(-borderwidth => 2, -relief => 'raised')
79 ->pack(@wd_packleft, -ipadx => 20, @wd_fullpack);
80  
81 $bitmap = $fm->Label(Name => 'bitmap')
82 ->pack(@wd_packleft, -ipadx => 36, @wd_fullpack);
83  
84 ## Text Frame
85 $fm = $wdtop->Frame(-borderwidth => 2, -relief => 'raised')
86 ->pack(@wd_packleft, -ipadx => 20, @wd_fullpack);
87  
88 $txt1 = $fm->Label(-wraplength => '3i', -justify => 'center',
89 -textvariable => \$cw->{Configure}{-txt1})
90 ->pack(@wd_packtop, -pady => 3, @wd_fullpack);
91  
92 ### Eventually, I want to create a user configurable frame
93 ### in between the two frames
94 $uframe = $fm->Frame
95 ->pack(@wd_packtop);
96 $cw->Advertise(uframe => $uframe);
97  
98 $cw->{Configure}{-txt2} = "Please Wait"
99 unless defined($cw->{Configure}{-txt2});
100  
101 $txt2 = $fm->Label(-textvariable => \$cw->{Configure}{-txt2})
102 ->pack(@wd_packtop, @wd_fullpack, -pady => 9);
103  
104 ### We'll let the cancel frame and button wait until Show time
105  
106 ### Set up configuration
107 $cw->ConfigSpecs(-bitmap => [$bitmap, undef, undef, 'hourglass'],
108 -foreground=> [[$txt1,$txt2], 'foreground','Foreground','black'],
109 -background=> ['DESCENDANTS', 'background', 'Background',undef],
110 -font => [$txt1,'font','Font','-Adobe-Helvetica-Bold-R-Normal--*-180-*'],
111 -canceltext=> ['PASSIVE', undef, undef, 'Cancel'],
112 -cancelroutine=> ['PASSIVE', undef, undef, undef],
113 -txt1 => ['PASSIVE', undef, undef, undef],
114 -txt2 => ['PASSIVE',undef,undef,undef],
115 -resizeable => ['PASSIVE',undef,undef,1],
116 -takefocus => ['SELF', undef, undef, 1]);
117  
118 return;
119 }
120  
121 sub Version {return $Tk::WaitBoxFixed::VERSION;}
122  
123 sub Show {
124 ## Do last minute configuration and Show the dialog
125 my($wd, @args) = @_;
126  
127 if ( defined($wd->{Configure}{-cancelroutine}) &&
128 !defined($wd->{CanFrame})) {
129 my($canFrame) = $wd->Frame (-background => $wd->cget('-background'));
130 $wd->{CanFrame} = $canFrame;
131 $canFrame->pack(-side => 'top', @wd_packtop, -fill => 'both');
132 $canFrame->configure(-cursor => 'top_left_arrow');
133 $canFrame->Button(-text => $wd->{Configure}{-canceltext},
134 -command => $wd->{Configure}{-cancelroutine})
135 ->pack(-padx => 5, -pady => 5,
136 -ipadx => 5, -ipady => 5);
137 }
138  
139 ## Grab the input queue and focus
140 $wd->parent->configure(-cursor => 'watch') if $wd->{Configure}{-takefocus};
141 $wd->configure(-cursor => 'watch');
142 $wd->update;
143  
144 my($x) = int( ($wd->screenwidth
145 - $wd->reqwidth)/2
146 - $wd->vrootx);
147  
148 my($y) = int( ($wd->screenheight
149 - $wd->reqheight)/2
150 - $wd->vrooty);
151  
152 $wd->geometry("+$x+$y");
153  
154 $wd->{Shown} = 1;
155  
156 $wd->deiconify;
157 $wd->tkwait('visibility', $wd);
158  
159 if ($wd->{Configure}{-takefocus}) {
160 $wd->grab();
161 $wd->focus();
162 }
163 $wd->update;
164  
165 return $wd;
166  
167 }
168  
169 sub unShow {
170 my($wd) = @_;
171  
172 return unless $wd->{Shown};
173 $wd->{CanFrame}->destroy if defined($wd->{CanFrame});
174 $wd->{CanFrame} = undef;
175 $wd->parent->configure(-cursor => 'top_left_arrow');
176  
177 $wd->grab('release');
178 $wd->withdraw;
179 $wd->parent->update;
180 $wd->{Shown} = 0;
181  
182 return;
183 }
184  
185 1;
186  
187 __END__
↑ Summary