[pygtk] PyGTK GUI update without signals from GUI

Stephen George steve_geo at optusnet.com.au
Tue Apr 15 07:04:34 WST 2008


Hi Andrew,

Andrew Lapidas wrote:
>  I am currently having a problem updating a GUI.
>
>  I am using PyGTK and Glade to design an interface for a project.  This
>  interface contains no buttons, just images, labels, and a progress
>  bar.  The code for the project is small, and it basically does some
>  things independent of the GUI in an infinite loop.
Regarding  'does some things'
Is this constant processing or periodic checking.
Periodic checking would be easier to do with timers
http://www.pygtk.org/pygtk2tutorial/ch-TimeoutsIOAndIdleFunctions.html#sec-Timeouts

also have a read of 
http://www.pygtk.org/pygtk2tutorial/sec-IdleFunctions.html


>   I need the project
>  code to update the GUI intermittently.  I have found, though, that
>  generally it seems that the gtk.main loop is looking for signals from
>  the GUI and I cannot figure out how to give it signals from another
>  application.
Do you really want a separate application to talk to your GUI, means you 
will have to look at some sort of inter process communication.
sockets, or something more elaborate pyro http://pyro.sourceforge.net/   
I'm sure there is many others.

>   I have thought spawning a new thread from the __init__
>  in the GUI and somehow having it send signals to gtk.main, but I do
>  not know if this will work.
>   
Yes, .. you can set up your own 'signals' but I found it's not well 
documented in pyGTK manual
http://www.pygtk.org/pygtk2tutorial/ch-AdvancedEventAndSignalHandling.html

Instead I referred to gobject documentation from here
http://www.sicem.biz/personal/lgs/docs/gobject-python/docs/gobject-python/gobject-tutorial.html
look at section 'creating your own signals'
but I'm sure there is many other gobject documentation around on net.

When emiting from a thread for any signal whose handler updates the 
GUI., need to do it safely by adding the emit to the idle loop.
gobject.idle_add(self.emit, "cntlrFinaliseConnection")

Have a read, try an implementation, .. if you then get problems ask more 
questions

Steve





More information about the pygtk mailing list