Re: GUI freezes waiting for callback function to return



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



-- 
~~~ PEr aRDUa ad asTrA ~~~
(Through adversity to the stars)



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