source: geniuswebcore/geniusweb/simplerunner/gui/GUI.py@ 92

Last change on this file since 92 was 90, checked in by Bart Vastenhouw, 3 years ago

Refactor to help reusing partiesserver.

File size: 2.3 KB
Line 
1import logging
2import sys
3from typing import List, Optional
4
5from PyQt5 import QtCore
6from PyQt5.QtWidgets import QWidget, QTextEdit, QGridLayout, QPushButton, \
7 QApplication, QMainWindow
8from tudelft_utilities_logging.Reporter import Reporter
9
10from geniusweb.simplerunner.ClassPathConnectionFactory import ClassPathConnectionFactory
11from geniusweb.simplerunner.Runner import Runner
12from geniusweb.simplerunner.gui.SettingsPanel import SettingsPanel
13
14
15class GUI (QWidget):
16 '''
17 Simple GUI allowing users to create the settings interactively, much like on
18 the runserver
19 '''
20 # dataChannel needed to pipe output text from the runner
21 # into the PyQt system
22 dataChannel = QtCore.pyqtSignal(str)
23
24 def __init__(self):
25 super().__init__()
26 self.dataChannel.connect(self.receive)
27 self.resultarea = QTextEdit()
28 self.resultarea.setReadOnly(True)
29 self.resultarea.setText("Results will appear here after run")
30 # set dimension , 9, 40
31
32 layout = QGridLayout()
33 self.setLayout(layout)
34
35 self.settingsPanel = SettingsPanel()
36 layout.addWidget(self.settingsPanel)
37 layout.addWidget(self.startPanel())
38
39 def startPanel(self) -> QWidget:
40 startpanel = QWidget()
41 layout = QGridLayout()
42 startpanel.setLayout(layout)
43
44 startbutton = QPushButton()
45 startbutton.setText("Start Session")
46 layout.addWidget(startbutton)
47 layout.addWidget(self.resultarea)
48
49 this = self
50 startbutton.clicked.connect(this.runsession) # type:ignore
51 return startpanel;
52
53 def runsession(self, b):
54 self.resultarea.setText("")
55 this = self
56
57 class MyReporter(Reporter):
58
59 # override
60 def log(self, level:int, msg:str, thrown:Optional[BaseException]=None):
61 text = "[" + logging._levelToName[level] + "] " + msg + "\n"
62 # in python you can not turn a exception into a string
63 if thrown:
64 text = text + str(thrown) + "\n"
65 this.dataChannel.emit(text)
66
67 myreporter = MyReporter()
68 runner = Runner(self.settingsPanel.getSettings(),
69 ClassPathConnectionFactory(), myreporter, 0)
70 runner.run()
71
72 def receive(self, text:str):
73 self.resultarea.append(text)
74
75 @staticmethod
76 def main(args:List[str]):
77 app = QApplication([])
78
79 win = QMainWindow()
80 win.setWindowTitle("GeniusWeb SimpleRunner GUI")
81 win.setCentralWidget(GUI())
82 win.show()
83 sys.exit(app.exec_())
84
85
86if __name__ == '__main__':
87 GUI.main([])
Note: See TracBrowser for help on using the repository browser.