Skip to content

Commit

Permalink
add pause button (#480)
Browse files Browse the repository at this point in the history
* add pause button &  logic

* Update gui.png
  • Loading branch information
bimac authored Sep 11, 2023
1 parent 6da0a84 commit 25a7bdd
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 144 deletions.
Binary file modified docs/source/gui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions iblrig/base_choice_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def _run(self):
time_last_trial_end = time.time()
self.trial_completed(self.bpod.session.current_trial.export())
self.show_trial_log()
while self.paths.SESSION_FOLDER.joinpath('.pause').exists():
time.sleep(1)
if self.paths.SESSION_FOLDER.joinpath('.stop').exists():
self.paths.SESSION_FOLDER.joinpath('.stop').unlink()
break
Expand Down
28 changes: 28 additions & 0 deletions iblrig/gui/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import webbrowser

from PyQt5 import QtWidgets, QtCore, uic
from PyQt5.QtWidgets import QStyle

from one.api import ONE
import iblrig_tasks
Expand Down Expand Up @@ -130,10 +131,20 @@ def __init__(self, *args, **kwargs):
self.uiPushHelp.clicked.connect(self.help)
self.uiPushFlush.clicked.connect(self.flush)
self.uiPushStart.clicked.connect(self.startstop)
self.uiPushPause.clicked.connect(self.pause)
self.uiPushConnect.clicked.connect(self.alyx_connect)
self.lineEditSubject.textChanged.connect(self._filter_subjects)
self.running_task_process = None

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 Down Expand Up @@ -168,6 +179,17 @@ def _filter_subjects(self):
result = [self.model.test_subject_name]
self.uiComboSubject.setModel(QtCore.QStringListModel(result))

def pause(self):
match self.uiPushPause.isChecked():
case True:
print('Pausing after current trial ...')
if self.model.session_folder.exists():
self.model.session_folder.joinpath('.pause').touch()
case False:
print('Resuming ...')
if self.model.session_folder.joinpath('.pause').exists():
self.model.session_folder.joinpath('.pause').unlink()

def startstop(self):
match self.uiPushStart.text():
case 'Start':
Expand All @@ -193,7 +215,10 @@ 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)
case 'Stop':
# if the process crashed catastrophically, the session folder might not exist
if self.model.session_folder.exists():
Expand All @@ -202,7 +227,10 @@ def startstop(self):
self.running_task_process.communicate()
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)

def flush(self):
try:
Expand Down
Loading

0 comments on commit 25a7bdd

Please sign in to comment.