-
Notifications
You must be signed in to change notification settings - Fork 47
/
exercise_runner_overlay.py
125 lines (103 loc) · 3.6 KB
/
exercise_runner_overlay.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import typing
from PyQt6 import QtCore
from exercise_runner import run_exercise
from PyQt6.QtWidgets import *
from PyQt6.QtGui import QIcon, QRegularExpressionValidator
from PyQt6.QtCore import Qt, QThread, QObject, pyqtSignal, QRegularExpression
from sys import argv
class Worker(QObject):
finished: pyqtSignal = pyqtSignal()
window: pyqtSignal = pyqtSignal(QObject)
def __init__(self) -> None:
super().__init__()
def run(self,
lecture_no: int,
algorithm: str,
network_type: str,
number_of_devices: int,
):
self.window.emit(run_exercise(lecture_no, algorithm, network_type, number_of_devices, True))
self.finished.emit()
class InputArea(QFormLayout):
def __init__(self) -> None:
super().__init__()
self.__algs = [
"PingPong",
"Gossip",
"RipCommunication",
"TokenRing",
"TOSEQMulticast",
"PAXOS",
"Bully",
"GfsNetwork",
"MapReduceNetwork",
"BlockchainNetwork",
"ChordNetwork",
"AodvNode",
]
self.lecture = QComboBox()
self.lecture.addItems([str(i) for i in range(13) if i != 3])
self.type = QComboBox()
self.type.addItems(["stepping", "async", "sync"])
self.alg = QComboBox()
self.alg.addItems(self.__algs)
self.device = QLineEdit(text="3")
self.device.setValidator(
QRegularExpressionValidator(
QRegularExpression(r"[0-9]*")
))
self.addRow("Lecture", self.lecture)
self.addRow("Type", self.type)
self.addRow("Algorithm", self.alg)
self.addRow("Devices", self.device)
self.lecture.currentTextChanged.connect(self.__lecture_handler)
self.__lecture_handler("0")
def __lecture_handler(self, text: str):
self.alg.setCurrentText(self.__algs[int(text)])
def data(self):
return (
int(self.lecture.currentText()),
self.alg.currentText(),
self.type.currentText(),
int(self.device.text())
)
class MainWindow(QMainWindow):
def __init__(self) -> None:
super().__init__(
windowTitle="Distributed Exercises AAU",
windowIcon=QIcon("icon.ico")
)
self.__thread = None
self.__worker = None
self.__windows = []
layout = QVBoxLayout()
self.__start_btn = QPushButton("Start")
group = QGroupBox(title="Inputs")
self.__input_area = InputArea()
group.setLayout(self.__input_area)
layout.addWidget(group)
layout.addWidget(self.__start_btn)
widget = QWidget()
widget.setLayout(layout)
self.setCentralWidget(widget)
self.__start_btn.clicked.connect(self.__start)
def __start(self):
if self.__worker is not None:
return
self.__thread = QThread()
self.__worker = Worker()
self.__thread.started.connect(lambda: self.__worker.run(*self.__input_area.data()))
self.__worker.finished.connect(self.__thread.quit)
self.__worker.window.connect(self.__window_handler)
self.__worker.finished.connect(self.__worker.deleteLater)
self.__thread.finished.connect(self.__thread.deleteLater)
self.__thread.start()
def __window_handler(self, window: QObject):
self.__windows.append(window)
def show(self) -> None:
self.resize(600, 100)
return super().show()
app = QApplication(argv)
window = MainWindow()
window.show()
app.exec()