1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os
import pygtk
pygtk.require('2.0')
import gtk
import time
class CountDownTimer:
def run(self,output,t,step=1.0):
counter=float(t)
steps=range(int(t/step))
for sec in steps:
print counter
output.set_label(str(int(counter)))
while gtk.events_pending():
gtk.main_iteration()
time.sleep(step)
counter-=step
print 'done'
class myprog:
def evnmt_delete(self, widget, evenement, data=None):
gtk.main_quit()
return False
def go(self,data):
c = CountDownTimer()
c.run(self.go_osd,10.0,0.5)
print 'GO'
gtk.main_quit()
def __init__(self):
self.fenetre = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.fenetre.set_title("Download Manager")
self.fenetre.connect("delete_event", self.evnmt_delete)
self.fenetre.set_border_width(4)
#
self.box1 = gtk.VBox(False, 0)
self.fenetre.add(self.box1)
# go
self.box2= gtk.HBox(False,0)
self.go_osd = gtk.Button("Go")
self.go_osd.connect("clicked", self.go)
self.box2.pack_start(self.go_osd, True, True, 0)
self.box1.pack_start(self.box2, False, False, 0)
self.go_osd.show()
self.box2.show()
# quit
self.quitbox = gtk.HBox(False, 0)
self.quit_osd = gtk.Button("Quit/Stop")
self.quit_osd.connect("clicked", lambda w: gtk.main_quit())
self.quitbox.pack_start(self.quit_osd, True, False, 0)
self.box1.pack_start(self.quitbox, False, False, 0)
self.quit_osd.show()
self.quitbox.show()
#
self.box1.show()
self.fenetre.show()
def waitForEvents():
gtk.main()
if __name__ == "__main__":
myProg = myprog()
waitForEvents() |
Partager