Re: Refreshing GUI
- From: Dov Grobgeld <dov imagic weizmann ac il>
- To: bcorr micron com
- Cc: gtk-perl-list gnome org
- Subject: Re: Refreshing GUI
- Date: Sun, 2 Jun 2002 17:18:33 +0300
The usual way this is done is by using the Gtk::Gdk::input_add function.
E.g. you would do:
:
open (TMP, "$external_job_script 2>&1 |");
$window->Gtk::Gdk::input_add(fileno(TMP), ['read'],
\&external_job_handler);
:
main Gtk;
sub external_job_handler {
while(<TMP>) {
$text->insert($font, undef, undef, $_);
}
}
The main loop is all within Gtk and the sub external_job_handler()
is only called when there is data to be read on the tmp file handler.
Here is a complete program:
#!/usr/bin/perl -w
######################################################################
# Example program for input_add.
#
# Dov Grobgeld
# 2002-06-02
######################################################################
use Gtk;
my ($window, $text);
sub create_widgets {
# Create some gtk widgets
$window = Gtk::Widget->new("Gtk::Window",
-type => "-toplevel",
-title => "GtkFileTail",
-delete_event => sub { print "Ouch!\n"; exit }
);
$text = new Gtk::Text();
$text->set_usize(300,100);
$window->add($text);
$window->show_all();
}
# open all the files for reading
sub open_proc {
my($proc) = @_;
open (PROC, "$proc 2>&1 |");
$window->Gtk::Gdk::input_add(fileno(PROC), ['read'],
[\&external_job_handler, \*PROC]);
}
# called whenever there is something to read on the file handle
sub external_job_handler {
my($fh) = @_;
# read a line
$_ = <$fh>;
$text->insert(undef,undef,undef, $_);
return 1;
}
# Leave control to gtk
init Gtk;
create_widgets();
open_proc("perl -ne '\$|=1; print; sleep 1' /etc/passwd");
main Gtk;
__END__
Hope this helps.
Dov
On Tue, May 28, 2002 at 04:47:13AM -0600, bcorr wrote:
I have a GUI that is used to drive the running of various tasks, some
run locally by the GUI, others run remotely via LSF and I am wondering
what the best method for keeping the GUI window contents refreshed would
be.
The problem is that should the GUI be waiting on a job and is
temporarily obscured by another window, when it is revealed again it
sits there looking blank and obviously waiting for a refresh. I have
tried something like this:
open (TMP, "$external_job_script 2>&1 |");
while (<TMP>) {
Gtk->main_iteration while Gtk->events_pending;
}
close TMP;
but the problem is that the external jobs that use LSF just sit there
waiting to run and so don't really kick the while (<TMP>) loop into
life.
Can someone tell me what the best way of keeping the GUI window
regularly refreshed would be?
Cheers,
Bill.
--
___ ___
/ o \ o \
Dov Grobgeld ( o o ) o |
The Weizmann Institute of Science, Israel \ o /o o /
"Where the tree of wisdom carries oranges" | | | |
_| |_ _| |_
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]