Re: GTK Queue Draw Subtle Question




Thanks Paul,

I put the g_idle_add() in to join the thread. A better place for doing that. Could move the widgets queue redraws from the timer there also. Probably a better design. Some options I will have to consider. The timer is still needed for updating the progress bar and status bar text during drawing though.

A lot you can do with threads but they aren't the easiest to figure out.

Eric



-----Original Message-----
From: Paul Davis <paul linuxaudiosystems com>
To: cecashon <cecashon aol com>
Cc: Thomas Dineen <tdineen ix netcom com>; ML-gtk <gtk-list gnome org>
Sent: Sat, Feb 18, 2017 8:33 am
Subject: Re: GTK Queue Draw Subtle Question

You can call g_idle_add() and various related functions from a non-GTK thread. This is easier and more reliable than using a timer. When your other thread has finished some work, add an idle callback in the main context. the idle callback should call gtk_queue_redraw() for the appropriate window/widgets.

On Sat, Feb 18, 2017 at 12:47 AM, Eric Cashon via gtk-list <gtk-list gnome org> wrote:
Thomas,

You could implement a worker thread that you can monitor it's progress. Once it is done, you can update your display. There are some things to keep in mind when doing this though. You don't want to call GTK functions from your worker thread. If you are drawing your results to a cairo surface, you can draw with your worker thread and when it is all done, update the surface in your drawing area widget. If you need to keep other data you can use glib. Having a worker thread will keep your application responsive.

Some of these concepts are useful for drawing a Mandelbrot fractal so I put a little demo together if you are interested. It uses a timer to check when the drawing is done. When it is, it updates the drawing area. It is in GTK3 but the concepts should be the same for GTK2. Would have to make a few code changes though for GTK2.

https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/cairo_drawings/mandelbrot1.c

Anyways, hope it is of some help.

Eric




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




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