Perl Curses::UI 窗口不绘制所有小部件
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将
TextEntry
与-readonly => 一起使用1
选项代替TextViewer
作为显示文本元素的解决方法。至少它对我有用。
You can use
TextEntry
with-readonly => 1
option instead ofTextViewer
as a workaround to display the text elements.At least it works for me.
第一个小部件与其他小部件重叠。修复每个小部件的高度和宽度,并确保没有小部件与其他小部件的空间重叠。确保 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.