Curses-UI-POE

 view release on metacpan or  search on metacpan

examples/color_editor  view on Meta::CPAN

	      " ^Q Quit from the program ^S save file"
	    . " ^W toggle wrapping\n"
	    . " ^X Open the menu         ^O open file"
	    . " ^R toggle hard returns viewing",
);

# ----------------------------------------------------------------------
# Callback routines
# ----------------------------------------------------------------------
	
sub open_dialog()
{
	my $file = $cui->loadfilebrowser( 
		-file         => $currentfile,
		-bg           => "green",
		-fg           => "white",
		-bbg           => "green",
		-bfg           => "white",
		-tbg           => "green",
		-tfg           => "white",
	);

examples/color_editor  view on Meta::CPAN

		    close F;
		    $editor->text($text);
		    $editor->cursor_to_home;
	 	    $currentfile = $file;
		} else { 
		    $cui->error(-message => "Can't read file \"$file\":\n$!");
		}
	}
}

sub save_dialog()
{

	my $file = $cui->savefilebrowser(
		-file         => $currentfile,
		-bg           => "green",
		-fg           => "white",
		-bbg           => "green",
		-bfg           => "white",
		-tbg           => "green",
		-tfg           => "white",

examples/color_editor  view on Meta::CPAN

		$cui->dialog(-message => "File \"$file\"\nsuccessfully saved");
		$currentfile = $file;
	    } else {
		$cui->error(-message => "Error on closing file \"$file\":\n$!");
	    }
	} else {
	    $cui->error(-message => "Can't write to $file:\n$!");
	}
}

sub about_dialog()
{
	$cui->dialog(
		-title => 'About editor',
		-message => "Program : Curses::UI::POE Editor\n"
	 		  . "Author  : Maurice Makaay\n"
		          . "          Marcus Thiesen\n"
			  . "\n"
			  . "The sole purpose of this editor\n"
			  . "is the demonstration of the perl\n"
		 	  . "Curses::UI::POE widget set and the newly\n"
		          . "developed color support.\n",
		-bg           => "white",
		-fg           => "red",
		-bbg           => "white",
		-bfg           => "red",
		-tbg           => "white",
		-tfg           => "red",
	);
}
		
sub exit_dialog()
{
	my $return = $cui->dialog(
			-title     => "Are you sure???", 
			-buttons   => ['yes', 'no'],
			-message => "Do you really want to quit?",
            	        -tbg => "white",
			-tfg => "red",
            	        -bg => "white",
			-fg => "red",
            	        -bbg => "white",

examples/demo-widgets  view on Meta::CPAN

# 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)}        },
],

examples/demo-widgets  view on Meta::CPAN

);

$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 => [

examples/demo-widgets  view on Meta::CPAN

    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(

examples/demo-widgets  view on Meta::CPAN

            -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])
    );
}

examples/demo-widgets  view on Meta::CPAN

# ----------------------------------------------------------------------
# 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;

examples/editor  view on Meta::CPAN

	      " ^Q Quit from the program ^S save file"
	    . " ^W toggle wrapping\n"
	    . " ^X Open the menu         ^O open file"
	    . " ^R toggle hard returns viewing",
);

# ----------------------------------------------------------------------
# Callback routines
# ----------------------------------------------------------------------
	
sub open_dialog()
{
	my $file = $cui->loadfilebrowser( 
		-file         => $currentfile,
	);

	if (defined $file) 
	{
		if (open F, "<$file") {
		    my $text = "";
		    while (<F>) { $text .= $_ }
		    close F;
		    $editor->text($text);
		    $editor->cursor_to_home;
	 	    $currentfile = $file;
		} else { 
		    $cui->error(-message => "Can't read file \"$file\":\n$!");
		}
	}
}

sub save_dialog()
{

	my $file = $cui->savefilebrowser(
		-file         => $currentfile,
	);
	return unless defined $file;

	if (open F, ">$file") {
	    print F $editor->text;
	    if (close F) {
		$cui->dialog(-message => "File \"$file\"\nsuccessfully saved");
		$currentfile = $file;
	    } else {
		$cui->error(-message => "Error on closing file \"$file\":\n$!");
	    }
	} else {
	    $cui->error(-message => "Can't write to $file:\n$!");
	}
}

sub about_dialog()
{
	$cui->dialog(
		-title => 'About editor',
		-message => "Program : Curses::UI::POE Editor\n"
	 		  . "Author  : Maurice Makaay\n"
			  . "\n"
			  . "The sole purpose of this editor\n"
			  . "is the demonstration of my perl\n"
		 	  . "Curses::UI::POE widget set."
	);
}
		
sub exit_dialog()
{
	my $return = $cui->dialog(
			-title     => "Are you sure???", 
			-buttons   => ['yes', 'no'],
			-message => "Do you really want to quit?"
	);

	exit(0) if $return;
}

examples/pop3_reader  view on Meta::CPAN

my $pop3       = undef;
my $connection = undef;

# We do not want STDERR to clutter our screen.
open STDERR, ">/dev/null";

# ----------------------------------------------------------------------
# setup(): Setup the connection
# ----------------------------------------------------------------------

sub check_connection($;)
{
	my $buttons = shift;
	my $conwin  = $buttons->parent;
	my $cui     = $conwin->root;

	foreach my $key ('username','password','host','port') 
	{
		my $obj = $conwin->getobj($key);
		my $value = $obj->get;
		$connection->{$key} = $value;

examples/pop3_reader  view on Meta::CPAN

		if ($value =~ /^\s*$/) {
			$cui->error("Missing value for $key field");
			$obj->focus;
			return;
		}
	}

	return 1;
}

sub setup_connection()
{
	my $conwin = $cui->add(
		'connection_window', 'Window',
		-border => 1,
		-ipad => 2,
		-height => 15,
		-width => 60,
		-centered => 1,
		-title => "POP3 connection",
	);	 

examples/pop3_reader  view on Meta::CPAN

	);

	$conwin->modalfocus;
	$cui->delete('connection_window')
}

# ----------------------------------------------------------------------
# pop3_connect(): Connect to the POP3 server and exit if it fails
# ----------------------------------------------------------------------

sub pop3_connect()
{
	$cui->progress(
		-message => "Connecting to the POP3 server...",
		-max => 4,
		-pos => 1,
	);

	my $error = 0;

	$pop3 = Net::POP3->new(

examples/pop3_reader  view on Meta::CPAN


	$cui->noprogress;

	return !$error;
}

# ----------------------------------------------------------------------
# The inbox screen
# ----------------------------------------------------------------------

sub build_inbox()
{
	my $list = $pop3->list();
	my @ids = sort {$a<=>$b} keys %$list;

	my $msg = "Retrieving headers";
	$cui->progress(
		-max => scalar(@ids),
		-message => $msg,
	);

examples/pop3_reader  view on Meta::CPAN

	);
	
	$ml->set_binding(sub{exit(0)}, "\cC", "\cQ");
	$ml->set_routine('option-select', \&view_message);
}

# ----------------------------------------------------------------------
# view_message(): callback routine for the inbox list
# ----------------------------------------------------------------------

sub view_message()
{
	my $this = shift;	

	# Get the selected message id.
	$this->{-selected} = $this->{-ypos};
	my $id = $this->get;
	$this->{-selected} = undef;
	
	# Retrieve the message from the POP3 server.
	$cui->status("Retrieving message $id from the POP3 server...");

examples/tutorial  view on Meta::CPAN

);

my $win1 = $cui->add(
		     'win1', 'Window',
		     -border => 1,
		     -y    => 1,
		     -bfg  => 'red',
		     );


sub exit_dialog()
{
	my $return = $cui->dialog(
			-message   => "Do you really want to quit?",
			-title     => "Are you sure???", 
			-buttons   => ['yes', 'no'],

	);

	exit(0) if $return;
}



( run in 1.204 second using v1.01-cache-2.11-cpan-65fba6d93b7 )