On Thu, Feb 20, 2003 at 05:10:47PM -0600, John Hunter wrote:
> I have a long, computationally intensive task that I want to use a
> progress bar for.
>
> My problem is that the progress bar is only displaying at the end of
> the computation, even though the function updating the progress bar is
> being called during the long computation
>
> dlg = gtk.Dialog('Computing coherences', flags=gtk.DIALOG_MODAL)
> dlg.set_transient_for(parent)
> dlg.show()
>
> progBar = gtk.ProgressBar()
> progBar.set_text('Almost there...')
> progBar.set_usize(300, 40)
> progBar.set_fraction(0)
> progBar.show()
> dlg.vbox.pack_start(progBar)
> def progress_callback(frac, msg):
> print msg, frac
> progBar.set_text(msg)
> progBar.set_fraction(frac)
>
> somelongcomputation(pars, progress_callback)
>
> somelongcomputation periodically calls progress_callback with a
> fraction and a message.
[...]
> In my search of the archives, I've seen some references to
>
> while gtk.events_pending():
> gtk.mainiteration()
>
> but am not sure if this is relevant here.
Definitely relevant. Some the events that are pending are widget updates
that change the progress bar's image. If you do not periodically call
mainiteration(), you will notice other effects like parts of your
windows that were covered and uncovered not being redrawn and so forth.
So you could put the above "while..." fragment at the end of
progress_callback, for example.
Malcolm
--
The early bird may get the worm, but the second mouse gets the cheese.
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/