From ec564d93cef95b285c59f713329a8a43a79864ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Veres-Szentkir=C3=A1lyi?= Date: Tue, 5 Nov 2013 19:38:40 +0100 Subject: [PATCH] update ProgressCanvas in separate thread --- pysstv/examples/gimp-plugin.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pysstv/examples/gimp-plugin.py b/pysstv/examples/gimp-plugin.py index 48fb429..77e213e 100755 --- a/pysstv/examples/gimp-plugin.py +++ b/pysstv/examples/gimp-plugin.py @@ -13,6 +13,7 @@ from pysstv.examples.pyaudio_sstv import PyAudioSSTV from pysstv.sstv import SSTV from itertools import repeat from threading import Thread +from Queue import Queue import os MODULE_MAP = pysstv_main.build_module_map() @@ -72,6 +73,20 @@ class Transmitter(object): self.root.destroy() +class CanvasUpdater(Thread): + def __init__(self, progress): + Thread.__init__(self) + self.progress = progress + self.queue = Queue() + + def update_image(self, line=None): + self.queue.put(line) + + def run(self): + while True: + self.progress.update_image(self.queue.get()) + + class ProgressCanvas(Canvas): def __init__(self, master, image): self.height_ratio = 1 @@ -123,7 +138,9 @@ def transmit_current_image(image, drawable, mode, vox, fskid): s.add_fskid_text(fskid) pc = ProgressCanvas(root, pil_img) pc.pack() - tm = Transmitter(s, root, pc) + cu = CanvasUpdater(pc) + cu.start() + tm = Transmitter(s, root, cu) tm1750 = Transmitter(Sine1750(None, 44100, 16), None, None) buttons = Frame(root) for text, tram in (('TX', tm), ('1750 Hz', tm1750)):