Skip to content

Commit 0fb707f

Browse files
committed
Merge branch 'main' into seb/matplotlib_keypoint_viewer
2 parents fe36a98 + 4d34cd2 commit 0fb707f

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ install_requires =
3939
opencv-python-headless
4040
pandas
4141
pyyaml
42-
qtpy
42+
qtpy>=2.4
4343
scikit-image
4444
tables
4545
python_requires = >=3.8

src/napari_deeplabcut/_widgets.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from napari.utils.events import Event
2323
from napari.utils.history import get_save_history, update_save_history
2424
from qtpy.QtCore import Qt, QTimer, Signal, QSize, QPoint, QSettings
25-
from qtpy.QtGui import QPainter, QIcon, QAction
25+
from qtpy.QtGui import QPainter, QIcon, QAction, QCursor
2626
from qtpy.QtWidgets import (
2727
QButtonGroup,
2828
QCheckBox,
@@ -1110,6 +1110,26 @@ def dropEvent(self, event):
11101110
self.sig_dropped.emit(event)
11111111

11121112

1113+
class ClickableLabel(QLabel):
1114+
clicked = Signal(str)
1115+
1116+
def __init__(self, text="", color="turquoise", parent=None):
1117+
super().__init__(text, parent)
1118+
self._default_style = self.styleSheet()
1119+
self.color = color
1120+
1121+
def mousePressEvent(self, event):
1122+
self.clicked.emit(self.text())
1123+
1124+
def enterEvent(self, event):
1125+
self.setCursor(QCursor(Qt.PointingHandCursor))
1126+
self.setStyleSheet(f"color: {self.color}")
1127+
1128+
def leaveEvent(self, event):
1129+
self.unsetCursor()
1130+
self.setStyleSheet(self._default_style)
1131+
1132+
11131133
class LabelPair(QWidget):
11141134
def __init__(self, color: str, name: str, parent: QWidget):
11151135
super().__init__(parent)
@@ -1118,7 +1138,7 @@ def __init__(self, color: str, name: str, parent: QWidget):
11181138
self._part_name = name
11191139

11201140
self.color_label = QLabel("", parent=self)
1121-
self.part_label = QLabel(name, parent=self)
1141+
self.part_label = ClickableLabel(name, color=color, parent=self)
11221142

11231143
self.color_label.setToolTip(name)
11241144
self.part_label.setToolTip(name)
@@ -1178,6 +1198,15 @@ def __init__(self, parent):
11781198

11791199
self._build()
11801200

1201+
@property
1202+
def labels(self):
1203+
labels = []
1204+
for i in range(self._layout.count()):
1205+
item = self._layout.itemAt(i)
1206+
if w := item.widget():
1207+
labels.append(w)
1208+
return labels
1209+
11811210
def _build(self):
11821211
self._container.setSizePolicy(
11831212
QSizePolicy.Fixed, QSizePolicy.Maximum

0 commit comments

Comments
 (0)