The basic idea is this: You have some need in your pygtk app for some code to run asynchronously in a seperate thread (the "background task"). In order for it to be useful, you need two way communication between the background task and your main thread which handles all the GUI stuff. e.g.
class BackgroundTask(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.in_q = Queue.Queue() self.out_q = Queue.Queue() self.die = False # ...
def run(self): while not self.die: args = self.in_q.get() result = self.do_stuff(*args) self.out_q.put(result)
And then in your gtk idle function a fragment like this:
if not background_task.out_q.empty(): result = background_task.out_q.get()
# do stuff with the result...
And then in whatever part of your program that initiates background tasks something like
background_task.in_q.put(args)
Oops. I went back and looked at some of my code and realized I left out an important detail. The problem with what I wrote above is that I said to put the out_q processing code in a gtk idle function and that implies _polling_ which is sooo wrong.
What I end up doing in my code is creating a pipe with os.pipe, passing the write_end to the background task and passing the read_end to gtk.input_add. When the background task wants to wake up with GUI thread, it writes a single char to the pipe using os.write.
Unfortunately, I don't know if this will work on Microsoft Windows. I know that Windows python has os.pipe, but I have no idea if gtk.input_add on Windows will accept and work with a pipe endpoint. I don't have a windows machine here to test it out on. Does anyone know about this?
_______________________________________________ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
