-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
172 lines (151 loc) · 6.44 KB
/
main.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import sys
import os
import ctypes
from plotting import PicoPlotter
import picoS2000aRealtimeStreaming as pico
from settings import Settings
from PySide6 import QtWidgets, QtCore, QtUiTools, QtGui
from devicesLink import list_all_devices
from logger import log_action, log_values
def loadUiWidget(uifilename, parent=None):
"""
Load a UI file and return the corresponding widget.
Parameters:
- uifilename (str): The path to the UI file.
- parent (QWidget): The parent widget (default: None).
Returns:
- QWidget: The loaded widget.
"""
loader = QtUiTools.QUiLoader()
uifile = QtCore.QFile(uifilename)
uifile.open(QtCore.QFile.ReadOnly)
ui = loader.load(uifile, parent)
uifile.close()
return ui
def init_settings_tab():
"""
Initializes the settings tab by setting up various UI elements and their corresponding actions.
This function performs the following tasks:
- Sets the log path and displays it in the list widget.
- Sets the log frequency and connects it to the settings file.
- Sets the file size limit and connects it to the settings file.
- Sets the log on/off button and connects it to the settings file.
- Refreshes the list of connected devices and displays them in the list widget.
Parameters:
None
Returns:
None
"""
settings = Settings()
# Log Path
if not settings.does_setting_exist('logPath'):
settings.write_to_settings_file('logPath', '/logs/')
listWidget_logPath = main_window.findChild(
QtWidgets.QListWidget, "listWidget_logPath")
listWidget_logPath.addItem(
os.getcwd()+settings.read_from_settings_file('logPath'))
# Log Frequency
doubleSpinBox_logFrequency = main_window.findChild(
QtWidgets.QDoubleSpinBox, "spinBox_logFrequency")
if not settings.does_setting_exist('logFrequency'):
settings.write_to_settings_file(
'logFrequency', doubleSpinBox_logFrequency.value())
else:
doubleSpinBox_logFrequency.setValue(
float(settings.read_from_settings_file('logFrequency')))
doubleSpinBox_logFrequency.valueChanged.connect(
lambda value: settings.write_to_settings_file('logFrequency', value))
doubleSpinBox_logFrequency.valueChanged.connect(lambda: log_action(
"Log frequency is set to " + str(doubleSpinBox_logFrequency.value()) + " seconds"))
# File Size Limit
spinBox_fileSizeLimit = main_window.findChild(
QtWidgets.QSpinBox, "spinBox_fileSizeLimit")
if not settings.does_setting_exist('fileSizeLimit'):
settings.write_to_settings_file(
'fileSizeLimit', spinBox_fileSizeLimit.value())
else:
spinBox_fileSizeLimit.setValue(
int(settings.read_from_settings_file('fileSizeLimit')))
spinBox_fileSizeLimit.valueChanged.connect(
lambda value: settings.write_to_settings_file('fileSizeLimit', value))
spinBox_fileSizeLimit.valueChanged.connect(lambda: log_action(
"File size limit is set to " + str(spinBox_fileSizeLimit.value()) + " megabytes"))
# Log On/Off
pushButton_LogOnOff = main_window.findChild(
QtWidgets.QPushButton, "pushButton_LogOnOff")
if not settings.does_setting_exist('logOnOff'):
settings.write_to_settings_file(
'logOnOff', pushButton_LogOnOff.isChecked())
else:
pushButton_LogOnOff.setChecked(
settings.read_from_settings_file('logOnOff') == 'True')
pushButton_LogOnOff.setText("On") if settings.read_from_settings_file(
'logOnOff') == 'True' else pushButton_LogOnOff.setText("Off")
pushButton_LogOnOff.clicked.connect(lambda: settings.write_to_settings_file(
'logOnOff', pushButton_LogOnOff.isChecked()))
pushButton_LogOnOff.clicked.connect(lambda: pushButton_LogOnOff.setText(
"On") if settings.read_from_settings_file('logOnOff') == 'True' else pushButton_LogOnOff.setText("Off"))
pushButton_LogOnOff.clicked.connect(lambda: log_action(
"Logging is turned on" if settings.read_from_settings_file('logOnOff') == 'True' else "Logging is turned off"))
# Connected devices
def refresh_ports():
"""
Refreshes the list of ports in the UI.
This function clears the existing list of ports in the UI, retrieves the updated list of ports,
and populates the UI with the new list of ports. If no ports are detected, it displays a message
indicating that no device is detected.
Args:
None
Returns:
None
"""
listWidget_PortList = main_window.findChild(
QtWidgets.QListView, "listWidget_PortList")
listWidget_PortList.clear()
item = QtWidgets.QListWidgetItem("Refreshing...")
listWidget_PortList.addItem(item)
ports = list_all_devices()
if not ports:
listWidget_PortList.clear()
item = QtWidgets.QListWidgetItem("No device detected")
listWidget_PortList.addItem(item)
else:
listWidget_PortList.clear()
for port in ports:
item = QtWidgets.QListWidgetItem(port)
listWidget_PortList.addItem(item)
refresh_ports()
pushButton_Refresh = main_window.findChild(
QtWidgets.QPushButton, "pushButton_Refresh")
pushButton_Refresh.clicked.connect(refresh_ports)
pushButton_Refresh.clicked.connect(
lambda: log_action("Refreshing connected devices"))
if __name__ == '__main__':
# Init app
if os.name == 'nt':
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(
'aima.testbench')
app = QtWidgets.QApplication([])
main_window = loadUiWidget("GUI.ui")
main_window.setWindowTitle("AIMA - Test Bench")
main_window.showFullScreen()
main_window.showMaximized()
app_icon = QtGui.QIcon("assets/icon.ico")
app.setWindowIcon(app_icon)
tabWidget = main_window.findChild(QtWidgets.QTabWidget, "tabWidget")
tabWidget.setCurrentIndex(0)
# Log
log_action("Application started")
# Settings
init_settings_tab()
# Plotting
try:
pico.open_pico()
listWidget_testBench = main_window.findChild(QtWidgets.QWidget, "listWidget_testBench")
channels = ['PS2000A_CHANNEL_A', 'PS2000A_CHANNEL_B', 'PS2000A_CHANNEL_C']
plotter = PicoPlotter(channels, "PicoScope", listWidget_testBench)
except Exception as e:
print("Error : "+str(e))
main_window.show()
sys.exit(app.exec())
# © AIMA DEVELOPPEMENT 2024