-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodule_one_a_simulation.py
61 lines (45 loc) · 1.72 KB
/
module_one_a_simulation.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
60
61
# Title : Module 1a
# Objective : Connections GUI module 1a
# Written by: Saskia Kutz
import sys
from PyQt5 import QtWidgets as qtw
from PyQt5 import QtCore as qtc
from sim.view_simulation_module import ViewSim
from sim.model_simulation_module import ModelSim
class MainWindowSimulation(qtw.QWidget):
"""Connecting GUI to module 1a"""
finished_sim = qtc.pyqtSignal(str)
start_sim = qtc.pyqtSignal(str)
# noinspection PyArgumentList,PyTypeChecker
def __init__(self):
"""MainWindow constructor"""
super().__init__()
# Main UI code goes here
self.model = ModelSim()
self.view = ViewSim()
self.setLayout(qtw.QVBoxLayout())
self.layout().addWidget(self.view)
self.sim_thread = qtc.QThread(parent=self)
self.model.moveToThread(self.sim_thread)
self.model.finished.connect(self.sim_thread.quit)
self.sim_thread.start()
self.view.submitted.connect(self.model.set_data)
self.view.startsim.connect(self.sim_thread.start)
self.view.startsim.connect(self.on_started)
self.view.submitted.connect(self.model.print_income)
self.model.error.connect(self.view.show_error)
self.model.finished.connect(self.on_finished)
# End main UI code
self.show()
def on_started(self):
"""Status bar update upon start"""
self.start_sim.emit('Simulating clusters.')
def on_finished(self):
"""GUI preparation after finish of calculations:
- thread termination
- statusbar update
"""
self.sim_thread.quit()
self.model.deleteLater()
self.view.start_btn.setEnabled(True)
self.finished_sim.emit('Simulation finished.')