new(是否平分每个box, 内部各个Widget之间的距离)
Window设置内部间隔:
set_border_width($px)
让scroll到最底部:
use Glib qw(FALSE);
use Gtk2 -init;
# create a window with a scrolled text view.
my $window = Gtk2::Window->new;
$window->signal_connect (delete_event => sub {exit});
my $scroll = Gtk2::ScrolledWindow->new;
my $textview = Gtk2::TextView->new;
$scroll->add ($textview);
$window->add ($scroll);
$window->show_all;
my $buffer = $textview->get_buffer;
# create a mark at the end of the buffer, with right gravity,
# so that when you insert text, the mark always stays on
# the right (at the end).
my $end_mark = $buffer->create_mark ('end', $buffer->get_end_iter, FALSE);
# every time we insert text, scroll to that mark.
$buffer->signal_connect (insert_text => sub {
$textview->scroll_to_mark ($end_mark, 0.0, TRUE, 0.0, 1.0);
});
# display the output of some long-running command...
open IN, "sleep 1; ls -l |";
Glib::IO->add_watch (fileno IN, ['in', 'hup'], sub {
my ($fd, $condition) = @_;
if ($condition >= 'in') {
$buffer->insert ($buffer->get_end_iter, scalar );
}
if ($condition >= 'hup') {
close IN;
return FALSE;
}
return TRUE;
});
Gtk2->main;
LINK:http://gtk2-perl.sourceforge.net/faq/#46

博客展示了使用GTK和Perl实现文本插入与滚动的代码。通过创建缓冲区标记,在插入文本时滚动到标记位置。还展示了如何显示长时间运行命令的输出,利用Glib::IO监控文件描述符,根据条件插入文本或关闭文件。

2017

被折叠的 条评论
为什么被折叠?



