On 2010-06-27 10:59, Brian Rowlands (Greymouth High School) wrote:
> a) What does putting gtk.main() between gtk.gdk.threads _enter &
> gtk.gdk.threads _leave actually do?

If you've initialised threads (the gtk.gdk.threads_init) call, then 
gtk.main() and any other function that might modify a win32 window, must 
be called with the gdk lock held. By default the lock starts off not 
held, so you need to grab it before calling gtk.main().

> b) Am I right in thinking the time.sleep(2) are there so that the
> progressbar is changed and the gui window is updated?
 >
> c) Without the time.sleep(2) I’m thinking the progressbar would be
> changed but the gui window wouldn’t be updated. Correct?

The code you have posted will, unless you're very lucky, lock up. On 
Windows you can't make GTK+ calls like progressbar.set_fraction in any 
thread other than the main one. To do it properly, add this at the outer 
level of your code somewhere:

def update_progressbar(fraction):
     with gtk.gdk.lock:
         progressbar.set_fraction(fraction)

Then replace the progressbar.set_fraction calls in FractionSetter.run with:

         update_progressbar(random.random())

The time.sleep calls are just there so the whole thing doesn't finish 
and close instantly. Eventually you can replace those calls with actual 
code that takes some time to complete. Updating the UI is handled by the 
code behind the gtk.main() call that you make in the main thread.

> Still getting my head around threads. See all sorts of references all of
> which seem a wee bit beyond my comprehension at the moment. Any comments
> would be appreciated.

-- 
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