Perl Curses::UI 窗口不绘制所有小部件

发布于 2024-12-27 14:56:14 字数 2035 浏览 1 评论 0原文

我正在使用 perl 的 Curses::UI 为相当简单的脚本构建 ui。然而,并不是我添加到窗口的所有内容都被绘制了。仅绘制两件事:添加的第一个小部件,以及获得焦点的第一个小部件是什么。执行下面的代码,只绘制第一个TextViewer,然后绘制按钮。未绘制第二个和第三个 TextViewers(对于两个 Windows)。如果我让它们可聚焦,然后点击它们,它们就会被吸引。我做错了什么?

#!/usr/bin/perl -w
use Curses::UI;

my $cui = new Curses::UI;

my $win = $cui->add(
   'window','Window',
   -border  => 1,
   -title   => 'Test Big Window'
);
$win->add(
   'test0','TextViewer',
   -x => 1,
   -y => 1,
   -text => 'test0',
   -focusable  => 0
);
$win->add(
   'test1','TextViewer',
   -x => 1,
   -y => 2,
   -text => 'test1',
   -focusable  => 0
);
$win->add(
   'test2','TextViewer',
   -x => 1,
   -y => 3,
       -text => 'test2',
   -focusable  => 0
);
$win->add(
   'winButtons','Buttonbox',
   -x => 1,
   -y => 4,
   -buttons => [{-label=>'sub_window',-onpress=>sub{show_win2($win);}}]
);

sub show_win2 {
    $win = shift;
    my $win2 = $win->add(
       'window2','Window',
       -border  => 1,
       -title   => 'Test Little Window',
       -centered   => 1,
       -height  => 20,
       -width   => 40
    );
    $win2->add(
       'test3','TextViewer',
       -x => 1,
       -y => 1,
       -text => 'test3',
       -focusable  => 0
    );
    $win2->add(
       'test4','TextViewer',
       -x => 1,
       -y => 2,
       -text => 'test4',
       -focusable  => 0
    );
    $win2->add(
       'test5','TextViewer',
       -x => 1,
       -y => 3,
       -text => 'test5',
       -focusable  => 0
    );
    my $buttons = $win2->add(
       'addOutputButtons','Buttonbox',
       -buttonalignment  => 'right',
       -bg               => -1,
       -fg               => -1,
       -y                => 4,
       -buttons          => [{-label=>'Exit',-onpress=>sub{exit(0);}}]
    );
    $win2->modalfocus();
}

$cui->mainloop();
$win->modalfocus();

PS 除了在每行前手动添加 4 个空格之外,是否有更简单的方法来插入这样的代码块?

I'm using perl's Curses::UI to build a ui for a fairly simple script. However, not everything I add to a window is being drawn. Only two things get drawn, the first widget added, and whatever the first widget to get focus is. Executing the code below, only the first TextViewer and then the button are drawn. The 2nd and 3rd TextViewers (for both Windows) aren't drawn. If I make them focusable, and then tab to them, they get drawn. What am I doing wrong?

#!/usr/bin/perl -w
use Curses::UI;

my $cui = new Curses::UI;

my $win = $cui->add(
   'window','Window',
   -border  => 1,
   -title   => 'Test Big Window'
);
$win->add(
   'test0','TextViewer',
   -x => 1,
   -y => 1,
   -text => 'test0',
   -focusable  => 0
);
$win->add(
   'test1','TextViewer',
   -x => 1,
   -y => 2,
   -text => 'test1',
   -focusable  => 0
);
$win->add(
   'test2','TextViewer',
   -x => 1,
   -y => 3,
       -text => 'test2',
   -focusable  => 0
);
$win->add(
   'winButtons','Buttonbox',
   -x => 1,
   -y => 4,
   -buttons => [{-label=>'sub_window',-onpress=>sub{show_win2($win);}}]
);

sub show_win2 {
    $win = shift;
    my $win2 = $win->add(
       'window2','Window',
       -border  => 1,
       -title   => 'Test Little Window',
       -centered   => 1,
       -height  => 20,
       -width   => 40
    );
    $win2->add(
       'test3','TextViewer',
       -x => 1,
       -y => 1,
       -text => 'test3',
       -focusable  => 0
    );
    $win2->add(
       'test4','TextViewer',
       -x => 1,
       -y => 2,
       -text => 'test4',
       -focusable  => 0
    );
    $win2->add(
       'test5','TextViewer',
       -x => 1,
       -y => 3,
       -text => 'test5',
       -focusable  => 0
    );
    my $buttons = $win2->add(
       'addOutputButtons','Buttonbox',
       -buttonalignment  => 'right',
       -bg               => -1,
       -fg               => -1,
       -y                => 4,
       -buttons          => [{-label=>'Exit',-onpress=>sub{exit(0);}}]
    );
    $win2->modalfocus();
}

$cui->mainloop();
$win->modalfocus();

P.S. Is there an easier way to insert code blocks like that, besides manually adding 4 spaces before each line??

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

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

发布评论

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

评论(2

温柔嚣张 2025-01-03 14:56:14

您可以将 TextEntry-readonly => 一起使用1 选项代替 TextViewer 作为显示文本元素的解决方法。

至少它对我有用。

...
$win->add(
   'test1','TextEntry',
   -x => 1,
   -y => 2,
   -text => 'test1',
   -readonly => 1,
   -focusable => 0,
);
...

You can use TextEntry with -readonly => 1 option instead of TextViewer as a workaround to display the text elements.

At least it works for me.

...
$win->add(
   'test1','TextEntry',
   -x => 1,
   -y => 2,
   -text => 'test1',
   -readonly => 1,
   -focusable => 0,
);
...
惟欲睡 2025-01-03 14:56:14

第一个小部件与其他小部件重叠。修复每个小部件的高度和宽度,并确保没有小部件与其他小部件的空间重叠。确保 x 和 y 参数也设置正确以避免重叠。

First widget is overlapping other widgets. Fix each widget height and width and make sure that no widget overlaps other widget's space. Make sure x and y parameters are also set correctly to avoid overlapping.

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