From b5ba501ad03ef2454e05c4806c56e9f29fe9f337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Veres-Szentkir=C3=A1lyi?= Date: Mon, 4 Nov 2013 15:08:24 +0100 Subject: [PATCH] added Stop button to GIMP plugin --- pysstv/examples/gimp-plugin.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/pysstv/examples/gimp-plugin.py b/pysstv/examples/gimp-plugin.py index eee2d9c..92a4353 100755 --- a/pysstv/examples/gimp-plugin.py +++ b/pysstv/examples/gimp-plugin.py @@ -10,21 +10,41 @@ from PIL import Image, ImageTk from Tkinter import Tk, Label, Button from pysstv import __main__ as pysstv_main from pysstv.examples.pyaudio_sstv import PyAudioSSTV +from threading import Thread import os MODULE_MAP = pysstv_main.build_module_map() +class AudioThread(Thread): + def __init__(self, sstv): + Thread.__init__(self) + self.pas = PyAudioSSTV(sstv) + + def run(self): + self.pas.execute() + + def stop(self): + self.pas.sampler = [] + + class Transmitter(object): def __init__(self, sstv, root): self.sstv = sstv self.root = root + self.audio_thread = None def start_tx(self, e): - PyAudioSSTV(self.sstv).execute() + self.audio_thread = AudioThread(self.sstv) + self.audio_thread.start() + + def stop_tx(self, e): + if self.audio_thread is not None: + self.audio_thread.stop() def close(self, e): self.root.destroy() + def transmit_current_image(image, drawable, mode, vox, fskid): sstv = MODULE_MAP[mode] handle, png_fn = mkstemp(suffix='.png', prefix='pysstv-gimp-') @@ -45,6 +65,9 @@ def transmit_current_image(image, drawable, mode, vox, fskid): start_btn = Button(root, text="TX") start_btn.bind('', tm.start_tx) start_btn.pack() + start_btn = Button(root, text="Stop") + start_btn.bind('', tm.stop_tx) + start_btn.pack() close_btn = Button(root, text="Close") close_btn.bind('', tm.close) close_btn.pack()