logo       

Re: ProgressBar: msg#00113

gnome.gtk+.python

Subject: Re: ProgressBar

On Sun, 19 Dec 2004 19:32:50 +0200 (SAST)
"Paul Malherbe" <paul@xxxxxxxxxxxxx> wrote:

> Hi
>
> I would appreciate some help on the following problem I am
> experiencing.
>
> I am migrating a suite from Tkinter to PyGtk and cannot update a
> Progressbar within a loop e.g.
>
> import pygtk
> pygtk.require('2.0')
> import gtk
>
> class ProgressBar:
> def __init__(self, scrn, max):
> align = gtk.Alignment(0.5, 0.5, 1, 0)
> align.show()
> scrn.add(align)
> self.progBar = gtk.ProgressBar()
> self.progBar.set_size_request(100, 20)
> self.progBar.set_orientation(0) # left to right
> self.progBar.set_fraction(0)
> self.progBar.show()
> align.add(self.progBar)
> self.max = max
>
> def increment(self, done):
> frac = float((done * 100.0) / self.max)
> self.progBar.set_text("%s (%s%s)" % \
> ("Updating Files", str(frac), "%"))
> self.progBar.set_fraction(frac/100.0)
>
> if __name__ == "__main__":
> def start(wd):
> pb = ProgressBar(box, 1000)
> for x in range(1000):
> ok = pb.increment(x)
> win = gtk.Window()
> win.show()
> box = gtk.VBox(gtk.FALSE, 0)
> box.show()
> win.add(box)
> but = gtk.Button("start")
> but.connect("clicked", start)
> box.add(but)
> but.show()
> gtk.main()

Try adding this to the end of the increment function:

while gtk.events_pending():
gtk.main_iteration(gtk.FALSE)

Regards,

Chris
_______________________________________________
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