Perl 诅咒::UI

发布于 2024-09-03 05:29:03 字数 1200 浏览 7 评论 0原文

我正在尝试使用 http://search.cpan.org/ 中的 Curses:UI 库dist/Curses-UI/ 在 Linux karmic 上构建 UI。

我可以创建一个简单的用户界面,例如:

#!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();

问题:我需要某种方式向 UI 传达信息,即我有一个循环,它将等待消息到来并更改窗口中的文本。一旦出现此消息,将显示一个弹出窗口。 尝试:

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();

问题:以上方法不起作用。我看到一个黑屏,显示我的消息。我已阅读文档,当我将 $ui->mainloop() 重新定位到 while 循环上方时,我得到了用户界面,但现在没有任何内容与窗口进行通信。

巧合的问题:我需要某种方式来显示用户界面等待输入并显示消息。

有人可以帮我解决这个问题吗?谢谢你!

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 documentation 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〗斷ホ乔殘χμё〖 2024-09-10 05:29:03

我只需用我自己的事件循环替换 $ui->mainloop() ,我自己的东西也会更新。

作为参考, $ui->mainloop() 的实现如下:

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 }
}

所以我只需将您自己的 tick() 函数添加到 while 循环中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文