electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 40b3b47d5b0f694424236b551333c5c25d0827c6
parent 13fa81a90efbc6fe72832257ddb083d19d3a18e9
Author: ThomasV <thomasv@gitorious>
Date:   Sat, 24 May 2014 22:54:54 +0200

rewrite WaiingDialog as child class of QThread

Diffstat:
Mgui/qt/main_window.py | 5++---
Mgui/qt/util.py | 32+++++++++++++++-----------------
2 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -29,7 +29,6 @@ import PyQt4 from PyQt4.QtGui import * from PyQt4.QtCore import * import PyQt4.QtCore as QtCore -print PyQt4.QtCore.PYQT_VERSION_STR from electrum.bitcoin import MIN_RELAY_TX_FEE, is_valid from electrum.plugins import run_hook @@ -856,7 +855,7 @@ class ElectrumWindow(QMainWindow): self.broadcast_transaction(tx) - WaitingDialog(self, 'Signing..').start(sign_thread, sign_done) + WaitingDialog(self, 'Signing..', sign_thread, sign_done).start() @@ -878,7 +877,7 @@ class ElectrumWindow(QMainWindow): else: QMessageBox.warning(self, _('Error'), msg, _('OK')) - WaitingDialog(self, 'Broadcasting..').start(broadcast_thread, broadcast_done) + WaitingDialog(self, 'Broadcasting..',broadcast_thread, broadcast_done).start() diff --git a/gui/qt/util.py b/gui/qt/util.py @@ -6,26 +6,24 @@ import time import threading -class WaitingDialog(QDialog): - def __init__(self, parent, message): - QDialog.__init__(self, parent) - self.setWindowTitle('Please wait') +class WaitingDialog(QThread): + def __init__(self, parent, message, run_task, on_complete=None): + QThread.__init__(self) + self.d = QDialog(parent) + self.d.setWindowTitle('Please wait') l = QLabel(message) - vbox = QVBoxLayout(self) + vbox = QVBoxLayout(self.d) vbox.addWidget(l) - self.show() - - def start(self, run_thread, on_complete=None): - def my_thread(): - self.result = run_thread() - self.emit(SIGNAL('done')) - self.accept() - + self.run_task = run_task if on_complete: - self.connect(self, SIGNAL('done'), lambda: on_complete(*self.result)) - - threading.Thread(target=my_thread).start() + self.d.connect(self.d, SIGNAL('done'), lambda: on_complete(*self.result)) + self.d.show() + def run(self): + self.result = self.run_task() + self.d.emit(SIGNAL('done')) + self.d.accept() + class Timer(QThread): @@ -186,5 +184,5 @@ class MyTreeWidget(QTreeWidget): if __name__ == "__main__": app = QApplication([]) - WaitingDialog(None, 'testing ...').start(lambda: [time.sleep(1)], lambda x: QMessageBox.information(None, 'done', "done", _('OK'))) + WaitingDialog(None, 'testing ...', lambda: [time.sleep(1)], lambda x: QMessageBox.information(None, 'done', "done", _('OK'))).start() app.exec_()