updating (refreshing) a window or widget

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

updating (refreshing) a window or widget

blitz00 (Bugzilla)
Hi !

I have to rewrite some perl/tk code to perl/gtk. Since I'm a beginner in
perl/gtk I've come across some problems in rewriting the code but some
how I've managed to succeed, until now.
My problem is pretty simple. I need to refresh (update) a window (in
fact a widget) every X seconds. Here is the relevant part from the
perl/tk code that i need to rewrite:


$top->repeat($update_time,sub{
   
         .............
   
    Write($command,$sock);
    $id=Tk::After->new($hlist,$read_time,'repeat',sub{
       
        ..........
     
    #somewhere:
        if ($buf eq $EOT){
            $id->cancel;
            $wait++;
            }
        }     );
    $hlist->waitVariable(\$wait);

    ...............
 
    });

where, $top is a Tk::Toplevel, and $hlist is a Tk::HList .
So, using Gtk2::Window and Gtk2::SimpleList how should i do refresh the
list, every X seconds, and in the meanwhile receive data from a daemon
(i don't want the exact code, but the idea and some examples or docs
about the api used)? Could you point me to some documentation sources
other than gtk2-perl.sourceforge.net/doc/ ?

Thank you !

--
Regards, blitz

_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: updating (refreshing) a window or widget

muppet-6

Blitzkrieg said:
> I need to refresh (update) a window (in
> fact a widget) every X seconds.

 $id = Glib::Timeout->add ($milliseconds, \&timeout_handler);

 sub timeout_handler {
    do_cool_stuff ();
    return $need_to_stay_installed;
 }

http://gtk2-perl.sourceforge.net/doc/pod/Glib/MainLoop.html#integer_Glib_Timeout
http://developer.gnome.org/doc/API/2.0/glib/glib-The-Main-Event-Loop.html#g-timeout-add


This will require a rework of your Tk code, as you need to ensure that the
main loop has control in order for the timeout to fire, but personally i find
the Tk model rather confusing.


> So, using Gtk2::Window and Gtk2::SimpleList how should i do refresh the
> list, every X seconds, and in the meanwhile receive data from a daemon
> (i don't want the exact code, but the idea and some examples or docs
> about the api used)? Could you point me to some documentation sources
> other than gtk2-perl.sourceforge.net/doc/ ?

Similarly, you can use Glib::IO->add_watch() to tell glib's main loop to poll
a file descriptor, and invoke a callback when data arrives.  That, coupled
with a timeout, is the traditional way to achieve what you want.

http://live.gnome.org/GTK2_2dPerl_2fFrequentlyAskedQuestions#head-3b88c68683fd189b09455a462d5e41669b7b1142
http://gtk2-perl.sourceforge.net/doc/pod/Glib/MainLoop.html#integer_Glib_IO_add_
http://developer.gnome.org/doc/API/2.0/glib/glib-IO-Channels.html#g-io-add-watch



--
muppet <scott at asofyet dot org>

_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list