Skip to content

Commit

Permalink
Merge branch 'mrariden-disable_gui_autosave' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
carsen-stringer committed Aug 22, 2023
2 parents fa29d9e + fb8e0a7 commit 208fe1d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
8 changes: 4 additions & 4 deletions cellpose/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ def remove_cell(self, idx):
if self.ncells==0:
self.ClearButton.setEnabled(False)
if self.NZ==1:
io._save_sets(self)
io._save_sets_with_check(self)

def merge_cells(self, idx):
self.prev_selected = self.selected
Expand Down Expand Up @@ -1209,7 +1209,7 @@ def merge_cells(self, idx):
self.remove_cell(self.selected)
print('GUI_INFO: merged two cells')
self.update_layer()
io._save_sets(self)
io._save_sets_with_check(self)
self.undo.setEnabled(False)
self.redo.setEnabled(False)

Expand All @@ -1227,7 +1227,7 @@ def undo_remove_cell(self):
self.zdraw.append([])
print('>>> added back removed cell')
self.update_layer()
io._save_sets(self)
io._save_sets_with_check(self)
self.removed_cell = []
self.redo.setEnabled(False)

Expand Down Expand Up @@ -1430,7 +1430,7 @@ def add_set(self):
self.ismanual = np.append(self.ismanual, True)
if self.NZ==1:
# only save after each cell if single image
io._save_sets(self)
io._save_sets_with_check(self)
self.current_stroke = []
self.strokes = []
self.current_point_set = []
Expand Down
14 changes: 9 additions & 5 deletions cellpose/gui/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,17 @@ def _save_outlines(parent):
else:
print('ERROR: cannot save 3D outlines')

def _save_sets_with_check(parent):
""" Save masks and update *_seg.npy file. Use this function when saving should be optional
based on the disableAutosave checkbox. Otherwise, use _save_sets """
if not parent.disableAutosave.isChecked():
_save_sets(parent)


def _save_sets(parent):
""" save masks to *_seg.npy """
""" save masks to *_seg.npy. This function should be used when saving
is forced, e.g. when clicking the save button. Otherwise, use _save_sets_with_check
"""
filename = parent.filename
base = os.path.splitext(filename)[0]
flow_threshold, cellprob_threshold = parent.get_thresholds()
Expand All @@ -496,16 +504,12 @@ def _save_sets(parent):
'cellprob_threshold': cellprob_threshold
})
else:
image = parent.chanchoose(parent.stack[parent.currentZ].copy())
if image.ndim < 4:
image = image[np.newaxis,...]
np.save(base + '_seg.npy',
{'outlines': parent.outpix.squeeze(),
'colors': parent.cellcolors[1:],
'masks': parent.cellpix.squeeze(),
'chan_choose': [parent.ChannelChoose[0].currentIndex(),
parent.ChannelChoose[1].currentIndex()],
'img': image.squeeze(),
'filename': parent.filename,
'flows': parent.flows,
'ismanual': parent.ismanual,
Expand Down
6 changes: 5 additions & 1 deletion cellpose/gui/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def mainmenu(parent):
parent.autoloadMasks = QAction("Autoload masks from _masks.tif file", parent, checkable=True)
parent.autoloadMasks.setChecked(False)
file_menu.addAction(parent.autoloadMasks)


parent.disableAutosave = QAction("Disable autosave _seg.npy file", parent, checkable=True)
parent.disableAutosave.setChecked(False)
file_menu.addAction(parent.disableAutosave)

parent.loadMasks = QAction("Load &masks (*.tif, *.png, *.jpg)", parent)
parent.loadMasks.setShortcut("Ctrl+M")
parent.loadMasks.triggered.connect(lambda: io._load_masks(parent))
Expand Down

0 comments on commit 208fe1d

Please sign in to comment.