Skip to content

Commit

Permalink
improvement: closes #573, closes #574
Browse files Browse the repository at this point in the history
  • Loading branch information
ElpadoCan committed Nov 16, 2024
1 parent b53495a commit d602a6f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
28 changes: 27 additions & 1 deletion cellacdc/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8642,14 +8642,18 @@ def ok_cb(self):
class editID_QWidget(QDialog):
def __init__(
self, clickedID, IDs, entryID=None, doNotShowAgain=False,
parent=None
parent=None, nextUniqueID=1, allIDs=None
):
self.IDs = IDs
self.clickedID = clickedID
self.cancel = True
self.how = None
self.mergeWithExistingID = True
self.doNotAskAgainExistingID = doNotShowAgain
self.allIDs = allIDs
if allIDs is None:
self.allIDs = set(self.IDs)
self.nextUniqueID = nextUniqueID

super().__init__(parent)
self.setWindowTitle("Edit ID")
Expand All @@ -8673,6 +8677,18 @@ def __init__(
entryWidget.setText(str(entryID))
entryWidget.selectAll()

VBoxLayout.addWidget(
QLabel(f'Next unique ID = {nextUniqueID}'), alignment=Qt.AlignCenter
)

VBoxLayout.addWidget(widgets.QHLine())

self.warnExistingIDLabel = QLabel()
self.warnExistingIDLabel.setStyleSheet('color: red')
VBoxLayout.addWidget(
self.warnExistingIDLabel, alignment=Qt.AlignCenter
)

note = QLabel(
'NOTE: To replace multiple IDs at once\n'
'write "(old ID, new ID), (old ID, new ID)" etc.'
Expand Down Expand Up @@ -8705,6 +8721,16 @@ def __init__(
# self.setModal(True)

def onTextChanged(self, text):
self.warnExistingIDLabel.setText('')
try:
ID = int(text)
if ID in self.allIDs:
self.warnExistingIDLabel.setText(
f'WARNING: ID {ID} was already used'
)
except Exception as err:
pass

# Get inserted char
idx = self.entryWidget.cursorPosition()
if idx == 0:
Expand Down
11 changes: 8 additions & 3 deletions cellacdc/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5516,9 +5516,12 @@ def gui_mousePressEventImg2(self, event):

posData.disableAutoActivateViewerWindow = True
currentIDs = posData.IDs.copy()
self.setAllIDsx(onlyVisited=True)
editID = apps.editID_QWidget(
ID, posData.IDs, doNotShowAgain=self.doNotAskAgainExistingID,
parent=self, entryID=self.getNearestLostObjID(y, x)
parent=self, entryID=self.getNearestLostObjID(y, x),
nextUniqueID=self.setBrushID(return_val=True),
allIDs=posData.allIDs
)
editID.show(block=True)
if editID.cancel:
Expand Down Expand Up @@ -11816,7 +11819,6 @@ def changeFontSize(self):

self.setAllIDs()
posData = self.data[self.pos_i]
allIDs = posData.allIDs
for ax in range(2):
self.textAnnot[ax].changeFontSize(self.fontSize)
if self.highLowResAction.isChecked():
Expand Down Expand Up @@ -12877,13 +12879,16 @@ def moveLabelButtonToggled(self, checked):
self.highLightIDLayerRightImage.clear()
self.setHighlightID(False)

def setAllIDs(self):
def setAllIDs(self, onlyVisited=False):
for posData in self.data:
posData.allIDs = set()
for frame_i in range(len(posData.segm_data)):
if frame_i >= len(posData.allData_li):
break
lab = posData.allData_li[frame_i]['labels']
if lab is None and onlyVisited:
break

if lab is None:
rp = skimage.measure.regionprops(posData.segm_data[frame_i])
else:
Expand Down

0 comments on commit d602a6f

Please sign in to comment.