/ProgressBar_v2.py Secret
Last active
August 29, 2015 14:21
Vanilla ProgressBar Window (v2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Modules | |
from time import sleep | |
from datetime import datetime | |
from vanilla import FloatingWindow, ProgressBar, TextBox | |
### Classes, functions, procedures, constants | |
class NiceProgressBar(object): | |
width = 300 | |
height = 80 | |
progress = 0 | |
def __init__(self, len_cycle): | |
self.begin = datetime.now() | |
self.plugin_window = FloatingWindow((self.width, self.height), | |
"Blinky Progress Bar", | |
closable=True) | |
self.plugin_window.progress = ProgressBar((20, 20, -60, 20), | |
minValue=0, | |
maxValue=len_cycle) | |
self.plugin_window.percentage = TextBox((-40, 20, 40, 20), | |
'0%') | |
self.plugin_window.elapsed = TextBox((20, 40, -20, 20), | |
"Elapsed time: 00:00") | |
self.plugin_window.open() | |
def oneStep(self): | |
self.plugin_window.hide() | |
self.plugin_window.show() | |
self.plugin_window.progress.increment(1) | |
self.progress +=1 | |
self.plugin_window.percentage.set('%d%%' % (int(round(self.progress *100 / len_cycle, 0)))) | |
delta = datetime.now() - self.begin | |
self.plugin_window.elapsed.set('%#02d:%#02d' % (int(delta.seconds / 60), delta.seconds % 60)) | |
def closeWindow(self): | |
self.plugin_window.close() | |
### Instructions | |
if __name__ == '__main__': | |
len_cycle = 20 | |
progress = NiceProgressBar(len_cycle) | |
for eachStep in xrange(len_cycle): | |
progress.oneStep() | |
sleep(.1) | |
progress.closeWindow() | |
print 'done' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment