Re: GUI freezes waiting for callback function to return



On 13.12.2012 14:27, Perdie Perduta wrote:
In C++ I create an object in the call back and that in it's
constructor registers itself to do lengthy processing during gtk idle
events using:

gint iTag = gtk_idle_add( GtkFunction fIdleActivity, gpointer   pMyObject );

On completion, in the destructor it unregisters itself with:

void gtk_idle_remove( gint iTag );

Sorry, but I also can't help you with Pythonese... I only started
learning Gtk recently after finally giving up on the Windows MFC,
Forms applications and other visual studio abominations. :^/

On Fri, Dec 14, 2012 at 1:08 AM,  <jcupitt gmail com> wrote:
On 13 December 2012 11:21, Mateusz Marzantowicz
<mmarzantowicz osdf com pl> wrote:
I'm writing very simple application in Python using pygobject. I'm using

What I've observed is that GUI (menu to be specific) freezes till my
callback function finishes. It's completely unacceptable for GUI
This is because callbacks are run by the main GUI thread, so until
your callback returns, the GUI can't do anything. To give a nice
experience for the user your callbacks must be very short.

If you have to do some lengthy processing, you need to process GUI
events at regular intervals. In PyGtk this used to be:

    def my_long_callback():
        for i in long_time():
            small_chunk_of_work()
            while gtk.events_pending():
                gtk.main_iteration()

I don't know what the pygobject equivalent is, something similar.

In C you can use threads for background tasks, but I think that's
difficult in Python.

John
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



Thanks for your reply.

I think I can figure it out, how to translate from C/C++ to Python but
I'm stuck with GTK+ application design.

Now, all I can think of is taking advantage of open source and try to
find out how others managed to deal with this GUI freeze.

My application is supposed to do some extensive file operations which
may take a while depending on number of files. I can chunk the work as
John suggested but I don't like this approach. 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.


Mateusz Marzantowicz



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