Browse Source

rewrite WaiingDialog as child class of QThread

283
ThomasV 11 years ago
parent
commit
40b3b47d5b
  1. 5
      gui/qt/main_window.py
  2. 32
      gui/qt/util.py

5
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()

32
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_()

Loading…
Cancel
Save