Gtk::ProgressBar doesn't work synchronously

2008-04-09 Thread Garth's KidStuff
Hi All,

I'm converting a large Windows/Mac project to run on Ubuntu, and I'm a
little stuck when trying to use a ProgressBar.  We have a cross-platform
class that assumes I can create a Progress Monitor dialog during
time-intensive tasks, and then periodically update the progress as the task
completes.

The problem that I'm having with using Gtk::ProgressBar seems to be a
fundemental one about when dialogs can actually appear in the main window.
For example, what I'd like to do is something along the lines of:

[in my main thread]
...
Start a complex task
Create a Progress Monitor dialog and show it
Update the dialog as the task progresses
Destroy the dialog


When I try this, nothing shows up *grin*.  As far as I can tell, I need to
let the run loop process so that the dialog can be shown. (i.e. if I omit
the destroy step in the above, I see the dialog as soon as I drop out of
my code in the main thread, but that's too late -- the task is already
completed)

One way to solve this is, of course, to rewrite all the places that use the
Progress Monitor so that the work is done in a thread and the main thread
can just be showing the progress bar.  I'd hesitate to try that with this
code base because of the number of places in cross-platform code that would
have to be rewritten.

Do any of you have any thoughts?

Thanks in advance!

-- 
Garth Upshaw
Garth's KidStuff
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Gtk::ProgressBar doesn't work synchronously

2008-04-09 Thread Gabriele Greco
 Start a complex task
 Create a Progress Monitor dialog and show it
 Update the dialog as the task progresses
 Destroy the dialog


Every time you update the dialog (or also more often if you can) you should
do something like:

while (gtk_events_pending())
   gtk_main_iteration();

To let GTK update the interface.

GTK runs only when you give the control to gtk_main() or if you give him
some space with gtk_main_iteration() :)

-- 
Bye,
 Gabry
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list