~ubuntu-branches/ubuntu/wily/libui-dialog-perl/wily

« back to all changes in this revision

Viewing changes to .pc/FixSpellingAndManDescription.diff/lib/UI/Dialog/Screen/Menu.pod

  • Committer: Package Import Robot
  • Author(s): Alejandro Garrido Mota
  • Date: 2013-08-10 17:03:03 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130810170303-z23sxbboezqbjcas
Tags: 1.09-1
* New upstream release. 
* Add watch file.
* d/control:
  - Update Standards-Version to 3.9.4
  - Add Vcs-Git and Vcs-Browser.  
* Add source-format 3.0.
* d/copyright:
  - Update to copyright-format 1.0.
  - Push copyright years.
* Update d/rules to dh.
* Remove docs file.
* Add d/libui-dialog-perl.examples file
* Add FixPod2manErrors.diff and FixSpellingAndManDescription.diff patches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
=head1 NAME
 
2
 
 
3
UI::Dialog::Screen::Menu
 
4
 
 
5
=head1 SYNOPSIS
 
6
 
 
7
  use UI::Dialog::Screen::Menu;
 
8
 
 
9
  # $d is an existing instance of UI::Dialog
 
10
 
 
11
  my $screen = new UI::Dialog::Screen::Menu ( dialog => $d );
 
12
  $screen->add_menu_item("This is the label", sub { print "Hello\n"; });
 
13
 
 
14
  # $rv is 0 if the user canceled, 1 if any menu item was selected.
 
15
  my $rv = $screen->run();
 
16
 
 
17
=head1 ABSTRACT
 
18
 
 
19
UI::Dialog::Screen::Menu is a helper class which enables a clean and
 
20
modular code flow for menu driven applications using UI::Dialog. Using
 
21
callbacks assigned to menu items, a reactionary model to scripting with
 
22
UI::Dialog becomes rapidly easy.
 
23
 
 
24
=head1 DESCRIPTION
 
25
 
 
26
UI::Dialog::Screen::Menu is actually "external" to the UI::Dialog core
 
27
usage. The class simply wraps around an existing UI::Dialog instance
 
28
for rendering a menu-driven flow of screens.
 
29
 
 
30
Using this class, you define a number of screen instances and assign
 
31
callbacks to each of the menu items. Once defined, simply call B<run()>
 
32
(or B<loop()> to execute B<run()> indefinitely). When a user selects
 
33
one of the menu items, the assigned function will be executed. From
 
34
within those functions, simply call other UI::Dialog::Screen::Menu
 
35
instances and that's how you branch your user's experience from one
 
36
screen to the next. See the B<EXAMPLES>
 
37
 
 
38
=head1 EXPORT
 
39
 
 
40
=over 2
 
41
 
 
42
None
 
43
 
 
44
=back
 
45
 
 
46
=head1 INHERITS
 
47
 
 
48
=over 2
 
49
 
 
50
None
 
51
 
 
52
=back
 
53
 
 
54
=head1 CONSTRUCTOR
 
55
 
 
56
=head2 new( %options )
 
57
 
 
58
=over 4
 
59
 
 
60
=item EXAMPLE
 
61
 
 
62
=over 6
 
63
 
 
64
 # Have UI::Dialog::Screen::Menu use an existing UI::Dialog instance
 
65
 # to render the user interface.
 
66
 my $s = new( dialog => $d );
 
67
 
 
68
 # Also accepts UI::Dialog constructor arguments, so that it can create
 
69
 # it's own instance of UI::Dialog if none is provided.
 
70
 my $s = new( title => 'Default Title', backtitle => 'Backtitle',
 
71
              width => 65, height => 20, listheight => 5,
 
72
              order => [ 'zenity', 'xdialog', 'gdialog' ] );
 
73
 
 
74
=back
 
75
 
 
76
=item DESCRIPTION
 
77
 
 
78
=over 6
 
79
 
 
80
This is the Class Constructor method. It accepts a list of key => value pairs
 
81
and uses them as the defaults when interacting with the various widgets.
 
82
 
 
83
=back
 
84
 
 
85
=item RETURNS
 
86
 
 
87
=over 6
 
88
 
 
89
A blessed object reference of the UI::Dialog::Screen::Menu class.
 
90
 
 
91
=back
 
92
 
 
93
=item OPTIONS
 
94
 
 
95
The (...)'s after each option indicate the default for the option. An * denotes
 
96
support by all the widget methods on a per-use policy defaulting to the values
 
97
decided during object creation.
 
98
 
 
99
=over 6
 
100
 
 
101
=item B<dialog = UI::Dialog> (undef)
 
102
 
 
103
=item B<debug = 0,1,2> (0)
 
104
 
 
105
=item B<order = [ zenity, xdialog, gdialog, kdialog, cdialog, whiptail, ascii ]> (as indicated)
 
106
 
 
107
=item B<PATH = [ /bin, /usr/bin, /usr/local/bin, /opt/bin ]> (as indicated)
 
108
 
 
109
=item B<backtitle = "backtitle"> ('') *
 
110
 
 
111
=item B<title = "title"> ('') *
 
112
 
 
113
=item B<beepbefore = 0,1> (0) *
 
114
 
 
115
=item B<beepafter = 0,1> (0) *
 
116
 
 
117
=item B<height = \d+> (20) *
 
118
 
 
119
=item B<width = \d+> (65) *
 
120
 
 
121
=item B<listheight = \d+> (5) *
 
122
 
 
123
=back
 
124
 
 
125
=back
 
126
 
 
127
=head1 STATE METHODS
 
128
 
 
129
=head2 run( )
 
130
 
 
131
=over 4
 
132
 
 
133
=item EXAMPLE
 
134
 
 
135
=over 6
 
136
 
 
137
 my $rv = $s->run();
 
138
 
 
139
=back
 
140
 
 
141
=item DESCRIPTION
 
142
 
 
143
=over 6
 
144
 
 
145
Render the screen menu immediately. This method blocks until the user
 
146
input has been received and acted upon.
 
147
 
 
148
=back
 
149
 
 
150
=item RETURNS
 
151
 
 
152
=over 6
 
153
 
 
154
TRUE if the user selected an item from the menu, FALSE otherwise.
 
155
 
 
156
=back
 
157
 
 
158
=back
 
159
 
 
160
=head2 loop( )
 
161
 
 
162
=over 4
 
163
 
 
164
=item EXAMPLE
 
165
 
 
166
=over 6
 
167
 
 
168
 $s->loop();
 
169
 
 
170
=back
 
171
 
 
172
=item DESCRIPTION
 
173
 
 
174
=over 6
 
175
 
 
176
Calls the B<run()> method immediately. Once B<run()> completes it's
 
177
execution, the B<loop()> decides whether or not to display again. If
 
178
the return value of run() is TRUE, the B<loop()> will continue. If the
 
179
use pressed Cancel (or Escape) or any other action other than one of
 
180
the menu items; the B<loop()> will end. The B<loop()> will also end
 
181
if the B<break_loop()> method is called.
 
182
 
 
183
=back
 
184
 
 
185
=item RETURNS
 
186
 
 
187
=over 6
 
188
 
 
189
TRUE if the user selected an item from the menu, FALSE otherwise.
 
190
 
 
191
=back
 
192
 
 
193
=back
 
194
 
 
195
=head2 is_looping( )
 
196
 
 
197
=over 4
 
198
 
 
199
=item EXAMPLE
 
200
 
 
201
=over 6
 
202
 
 
203
 if ($s->is_looping()) {
 
204
     print "Currently in a UI::Dialog::Screen::Menu loop\n";
 
205
 }
 
206
 
 
207
=back
 
208
 
 
209
=item DESCRIPTION
 
210
 
 
211
=over 6
 
212
 
 
213
Returns TRUE if the given screen is in a menu B<loop()>, FALSE
 
214
otherwise.
 
215
 
 
216
=back
 
217
 
 
218
=item RETURNS
 
219
 
 
220
=over 6
 
221
 
 
222
a single SCALAR.
 
223
 
 
224
=back
 
225
 
 
226
=back
 
227
 
 
228
=head2 break_loop( )
 
229
 
 
230
=over 4
 
231
 
 
232
=item EXAMPLE
 
233
 
 
234
=over 6
 
235
 
 
236
 $s->break_loop();
 
237
 
 
238
=back
 
239
 
 
240
=item DESCRIPTION
 
241
 
 
242
=over 6
 
243
 
 
244
Flags the screen menu to stop looping. This does not close or
 
245
otherwise clear the screen. This simply flags the loop to exit
 
246
at the end of it's current run.
 
247
 
 
248
=back
 
249
 
 
250
=item RETURNS
 
251
 
 
252
=over 6
 
253
 
 
254
None.
 
255
 
 
256
=back
 
257
 
 
258
=back
 
259
 
 
260
=head1 SCREEN METHODS
 
261
 
 
262
=head2 add_menu_item( )
 
263
 
 
264
=over 4
 
265
 
 
266
=item EXAMPLE
 
267
 
 
268
=over 6
 
269
 
 
270
 my $index = $s->add_menu_item( "Menu Item Label", \%some_function );
 
271
 
 
272
=back
 
273
 
 
274
=item DESCRIPTION
 
275
 
 
276
=over 6
 
277
 
 
278
Append a new item to the menu list.
 
279
 
 
280
=back
 
281
 
 
282
=item RETURNS
 
283
 
 
284
=over 6
 
285
 
 
286
Returns the list index (starting from 0) of the item that was just
 
287
appended to the list.
 
288
 
 
289
=back
 
290
 
 
291
=back
 
292
 
 
293
=head2 get_menu_items( )
 
294
 
 
295
=over 4
 
296
 
 
297
=item EXAMPLE
 
298
 
 
299
=over 6
 
300
 
 
301
 my @items = $s->get_menu_items();
 
302
 
 
303
=back
 
304
 
 
305
=item DESCRIPTION
 
306
 
 
307
=over 6
 
308
 
 
309
Returns an array of hashrefs. Each hash contains a "label" and
 
310
"func" key/value pairs.
 
311
 
 
312
=back
 
313
 
 
314
=item RETURNS
 
315
 
 
316
=over 6
 
317
 
 
318
An ARRAY.
 
319
 
 
320
=back
 
321
 
 
322
=back
 
323
 
 
324
=head2 del_menu_item( )
 
325
 
 
326
=over 4
 
327
 
 
328
=item EXAMPLE
 
329
 
 
330
=over 6
 
331
 
 
332
 my $old_item = $d->del_menu_item( $index );
 
333
 
 
334
=back
 
335
 
 
336
=item DESCRIPTION
 
337
 
 
338
=over 6
 
339
 
 
340
Remove a specific item from the menu, addressed by it's list index
 
341
(starting from 0), and return the menu item as a hashref.
 
342
 
 
343
=back
 
344
 
 
345
=item RETURNS
 
346
 
 
347
=over 6
 
348
 
 
349
A HASH containing the 'label' and 'func' of the menu item that was
 
350
just removed from the menu list.
 
351
 
 
352
=back
 
353
 
 
354
=back
 
355
 
 
356
=head2 set_menu_item( )
 
357
 
 
358
=over 4
 
359
 
 
360
=item EXAMPLE
 
361
 
 
362
=over 6
 
363
 
 
364
 # Modify the 'label' and 'func' for a specific menu item
 
365
 my $original_item = $s->set_menu_item( $index, $label, $func );
 
366
 
 
367
 # Modify just the label of a menu item
 
368
 my $original_item = $s->set_menu_item( $index, $label, undef );
 
369
 
 
370
 # Modify just the func of a menu item
 
371
 my $original_item = $s->set_menu_item( $index, undef, $func );
 
372
 
 
373
 # Effectively do nothing
 
374
 my $original_item = $s->set_menu_item( $index, undef, undef );
 
375
 
 
376
=back
 
377
 
 
378
=item DESCRIPTION
 
379
 
 
380
=over 6
 
381
 
 
382
Modify the menu item addressed by the given index (starting from 0).
 
383
If the 'label' and/or 'func' arguments are undef then the previous
 
384
value is kept.
 
385
 
 
386
=back
 
387
 
 
388
=item RETURNS
 
389
 
 
390
=over 6
 
391
 
 
392
A HASH of the original values for the modified menu item.
 
393
 
 
394
=back
 
395
 
 
396
=back
 
397
 
 
398
=head1 EXAMPLE USAGE
 
399
 
 
400
The below example assumed that $d is an instances of UI::Dialog.
 
401
 
 
402
 # Create our first screen
 
403
 my $s1 = new UI::Dialog::Screen::Menu ( dialog => $d );
 
404
 $s1->add_menu_item( "Just an option", \&some_function );
 
405
 
 
406
 # Add a menu item that updates it's own label every time
 
407
 # it is selected.
 
408
 our $counter = 0;
 
409
 $s1->add_menu_item
 
410
  ( "Counter: ".$counter,
 
411
    sub {
 
412
      my ($self,$dialog,$index) = @_;
 
413
      $counter++;
 
414
      $self->set_menu_item($index,"Counter: ".$counter, undef);
 
415
    }
 
416
  );
 
417
 
 
418
 # Create a second screen
 
419
 my $s2 = new UI::Dialog::Screen::Menu ( dialog => $d );
 
420
 $s2->add_menu_item( "Another item", \&another_function );
 
421
 
 
422
 # Link the second screen to an option of the first
 
423
 $s1->add_menu_item( "Goto Screen 2", sub { $s2->loop(); } );
 
424
 
 
425
 # Start a menu loop and actually display the first screen
 
426
 $s1->loop();
 
427
 
 
428
Users can get to second menu from selecting the third item on the first
 
429
menu screen. As long as the user continues to select items from the
 
430
second menu, it will continue to loop. If the user cancels the second
 
431
screen, the will return to the first which will itself continue to loop.
 
432
 
 
433
=head1 SEE ALSO
 
434
 
 
435
=over 2
 
436
 
 
437
=item PERLDOC
 
438
 
 
439
 UI::Dialog
 
440
 UI::Dialog::GNOME
 
441
 UI::Dialog::KDE
 
442
 UI::Dialog::Console
 
443
 UI::Dialog::Backend
 
444
 UI::Dialog::Backend::ASCII
 
445
 UI::Dialog::Backend::CDialog
 
446
 UI::Dialog::Backend::GDialog
 
447
 UI::Dialog::Backend::KDialog
 
448
 UI::Dialog::Backend::Nautilus
 
449
 UI::Dialog::Backend::Whiptail
 
450
 UI::Dialog::Backend::XDialog
 
451
 UI::Dialog::Backend::XOSD
 
452
 UI::Dialog::Backend::Zenity
 
453
 
 
454
=back
 
455
 
 
456
=over 2
 
457
 
 
458
=item MAN FILES
 
459
 
 
460
 dialog(1), whiptail(1), zenity(1), gdialog(1), Xdialog(1),
 
461
 osd_cat(1), kdialog(1) and nautilus(1)
 
462
 
 
463
=back
 
464
 
 
465
=head1 BUGS
 
466
 
 
467
Please email the author with any bug reports. Include the name of the
 
468
module in the subject line.
 
469
 
 
470
=head1 AUTHOR
 
471
 
 
472
Kevin C. Krinke, E<lt>kevin@krinke.caE<gt>
 
473
 
 
474
=head1 COPYRIGHT AND LICENSE
 
475
 
 
476
 Copyright (C) 2013  Kevin C. Krinke <kevin@krinke.ca>
 
477
 
 
478
 This library is free software; you can redistribute it and/or
 
479
 modify it under the terms of the GNU Lesser General Public
 
480
 License as published by the Free Software Foundation; either
 
481
 version 2.1 of the License, or (at your option) any later version.
 
482
 
 
483
 This library is distributed in the hope that it will be useful,
 
484
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 
485
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
486
 Lesser General Public License for more details.
 
487
 
 
488
 You should have received a copy of the GNU Lesser General Public
 
489
 License along with this library; if not, write to the Free Software
 
490
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
491
 
 
492
=cut