Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions src/napari_deeplabcut/_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from napari.utils.events import Event
from napari.utils.history import get_save_history, update_save_history
from qtpy.QtCore import Qt, QTimer, Signal, QSize, QPoint, QSettings
from qtpy.QtGui import QPainter, QIcon, QAction
from qtpy.QtGui import QPainter, QIcon, QAction, QCursor
from qtpy.QtWidgets import (
QButtonGroup,
QCheckBox,
Expand Down Expand Up @@ -989,6 +989,26 @@ def dropEvent(self, event):
self.sig_dropped.emit(event)


class ClickableLabel(QLabel):
clicked = Signal(str)

def __init__(self, text="", color="turquoise", parent=None):
super().__init__(text, parent)
self._default_style = self.styleSheet()
self.color = color

def mousePressEvent(self, event):
self.clicked.emit(self.text())

def enterEvent(self, event):
self.setCursor(QCursor(Qt.PointingHandCursor))
self.setStyleSheet(f"color: {self.color}")

def leaveEvent(self, event):
self.unsetCursor()
self.setStyleSheet(self._default_style)


class LabelPair(QWidget):
def __init__(self, color: str, name: str, parent: QWidget):
super().__init__(parent)
Expand All @@ -997,7 +1017,7 @@ def __init__(self, color: str, name: str, parent: QWidget):
self._part_name = name

self.color_label = QLabel("", parent=self)
self.part_label = QLabel(name, parent=self)
self.part_label = ClickableLabel(name, color=color, parent=self)

self.color_label.setToolTip(name)
self.part_label.setToolTip(name)
Expand Down Expand Up @@ -1057,6 +1077,15 @@ def __init__(self, parent):

self._build()

@property
def labels(self):
labels = []
for i in range(self._layout.count()):
item = self._layout.itemAt(i)
if w := item.widget():
labels.append(w)
return labels

def _build(self):
self._container.setSizePolicy(
QSizePolicy.Fixed, QSizePolicy.Maximum
Expand Down