-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
85 lines (67 loc) · 2.95 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
from PySide6.QtWidgets import QApplication, QWidget, QHBoxLayout
from PySide6.QtCore import QTimer
from ui.left_ui import LeftUI
from ui.temperature_ui import TemperatureUI
from serialcom.temperature import read_temperature, read_sensor_units
from serialcom.connect import find_connected_devices, handle_disconnect, handle_connect
from thread.signal_manager import SignalManager
class MainWindow(QWidget):
def __init__(self):
super().__init__()
# Create QHBoxlayout for the application, it will be split into a left and right part
self.layout = QHBoxLayout(self)
# Create instances of imported UI's
self.left_ui = LeftUI()
self.temperature_ui = TemperatureUI()
# Add left and right layouts to main layout
self.layout.addLayout(self.left_ui.layout)
self.layout.addLayout(self.temperature_ui.vlayout)
# Access attributes from instances of LeftUI
self.general_ui = self.left_ui.general_ui
self.connection_ui = self.left_ui.connection_ui
self.profibus_ui = self.left_ui.profibus_ui
self.curve_ui = self.left_ui.curve_ui
self.sensor_ui = self.left_ui.sensor_ui
# Create variables to store serial information
self.port = ''
self.baudrate = 115200
self.timeout = 1
self.ser = ''
# Initialize worker and thread
self.worker = None
self.worker_thread = None
# Initialize timer_worker and thread
self.timer_worker = None
self.timer_worker_thread = None
signal_manager = SignalManager()
# Connect the signal to a slot for updating the UI
signal_manager.update_ui_signal.connect(self.update_ui_slot)
# Connect the buttons
self.connection_ui.connect_button.clicked.connect(lambda: handle_connect(self, signal_manager))
self.connection_ui.disconnect_button.clicked.connect(lambda: handle_disconnect(self))
self.connection_ui.refresh_button.clicked.connect(lambda: find_connected_devices(self))
# Call the function to search for connected devices
find_connected_devices(self)
def update_ui_slot(self, element_str, command, value):
# Convert the string identifier to the correct UI element reference
ui_element = self.find_ui_element(element_str)
# Perform UI update safely
if command == "setItem":
row, column, item = value
getattr(ui_element, command)(row, column, item)
elif command == "clear":
ui_element.clear()
else:
getattr(ui_element, command)(value)
def find_ui_element(self, element_str):
full_element_str = "self." + element_str
try:
return eval(full_element_str)
except AttributeError:
print(f"UI element '{full_element_str}' not found.")
return None
if __name__ == "__main__":
app = QApplication([])
window = MainWindow()
window.show()
app.exec()