From 52dc577096f2fb9435a084422562e012cc9edcac Mon Sep 17 00:00:00 2001 From: Florian Rau Date: Fri, 13 Oct 2023 17:21:51 +0200 Subject: [PATCH] add control for LED --- iblrig/gui/ui_wizard.py | 14 ++++++++++---- iblrig/gui/ui_wizard.ui | 19 ++++++++++++++++--- iblrig/gui/wizard.py | 27 +++++++++++++++++++++------ 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/iblrig/gui/ui_wizard.py b/iblrig/gui/ui_wizard.py index c570b1dcd..22b7dd0dc 100644 --- a/iblrig/gui/ui_wizard.py +++ b/iblrig/gui/ui_wizard.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Form implementation generated from reading ui file 'iblrig/gui/ui_wizard.ui' +# Form implementation generated from reading ui file 'ui_wizard.ui' # # Created by: PyQt5 UI code generator 5.15.9 # @@ -14,7 +14,7 @@ class Ui_wizard(object): def setupUi(self, wizard): wizard.setObjectName("wizard") - wizard.resize(350, 527) + wizard.resize(472, 644) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) @@ -25,7 +25,7 @@ def setupUi(self, wizard): wizard.setSizeIncrement(QtCore.QSize(0, 0)) wizard.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu) icon = QtGui.QIcon() - icon.addPixmap(QtGui.QPixmap("iblrig/gui\\wizard.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) + icon.addPixmap(QtGui.QPixmap("wizard.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) wizard.setWindowIcon(icon) wizard.setWindowOpacity(1.0) wizard.setAutoFillBackground(False) @@ -304,7 +304,11 @@ def setupUi(self, wizard): sizePolicy.setHeightForWidth(self.uiPushHelp.sizePolicy().hasHeightForWidth()) self.uiPushHelp.setSizePolicy(sizePolicy) self.uiPushHelp.setObjectName("uiPushHelp") - self.gridLayout_3.addWidget(self.uiPushHelp, 1, 0, 1, 1) + self.gridLayout_3.addWidget(self.uiPushHelp, 2, 0, 1, 1) + self.uiPushStatusLED = QtWidgets.QPushButton(self.uiGroupTools) + self.uiPushStatusLED.setCheckable(True) + self.uiPushStatusLED.setObjectName("uiPushStatusLED") + self.gridLayout_3.addWidget(self.uiPushStatusLED, 1, 0, 1, 1) self.mainGrid.addWidget(self.uiGroupTools, 4, 0, 1, 1) self.uiGroupSessionControl = QtWidgets.QGroupBox(self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum) @@ -398,6 +402,8 @@ def retranslateUi(self, wizard): self.uiPushFlush.setText(_translate("wizard", "Flush")) self.uiPushHelp.setStatusTip(_translate("wizard", "open the iblrig documentation in your browser")) self.uiPushHelp.setText(_translate("wizard", "Help!")) + self.uiPushStatusLED.setStatusTip(_translate("wizard", "toggle the Bpod Status LED (always off during sessions)")) + self.uiPushStatusLED.setText(_translate("wizard", "Status LED")) self.uiGroupSessionControl.setTitle(_translate("wizard", "Session Control")) self.uiPushPause.setStatusTip(_translate("wizard", "pause the session after the current trial")) self.uiPushPause.setText(_translate("wizard", "Pause")) diff --git a/iblrig/gui/ui_wizard.ui b/iblrig/gui/ui_wizard.ui index 7c434757f..ffc351f41 100644 --- a/iblrig/gui/ui_wizard.ui +++ b/iblrig/gui/ui_wizard.ui @@ -6,8 +6,8 @@ 0 0 - 350 - 527 + 472 + 644 @@ -682,7 +682,7 @@ - + @@ -698,6 +698,19 @@ + + + + toggle the Bpod Status LED (always off during sessions) + + + Status LED + + + true + + + diff --git a/iblrig/gui/wizard.py b/iblrig/gui/wizard.py index 531149407..8f30996b2 100644 --- a/iblrig/gui/wizard.py +++ b/iblrig/gui/wizard.py @@ -144,6 +144,8 @@ def __init__(self, *args, **kwargs): self.uiComboTask.currentIndexChanged.connect(self.controls_for_extra_parameters) self.uiPushHelp.clicked.connect(self.help) self.uiPushFlush.clicked.connect(self.flush) + self.uiPushStatusLED.toggled.connect(self.toggle_status_led) + self.toggle_status_led(is_toggled=False) self.uiPushStart.clicked.connect(self.start_stop) self.uiPushPause.clicked.connect(self.pause) self.uiListProjects.clicked.connect(self.enable_UI_elements) @@ -182,8 +184,6 @@ def __init__(self, *args, **kwargs): self.statusbar.addWidget(tmp) self.controls_for_extra_parameters() - self.set_bpod_status_led(False) - self.setDisabled(True) QtCore.QTimer.singleShot(100, self.check_dirty) QtCore.QTimer.singleShot(100, self.check_for_update) @@ -203,7 +203,7 @@ def eventFilter(self, obj, event): def closeEvent(self, event): if self.running_task_process is None: - self.set_bpod_status_led(True) + self.toggle_status_led(is_toggled=False) event.accept() else: msgBox = QtWidgets.QMessageBox(parent=self) @@ -219,6 +219,7 @@ def closeEvent(self, event): self.repaint() self.start_stop() self.set_bpod_status_led(True) + self.toggle_status_led(is_toggled=False) event.accept() def check_dirty(self): @@ -501,6 +502,7 @@ def start_stop(self): self.uiPushStart.setStatusTip('start the session') self.uiPushStart.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay)) self.enable_UI_elements() + self.toggle_status_led() def check_sub_process(self): return_code = None if self.running_task_process is None else self.running_task_process.poll() @@ -529,9 +531,21 @@ def flush(self): if not self.uiPushFlush.isChecked(): bpod.close() - def set_bpod_status_led(self, enabled: bool) -> None: - bpod = Bpod(self.model.hardware_settings['device_bpod']['COM_BPOD']) - bpod.set_status_led(enabled) + def toggle_status_led(self, is_toggled: bool): + + # paint button green when in toggled state + self.uiPushStatusLED.setStyleSheet('QPushButton {background-color: rgb(128, 255, 128);}' + if is_toggled else '') + self.enable_UI_elements() + + try: + bpod = Bpod(self.model.hardware_settings['device_bpod']['COM_BPOD']) + bpod.set_status_led(is_toggled) + except (OSError, exceptions.bpod_error.BpodErrorException, AttributeError): + self.uiPushStatusLED.setChecked(False) + self.uiPushStatusLED.setStyleSheet('') + else: + bpod.close() def help(self): webbrowser.open('https://int-brain-lab.github.io/iblrig/usage.html') @@ -545,6 +559,7 @@ def enable_UI_elements(self): and len(self.uiListProcedures.selectedIndexes()) > 0) self.uiPushPause.setEnabled(is_running) self.uiPushFlush.setEnabled(not is_running) + self.uiPushStatusLED.setEnabled(not is_running) self.uiCheckAppend.setEnabled(not is_running) self.uiGroupParameters.setEnabled(not is_running) self.uiGroupTaskParameters.setEnabled(not is_running)