Re: how to process only some GTK events and leave the others in the queue



On Sun, Dec 28, 2008 at 6:45 AM, Francesco Montorsi
<f18m_cpp217828 yahoo it> wrote:
Hi,
  is it possible to process only some specific events from the GTK/GDK event
queue and leave the others in the queue so they can be processed later by
the main loop?

I'll try to explain it better: I have a GTK-based app which runs the
gtk_main() in its void main().
However at a certain point (e.g. upon user click on a GtkButton), I need to
perform a long computation. I don't want to use a secondary thread; rather
I'd like to do everything from the main thread. To avoid blocking the GUI of
my app during the computation, I call from time to time:

while (gtk_events_pending() != 0)
   gtk_main_iteration();

to process the pending events in the queue. However now I'd like to process
only _some_ of the events of the queue, and leave the others in the queue
itself.

Is it possible?

Hi, for some odd cases you can use:
   http://library.gnome.org/devel/gdk/stable/gdk-Events.html#gdk-event-put

i.e. by pumping the events out of the event queue yourself, and putting the
ones you didnt process back.

I doubt this is what you need, I think that removing the while
(gtk_events_pending())
code all together and replacing it with more returns to the event
loop, and shorter
iterations in timeouts and signal callbacks - will probably fix
whatever problems
you are having.

i.e. save an iterator position and process only a few iterations every time
the idle handler you install is called, when the loop is finally
finished then signal that
your computation is finished.

You can also push a progress bar and set your UI insensitive for the duration
of the process this way.

Cheers,
                    -Tristan



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