diff --git a/cellacdc/gui.py b/cellacdc/gui.py index bbb6e4ef..3a512b74 100755 --- a/cellacdc/gui.py +++ b/cellacdc/gui.py @@ -6835,14 +6835,8 @@ def gui_mousePressEventImg1(self, event): and not is_right_click_custom_ON and not copyContourON ) - # printl( - # f'{isOnlyRightClick = }\n' - # f'{self.isDoubleRightClick = }\n' - # f'{self.doubleRightClickTimeElapsed = }\n' - # f'{self.countRightClicks = }' - # ) - if isOnlyRightClick: + # Start timer or check if it is a double-right-click if self.countRightClicks == 0: self.isDoubleRightClick = False self.countRightClicks = 1 @@ -11385,32 +11379,10 @@ def retainSpaceSlidersToggled(self, checked): @exception_handler def keyPressEvent(self, ev): if ev.key() == Qt.Key_Q and self.debug: - # printl(self.xHoverImg, self.yHoverImg) - # printl(self.img1.mapToData(QCursor().pos())) - # x, y = QCursor().pos().x(), QCursor().pos().y() - # printl(self.graphLayout.mapToScene(x, y)) posData = self.data[self.pos_i] - is_segm_3D = self.isSegm3D - # all_metrics_names = measurements.get_all_metrics_names( - # posData, self.user_ch_name, is_segm_3D - # ) - # printl(self.metricsToSave) - self.initMetricsToSave(posData) + for worker, thread in self.autoSaveActiveWorkers: + printl(worker.isAutoSaveON) - # printl(self.bkgr_metrics_params, pretty=True) - printl(self.foregr_metrics_params, pretty=True) - printl(self.custom_metrics_params, pretty=True) - - # from acdctools.plot import imshow - # delIDs = posData.allData_li[posData.frame_i]['delROIs_info']['delIDsROI'] - # printl(delIDs) - # self.store_data() - # self.applyDelROIs() - # stored_lab = posData.allData_li[posData.frame_i]['labels'] - # imshow(posData.lab, stored_lab, parent=self) - - printl(self.setMeasWinState, pretty=True) - if not self.dataIsLoaded: self.logger.info( '[WARNING]: Data not loaded yet. ' diff --git a/cellacdc/workers.py b/cellacdc/workers.py index 1d3b5d9d..f1d1b99f 100755 --- a/cellacdc/workers.py +++ b/cellacdc/workers.py @@ -3,6 +3,7 @@ import os import time import json +from collections import deque from typing import Union, List @@ -493,7 +494,7 @@ def __init__(self, mutex, waitCond, savedSegmData): self.abortSaving = False self.isSaving = False self.isPaused = False - self.dataQ = queue.Queue() + self.dataQ = deque(maxlen=5) self.isAutoSaveON = False def pause(self): @@ -514,8 +515,9 @@ def enqueue(self, posData): def _enqueue(self, posData): if DEBUG: self.logger.log('Enqueing posData autosave...') - self.dataQ.put(posData) - if self.dataQ.qsize() == 1: + self.dataQ.append(posData) + if len(self.dataQ) == 1: + # Wake worker upon inserting first element self.abortSaving = False self.waitCond.wakeAll() @@ -525,8 +527,8 @@ def _stop(self): def abort(self): self.abortSaving = True - while not self.dataQ.empty(): - data = self.dataQ.get() + while not len(self.dataQ) == 0: + data = self.dataQ.pop() del data self._stop() @@ -536,10 +538,10 @@ def run(self): if self.exit: self.logger.log('Closing autosaving worker...') break - elif not self.dataQ.empty(): + elif not len(self.dataQ) == 0: if DEBUG: self.logger.log('Autosaving...') - data = self.dataQ.get() + data = self.dataQ.pop() try: self.saveData(data) except Exception as e: @@ -547,7 +549,7 @@ def run(self): print('*'*40) self.logger.log(error) print('='*40) - if self.dataQ.empty(): + if len(self.dataQ) == 0: self.sigDone.emit() else: self.pause() @@ -585,7 +587,7 @@ def saveData(self, posData): segm_npz_path = posData.segm_npz_temp_path end_i = self.getLastTrackedFrame(posData) - + if self.isAutoSaveON: if end_i < len(posData.segm_data): saved_segm_data = posData.segm_data @@ -628,7 +630,7 @@ def saveData(self, posData): if self.abortSaving: break - if not self.abortSaving: + if not self.abortSaving: if self.isAutoSaveON: segm_data = np.squeeze(saved_segm_data) self._saveSegm(segm_npz_path, posData.segm_npz_path, segm_data)