Re: GUI freezes waiting for callback function to return



I suggest you to read these interesting pages:

http://blog.borovsak.si/2009/06/multi-threaded-gtk-applications.html
http://blogs.operationaldynamics.com/andrew/software/gnome-desktop/gtk-thread-awareness

Warning: gdk_threads_enter has been deprecated since version 3.6 and should not be used in newly-written code. All GDK and GTK+ calls should be made from the main thread.
Nevertheless I find those pages useful.

Since I'm lazy I've used this approach (gdk_threads_enter/gdk_threads_leave) to change the gui layout from a secondary thread instead of using proper thread synchronization, I mean like using some kind of inter-thread communication, for example (asynchronous) queues (http://developer.gnome.org/glib/2.31/glib-Asynchronous-Queues.html#glib-Asynchronous-Queues.description) or (gtk)signal emitting to make the main thread execute a callback -- the same way when a gui button is pressed.
Unfortunately I use C, not Python, so these are just pointers.

Il 14/12/2012 04:04, Andrew Potter ha scritto:
On Thu, Dec 13, 2012 at 5:57 AM, Mateusz Marzantowicz <
mmarzantowicz osdf com pl> wrote:

My application is supposed to do some extensive file operations which
  may take a while depending on number of files.


If you don't want to offload your work to another thread, Glib has a whole
host of asynchronous file handling operations. I guess the python
documentation is here:
http://www.pygtk.org/docs/pygobject/gio-class-referenandce.html<http://www.pygtk.org/docs/pygobject/gio-class-reference.html>

I prefer to use threading of some kind and I'm little bit disappointed that
GTK+ doesn't offer that out of the box for menus, actions and callbacks.


AFAIK Windows and Android requires GUI functions to be called on the main
loop thread, so it is not unusual. Also, since GTK+ is supposed to work on
Windows it inherits that rule. You should be able to create a thread or
call whatever threading library you want from your callback, but if you
want to deliver results back to the GUI it has to be done back on the main
thread.
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


-----
Nessun virus nel messaggio.
Controllato da AVG - www.avg.com
Versione: 2013.0.2805 / Database dei virus: 2634/5954 -  Data di rilascio: 12/12/2012





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]