Skip to content

Commit

Permalink
various GUI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bimac committed Sep 12, 2023
1 parent 31689fe commit 0b09273
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 57 deletions.
82 changes: 58 additions & 24 deletions iblrig/gui/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,18 @@ def __init__(self, *args, **kwargs):
self.lineEditSubject.textChanged.connect(self._filter_subjects)
self.running_task_process = None
self.setDisabled(True)
QtCore.QTimer.singleShot(100, self.check_for_update)

self.uiPushStart.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay))
self.uiPushPause.setIcon(self.style().standardIcon(QStyle.SP_MediaPause))
self.uiPushFlush.setIcon(self.style().standardIcon(QStyle.SP_BrowserReload))
self.uiPushHelp.setIcon(self.style().standardIcon(QStyle.SP_DialogHelpButton))

self.checkSubProcessTimer = QtCore.QTimer()
self.checkSubProcessTimer.timeout.connect(self.checkSubProcess)

self.statusbar.showMessage("Checking for updates ...")
self.show()
QtCore.QTimer.singleShot(1, self.check_for_update)

def check_for_update(self):
update_available, remote_version = check_for_updates()
Expand All @@ -151,17 +162,9 @@ def check_for_update(self):
msgBox.findChild(QtWidgets.QPushButton).setText('Yes, I promise!')
msgBox.exec_()
self.setDisabled(False)
self.statusbar.showMessage(f"iblrig v{remote_version}")
self.update()

pixmapi = QStyle.SP_MediaPlay
self.uiPushStart.setIcon(self.style().standardIcon(pixmapi))
pixmapi = QStyle.SP_MediaPause
self.uiPushPause.setIcon(self.style().standardIcon(pixmapi))
pixmapi = QStyle.SP_BrowserReload
self.uiPushFlush.setIcon(self.style().standardIcon(pixmapi))
pixmapi = QStyle.SP_DialogHelpButton
self.uiPushHelp.setIcon(self.style().standardIcon(pixmapi))

def model2view(self):
# stores the current values in the model
self.controller2model()
Expand All @@ -177,6 +180,7 @@ def model2view(self):
self.uiComboSubject.setCurrentText(self.model.subject)
_set_list_view_from_string_list(self.uiListProcedures, self.model.procedures)
_set_list_view_from_string_list(self.uiListProjects, self.model.projects)
self.enable_UI_elements()

def controller2model(self):
self.model.procedures = [i.data() for i in self.uiListProcedures.selectedIndexes()]
Expand All @@ -197,6 +201,7 @@ def _filter_subjects(self):
self.uiComboSubject.setModel(QtCore.QStringListModel(result))

def pause(self):
self.uiPushPause.setStyleSheet('QPushButton {background-color: yellow;}' if self.uiPushPause.isChecked() else '')
match self.uiPushPause.isChecked():
case True:
print('Pausing after current trial ...')
Expand Down Expand Up @@ -233,24 +238,43 @@ def startstop(self):
if self.running_task_process is None:
self.running_task_process = subprocess.Popen(cmd)
self.uiPushStart.setText('Stop')
pixmapi = QStyle.SP_MediaStop
self.uiPushStart.setIcon(self.style().standardIcon(pixmapi))
self.uiPushFlush.setEnabled(False)
self.uiPushPause.setEnabled(True)
self.uiPushStart.setIcon(self.style().standardIcon(QStyle.SP_MediaStop))
self.checkSubProcessTimer.start(100)
case 'Stop':
self.checkSubProcessTimer.stop()
# if the process crashed catastrophically, the session folder might not exist
if self.model.session_folder.exists():
self.model.session_folder.joinpath('.stop').touch()
# this will wait for the process to finish, usually the time for the trial to end
self.running_task_process.communicate()

if self.running_task_process.returncode:
msgBox = QtWidgets.QMessageBox(parent=self)
msgBox.setWindowTitle("Oh no!")
msgBox.setText("The task was terminated with an error.\nPlease check the command-line output for details.")
msgBox.setIcon(QtWidgets.QMessageBox().Critical)
msgBox.exec_()

self.running_task_process = None
self.uiPushStart.setText('Start')
pixmapi = QStyle.SP_MediaPlay
self.uiPushStart.setIcon(self.style().standardIcon(pixmapi))
self.uiPushFlush.setEnabled(True)
self.uiPushPause.setEnabled(False)
self.uiPushStart.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay))
self.enable_UI_elements()

def checkSubProcess(self):
returncode = None if self.running_task_process is None else self.running_task_process.poll()
if returncode is None:
return
else:
self.startstop()


def flush(self):

# paint button blue when in toggled state
self.uiPushFlush.setStyleSheet('QPushButton {background-color: rgb(128, 128, 255);}'
if self.uiPushFlush.isChecked() else '')
self.enable_UI_elements()

try:
bpod = Bpod(self.model.hardware_settings['device_bpod']['COM_BPOD']) # bpod is a singleton
bpod.manual_override(bpod.ChannelTypes.OUTPUT, bpod.ChannelNames.VALVE, 1, self.uiPushFlush.isChecked())
Expand All @@ -260,17 +284,27 @@ def flush(self):
self.uiPushFlush.setChecked(False)
return

if self.uiPushFlush.isChecked():
self.uiPushFlush.setStyleSheet('QPushButton {background-color: rgb(128, 128, 255);}')
self.uiPushStart.setEnabled(False)
else:
if not self.uiPushFlush.isChecked():
bpod.close()
self.uiPushFlush.setStyleSheet('')
self.uiPushStart.setEnabled(True)

def help(self):
webbrowser.open('https://int-brain-lab.github.io/iblrig/usage.html')

def enable_UI_elements(self):
is_running = self.uiPushStart.text() == 'Stop'

self.uiPushStart.setEnabled(
not self.uiPushFlush.isChecked())
self.uiPushPause.setEnabled(is_running)
self.uiPushFlush.setEnabled(not is_running)
self.uiCheckAppend.setEnabled(not is_running)
self.uiGroupUser.setEnabled(not is_running)
self.uiGroupSubject.setEnabled(not is_running)
self.uiGroupTask.setEnabled(not is_running)
self.uiGroupProjects.setEnabled(not is_running)
self.uiGroupProcedures.setEnabled(not is_running)
self.repaint()


def main():
app = QtWidgets.QApplication([])
Expand Down
58 changes: 26 additions & 32 deletions iblrig/gui/wizard.ui
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<enum>QFrame::Plain</enum>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="1" column="2">
Expand Down Expand Up @@ -108,6 +108,15 @@
</disabled>
</palette>
</property>
<property name="cursor" stdset="0">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
Expand Down Expand Up @@ -200,6 +209,15 @@
</disabled>
</palette>
</property>
<property name="cursor" stdset="0">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
Expand Down Expand Up @@ -485,38 +503,14 @@
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>698</width>
<height>21</height>
</rect>
<widget class="QStatusBar" name="statusbar">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string/>
</property>
<widget class="QMenu" name="uiMenuFile">
<property name="enabled">
<bool>false</bool>
</property>
<property name="title">
<string>File</string>
</property>
<widget class="QMenu" name="uiMenuTemplates">
<property name="title">
<string>templates</string>
</property>
<addaction name="uiActionTrainingTemplate"/>
<addaction name="uiActionEphysTemplate"/>
</widget>
<addaction name="uiActionLoadSession"/>
<addaction name="separator"/>
<addaction name="uiActionRecent"/>
<addaction name="separator"/>
<addaction name="uiMenuTemplates"/>
</widget>
<addaction name="uiMenuFile"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="uiActionLoadSession">
<property name="text">
<string>load session</string>
Expand Down
2 changes: 1 addition & 1 deletion iblrig/version_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ def check_for_updates():
log.info(f'Update to iblrig {version_remote_str} found.')
else:
log.info('No update found.')
return version_remote > version_local, version_remote_str
return version_remote > version_local, version_remote_str if version_remote > version_local else version_local

0 comments on commit 0b09273

Please sign in to comment.