-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
133 lines (105 loc) · 4.19 KB
/
application.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
126
127
128
129
130
131
132
133
from PyQt6.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QLabel
from test_area import TestArea
from flows.assembled_electrical.flow import AssembledHexaboardFlow
import logging
import os
import sys
import argparse
import glob
import git
import log_utils
# Fix Ctrl+C
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
class MainWindow(QMainWindow):
def __init__(self, flow: str) -> None:
super().__init__()
self.setWindowTitle("Hexaboard Electrical Testing")
layout = QVBoxLayout()
# Create Header
# Add Title to header
header = QLabel("Hexaboard Testing GUI")
font = header.font()
font.setPointSize(font.pointSize() * 3)
font.setBold(True)
header.setFont(font)
layout.addWidget(header)
# Add Institution Name
header = QLabel("CERN")
font = header.font()
font.setPointSize(int(font.pointSize() * 2))
font.setBold(True)
header.setFont(font)
layout.addWidget(header)
# Version Check
logger.info("Running Version Check...")
repo = git.Repo(os.path.dirname(__file__))
repo.remotes.origin.fetch()
local_commit = repo.head.commit
logger.info(f"Detected local Electrical Testing GUI commit {local_commit}")
remote_commit = repo.remotes.origin.refs[repo.active_branch.name].commit
if local_commit == remote_commit:
logger.info("You are up-to-date!")
label = QLabel(f"Commit {local_commit}")
layout.addWidget(label)
else:
logger.critical(f"You are not running the latest version of the GUI.")
logger.critical(f"Remote branch is at {remote_commit}")
label = QLabel(f"Oudated version! Local branch is at {local_commit}, remote at {remote_commit}")
font = label.font()
font.setPointSize(int(font.pointSize() * 2))
font.setBold(True)
label.setStyleSheet("color: red")
label.setFont(font)
layout.addWidget(label)
# Add Testing Area
layout.addWidget(TestArea(AssembledHexaboardFlow(flow = flow)))
# Finalization
widget = QWidget()
widget.setLayout(layout)
self.setContentsMargins(10, 10, 10, 10)
self.setCentralWidget(widget)
self.showFullScreen()
if __name__ == "__main__":
log_utils.setup_logging()
logger = logging.getLogger("application")
logger.info(f"Starting Electrical Testing GUI with arguments {sys.argv}")
default_flow_directory = "flows/assembled_electrical" # TODO: Make this dynamic instead of hardcoded
default_flow = f"{default_flow_directory}/flow.yaml"
flow_pattern = f"{default_flow_directory}/flow*.yaml"
flows = glob.glob(flow_pattern)
parser = argparse.ArgumentParser(
prog = "python application.py",
description = "Hexaboard testing GUI",
formatter_class=argparse.RawTextHelpFormatter
)
parser.add_argument(
"-f",
"--flow",
default = default_flow,
help = "\n".join([
"specify the relative path to the flow.yaml file to use",
"(default: {default_flow})",
f"available flows found inside {default_flow_directory}:",
*[f"- {flow}" for flow in flows]
])
)
args = parser.parse_args()
choice = True
if args.flow == default_flow:
choice = input("\n".join([
f"Are you sure you want to execute the default flow?",
f"All files matching \"{flow_pattern}\":",
*[f"{f' {flow}' if flow != default_flow else f'> {flow} [DEFAULT]'}" for flow in flows],
f"For more help, execute",
f" python application.py -h",
f"[y/N]: "
])).lower() == "y"
# TODO: If the user doesn't want to use the default flow, allow them to choose another one
# (using a numbered list or a selector with up/down keys)
# If the user gave a non-default flow or is sure that they want to use the default flow
if choice:
app = QApplication(sys.argv)
app.setStyle("dark")
window = MainWindow(flow = args.flow)
app.exec()