-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
executable file
·59 lines (45 loc) · 1.65 KB
/
gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import logging, sys
from PyQt4.QtCore import QObject, Qt, QThread, pyqtSignal, pyqtSlot
from PyQt4.QtGui import QApplication, QDialog, QMainWindow
from ui_dlg import Ui_dlg
class MTDialog(QDialog, Ui_dlg):
def __init__(self, parent=None):
super(MTDialog, self).__init__(parent, Qt.Window)
self.setupUi(self)
class MTWorker(QObject):
start = pyqtSignal()
finished = pyqtSignal()
def __init__(self):
super(MTWorker, self).__init__()
self.start.connect(self.doWork)
@pyqtSlot()
def doWork(self):
logging.getLogger().info('doWork slot triggered, doing some work!')
self.finished.emit()
if __name__ == '__main__':
# set up logger so we can see the thread activity
logging.basicConfig(format='%(threadName)s: %(message)s', level=logging.DEBUG)
logger = logging.getLogger()
app = QApplication(sys.argv)
t = QThread()
w = MTWorker()
dlg = MTDialog()
# ensure no premature exit of the application event loop
app.setQuitOnLastWindowClosed(False)
# application dependent start of worker, or quit
dlg.accepted.connect(w.start)
dlg.rejected.connect(t.quit)
dlg.rejected.connect(app.quit)
# this is boiler plate, clean-up and quit
w.finished.connect(w.deleteLater)
w.finished.connect(t.quit)
w.finished.connect(app.quit)
app.aboutToQuit.connect(t.wait)
# move worker to thread
w.moveToThread(t)
# start worker thread (event loop)
t.start()
# main application thread (event loop)
logger.info('starting application')
dlg.show()
sys.exit(app.exec_())