diff --git a/__pycache__/ui_connerror.cpython-312.pyc b/__pycache__/ui_connerror.cpython-312.pyc index 3536310..c58dfb9 100644 Binary files a/__pycache__/ui_connerror.cpython-312.pyc and b/__pycache__/ui_connerror.cpython-312.pyc differ diff --git a/__pycache__/ui_mainwindow.cpython-312.pyc b/__pycache__/ui_mainwindow.cpython-312.pyc index 8c89b6f..eb7a30e 100644 Binary files a/__pycache__/ui_mainwindow.cpython-312.pyc and b/__pycache__/ui_mainwindow.cpython-312.pyc differ diff --git a/__pycache__/ui_scanning.cpython-312.pyc b/__pycache__/ui_scanning.cpython-312.pyc index 29a5214..e197eaa 100644 Binary files a/__pycache__/ui_scanning.cpython-312.pyc and b/__pycache__/ui_scanning.cpython-312.pyc differ diff --git a/main.py b/main.py index 6db4737..d437c28 100644 --- a/main.py +++ b/main.py @@ -69,12 +69,25 @@ class MainWindow(QMainWindow): self.ui.connButton.setCheckable(True) self.ui.connButton.clicked.connect(self.conn_button_press) + # Add radio button actions + self.ui.radiolocal.toggled.connect(self.handle_all_radios) + self.ui.radioscript.toggled.connect(self.handle_all_radios) + self.ui.radiopulse.toggled.connect(self.handle_all_radios) + # Hide other controls self.ui.sn.setHidden(True) self.ui.snLabel.setHidden(True) self.ui.fw.setHidden(True) self.ui.fwLabel.setHidden(True) - + self.ui.radiolocal.setHidden(True) + self.ui.radioscript.setHidden(True) + self.ui.radiopulse.setHidden(True) + self.ui.powerButton.setHidden(True) + self.ui.setvLabel.setHidden(True) + self.ui.setv.setHidden(True) + self.ui.actvLabel.setHidden(True) + self.ui.actv.setHidden(True) + # Set initial size initial_width = 1000 initial_height = 600 @@ -88,8 +101,8 @@ class MainWindow(QMainWindow): self.setFixedSize(1000, 600) # Setup serial port - self.serial = QSerialPort(self) - self.serial.readyRead.connect(self.on_data_received) + #self.serial = QSerialPort(self) + #self.serial.readyRead.connect(self.on_data_received) # Create serial rx flag self.serial_rx_flag = False @@ -113,6 +126,39 @@ class MainWindow(QMainWindow): self.show() + def handle_all_radios(self): + # sender() returns the widget that sent the signal + button = self.sender() + + if button.isChecked(): + if button.text() == "LOCAL CONTROL": + self.ui.powerButton.setHidden(False) + self.ui.setvLabel.setHidden(False) + self.ui.setv.setHidden(False) + self.ui.actvLabel.setHidden(False) + self.ui.actv.setHidden(False) + + elif button.text() == "SCRIPT CONTROL": + self.ui.powerButton.setHidden(True) + self.ui.setvLabel.setHidden(True) + self.ui.setv.setHidden(True) + self.ui.actvLabel.setHidden(True) + self.ui.actv.setHidden(True) + + elif button.text() == "PULSE TRIGGERED": + self.ui.powerButton.setHidden(True) + self.ui.setvLabel.setHidden(True) + self.ui.setv.setHidden(True) + self.ui.actvLabel.setHidden(True) + self.ui.actv.setHidden(True) + + else: + self.ui.powerButton.setHidden(True) + self.ui.setvLabel.setHidden(True) + self.ui.setv.setHidden(True) + self.ui.actvLabel.setHidden(True) + self.ui.actv.setHidden(True) + def conn_button_press (self): text_conn = self.ui.connButton.text() @@ -125,21 +171,23 @@ class MainWindow(QMainWindow): QApplication.processEvents() # Specify serial port and baud - self.serial.setPortName("/dev/ttyACM0") - self.serial.setBaudRate(115200) + #self.serial.setPortName("/dev/ttyACM0") + #self.serial.setBaudRate(115200) - if not self.serial.open(QIODevice.ReadWrite): - print(f"Failed to open port: {self.serial.errorString()}") + #if not self.serial.open(QIODevice.ReadWrite): + #print(f"Failed to open port: {self.serial.errorString()}") command = 73 #0x49 'I' ASCII state = 0 data = (command, state) byte_data = self.pack_integers_to_bytes(*data) - self.serial.write(QByteArray(byte_data)) + #self.serial.write(QByteArray(byte_data)) self.timeouttimer.start() + self.serial_rx_flag = True + while ((self.serial_rx_flag == False) and (self.timeoutflag == False)): QApplication.processEvents() @@ -147,7 +195,7 @@ class MainWindow(QMainWindow): if self.timeoutflag == True: self.windowresponse = NoDeviceWindow.get_response(self) - self.serial.close() + #self.serial.close() self.ui.connButton.setText("CONNECT") self.ui.sn.setHidden(True) self.ui.snLabel.setHidden(True) @@ -155,6 +203,9 @@ class MainWindow(QMainWindow): self.ui.fwLabel.setHidden(True) self.ui.sn.setText("---") self.ui.fw.setText("---") + self.ui.radiolocal.setHidden(True) + self.ui.radioscript.setHidden(True) + self.ui.radiopulse.setHidden(True) else: self.process_serial_number() @@ -164,14 +215,17 @@ class MainWindow(QMainWindow): self.timeoutflag = False else: - self.serial.close() + #self.serial.close() self.ui.connButton.setText("CONNECT") self.ui.sn.setHidden(True) self.ui.snLabel.setHidden(True) self.ui.fw.setHidden(True) self.ui.fwLabel.setHidden(True) self.ui.sn.setText("---") - self.ui.fw.setText("---") + self.ui.fw.setText("---") + self.ui.radiolocal.setHidden(True) + self.ui.radioscript.setHidden(True) + self.ui.radiopulse.setHidden(True) QApplication.processEvents() @@ -228,7 +282,8 @@ class MainWindow(QMainWindow): # Get and update serial number sub_sn = self.store_buffer[0:19] sn_chars = [chr(c) for c in sub_sn if 0 <= c <= 127] - sn_str = "".join(sn_chars) + sn_str = "".join(sn_chars) + sn_str = "ARRIVE-POWERSIM-001" self.ui.sn.setText(sn_str) # Get and update FW Rev @@ -239,13 +294,18 @@ class MainWindow(QMainWindow): minor = sub_fw[2:3] full = major + sep + minor fw_chars = [chr(c) for c in full if 0 <= c <= 127] - fw_str = "".join(fw_chars) + fw_str = "".join(fw_chars) + fw_str = "0:1" self.ui.fw.setText(fw_str) self.ui.sn.setHidden(False) self.ui.snLabel.setHidden(False) self.ui.fw.setHidden(False) self.ui.fwLabel.setHidden(False) + self.ui.radiolocal.setHidden(False) + self.ui.radioscript.setHidden(False) + self.ui.radiopulse.setHidden(False) + self.ui.radiolocal.setChecked(True) def pack_integers_to_bytes(self, *integers: int) -> bytes: diff --git a/ui_mainwindow.py b/ui_mainwindow.py index 7997ef0..e113d5f 100644 --- a/ui_mainwindow.py +++ b/ui_mainwindow.py @@ -2,7 +2,7 @@ from PySide6.QtCore import (QCoreApplication, QMetaObject, QRect, Qt) from PySide6.QtGui import (QBrush, QColor, QFont, QIcon, QPalette, QPixmap, QFontDatabase) -from PySide6.QtWidgets import (QCheckBox, QFrame, QLabel, QProgressBar, QSlider, QPushButton, QWidget, QVBoxLayout) +from PySide6.QtWidgets import (QRadioButton, QFrame, QLabel, QFileDialog, QPushButton, QWidget) class Ui_MainWindow(object): @@ -13,7 +13,8 @@ class Ui_MainWindow(object): MainWindow.setToolButtonStyle(Qt.ToolButtonIconOnly) MainWindow.setAnimated(True) MainWindow.setDocumentMode(False) - MainWindow.setWindowIcon(QIcon('/home/david-rice/Python/Automotive-Power-Simulator-App/arriveico.png')) + #MainWindow.setWindowIcon(QIcon('/home/david-rice/Python/Automotive-Power-Simulator-App/arriveico.png')) + MainWindow.setWindowIcon(QIcon('/home/dfr84/Python/Automotive-Power-Simulator-App/arriveico.png')) fontmain = QFont() fontmain.setFamilies([u"Optimism Sans"]) fontmain.setPointSize(8) @@ -21,7 +22,8 @@ class Ui_MainWindow(object): MainWindow.setFont(fontmain) # Ensure the path is correct for your system! - image_path = "/home/david-rice/Python/Automotive-Power-Simulator-App/appbackground.jpg" # Example Path + #image_path = "/home/david-rice/Python/Automotive-Power-Simulator-App/appbackground.jpg" + image_path = "/home/dfr84/Python/Automotive-Power-Simulator-App/appbackground.jpg" # --- Define and Apply the Style Sheet --- bg_style_sheet = f""" @@ -98,45 +100,105 @@ class Ui_MainWindow(object): self.snLabel = QLabel(self.test_area) self.snLabel.setObjectName(u"snlabel") - self.snLabel.setGeometry(QRect(450, 5, 200, 15)) + self.snLabel.setGeometry(QRect(350, 5, 200, 15)) self.snLabel.setAlignment(Qt.AlignCenter) self.snLabel.setStyleSheet(text_label_style) self.sn = QLabel(self.test_area) self.sn.setObjectName(u"sn") - self.sn.setGeometry(QRect(450, 25, 200, 25)) + self.sn.setGeometry(QRect(350, 25, 200, 25)) self.sn.setAlignment(Qt.AlignCenter) self.sn.setStyleSheet(label_style) self.powerButton = QPushButton(self.test_area) self.powerButton.setObjectName(u"powerButton") - self.powerButton.setGeometry(QRect(25, 75, 200, 25)) + self.powerButton.setGeometry(QRect(25, 150, 200, 25)) self.powerButton.setStyleSheet(button_style) self.setvLabel = QLabel(self.test_area) self.setvLabel.setObjectName(u"setvlabel") - self.setvLabel.setGeometry(QRect(450, 55, 200, 15)) + self.setvLabel.setGeometry(QRect(350, 130, 200, 15)) self.setvLabel.setAlignment(Qt.AlignCenter) self.setvLabel.setStyleSheet(text_label_style) self.setv = QLabel(self.test_area) self.setv.setObjectName(u"setv") - self.setv.setGeometry(QRect(450, 75, 200, 25)) + self.setv.setGeometry(QRect(350, 150, 200, 25)) self.setv.setAlignment(Qt.AlignCenter) self.setv.setStyleSheet(label_style) self.actvLabel = QLabel(self.test_area) self.actvLabel.setObjectName(u"actvlabel") - self.actvLabel.setGeometry(QRect(675, 55, 200, 15)) + self.actvLabel.setGeometry(QRect(675, 130, 200, 15)) self.actvLabel.setAlignment(Qt.AlignCenter) self.actvLabel.setStyleSheet(text_label_style) self.actv = QLabel(self.test_area) self.actv.setObjectName(u"actv") - self.actv.setGeometry(QRect(675, 75, 200, 25)) + self.actv.setGeometry(QRect(675, 150, 200, 25)) self.actv.setAlignment(Qt.AlignCenter) self.actv.setStyleSheet(label_style) - + + self.radiolocal = QRadioButton("LOCAL CONTROL", self.test_area) + self.radiolocal.setObjectName(u"radiolocal") + self.radiolocal.setGeometry(QRect(25, 75, 200, 25)) + self.radioscript = QRadioButton("SCRIPT CONTROL", self.test_area) + self.radioscript.setObjectName(u"radioscript") + self.radioscript.setGeometry(QRect(350, 75, 200, 25)) + self.radiopulse = QRadioButton("PULSE TRIGGERED", self.test_area) + self.radiopulse.setObjectName(u"radiopulse") + self.radiopulse.setGeometry(QRect(675, 75, 200, 25)) + + radiostyle = (""" + QRadioButton { + font-size: 14px; + background-color: #FF80D4; + border: 1px solid #FF33BB; + border-radius: 1px; + spacing: 10px; + padding-left: 30px; + } + + QRadioButton::indicator { + subcontrol-origin: content; + subcontrol-position: center left; + width: 15px; + height: 15px; + } + """) + + self.radiolocal.setStyleSheet(radiostyle) + self.radioscript.setStyleSheet(radiostyle) + self.radiopulse.setStyleSheet(radiostyle) + + self.fileexplorer = QFileDialog (self.test_area) + self.fileexplorer.setOption(QFileDialog.Option.DontUseNativeDialog, True) + self.fileexplorer.setObjectName(u"fileexplorer") + self.fileexplorer.setGeometry(QRect(25, 150, 200, 25)) + + filedialogstyle = (""" + QFileDialog { + background-color: #FF80D4; + border: 4px solid #FF33BB; + } + /* Style the file list/tree area */ + QTreeView, QListView { + background-color: white; + border: 1px solid #FF33BB; + selection-background-color: #FF33BB; + } + /* Style the bottom buttons */ + QPushButton { + background-color: #FF33BB; + color: white; + border-radius: 4px; + min-width: 80px; + padding: 5px; + } + """) + + self.fileexplorer.setStyleSheet(filedialogstyle) + frame_style = """ QFrame { background-image: url("");