Curses::UI - How to close a window?

How could I close win2 when pressing the "Back"-button?

#!/usr/bin/env perl
use warnings; use 5.012;
use Curses::UI;
$Curses::UI::debug = 0;
my $list = [ qw( Use the libraries from distribution instead of system ) ];
my %hash; my $y=0; my $x_1=0; my $width_1=14; my $x_2=16; my $width_2=30;

my $cui = new Curses::UI(  -color_support => 1 );
my $win1 = $cui->add( "win1", 'Window', );

for my $entry ( @$list ) {
    $win1->add( undef, 'TextEntry', -x => $x_1, -y => $y, -width => $width_1, 
        -text => $entry, -focusable => 0, -readonly => 1, );
    $hash{$entry} = $win1->add( $entry, 'TextEntry', -x => $x_2, -y => $y, 
        -width => $width_2, -focusable => 1, -readonly => 0, );
    $y++;
}
my $but1 = $win1->add(  "addbutton1", 'Buttonbox', 
        -buttons => [ { -label => "< OK >", -onpress => \&add } ], 
        -x => 5, -y => $y + 2 );

sub add { 
    my $y = 0;
    my $win2 = $cui->add( "win2", 'Window', );
    for my $entry ( @$list ) {
        my $input = $hash{$entry}->get();
        $win2->add( undef, 'TextEntry', -x => $x_1, -y => $y, -width => $width_1, 
           -text => $entry, -focusable => 0, -readonly => 1, -bg => 'cyan' );
        $win2->add( $y, 'TextEntry', -x => $x_2, -y => $y, -width => $width_2, 
           -text => $input, -focusable => 0, -readonly => 1, -bg => 'cyan' );
        $y++;
    }
    my $but2 = $win2->add(  "addbutton2", 'Buttonbox', 
        -buttons => [{ -label => "< Back >", ###
        -onpress => sub{ $win1->focus() }}], -x => 5, -y => $y + 2 );
    sub add2 { $win1->focus(); };
    $win2->focus();
}

$cui->mainloop;

Answers


Call the delete method on $cui.

@@ -32,7 +32,7 @@
     }
     my $but2 = $win2->add(  "addbutton2", 'Buttonbox', 
         -buttons => [{ -label => "", ###
-        -onpress => sub{ $win1->focus() }}], -x => 5, -y => $y + 2 );
+        -onpress => sub{ $win1->focus(); $cui->delete('win2') }}], -x => 5, -y => $y + 2 );
     sub add2 { $win1->focus(); };
     $win2->focus();
 }

Need Your Help

Automatically clicking a pre-defined region on a webpage?

javascript

I'm trying to do something with Chrome's new speech recognition abilities with HTML5.

Verbose Rexster output/logging on error `null`

java database ubuntu titan rexster

I use Titan in a small Ubuntu server cloud with size 3 and deployed a Rexster extension to to $TITAN_HOME/ext. However, if I try to call an endpoint of the extension I get

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.