add preprocessing to ThreadedButton

This commit is contained in:
ThomasV 2015-04-21 11:00:40 +02:00
parent f50e56d229
commit acf4ad5ec8
1 changed files with 5 additions and 1 deletions

View File

@ -73,8 +73,9 @@ class EnterButton(QPushButton):
class ThreadedButton(QPushButton):
def __init__(self, text, func, on_success=None):
def __init__(self, text, func, on_success=None, before=None):
QPushButton.__init__(self, text)
self.before = before
self.run_task = func
self.on_success = on_success
self.clicked.connect(self.do_exec)
@ -95,12 +96,15 @@ class ThreadedButton(QPushButton):
try:
self.result = self.run_task()
except BaseException as e:
traceback.print_exc(file=sys.stdout)
self.error = str(e.message)
self.emit(SIGNAL('error'))
return
self.emit(SIGNAL('done'))
def do_exec(self):
if self.before:
self.before()
t = threading.Thread(target=self.do_func)
t.setDaemon(True)
t.start()