add handling
parent
1a62f4caf0
commit
799e38c50c
|
|
@ -22,14 +22,15 @@ class Updater(threading.Thread):
|
||||||
def __init__(self, target):
|
def __init__(self, target):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.target = target
|
self.target = target
|
||||||
|
self.exit = threading.Event()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while True:
|
while not self.exit.is_set():
|
||||||
self.target.update()
|
|
||||||
try:
|
try:
|
||||||
time.sleep(10*60)
|
self.target.update()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e, e.args)
|
print(e, e.args)
|
||||||
|
self.exit.wait(10)
|
||||||
|
|
||||||
|
|
||||||
class Window(object):
|
class Window(object):
|
||||||
|
|
@ -39,6 +40,7 @@ class Window(object):
|
||||||
#self.window.set_default_size(150, 150)
|
#self.window.set_default_size(150, 150)
|
||||||
self.window.connect("destroy", self.destroy)
|
self.window.connect("destroy", self.destroy)
|
||||||
self.window.connect("key-press-event", self.on_key)
|
self.window.connect("key-press-event", self.on_key)
|
||||||
|
self.window.connect("button-press-event", self.on_click)
|
||||||
self.window.fullscreen()
|
self.window.fullscreen()
|
||||||
self.args = args
|
self.args = args
|
||||||
self.image = Gtk.Image()
|
self.image = Gtk.Image()
|
||||||
|
|
@ -47,11 +49,15 @@ class Window(object):
|
||||||
self.window.show()
|
self.window.show()
|
||||||
|
|
||||||
def destroy(self, data=None):
|
def destroy(self, data=None):
|
||||||
|
if self.updater:
|
||||||
|
self.updater.exit.set()
|
||||||
Gtk.main_quit()
|
Gtk.main_quit()
|
||||||
def main(self):
|
def main(self):
|
||||||
self.updater = Updater(self)
|
self.updater = Updater(self)
|
||||||
self.updater.start()
|
self.updater.start()
|
||||||
Gtk.main()
|
Gtk.main()
|
||||||
|
def on_click(self, widget, data=None):
|
||||||
|
self.update()
|
||||||
def on_key(self, event, data=None):
|
def on_key(self, event, data=None):
|
||||||
self.destroy()
|
self.destroy()
|
||||||
def update(self):
|
def update(self):
|
||||||
|
|
@ -68,17 +74,6 @@ class Window(object):
|
||||||
loader.close()
|
loader.close()
|
||||||
return pixbuf
|
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__":
|
if __name__=="__main__":
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("base_url", nargs="?", default=DEFAULT_BASE)
|
parser.add_argument("base_url", nargs="?", default=DEFAULT_BASE)
|
||||||
Loading…
Reference in New Issue