add handling

master
agp8x 2018-08-23 19:59:51 +02:00
parent 1a62f4caf0
commit 799e38c50c
1 changed files with 9 additions and 14 deletions

View File

@ -22,14 +22,15 @@ class Updater(threading.Thread):
def __init__(self, target):
threading.Thread.__init__(self)
self.target = target
self.exit = threading.Event()
def run(self):
while True:
self.target.update()
while not self.exit.is_set():
try:
time.sleep(10*60)
self.target.update()
except Exception as e:
print(e, e.args)
self.exit.wait(10)
class Window(object):
@ -39,6 +40,7 @@ class Window(object):
#self.window.set_default_size(150, 150)
self.window.connect("destroy", self.destroy)
self.window.connect("key-press-event", self.on_key)
self.window.connect("button-press-event", self.on_click)
self.window.fullscreen()
self.args = args
self.image = Gtk.Image()
@ -47,11 +49,15 @@ class Window(object):
self.window.show()
def destroy(self, data=None):
if self.updater:
self.updater.exit.set()
Gtk.main_quit()
def main(self):
self.updater = Updater(self)
self.updater.start()
Gtk.main()
def on_click(self, widget, data=None):
self.update()
def on_key(self, event, data=None):
self.destroy()
def update(self):
@ -67,17 +73,6 @@ class Window(object):
pixbuf = loader.get_pixbuf()
loader.close()
return pixbuf
def image2pixbuf(self, im):
buff = BytesIO()
im.save(buff, 'ppm')
contents = buff.getvalue()
buff.close()
loader = GdkPixbuf.PixbufLoader.new_with_type('png')
loader.write(contents)
pixbuf = loader.get_pixbuf()
loader.close()
return pixbuf
if __name__=="__main__":
parser = argparse.ArgumentParser()