Hi,

Am Freitag, den 13.05.2005, 09:43 +1200 schrieb Tim Evans:
> manatlan wrote:
> > I really need some help ... i'm going to be mad ...
> > 
> > I've switched from wx to gtk, and try to make a "self-made listview of
> > pictures".
> > To build the pixbuf of an "item which is displayed in my listview" : I
> > start a thread to load the jpeg in the background ... when the thread
> > has done its job, it tell the listview that it can reload the pixbuf
> > (which was cached)... a "gtk userevent" is sended from the thread to
> > my listview
> > 
> > threads_init() is called before the main.loop(), and the thread is
> > delimited by threads_enter() and threads_leave() ... and gtk/pygtk are
> > the latest version on win32/linux
> > 
> > It works very well, and very very very fast, on gnu/linux (ubuntu hoary) !
> > 
> > on win32 :  the main window freeze at the beginning ...
> > after deleted the line "threads_init()" before the main.loop : it
> > works better ... (i can run my app)
> > but it's very long to display items ! (1000 to 10000 times longer)
> > 
> > I've tried the "sleep tricks" of the "pygtk faq" : but it doesn't
> > seems to work better ... (i have changed some values, but doesn't
> > seems to do something)
> > 
> > Every where, i read that a good idea is to change the design ... but i
> > my case : i don't see how i can do that ?! (i anybody can tell me a
> > better idea ?! how can i do it more simple ?!)
> > 
> > I don't know what to do ... is it possible to achieve my goal on win32
> > ? what tricks could i try in my cases ? should i wait a new version of
> > gtk/pygtk to release a win32 version ? should i   back to wx, or
> > maintain 2 versions : a gtk for linux and a wx for windows, or give up
> > gtk/wx to go in qt !?
> > i really need help on this problem
> 
> The current (and unlikely to change) status of threadson win32 is that 
> you basically can't perform gui operations from a subthread, even with 
> gdk_threads_enter/leave.  Essentially, the X11 and win32 gui/threading 
> models are different, and making gtk work the same on both would be very 
> hard.
> 
> This isn't entirely bad news, though, because I think your problem can 
> be fixed qute easily.  You just need to make sure that the signal sent 
> to your listview is done from the main thread instead of the subthread. 
>   The easiest way to do this is using gobject.idle_add via a wrapper 
> function:
> 
>    def do_gui_operation(function, *args, **kw):
>        def idle_func():
>            gtk.threads_enter()
>            try:
>                function(*args, **kw)
>                return False
>            finally:
>                gtk.threads_leave()
>        gobject.idle_add(idle_func)
> 
> Now, in your subthread, instead of calling:
> 
>    gtk.threads_enter()
>    add_image_to_list(list, image)
>    gtk.threads_leave()
> 
> You should call:
> 
>    do_gui_operation(add_image_to_list, list, image)
> 
> You don't need to hold the thread lock to call gobject.idle_add (or 
> do_gui_operation) but you do need to acquire it inside the idle function 
> because they are, by default, run without holding the thread lock.
> 

Does gdk_pixbuf_new_from_file count as gui operation ?

cheers,
   Danny

-- 
www.keyserver.net key id A334AEA6

Attachment: signature.asc
Description: This is a digitally signed message part

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

Reply via email to