/usr/share/doc/libcurses-ui-perl/examples/demo-widgets is in libcurses-ui-perl 0.9609-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 | #!/usr/bin/perl -w
use strict;
use File::Temp qw( :POSIX );
use lib "../lib";
# make KEY_BTAB (shift-tab) working in XTerm
# and also at the same time enable colors
#$ENV{TERM} = "xterm-vt220" if ($ENV{TERM} eq 'xterm');
my $debug = 0;
if (@ARGV and $ARGV[0] eq '-d') {
my $fh = tmpfile();
open STDERR, ">&fh";
$debug = 1;
} else {
# We do not want STDERR to clutter our screen.
my $fh = tmpfile();
open STDERR, ">&fh";
}
use FindBin;
use lib "$FindBin::RealBin/../lib";
use Curses::UI;
# Create the root object.
my $cui = new Curses::UI (
-clear_on_exit => 1,
-debug => $debug,
);
# Demo index
my $current_demo = 1;
# Demo windows
my %w = ();
# ----------------------------------------------------------------------
# Create a menu
# ----------------------------------------------------------------------
sub select_demo($;)
{
my $nr = shift;
$current_demo = $nr;
$w{$current_demo}->focus;
}
my $file_menu = [
{ -label => 'Quit program', -value => sub {exit(0)} },
],
my $widget_demo_menu = [
{ -label => 'Label', -value => sub{select_demo(1)} },
{ -label => 'Buttons', -value => sub{select_demo(2)} },
{ -label => 'Checkbox', -value => sub{select_demo(3)} },
{ -label => 'Texteditor', -value => sub{select_demo(4)} },
{ -label => 'Listbox', -value => sub{select_demo(5)} },
{ -label => 'Popupmenu', -value => sub{select_demo(6)} },
{ -label => 'Progressbar', -value => sub{select_demo(7)} },
{ -label => 'Calendar', -value => sub{select_demo(8)} },
];
my $dialog_demo_menu = [
{ -label => 'Basic dialog', -value => sub{select_demo(9)} },
{ -label => 'Error dialog', -value => sub{select_demo(10)} },
{ -label => 'Filebrowser dialog', -value => sub{select_demo(11)} },
{ -label => 'Progress dialog', -value => sub{select_demo(12)} },
{ -label => 'Status dialog', -value => sub{select_demo(13)} },
{ -label => 'Calendar dialog', -value => sub{select_demo(14)} },
{ -label => 'Question dialog', -value => sub{select_demo(15)} },
];
my $demo_menu = [
{ -label => 'Widget demos', -submenu => $widget_demo_menu },
{ -label => 'Dialog demos', -submenu => $dialog_demo_menu },
{ -label => '------------', -value => sub{} },
{ -label => 'Next demo', -value => \&goto_next_demo },
{ -label => 'Previous demo', -value => \&goto_prev_demo },
];
my $menu = [
{ -label => 'File', -submenu => $file_menu },
{ -label => 'Select demo', -submenu => $demo_menu },
];
$cui->add('menu', 'Menubar', -menu => $menu);
# ----------------------------------------------------------------------
# Create the explanation window
# ----------------------------------------------------------------------
my $w0 = $cui->add(
'w0', 'Window',
-border => 1,
-y => -1,
-height => 3,
);
$w0->add('explain', 'Label',
-text => "CTRL+P: previous demo CTRL+N: next demo "
. "CTRL+X: menu CTRL+Q: quit"
);
# ----------------------------------------------------------------------
# Create the demo windows
# ----------------------------------------------------------------------
my %screens = (
'1' => 'Label',
'2' => 'Buttons',
'3' => 'Checkbox',
'4' => 'Texteditor',
'5' => 'Listbox',
'6' => 'Popupmenu',
'7' => 'Progressbar',
'8' => 'Calendar',
'9' => 'Basic dialog',
'10' => 'Error dialog',
'11' => 'Filebrowser dialog',
'12' => 'Progress dialog',
'13' => 'Status dialog',
'14' => 'Calendar dialog',
'15' => 'Question dialog',
);
my @screens = sort {$a<=>$b} keys %screens;
my %args = (
-border => 1,
-titlereverse => 0,
-padtop => 2,
-padbottom => 3,
-ipad => 1,
);
while (my ($nr, $title) = each %screens)
{
my $id = "window_$nr";
$w{$nr} = $cui->add(
$id, 'Window',
-title => "Curses::UI demo: $title ($nr/" . @screens . ")",
%args
);
}
# ----------------------------------------------------------------------
# Label demo
# ----------------------------------------------------------------------
$w{1}->add(
undef, 'Label',
-text => "A label is a widget which can be used to display\n"
. "a piece of text. This text can be formatted. The\n"
. "supported formats are shown below. It depends upon\n"
. "your terminal if all formats are shown correctly."
);
$w{1}->add(undef,'Label',-text=>"dim font",-y=>5,-dim=>1 );
$w{1}->add(undef,'Label',-text=>"bold font",-y=>7,-bold=>1 );
$w{1}->add(undef,'Label',-text=>"reversed font",-y=>9,-reverse => 1 );
$w{1}->add(undef,'Label',-text=>"underlined font",-x=>15,-y=>5,-underline=>1 );
$w{1}->add(undef,'Label',-text=>"blinking font",-x=>15,-y=>7,-blink=>1 );
# ----------------------------------------------------------------------
# Buttons demo
# ----------------------------------------------------------------------
$w{2}->add(
undef, 'Label',
-text => "The buttons widget displays an array of buttons.\n"
. "As you would have guessed, these buttons can be pressed.\n"
. "Select a button using <TAB>, the arrow keys or <H> and <L>\n"
. "and press a button using the <SPACE> or <ENTER> key."
);
$w{2}->add(
'buttonlabel', 'Label',
-y => 7,
-width => -1,
-bold => 1,
-text => "Press a button please...",
);
sub button_callback($;)
{
my $this = shift;
my $label = $this->parent->getobj('buttonlabel');
$label->text("You pressed: " . $this->get);
}
$w{2}->add(
undef, 'Buttonbox',
-y => 5,
-buttons => [
{
-label => "< Button 1 >",
-value => "the first button",
-onpress => \&button_callback,
},{
-label => "< Button 2 >",
-value => "the second button",
-onpress => \&button_callback,
},{
-label => "< Button 3 >",
-value => "the third button",
-onpress => \&button_callback,
},
],
);
# ----------------------------------------------------------------------
# Checkbox demo
# ----------------------------------------------------------------------
$w{3}->add(
undef, 'Label',
-text => "The checkbox can be used for selecting a true or false\n"
. "value. If the checkbox is checked (a 'X' is inside it)\n"
. "the value is true. <SPACE> and <ENTER> will toggle the\n"
. "state of the checkbox, <Y> will check it and <N> will\n"
. "uncheck it."
);
my $cb_no = "The checkbox says: I don't like it :-(";
my $cb_yes = "The checkbox says: I do like it! :-)";
$w{3}->add(
'checkboxlabel', 'Label',
-y => 8,
-width => -1,
-bold => 1,
-text => "Check the checkbox please...",
);
$w{3}->add(
undef, 'Checkbox',
-y => 6,
-checked => 0,
-label => 'I like this Curses::UI demo so far!',
-onchange => sub {
my $cb = shift;
my $label = $cb->parent->getobj('checkboxlabel');
$label->text($cb->get ? $cb_yes : $cb_no);
},
);
# ----------------------------------------------------------------------
# Texteditor demo
# ----------------------------------------------------------------------
$w{4}->add(
undef, 'Label',
-text => "The texteditor can be used for entering lines or blocks\n"
. "of text. It also can be used in read-only mode as a\n"
. "textviewer. Below you see some of the possibilities that\n"
. "the texteditor widget offers."
);
$w{4}->add(
'te1', 'TextEditor',
-title => 'not wrapping',
-y => 5, -width => 20, -border => 1,
-padbottom => 4,
-vscrollbar => 1,
-hscrollbar => 1,
-onChange => sub {
my $te1 = shift;
my $te2 = $te1->parent->getobj('te2');
my $te3 = $te1->parent->getobj('te3');
$te2->text($te1->get);
$te3->text($te1->get);
$te2->pos($te1->pos);
},
);
$w{4}->add(
'te2', 'TextEditor',
-title => 'wrapping',
-y => 5, -x => 21, -width => 20, -border => 1,
-padbottom => 4,
-vscrollbar => 1,
-hscrollbar => 1,
-wrapping => 1,
-onChange => sub {
my $te2 = shift;
my $te1 = $te2->parent->getobj('te1');
my $te3 = $te2->parent->getobj('te3');
$te1->text($te2->get);
$te3->text($te2->get);
$te1->pos($te2->pos);
},
);
$w{4}->add(
'te3', 'TextViewer',
-y => 5, -x => 42, -width => 20, -border => 1,
-padbottom => 4,
-title => "Read only",
-vscrollbar => 1,
-hscrollbar => 1,
);
$w{4}->add(
undef, 'Label', -y => -3,
-text => "Single line entry:",
-width => 20,
);
$w{4}->add(
undef, 'TextEntry',
-sbborder => 1,
-y => -3,
-x => 21,
-width => 20,
);
$w{4}->add(
undef, 'Label', -y => -1,
-text => "Password entry:",
-width => 20,
);
$w{4}->add(
undef, 'PasswordEntry',
-sbborder => 1,
-y => -1,
-x => 21,
-width => 20,
);
# ----------------------------------------------------------------------
# Listbox demo
# ----------------------------------------------------------------------
my $values = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
my $labels = {
1 => 'One', 2 => 'Two',
3 => 'Three', 4 => 'Four',
5 => 'Five', 6 => 'Six',
7 => 'Seven', 8 => 'Eight',
9 => 'Nine', 10 => 'Ten',
};
$w{5}->add(
undef, 'Label',
-text => "The listbox can be used for selecting on or more options\n"
. "out of a predefined list of options. <SPACE> and <ENTER> will\n"
. "change the current selected option for a normal listbox and a\n"
. "radiobuttonbox, They will toggle the state of the active option in\n"
. "a multi-select listbox. In a multi-select listbox you can also\n"
. "use <Y> and <N> to check or uncheck options. Press </> for a\n"
. "'less'-like search through the list."
);
sub listbox_callback()
{
my $listbox = shift;
my $label = $listbox->parent->getobj('listboxlabel');
my @sel = $listbox->get;
@sel = ('<none>') unless @sel;
my $sel = "selected: " . join (", ", @sel);
$label->text($listbox->title . " $sel");
}
$w{5}->add(
undef, 'Listbox',
-y => 8,
-padbottom => 2,
-values => $values,
-labels => $labels,
-width => 20,
-border => 1,
-title => 'Listbox',
-vscrollbar => 1,
-onchange => \&listbox_callback,
);
$w{5}->add(
undef, 'Listbox',
-y => 8,
-padbottom => 2,
-x => 21,
-values => $values,
-labels => $labels,
-width => 20,
-border => 1,
-multi => 1,
-title => 'Multi-select',
-vscrollbar => 1,
-onchange => \&listbox_callback,
);
$w{5}->add(
undef, 'Radiobuttonbox',
-y => 8,
-padbottom => 2,
-x => 42,
-values => $values,
-labels => $labels,
-width => 20,
-border => 1,
-title => 'Radiobuttonbox',
-vscrollbar => 1,
-onchange => \&listbox_callback,
);
$w{5}->add(
'listboxlabel', 'Label',
-y => -1,
-bold => 1,
-text => "Select any option in one of the listboxes please....",
-width => -1,
);
# ----------------------------------------------------------------------
# Popupmenu
# ----------------------------------------------------------------------
$w{6}->add(
undef, 'Label',
-text => "The popmenu is much like a standard listbox. The difference is\n"
. "that only the currently selected value is visible (or ---- if\n"
. "no value is yet selected). The list of possible values will be\n"
. "shown as a separate popup windows if requested.\n"
. "Press <ENTER> or <CURSOR-RIGHT> to open the popupbox and use\n"
. "those same keys to select a value (or use <CURSOR-LEFT> to close\n"
. "the popup listbox without selecting a value from it). Press\n"
. "</> in the popup for a 'less'-like search through the list."
);
$w{6}->add(
undef, 'Popupmenu',
-y => 9,
-values => $values,
-labels => $labels,
-width => 20,
-onchange => sub {
my $pm = shift;
my $lbl = $pm->parent->getobj('popupmenulabel');
my $val = $pm->get;
$val = "<undef>" unless defined $val;
my $lab = $pm->{-labels}->{$val};
$val .= " (label = '$lab')" if defined $lab;
$lbl->text($val);
$lbl->draw;
},
);
$w{6}->add(
undef, 'Label', -y => 9, -x => 21,
-text => "--- selected --->"
);
$w{6}->add(
'popupmenulabel', 'Label',
-y => 9, -x => 39, -width => -1,
-bold => 1,
-text => "none"
);
# ----------------------------------------------------------------------
# Progressbar
# ----------------------------------------------------------------------
$w{7}->add(
'progressbarlabel', 'Label',
-x => -1, -y => 3, -width => 10, -border => 1,
-text => "the time"
);
$w{7}->add(
undef, 'Label',
-text => "The progressbar can be used to provide some progress information\n"
. "to the user of a program. Progressbars can be drawn in several\n"
. "ways (see below for a couple of examples). In this example, I\n"
. "just built a kind of clock (the values for the bars are \n"
. "depending upon the current time)."
);
$w{7}->add( undef, "Label", -y => 7, -text => "Showing value");
$w{7}->add( 'p1', 'Progressbar', -max => 24,
-x => 15, -y => 6, -showvalue => 1 );
$w{7}->add( undef, "Label", -y => 10, -text => "No centerline");
$w{7}->add( 'p2', 'Progressbar', -max => 60,
-x => 15, -y => 9, -nocenterline => 1 );
$w{7}->add( undef, "Label", -y => 13, -text => "No percentage");
$w{7}->add( 'p3', 'Progressbar', -max => 60,
-x => 15, -y => 12, -nopercentage => 1 );
sub progressbar_timer_callback($;)
{
my $cui = shift;
my @l = localtime;
$w{7}->getobj('p1')->pos($l[2]);
$w{7}->getobj('p2')->pos($l[1]);
$w{7}->getobj('p3')->pos($l[0]);
$w{7}->getobj('progressbarlabel')->text(
sprintf("%02d:%02d:%02d", @l[2,1,0])
);
}
$cui->set_timer(
'progressbar_demo',
\&progressbar_timer_callback, 1
);
$cui->disable_timer('progressbar_demo');
$w{7}->onFocus( sub{$cui->enable_timer ('progressbar_demo')} );
$w{7}->onBlur( sub{$cui->disable_timer ('progressbar_demo')} );
# ----------------------------------------------------------------------
# Calendar
# ----------------------------------------------------------------------
$w{8}->add(
undef, 'Label',
-text => "The calendar can be used to select a date, somewhere between\n"
. "the years 0 and 9999. It honours the transition from the\n"
. "Julian- to the Gregorian calender in 1752."
);
$w{8}->add(
undef, 'Label',
-y => 5, -x => 27,
-text => "Use your cursor keys (or <H>, <J>, <K> and <L>)\n"
. "to walk through the calender. Press <ENTER>\n"
. "or <SPACE> to select a date. Press <SHIFT+J> to\n"
. "go one month forward and <SHIFT+K> to go one\n"
. "month backward. Press <SHIFT+L> or <N> to go one\n"
. "year forward and <SHIFT+H> or <P> to go one year\n"
. "backward. Press <T> to go to today's date. Press\n"
. "<C> to go to the currently selected date."
);
$w{8}->add(
'calendarlabel', 'Label',
-y => 14, -x => 27,
-bold => 1,
-width => -1,
-text => 'Select a date please...'
);
$w{8}->add(
'calendar', 'Calendar',
-y => 4, -x => 0,
-border => 1,
-onchange => sub {
my $cal = shift;
my $label = $cal->parent->getobj('calendarlabel');
$label->text("You selected the date: " . $cal->get);
},
);
# ----------------------------------------------------------------------
# Dialog::Basic
# ----------------------------------------------------------------------
$w{9}->add(
undef, 'Label',
-text => "Curses::UI has a number of ready-to-use dialog windows.\n"
. "The basic dialog is one of them. It consists of a dialog\n"
. "showing a message and one or more buttons. Press the\n"
. "buttons to see some examples of this."
);
$w{9}->add(
undef, 'Buttonbox',
-y => 7,
-buttons => [
{
-label => "< Example 1 >",
-onpress => sub {
shift()->root->dialog("As basic as it gets")
}
},{
-label => "< Example 2 >",
-onpress => sub {
shift()->root->dialog(
-message => "Basic, but carrying a\n"
. "title this time.",
-title => 'Dialog::Basic demo',
);
}
},{
-label => "< Example 3 >",
-onpress => sub {
my $b = shift();
my $value = $b->root->dialog(
-message => "Basic, but carrying a\n"
. "title and multiple buttons.",
-buttons => ['ok','cancel', 'yes', 'no'],
-title => 'Dialog::Basic demo',
);
$b->root->dialog(
-message => "The value for that\n"
. "button was: $value",
-title => "Value?"
);
}
}
],
);
# ----------------------------------------------------------------------
# Dialog::Error
# ----------------------------------------------------------------------
$w{10}->add(
undef, 'Label',
-text => "Curses::UI has a number of ready-to-use dialog windows.\n"
. "The Error dialog is one of them. It consists of a dialog\n"
. "showing an errormessage, an ASCII art exclamation sign\n"
. "and one or more buttons. Press the buttons to see some\n"
. "examples of this."
);
$w{10}->add(
undef, 'Buttonbox',
-y => 7,
-buttons => [
{
-label => "< Example 1 >",
-onpress => sub {
shift()->root->error("Some error occurred, I guess...")
}
},{
-label => "< Example 2 >",
-onpress => sub {
shift()->root->error(
-message => "Unfortunately this program is\n"
. "unable to cope with the enless\n"
. "stream of bugs the programmer\n"
. "has induced!!!!",
-title => 'Serious trouble',
);
}
},{
-label => "< Example 3 >",
-onpress => sub {
my $b = shift();
my $value = $b->root->error(
-message => "General error somewhere in the program\n"
. "Are you sure you want to continue?",
-buttons => ['yes', 'no'],
-title => 'Vague problem detected',
);
$b->root->dialog(
-message => "You do " . ($value?'':'not ')
. "want to continue.",
-title => "What did you answer?"
);
}
}
],
);
# ----------------------------------------------------------------------
# Dialog::Filebrowser
# ----------------------------------------------------------------------
$w{11}->add(
undef, 'Label',
-text => "Curses::UI has a number of ready-to-use dialog windows.\n"
. "The Filebrowser dialog is one of them. Using this dialog\n"
. "it is possible to select a file anywhere on the file-\n"
. "system. Press the buttons below for a demo"
);
$w{11}->add(
undef, 'Buttonbox',
-y => 7,
-buttons => [
{
-label => "< Load file >",
-onpress => sub {
my $cui = shift()->root;
my $file = $cui->loadfilebrowser(
-title => "Select some file",
-mask => [
['.', 'All files (*)' ],
['\.txt$', 'Text files (*.txt)' ],
['\.pm$', 'Perl modules (*.pm)'],
],
);
$cui->dialog("You selected the file:\n$file")
if defined $file;
}
},{
-label => "< Save file (is fake) >",
-onpress => sub {
my $cui = shift()->root;
my $file = $cui->savefilebrowser("Select some file");
$cui->dialog("You selected the file:\n$file")
if defined $file;
}
}
]
);
# ----------------------------------------------------------------------
# Dialog::Progress
# ----------------------------------------------------------------------
$w{12}->add(
undef, 'Label',
-text => "Curses::UI has a number of ready-to-use dialog windows.\n"
. "The Progress dialog is one of them. Using this dialog\n"
. "it is possible to present some progress information to\n"
. "the user. Press the buttons below for a demo."
);
$w{12}->add(
undef, 'Buttonbox',
-y => 7,
-buttons => [
{
-label => "< Example 1 >",
-onpress => sub {
$cui->progress(
-min => 0,
-max => 700,
-title => 'Progress dialog without a message',
-nomessage => 1,
);
for my $pos (0..700) {
$cui->setprogress($pos);
}
sleep 1;
$cui->noprogress;
}
},{
-label => "< Example 2 >",
-onpress => sub {
my $msg = "Counting from 0 to 700...\n";
$cui->progress(
-min => 0,
-max => 700,
-title => 'Progress dialog with a message',
-message => $msg,
);
for my $pos (0..700) {
$cui->setprogress($pos, $msg . $pos . " / 700");
}
$cui->setprogress(undef, "Finished counting!");
sleep 1;
$cui->noprogress;
}
}
]
);
# ----------------------------------------------------------------------
# Dialog::Status
# ----------------------------------------------------------------------
$w{13}->add(
undef, 'Label',
-text => "Curses::UI has a number of ready-to-use dialog windows.\n"
. "The Status dialog is one of them. Using this dialog\n"
. "it is possible to present some status information to\n"
. "the user. Press the buttons below for a demo."
);
$w{13}->add(
undef, 'Buttonbox',
-y => 7,
-buttons => [
{
-label => "< Example 1 >",
-onpress => sub {
$cui->status("This is a status dialog...");
sleep 1;
$cui->nostatus;
}
},{
-label => "< Example 2 >",
-onpress => sub {
$cui->status("A status dialog can contain\n"
. "more than one line, but that is\n"
. "about all that can be told about\n"
. "status dialogs I'm afraid :-)"
);
sleep 3;
$cui->nostatus;
}
}
]
);
# ----------------------------------------------------------------------
# Dialog::Calendar
# ----------------------------------------------------------------------
$w{14}->add(
undef, 'Label',
-text => "Curses::UI has a number of ready-to-use dialog windows.\n"
. "The calendar dialog is one of them. Using this dialog\n"
. "it is possible to select a date."
);
$w{14}->add( undef, 'Label', -y => 7, -text => 'Date:' );
$w{14}->add(
'datelabel', 'Label',
-width => 10,
-y => 7,
-x => 6,
-text => 'none',
);
$w{14}->add(
undef, 'Buttonbox',
-y => 7,
-x => 17,
-buttons => [
{
-label => "< Set date >",
-onpress => sub {
my $label = shift()->parent->getobj('datelabel');
my $date = $label->get;
print STDERR "$date\n";
$date = undef if $date eq 'none';
my $return = $cui->calendardialog(-date => $date);
$label->text($return) if defined $return;
}
},{
-label => "< Clear date >",
-onpress => sub {
my $label = shift()->parent->getobj('datelabel');
$label->text('none');
}
}
]
);
# ----------------------------------------------------------------------
# Dialog::Question
# ----------------------------------------------------------------------
$w{15}->add(
undef, 'Label',
-text => "Curses::UI has a number of ready-to-use dialog windows.\n"
. "The question dialog is one of them. Using this dialog\n"
. "it is possible to prompt the user to enter an answer.",
);
$w{15}->add(
undef, 'Buttonbox',
-y => 7,
-buttons => [
{
-label => "< Example 1 >",
-onpress => sub {
my $button = shift;
my $feeling = $button->root->question("How awesome are you?");
if ($feeling) {
$button->root->dialog("You answered '$feeling'");
}
else {
$button->root->dialog("Question cancelled.");
}
}
},{
-label => "< Example 2 >",
-onpress => sub {
my $button = shift;
my $feeling = $button->root->question(
-question => "How does coffee make you feel?",
-title => 'Dialog::Question example',
);
if ($feeling) {
$button->root->dialog("You answered '$feeling'");
}
else {
$button->root->dialog("Question cancelled.");
}
}
},{
-label => "< Example 3 >",
-onpress => sub {
my $button = shift;
my $feeling = $button->root->question(
-question => "How does coffee make you feel?",
-title => 'Dialog::Question example',
-answer => "Really good.",
);
if ($feeling) {
$button->root->dialog("You answered '$feeling'");
}
else {
$button->root->dialog("Question cancelled.");
}
}
}
],
);
# ----------------------------------------------------------------------
# Setup bindings and focus
# ----------------------------------------------------------------------
# Bind <CTRL+Q> to quit.
$cui->set_binding( sub{ exit }, "\cQ" );
# Bind <CTRL+X> to menubar.
$cui->set_binding( sub{ shift()->root->focus('menu') }, "\cX" );
sub goto_next_demo()
{
$current_demo++;
$current_demo = @screens if $current_demo > @screens;
$w{$current_demo}->focus;
}
$cui->set_binding( \&goto_next_demo, "\cN" );
sub goto_prev_demo()
{
$current_demo--;
$current_demo = 1 if $current_demo < 1;
$w{$current_demo}->focus;
}
$cui->set_binding( \&goto_prev_demo, "\cP" );
$w{$current_demo}->focus;
# ----------------------------------------------------------------------
# Get things rolling...
# ----------------------------------------------------------------------
$cui->mainloop;
|