Perl Curses::UI
I am trying to use the library Curses:UI from http://search.cpan.org/dist/Curses-UI/ to build a UI on linux karmic.
I can create a simple user interface e.g.:
#!usr/usr/bin/perl
use strict;
use Curses;
use Curses::UI;
$ui = new Curses::UI(-color_support=>1,-clear_on_exit=>1,-intellidraw=>1);
my $window = $ui->add('window', 'Window',-intellidraw=>1);
my $message = $window->add(-text=>"Hello!",-intellidraw=>1);
$window->focus();
$ui->mainloop();
Question: I need some way to communicate informatio to the UI i.e. I have a loop which will wait for message to come and change the text in window. Once this message comes a popup will be displayed. Attempt:
my $ui = new Curses::UI(-color_support=>1,-clear_on_exit=>1,-intellidraw=>1);
my $window = $ui->add('window', 'Window',-intellidraw=>1);
my $message = $window->add(-text=>"Hello!",-intellidraw=>1);
pseudocode
while(true) #implemented a function to wait
{
popup($window->text("Hello how are you?"));
}
$window->focus();
$ui->mainloop();
Problem: The above does not work. I am given a dark screen where my message is displayed. I have read the docume开发者_StackOverflow中文版ntation and when I relocate : $ui->mainloop() above the while loop I am given the user interface but now nothing communicates to the window.
Coincise Question: I need some way of displaying the user interface wait for inputs and display messages.
Could anyone please help me on this? Thank you!
I would just replace $ui->mainloop() with my own eventloop where my own stuff is updated aswell.
For reference $ui->mainloop() is implemented as follows:
sub mainloop {
my ($self) = @_;
# Draw the initial screen.
$self->focus(undef, 1); # 1 = forced focus
$self->draw;
doupdate();
# Inifinite event loop.
while (1) { $self->do_one_event }
}
So I would simply add your own tick() function to the while loop.
精彩评论