blib/lib/Curses/UI/Dialog/Progress.pm untested

filter: Statementstmt 0.0% 0 / 52 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 89 CC 8 SCAR 25.2
CC
8
Cov
0%
layout
30.0
new
12.0
message
6.0
CRAP 12.5
1 # ----------------------------------------------------------------------
2 # Curses::UI::Dialog::Progress
3 #
4 # (c) 2001-2002 by Maurice Makaay. All rights reserved.
5 # This file is part of Curses::UI. Curses::UI is free software.
6 # You can redistribute it and/or modify it under the same terms
7 # as perl itself.
8 #
9 # Currently maintained by Marcus Thiesen
10 # e-mail: marcus@cpan.thiesenweb.de
11 # ----------------------------------------------------------------------
12  
13 package Curses::UI::Dialog::Progress;
14  
15 use strict;
16 use Curses;
17 use Curses::UI::Common;
18 use Curses::UI::Window;
19  
20 use vars qw(
21 $VERSION
22 @ISA
23 );
24  
25 @ISA = qw(
26 Curses::UI::Window
27 Curses::UI::Common
28 );
29  
30 $VERSION = '1.10';
31  
32 sub new ()
33 {
34 my $class = shift;
35  
36 my %userargs = @_;
37 keys_to_lowercase(\%userargs);
38  
39 my %args = (
40 -nomessage => 0, # Do we want a message or not?
41 -message => '', # The message to show
42 -min => undef, # Arguments for the progressbar
43 -max => undef,
44 -pos => undef,
45 -nocenterline => undef,
46 -nopercentage => undef,
47 -ipad => 1, # Default widget settings
48 -border => 1,
49 -width => 60,
50 -height => undef,
51  
52 -fg => -1,
53 -bg => -1,
54  
55 %userargs,
56  
57 -centered => 1,
58 );
59  
60 my $this = $class->SUPER::new(%args);
61  
62 unless ($args{-nomessage})
63 {
64 $this->add(
65 'label', 'Label',
66 -width => -1,
67 -text => $this->{-message},
68 -intellidraw => 0,
69
70 );
71 }
72  
73 # Create the progress bar arguments.
74 my %pb_args = ();
75 foreach my $var (qw(-min -max -pos -nopercentage -nocenterline))
76 {
77 if (defined $this->{$var}) {
78 $pb_args{$var} = $this->{$var};
79 }
80 }
81  
82 $this->add(
83 'progressbar', 'Progressbar',
84 -y => -1,
85 -width => -1,
86 -fg => $this->{-fg},
87 -bg => $this->{-bg},
88  
89 %pb_args,
90 -intellidraw => 0,
91 );
92  
93 $this->layout();
94  
95 bless $this, $class;
96 }
97  
98 # There is no need to focus a progress dialog
99 sub focus() {} ;
100  
101 sub layout()
102 {
103 my $this = shift;
104  
105 if (not defined $this->{-height}
106 and defined $this->getobj('progressbar'))
107 {
108 # Space between progressbar and message.
109 my $need = ($this->{-nomessage} ? 0 : 1);
110  
111 # The height for the message.
112 if (defined $this->getobj('label')) {
113 $need += $this->getobj('label')->height;
114 }
115
116 # The height for the progressbar.
117 if (defined $this->getobj('progressbar')) {
118 my $pbheight = $this->getobj('progressbar')->height;
119 $need += $pbheight;
120 }
121  
122  
123 my $height = $this->height_by_windowscrheight($need, %$this);
124 $this->{-height} = $height;
125 }
126  
127 $this->SUPER::layout or return;
128  
129 return $this;
130 }
131  
132 sub pos($;)
133 {
134 my $this = shift;
135 my $pos = shift;
136 $this->getobj('progressbar')->pos($pos);
137 return $this;
138 }
139  
140 sub message()
141 {
142 my $this = shift;
143 return $this if $this->{-nomessage};
144 my $msg = shift;
145 $this->getobj('label')->text($msg);
146 return $this;
147 }
148  
149 1;
150  
151  
152 =pod
153  
154 =head1 NAME
155  
156 Curses::UI::Dialog::Progress - Create and manipulate progress dialogs
157  
158 =head1 CLASS HIERARCHY
159  
160 Curses::UI::Widget
161 |
162 +----Curses::UI::Container
163 |
164 +----Curses::UI::Window
165 |
166 +----Curses::UI::Dialog::Progress
167  
168  
169 =head1 SYNOPSIS
170  
171 use Curses::UI;
172 my $cui = new Curses::UI;
173 my $win = $cui->add('window_id', 'Window');
174  
175 # The hard way.
176 # -------------
177 my $dialog = $win->add(
178 'mydialog', 'Dialog::Progress',
179 -max => 100,
180 -message => 'Some message',
181 );
182  
183 $dialog->pos(10);
184 $dialog->message('Some other message');
185 $dialog->draw();
186  
187 $win->delete('mydialog');
188  
189 # The easy way (see Curses::UI documentation).
190 # --------------------------------------------
191 $cui->progress(
192 -max => 100,
193 -message => 'Some message',
194 );
195 $cui->setprogress(10, 'Some other message');
196 $cui->noprogress;
197  
198  
199  
200  
201  
202 =head1 DESCRIPTION
203  
204 Curses::UI::Dialog::Progress is not really a dialog, since
205 the user has no way of interacting with it. It is merely
206 a way of presenting progress information to the user of
207 your program.
208  
209  
210 See exampes/demo-Curses::UI::Dialog::Progress in the
211 distribution for a short demo.
212  
213  
214  
215 =head1 OPTIONS
216  
217 =over 4
218  
219 =item * B<-title> < TEXT >
220  
221 Set the title of the dialog window to TEXT.
222  
223 =item * B<-message> < TEXT >
224  
225 This option sets the initial message to show to TEXT.
226 This message is displayed using a L<Curses::UI::Label|Curses::UI::Label>,
227 so it can not contain any newline (\n) characters.
228  
229 =item * B<-nomessage> < BOOLEAN >
230  
231 If BOOLEAN has a true value, the dialog window will not contain
232 a message label. By default B<-nomessage> has a false value.
233  
234 =item * B<-min> < VALUE >
235  
236 =item * B<-max> < VALUE >
237  
238 =item * B<-pos> < VALUE >
239  
240 =item * B<-nopercentage> < BOOLEAN >
241  
242 =item * B<-nocenterline> < BOOLEAN >
243  
244 These options control the progressbar of the dialog. For an explanation
245 of these options, see L<Curses::UI::Progressbar|Curses::UI::Progressbar>.
246  
247 =back
248  
249  
250  
251  
252 =head1 METHODS
253  
254 =over 4
255  
256 =item * B<new> ( OPTIONS )
257  
258 =item * B<layout> ( )
259  
260 =item * B<draw> ( BOOLEAN )
261  
262 These are standard methods. See L<Curses::UI::Container|Curses::UI::Container>
263 for an explanation of these.
264  
265 =item * B<pos> ( VALUE )
266  
267 This method will update the position of the progressbar
268 to SCALAR. You will have to call the B<draw> method to see the changes.
269  
270 =item * B<message> ( TEXT )
271  
272 This method will update the message of the progress dialog
273 to TEXT. You will have to call the B<draw> method to see the changes.
274  
275 =back
276  
277  
278  
279  
280 =head1 SEE ALSO
281  
282 L<Curses::UI|Curses::UI>,
283 L<Curses::UI::Container|Curses::UI::Container>,
284 L<Curses::UI::Progressbar|Curses::UI::Progressbar>
285  
286  
287  
288  
289 =head1 AUTHOR
290  
291 Copyright (c) 2001-2002 Maurice Makaay. All rights reserved.
292  
293 Maintained by Marcus Thiesen (marcus@cpan.thiesenweb.de)
294  
295  
296 This package is free software and is provided "as is" without express
297 or implied warranty. It may be used, redistributed and/or modified
298 under the same terms as perl itself.
299