From: Tim Roberts <
timr@probo.com>
To: wxPython-users@lists.wxwidgets.org
Date: Thu, 27 Jul 2006 17:09:15 -0700
Subject: Re: wx.Timer accurate?No. The final result will need to be an integer, anyway; the progress
bar accepts an integer parameter. The integer division is only aproblem because it truncates; by rearranging so the division is the last
operation, the truncation does the minimum amount of damage.
Ok, I’m still a little confused. I understand the difference in the two methods because I ran this code:
def OnTimer(self, event):
if self.minutes_remaining != 0:
self.progress.SetValue(self.minutes_passed * 100 / self.time)
print self.progress.GetValue()
print self.minutes_passed * (100.0 / self.time)
self.status.SetLabel('%s minute(s) remaining.' % self.minutes_remaining)
self.minutes_passed += 1
self.minutes_remaining -= 1
else:
self.timer.Stop()
self.progress.SetValue(self.minutes_passed * (100.0 / self.time))
self.status.SetLabel('%s minute(s) have elapsed.' % self.time)
wx.Sound.Play
(wx.Sound(r’C:\Windows\Media\notify.wav’))
The print statement helps me to see the two different values. So is the point just that the difference between integer and float division is negligible when done without the parentheses? Because somehow float division seems more accurate, and the progress bar’s SetValue() method takes the float result for whatever reason (maybe it truncates it anyway?). It just seems to me that those slight differences in integer and float division should add up eventually and the progress bar won’t fill up all the way (which was my original problem when I had self.minutes_passed * (100 / self.time)).
So my issue, I guess, is that I understand the difference, but I don’t understand why, since there is a difference, they result in the same thing – unless, like I said, the SetValue method is truncating the argument before processing it.
John
···
---------- Forwarded message ----------
On Thu, 27 Jul 2006 14:30:57 -0400, “John Salerno” < > johnjsal@gmail.com> > wrote: