Progressbar does not get totally filled

View: New views
3 Messages — Rating Filter:   Alert me  

Progressbar does not get totally filled

by Sandra Derbring :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am using a progressbar to show my users how fast the program is working. My code looks like this:

(self.seq is the number the user chooses (how many word should be shown). I set self.x to 0 first time I run it.)

self.step = 1./self.seq

for i in range(start,end):
self.processedfiles += 1
self.x += self.step
self.progressbar.set_fraction(self.x)
while gtk.events_pending(): gtk.main_iteration()

It works as far as the bar gets filled when I run the program, but it does not fill up the whole bar (maybe half a step away), and I get this warning:

:GtkWarning: gtk_progress_set_percentage: assertion `percentage >= 0 && percentage <= 1.0' failed
self.progressbar.set_fraction(self.x)


What is wrong? What can I do to get it totally filled?

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

RE: Progressbar does not get totally filled

by snafu_101 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Due to the nature of floating point numbers and depending on the value of self.step, you may have a value just less than 1.0 on one step and a value greater than 1.0 on the next. Try adding:

    if (self.x> 1.0) self.x = 1.0;

snafu

________________________________
Date: Fri, 13 Jun 2008 13:11:05 +0200
From: sandra.derbring@...
To: gtk-list@...
Subject: Progressbar does not get totally filled

I am using a progressbar to show my users how fast the program is working. My code looks like this:





(self.seq is the number the user chooses (how many word should be shown). I set self.x to 0 first time I run it.)





self.step = 1./self.seq





for i in range(start,end):


self.processedfiles += 1


self.x += self.step


self.progressbar.set_fraction(self.x)


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





It works as far as the bar gets filled when I run the program, but it
does not fill up the whole bar (maybe half a step away), and I get this
warning:





:GtkWarning: gtk_progress_set_percentage: assertion `percentage>= 0 && percentage <= 1.0' failed


self.progressbar.set_fraction(self.x)








What is wrong? What can I do to get it totally filled?

_________________________________________________________________
Need to know now? Get instant answers with Windows Live Messenger.
http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_062008
_______________________________________________
gtk-list mailing list
gtk-list@...
http://mail.gnome.org/mailman/listinfo/gtk-list

Re: Progressbar does not get totally filled

by Robert Pearce-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thursday 19 June 2008, John Smith wrote:
> Due to the nature of floating point numbers and depending on the value of
> self.step, you may have a value just less than 1.0 on one step and a value
> greater than 1.0 on the next. Try adding:
>
>     if (self.x> 1.0) self.x = 1.0;
>
> snafu

Indeed. Always try to do The Right Thing and design your code not to rely on
exact results from floating point, since it NEVER gives them. In your case,
don't use addition:

# don't do self.step = 1./self.seq
for i in range(start,end):
    self.processedfiles += 1
    #don't do self.x += self.step, instead do
    self.x = 1.*self.processedfiles/(end-start)
    self.progressbar.set_fraction(self.x)
    while gtk.events_pending(): gtk.main_iteration()

Since self.processedfiles, end and start are all integers, the calculation for
self.x is now properly bounded. There are still rounding errors, but they
don't accumulate so they never become significant.
_______________________________________________
gtk-list mailing list
gtk-list@...
http://mail.gnome.org/mailman/listinfo/gtk-list
LightInTheBox - Buy quality products at wholesale price