#!/usr/bin/perl -w use strict; use warnings; 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 lib "$FindBin::RealBin/perllib"; use Curses::UI; # Create the root object. my $cui = new Curses::UI ( -clear_on_exit => 1, -debug => $debug, -color_support => 1, ); # Demo index my $current_demo = 2; # Demo windows my %w = (); # ---------------------------------------------------------------------- # Create the explanation window # ---------------------------------------------------------------------- my $w0 = $cui->add( 'w0', 'Window', -border => 1, -y => -1, -height => 3, -bfg => 'red', ); $w0->add('explain', 'Label', -text => "CTRL+B: Back CTRL+O: Options " . "CTRL+X: Menu CTRL+Q: Quit" ); # ---------------------------------------------------------------------- # Creating the windows for the front end # ---------------------------------------------------------------------- my %screens = ( '2' => 'Options page', ); my @screens = sort {$a<=>$b} keys %screens; my %args = ( -border => 1, -titlereverse => 1, -padtop => 0, -padbottom => 5, -ipad => 5, -bfg => 'red', ); while (my ($nr, $title) = each %screens) { my $id = "window_$nr"; $w{$nr} = $cui->add( $id, 'Window', -title => "Curses::UI demo: $title The APE Test($nr/" . @screens . ")", %args,); $w{$nr}-> add( undef,'Label', -y => 0, -x => 5, -bfg => 'blue', -text => " _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n" . "|_ _| | | | | | _ _| | _ | | _ | | _ _| |_ _| | _ _| | _ _| |_ _| \n" . " | | | |_| | | |_ _ | |_| | | |_| | | |_ _ | | | |_ _ | |_ _ | | \n" . " | | | _ | | _ _| | _ | | _ _| | _ _| | | | _ _| |_ _ | | | \n" . " | | | | | | | |_ _ | | | | | | | |_ _ | | | |_ _ _ _| | | | \n" . " |_| |_| |_| |_ _ _| |_| |_| |_| |_ _ _| |_| |_ _ _| |_ _ _| |_| \n" ); } ########################## ##### OPTIONS PAGE ##### ########################## my $EMAIL; $w{2}->add( undef, 'Label', -y => -10, -text => "Please add email address here below in the event that the results will be mailed to you(Optional)\n" ); my $temp; $w{2}->add(undef, 'Buttonbox', -y => -7, -buttons => [ { -label => " [EMAIL] ", -value => 1, -onpress => sub { my $cui=shift()->root; $EMAIL = $cui->question("PLEASE ENTER EMAIL:"); if ($EMAIL) { $w{2}->add( undef, 'Label', -y => -5, -text => "The email you entered is $EMAIL\n"); } else { $cui->dialog("Question cancelled."); } }, }, ], ); # ---------------------------------------------------------------------- # Setup bindings and focus # ---------------------------------------------------------------------- # Bind to quit. $cui->set_binding( sub{ exit }, "\cQ" ); # Bind 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, "\cB" ); sub goto_Options() { $w{2}->focus; } $cui->set_binding( \&goto_Options, "\cO" ); $w{$current_demo}->focus; # ---------------------------------------------------------------------- # Get things rolling... # ---------------------------------------------------------------------- $cui->mainloop;