Skip to content

Commit 82e233d

Browse files
committed
Removed _record so there is only separate functions to start and stop recordings
1 parent c5a143c commit 82e233d

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

microscope/plugins/record_plugin.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ def update_image_data(self, image: QImage):
244244
if self.recording and image:
245245
if (datetime.now() - self.start_time).seconds >= 3600 * self.hours_per_file:
246246
# Stop recording after x hours
247-
self._record()
247+
self._set_record(False)
248248
# Restart recording
249-
self._record()
249+
self._set_record(True)
250250

251251
if self.raw_image:
252252
recorded_image = image.copy()
@@ -270,14 +270,16 @@ def mouse_release_event(self, event: QMouseEvent):
270270
def context_menu_entry(self):
271271
actions = []
272272
label = "Stop recording" if self.recording else "Start recording"
273-
self.record_action = QAction(label, self.parent())
274-
self.record_action.triggered.connect(self._record)
275-
actions.append(self.record_action)
273+
if self.recording:
274+
actions.append(self.stop_record_action)
275+
else:
276+
actions.append(self.start_record_action)
276277
return actions
277278

278279
def _set_record(self, start):
279-
if start:
280-
print("Starting record in _record")
280+
if start and not self.recording:
281+
print("Starting record in _set_record")
282+
self.recording = True
281283
self.start_time = datetime.now()
282284
self.current_filepath = Path(self.filename.parent) / Path(
283285
f'{self.filename.stem}_{self.start_time.strftime("%b-%d-%Y_%H%M%S")}.{self.file_extension}'
@@ -290,8 +292,9 @@ def _set_record(self, start):
290292
self.video_recorder_thread.start(
291293
self.current_filepath, self.fourcc, self.fps, self.width, self.height
292294
)
293-
else:
294-
print("Stopping record in _record")
295+
elif not start and self.recording:
296+
print("Stopping record in _set_record")
297+
self.recording = False
295298
if not self.current_filepath:
296299
return
297300
self.video_recorder_thread.stop()
@@ -308,10 +311,6 @@ def _set_record(self, start):
308311
)
309312
self._update_files()
310313

311-
def _record(self):
312-
self.recording = not self.recording
313-
self._set_record(self.recording)
314-
315314
def _update_files(self):
316315
"""Function to check if number of files in the destination folder is correct
317316
Otherwise delete oldest file(s)

0 commit comments

Comments
 (0)