what to use except of gtk.main()?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

what to use except of gtk.main()?

Paweł Mączewski
Hi,
 I'm trying to use anything to avoid using gtk.main() as a main loop. The
reson is, when I start a new thread inside the gtk.main() loop, it seems not
to work at all. So I use this construct:
while 1:
        while gtk.events_pending():
                ret = gtk.main_iteration(block=False)
        time.sleep(0.01)

It's ugly and doesn't really work well - can't leave the loop with
gtk.main_quit().

Is there any way to make program leave the loop like that? Or to make it work
well with threads? (I'll make some quick example of code that doesn't work
with threads and send it tomorrow, when I'll have access to my code).

thanks in advance,
 Pawel
--
Paweł Mączewski http://maczewski.dyndns.org
phone: +48 605 996 462 || jabber: [hidden email] || gg #2646463

_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Reply | Threaded
Open this post in threaded view
|

Re: what to use except of gtk.main()?

Jody Steele
Have you checked the following pages?

PyGTK FAQ:
http://www.async.com.br/faq/pygtk/index.py?req=index
(Relevant section: 20)

PyGTK reference:
http://www.pygtk.org/pygtk2reference/gdk-functions.html#function-gdk--threads-init
http://www.pygtk.org/pygtk2reference/gdk-functions.html#function-gdk--threads-enter
http://www.pygtk.org/pygtk2reference/gdk-functions.html#function-gdk--threads-leave


Basically what you need to do is call gtk.gdk.threads_init() followed by  
wrapping gtk.main() in gtk.gdk.threads_enter()/ gtk.gdk.threads_leave().

Where ever another of your other threads uses and gtk objects, you also  
have to wrap that with gtk.gdk.threads_enter() and  
gtk.gdk.threads_leave().  This assures that only one thread is accessing  
any GTK objects at any one time (otherwise there could be serious race  
conditions).

Here's a suitable call to gtk.main()

if __name__ == "__main__":
     gtk.gdk.threads_init()
     gtk.gdk.threads_enter()
     gtk.main()
     gtk.gdk.threads_leave()


Hope this helps.

Jody Steele

On Sun, 05 Jun 2005 11:36:28 -0400, Paweł Mączewski  
<[hidden email]> wrote:

> Hi,
>  I'm trying to use anything to avoid using gtk.main() as a main loop. The
> reson is, when I start a new thread inside the gtk.main() loop, it seems  
> not
> to work at all. So I use this construct:
> while 1:
>         while gtk.events_pending():
>                 ret = gtk.main_iteration(block=False)
>         time.sleep(0.01)
>
> It's ugly and doesn't really work well - can't leave the loop with
> gtk.main_quit().
>
> Is there any way to make program leave the loop like that? Or to make it  
> work
> well with threads? (I'll make some quick example of code that doesn't  
> work
> with threads and send it tomorrow, when I'll have access to my code).
>
> thanks in advance,
>  Pawel



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Reply | Threaded
Open this post in threaded view
|

Re: what to use except of gtk.main()?

Johan Dahlin
> if __name__ == "__main__":
>     gtk.gdk.threads_init()

threads_init should be called earlier, before any calls are made
to gobject or gtk.

It should be called right after importing gtk to avoid any surprises.

--
Johan Dahlin <[hidden email]>
Async Open Source


_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/