Skip to content

Commit a4ce460

Browse files
committed
Auto lock keypoint selection when in loop mode
1 parent 7e1b20b commit a4ce460

File tree

5 files changed

+15
-33
lines changed

5 files changed

+15
-33
lines changed

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
include LICENSE
22
include README.md
3-
include src/napari_deeplabcut/assets/*.svg
43

54
recursive-exclude * __pycache__
65
recursive-exclude * *.py[co]

src/napari_deeplabcut/_widgets.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
from napari.layers.utils.layer_utils import _features_to_properties
1919
from napari.utils.events import Event
2020
from napari.utils.history import get_save_history, update_save_history
21-
from qtpy.QtCore import Qt, QTimer, Signal, QSize, QPoint, QSettings
22-
from qtpy.QtGui import QPainter, QIcon, QAction, QCursor
21+
from qtpy.QtCore import Qt, QTimer, Signal, QPoint, QSettings
22+
from qtpy.QtGui import QPainter, QAction, QCursor
2323
from qtpy.QtWidgets import (
2424
QButtonGroup,
2525
QCheckBox,
@@ -41,8 +41,6 @@
4141
QWidget,
4242
)
4343

44-
ICON_FOLDER = os.path.join(os.path.dirname(__file__), "assets")
45-
4644
from napari_deeplabcut import keypoints
4745
from napari_deeplabcut._reader import _load_config
4846
from napari_deeplabcut._writer import _write_config, _write_image, _form_df
@@ -764,8 +762,15 @@ def label_mode(self):
764762
def label_mode(self, mode: Union[str, keypoints.LabelMode]):
765763
self._label_mode = keypoints.LabelMode(mode)
766764
self.viewer.status = self.label_mode
765+
mode_ = str(mode)
766+
if mode_ == "loop":
767+
for menu in self._menus:
768+
menu._locked = True
769+
else:
770+
for menu in self._menus:
771+
menu._locked = False
767772
for btn in self._radio_group.buttons():
768-
if btn.text() == str(mode):
773+
if btn.text() == mode_:
769774
btn.setChecked(True)
770775
break
771776

@@ -827,11 +832,6 @@ def __init__(
827832
layout2 = QVBoxLayout()
828833
for menu in self.menus.values():
829834
layout2.addWidget(menu)
830-
self.lock_button = QPushButton("Lock selection")
831-
self.lock_button.setIcon(QIcon(os.path.join(ICON_FOLDER, "unlock.svg")))
832-
self.lock_button.setIconSize(QSize(24, 24))
833-
self.lock_button.clicked.connect(self._lock_current_keypoint)
834-
layout2.addWidget(self.lock_button)
835835
group_box.setLayout(layout2)
836836
layout1.addWidget(group_box)
837837
self.setLayout(layout1)
@@ -861,15 +861,6 @@ def _update_items(self):
861861
self.menus["id"].update_items(list(self.id2label))
862862
self.menus["label"].update_items(self.id2label[id_])
863863

864-
def _lock_current_keypoint(self):
865-
self._locked = not self._locked
866-
if self._locked:
867-
self.lock_button.setText("Unlock selection")
868-
self.lock_button.setIcon(QIcon(os.path.join(ICON_FOLDER, "lock.svg")))
869-
else:
870-
self.lock_button.setText("Lock selection")
871-
self.lock_button.setIcon(QIcon(os.path.join(ICON_FOLDER, "unlock.svg")))
872-
873864
def update_menus(self, event):
874865
keypoint = self.store.current_keypoint
875866
for attr, menu in self.menus.items():
@@ -886,7 +877,7 @@ def refresh_label_menu(self, text: str):
886877

887878
def smart_reset(self, event):
888879
"""Set current keypoint to the first unlabeled one."""
889-
if self._locked:
880+
if self._locked: # The currently selected point is not updated
890881
return
891882
unannotated = ""
892883
already_annotated = self.store.annotated_keypoints

src/napari_deeplabcut/assets/lock.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/napari_deeplabcut/assets/unlock.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/napari_deeplabcut/keypoints.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,8 @@ class LabelMode(CycleEnum):
4141
clicking to add an already annotated point has no effect.
4242
QUICK: similar to SEQUENTIAL, but trying to add an already
4343
annotated point actually moves it to the cursor location.
44-
LOOP: the first point is placed frame by frame, then it wraps
45-
to the next label at the end and restart from frame 1, etc.
46-
Unless the keypoint selection is locked, the dropdown menu is
47-
automatically set to the first unlabeled keypoint of
48-
the current frame.
44+
LOOP: the currently selected point is placed frame after frame,
45+
before wrapping at the end to frame 1, etc.
4946
"""
5047

5148
SEQUENTIAL = auto()
@@ -63,11 +60,8 @@ def default(cls):
6360
"clicking to add an already annotated point has no effect.",
6461
"QUICK": "Similar to SEQUENTIAL, but trying to add an already\n"
6562
"annotated point actually moves it to the cursor location.",
66-
"LOOP": "The first point is placed frame by frame, then it wraps\n"
67-
"to the next label at the end and restart from frame 1, etc.\n"
68-
"Unless the keypoint selection is locked, the dropdown menu is\n"
69-
"automatically set to the first unlabeled keypoint of\n"
70-
"the current frame.",
63+
"LOOP": "The currently selected point is placed frame after frame,\n"
64+
"before wrapping at the end to frame 1, etc.",
7165
}
7266

7367

0 commit comments

Comments
 (0)