On 2010-06-23 11:33, Brian Rowlands (Greymouth High School) wrote:
> Novice but eager to learn. I'm writing a login script which displays a
> GUI window and which I want to update with comments as the script runs.

My preferred pattern for this, especially on Windows, is to use threads. 
The main thread must run the GTK main loop, while background threads do 
the processing.

First thing to note, is that you have to enable threading in pygtk 
before starting. Use this pattern:

   import gtk, gobject, threading

   window = load_my_window() # or whatever
   thread = threading.Thread(target=my_processing_function)
   thread.start()
   gtk.gdk.threads_init()
   with gtk.gdk.lock():
       gtk.main()

The next thing is that background threads must not make calls directly 
to GTK, or your app will lock up. Instead, use gobject.idle_add to tell 
GTK to run a function in the UI thread, and do your GTK calls in that 
function:

   def ui_thread_append_message(message):
       with gtk.gdk.lock:
           XXX add code here to display your message
           return False

   def ui_thread_complete():
       with gtk.gdk.lock:
           window.destroy()
           gtk.main_quit()

   def my_processing_function():
       XXX do some stuff
       gobject.idle_add(ui_thread_append_message, 'Hello World!')
       XXX do some more stuff
       gobject.idle_add(ui_thread_complete)

Post your code, or the important parts of it at least, if you can't get 
this working and I'll have a look at it.

-- 
Tim Evans
Applied Research Associates NZ
http://www.aranz.com/
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to