logo       

Re: Two nasty problems of mine: msg#00206

gnome.gtk+.python

Subject: Re: Two nasty problems of mine

On Sun, Aug 17, 2003 at 06:11:11PM -0300, Christian Reis wrote:
> On Fri, Aug 15, 2003 at 11:33:24PM +0100, Gustavo J A M Carneiro wrote:
> > > for i in range(1, 100):
> > > my_silly_label.set_text(s[i % 4])
> > > time.sleep(0.1)
> > >
> > > In this example `my_silly_label' (which is a `Label' as you might
> > > guess :) doesn't get refreshed in the loop, but right after that.
> >
> > No, this woudn't work. You have to use timeouts. When calling
> > time.sleep(), gtk becomes blocked and doesn't update the gui. Some code
> > to do what you want would be:
> >
> > def timeout_func(data):
> > itr, label = data
> > i = itr.next()
> > label.set_text(s[i % 4])
> > return True
> > gobject.timeout_add(100, timeout_func, (iter(xrange(1, 100)), label))

This turned to be the solution. I've realized this was a newbie
question after having read the related part of the tutorial :).

> Another (simpler) option would be to call gtk.mainiteration() before the
> time.sleep() -- the FAQ has an entry on this.

Unfortunately with gtk.mainiteration refreshing is too rare. My label
gets refreshed roughly in every tenth iteration. The FAQ mentions that
if your callback takes a long time to process, this isn't an option
and that's the case.

Regards,
--
Laci

Please sign http://noepatents.org against software patents in Europe!
_______________________________________________
pygtk mailing list pygtk@xxxxxxxxxx
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise