GTK2-perl programming question .....?

sparky_dy

New member
I have a GTK window in which I want to update certain fields with values read by my script from an external device.

When I call Gtk2->Main(), the perl program stops, until some event calls Gtk2->main_quit() and then it continues with the line after.

What I want to be able to do is display the window (and leave its widgets listening out for events and triggering callbacks as per my signal_connect()s); but then let my program carry on running so it can talk to the attached device and update values in the main window.

How do I do this? Or is there some event that just fires continuously, and to which I can connect a signal to do my updating thing?
It's O.K. -- I cracked it. So I'm going to post the answer here just in case anybody else wanting to know the same thing ever runs a search and finds this question.

$idle_loop = Glib::Idle->add (\&foo, $data, $priority)

calls the function "foo" everytime around the main() loop. $data is a scalar (if you want to pass a list, you have to pass a reference to it) and $priority can usually be omitted.

You can disable the idle loop you just added with
Glib::Source->remove($idle_loop)
or by having the function foo return a false value (that is to say 0, "" or undef).
 
Back
Top