1#!/usr/bin/perl 2use strict; 3use warnings; 4use diagnostics; 5use Time::HiRes qw(usleep); 6 7# demo helper 8sub printerr { print STDERR "\n".'UI::Dialog : '.join( " ", @_ )."\n"; sleep(1); } 9 10use UI::Dialog::Backend::KDialog; 11my $d = new UI::Dialog::Backend::KDialog 12 ( title => "KDialog Demo", 13 height => 16, width => 65, 14 listheight => 5, 15 debug => 1, 16 test_mode => 0, 17 ); 18 19# placeholder variable 20our $text; 21 22#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 23$text = 24 q{This is a "yesno" question widget. There should be "YES" and "NO" buttons below this text message. The title of this message box should be "$d->yesno()".}; 25my $is_yes = $d->yesno( title => '$d->yesno()', text => $text ); 26if ($d->state() eq "OK" && $is_yes) { 27 printerr("The user has answered YES to the yesno widget."); 28} else { 29 printerr("The user has answered NO or pressed ESC to the yesno widget."); 30} 31 32#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 33$text = 34 q{This is a "yesnocancel" question widget. There should be "YES", "NO" and "CANCEL" buttons below this text message. The title of this message box should be "$d->yesno()".}; 35$is_yes = $d->yesnocancel( title => '$d->yesnocancel()', text => $text ); 36if ($d->state() eq "OK" && $is_yes) { 37 printerr("The user has answered YES to the yesnocancel widget."); 38} else { 39 printerr("The user has answered NO or pressed ESC to the yesnocancel widget."); 40} 41 42#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 43$text = 44 q{This is a "warningyesno" question widget. There should be "YES" and "NO" buttons below this text message and a warning icon to the left. The title of this message box should be "$d->warningyesno()".}; 45$is_yes = $d->warningyesno( title => '$d->warningyesno()', text => $text ); 46if ($d->state() eq "OK" && $is_yes) { 47 printerr("The user has answered YES to the warningyesno widget."); 48} else { 49 printerr("The user has answered NO or pressed ESC to the warningyesno widget."); 50} 51 52#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 53$text = 54 q{This is a "warningyesnocancel" question widget. There should be "YES", "NO" and "CANCEL" buttons below this text message and a warning icon to the left. The title of this message box should be "$d->warningyesnocancel()".}; 55$is_yes = $d->warningyesnocancel 56 ( title => '$d->warningyesnocancel()', 57 text => $text 58 ); 59if ($d->state() eq "OK" && $is_yes) { 60 printerr("The user has answered YES to the warningyesnocancel widget."); 61} else { 62 printerr("The user has answered NO or pressed ESC to the warningyesnocancel widget."); 63} 64 65#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 66$text = 67 q{This is the msgbox widget. There should be a single "OK" button below this text message and the title of this message box should be "msgbox".}; 68$d->msgbox( title => 'msgbox', text => $text ); 69if ($d->state() eq "OK") { 70 printerr("The user pressed OK."); 71} else { 72 printerr("The user pressed CTRL+C or ESC instead of OK."); 73} 74 75#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 76$text = 77 q{This is an infobox widget. There should be a single "OK" button below this text message and the title of this message box should be "$d->infobox()". Unlike other implementations, this infobox does not pause for any time and is essentially a messagebox at heart.}; 78$d->infobox( timeout => 3000, title => '$d->infobox()', text => $text); 79if ($d->state() eq "OK") { 80 printerr("The user pressed OK."); 81} else { 82 printerr("The user pressed ESC or CTRL+C."); 83} 84 85#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 86$text = 87 q{This is a password input box. The field below should be pre-populated with the words "insecure password entry" but displayed as asterisks for each character. Providing "entry" text to a password field is inherently insecure.}; 88my $password = $d->password 89 ( title => '$d->password()', 90 text => $text, 91 entry => 'insecure password entry', 92 ); 93if ($d->state() eq "OK") { 94 printerr( "You input: ".($password||'NULL')); 95} else { 96 printerr("The user pressed CTRL+C or ESC instead of OK."); 97} 98 99#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 100$text = 101 q{This is a text input box. The field below should be pre-populated with the words "preset text entry".}; 102my $user_input = $d->inputbox 103 ( title => '$d->inputbox()', text => $text, entry => 'preset text entry' ); 104if ($d->state() eq "OK") { 105 printerr( "You input: ".($user_input||'NULL') ); 106} 107 108#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 109$d->textbox( title => '$d->textbox()', path => $0 ); 110if ($d->state() eq "OK") { 111 printerr("The user pressed EXIT."); 112} else { 113 printerr("The user pressed CTRL+C or ESC instead of EXIT."); 114} 115 116#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 117$text = 118 q{This text is in the second column of the first row of a menu list dialog. The title should be "$d->menu()" and there should be two items in the list. "Test" with the label "testing" and "WT" with the label "Whiptail".}; 119my $menuSelect = $d->menu 120 ( title => '$d->menu()', 121 text => $text, 122 list => 123 [ 'Test', 'testing', 124 'WT', 'Whiptail' 125 ] 126 ); 127if ($d->state() eq "OK") { 128 printerr( "You selected: '".($menuSelect||'NULL')."'\n"); 129} else { 130 printerr("The user pressed CTRL+C or ESC instead of OK."); 131} 132 133#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 134$text = 135 q{This text is in the third column of the first row of a checklist dialog. The title should be "$d->checklist()" and there should be two items in the list. "Test" with the label "testing" (already selected) and "WT" with the label "Whiptail" (not selected).}; 136my @checkSelect = $d->checklist 137 ( title => '$d->checklist()', 138 text => $text, 139 list => 140 [ 'Test', [ 'testing', 1 ], 141 'WT', [ 'Whiptail', '0' ] 142 ] 143 ); 144if ($d->state() eq "OK") { 145 printerr( "You selected: '".(join("' '",@checkSelect))."'"); 146} else { 147 printerr("The user pressed CTRL+C or ESC instead of OK."); 148} 149 150#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 151$text = 152 q{This text is in the third column of the first row of a radiolist dialog. The title should be "$d->radiolist()" and there should be two items in thbe list. "Test" with the label "testing" (not selected) and "WT" with the label "Whiptail" (already selected).}; 153my $radioSelect = $d->radiolist 154 ( title => '$d->radiolist()', 155 text => $text, 156 list => 157 [ 'test',[ 'testing', 0 ], 158 'WT', [ 'Whiptail', 1 ] 159 ] 160 ); 161if ($d->state() eq "OK") { 162 printerr( "You selected: '".$radioSelect."'"); 163} else { 164 printerr("The user pressed CTRL+C or ESC instead of OK."); 165} 166 167#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 168$text = 169 q{The next screen is a file selection widget. The title should be "$d->fselect()" and the starting path should be this script file. Should only let you select files and not directories.}; 170$d->msgbox(text=>$text); 171my $filename = $d->fselect 172 ( title => '$d->fselect()', 173 height => 10, 174 path => $0, 175 ); 176if ($d->state() eq "OK") { 177 printerr( "You selected: '".$filename."'"); 178} else { 179 printerr("The user pressed CTRL+C or ESC instead of OK."); 180} 181 182#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 183$text = 184 q{The next screen is a path selection widget. The title should be "$d->dselect()" and the starting path should be this script file. Should not let you select files, only directories.}; 185$d->msgbox(text=>$text); 186my $dirname = $d->dselect 187 ( title => '$d->dselect()', 188 height => 10, 189 path => $0, 190 ); 191if ($d->state() eq "OK") { 192 printerr( "You selected: '".$dirname."'"); 193} else { 194 printerr("The user pressed CTRL+C or ESC instead of OK."); 195} 196 197#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 198exit(); 199