Skip to content

Instantly share code, notes, and snippets.

@roberto-arista
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roberto-arista/ee737aa745d776f84a22 to your computer and use it in GitHub Desktop.
Save roberto-arista/ee737aa745d776f84a22 to your computer and use it in GitHub Desktop.
Vanilla ProgressBar Window (v2)
### 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