Skip to content

Commit

Permalink
add control for LED
Browse files Browse the repository at this point in the history
  • Loading branch information
bimac committed Oct 13, 2023
1 parent 7c285f0 commit 52dc577
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
14 changes: 10 additions & 4 deletions iblrig/gui/ui_wizard.py
Original file line number Diff line number Diff line change
@@ -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
#
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"))
Expand Down
19 changes: 16 additions & 3 deletions iblrig/gui/ui_wizard.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>350</width>
<height>527</height>
<width>472</width>
<height>644</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -682,7 +682,7 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QPushButton" name="uiPushHelp">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
Expand All @@ -698,6 +698,19 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="uiPushStatusLED">
<property name="statusTip">
<string>toggle the Bpod Status LED (always off during sessions)</string>
</property>
<property name="text">
<string>Status LED</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
27 changes: 21 additions & 6 deletions iblrig/gui/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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')
Expand All @@ -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)
Expand Down

0 comments on commit 52dc577

Please sign in to comment.