Reputation:
I'm working on my python script for xbmc media application so I can update the text label with the percent string. I have set the label text with "0%" for the start, but I have no idea how to update the label text with "1%", "10%", "20%" and so on.
When I try this:
progressStartTime = datetime.datetime.now()
delta = datetime.datetime.now() - progressStartTime
secondsLeft = int(delta.seconds) / float(percentageComplete) * (100.0 -
percentageComplete)
if secondsLeft > 30:
secondsLeft -= secondsLeft % 10
self.setControlLabel(self.main_loading_time_left, "" % secondsLeft)
I'm having trouble with update the text in the label where I'm getting an error. The error I'm getting is: ZeroDivisionError: float division
The error are jumping on this line:
secondsLeft = int(delta.seconds) / float(percentageComplete) * (100.0
- percentageComplete)
Can you please help me how I can update the text in the label with the percent string?
Edit: Here is the update code:
percentageComplete = 0
if percentageComplete < 1:
self.getControl(4202).setLabel("1%")
progressStartTime = datetime.datetime.now()
delta = datetime.datetime.now() - progressStartTime
secondsLeft = int(delta.seconds) * (100.0 - percentageComplete)
if percentageComplete > 1:
secondsLeft -= secondsLeft % 10
self.getControl(4202).setLabel(secondsLeft + "%")
#self.setControlLabel(self.main_loading_time_left, "%" % secondsLeft)
Upvotes: 0
Views: 442
Reputation: 1545
You can't determine what time is left when you're at 0%. Exclude that case with a if case.
Upvotes: 1