add preprocessing to ThreadedButton
This commit is contained in:
parent
f50e56d229
commit
acf4ad5ec8
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue