Skip to content

Commit

Permalink
compatibility with napari==0.4.16
Browse files Browse the repository at this point in the history
  • Loading branch information
bauerdavid committed Aug 30, 2022
1 parent a4caf6a commit da82a5f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 41 deletions.
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ install_requires =
qtpy
opencv-python
matplotlib
napari==0.4.15
vispy==0.9.6
napari>=0.4.15
vispy>=0.9.6
scikit-image
[options.extras_require]
testing =
Expand Down
16 changes: 11 additions & 5 deletions src/napari_nd_annotator/_widgets/object_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import warnings

import cv2
import napari
import numpy as np

from qtpy.QtCore import QEvent, Qt, QObject
Expand Down Expand Up @@ -408,12 +409,16 @@ def eventFilter(self, source: QObject, event: QEvent) -> bool:
if item is None:
return False
idx = self.indexFromItem(item).row()
self.bounding_box_layer._value = (idx, None)
self.bounding_box_layer._set_highlight()
with warnings.catch_warnings():
warnings.simplefilter("ignore")
self.bounding_box_layer._value = (idx, None)
self.bounding_box_layer._set_highlight()
return True
elif event.type() == QEvent.Leave and type(source) == QObjectWidget:
self.bounding_box_layer._value = (None, None)
self.bounding_box_layer._set_highlight()
with warnings.catch_warnings():
warnings.simplefilter("ignore")
self.bounding_box_layer._value = (None, None)
self.bounding_box_layer._set_highlight()
return True
return super().eventFilter(source, event)

Expand All @@ -436,7 +441,8 @@ def bounding_box_change(self, layer, event):
if len(layer.data)>len(previous_data):
self.bounding_box_layer.features["label"].iat[-1] = self.next_index()
text = dict(self.bounding_box_layer.text)
del text["values"]
if napari.__version__ == "0.4.15":
del text["values"]
text["text"] = "{label:d}"
self.bounding_box_layer.text = text
while event.type == "mouse_move":
Expand Down
33 changes: 22 additions & 11 deletions src/napari_nd_annotator/boundingbox/bounding_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,17 @@ def __init__(self,
default="black",
)
self.current_properties = {}

self._text = TextManager._from_layer(
text=text,
n_text=self.nbounding_boxes,
properties=self.properties,
)
if napari.__version__ == "0.4.15":
self._text = TextManager._from_layer(
text=text,
n_text=self.nbounding_boxes,
properties=self.properties,
)
else:
self._text = TextManager._from_layer(
text=text,
features=self.features
)

# Trigger generation of view slice and thumbnail
self._update_dims()
Expand Down Expand Up @@ -481,11 +486,17 @@ def text(self) -> TextManager:

@text.setter
def text(self, text):
self._text._update_from_layer(
text=text,
n_text=self.nbounding_boxes,
properties=self.properties,
)
if napari.__version__ == "0.4.15":
self._text._update_from_layer(
text=text,
n_text=self.nbounding_boxes,
properties=self.properties,
)
else:
self._text._update_from_layer(
text=text,
features=self.features,
)

@property
def edge_color(self):
Expand Down
57 changes: 34 additions & 23 deletions src/napari_nd_annotator/boundingbox/qt_bounding_box_control.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# A copy of napari._qt.layer_controls.qt_shapes_controls
from typing import Iterable

import napari
from PyQt5.QtWidgets import QCheckBox
from napari._qt.widgets.qt_color_swatch import QColorSwatchEdit
from napari.utils.action_manager import action_manager
Expand Down Expand Up @@ -222,29 +223,39 @@ def _radio_button(
text_disp_cb.stateChanged.connect(self.change_text_visibility)
self.textDispCheckBox = text_disp_cb


# grid_layout created in QtLayerControls
# addWidget(widget, row, column, [row_span, column_span])
self.grid_layout.addLayout(button_row, 0, 1)
self.grid_layout.addWidget(QLabel(trans._('opacity:')), 1, 0)
self.grid_layout.addWidget(self.opacitySlider, 1, 1)
self.grid_layout.addWidget(QLabel(trans._('edge width:')), 2, 0)
self.grid_layout.addWidget(self.widthSlider, 2, 1)
self.grid_layout.addWidget(QLabel(trans._('blending:')), 3, 0)
self.grid_layout.addWidget(self.blendComboBox, 3, 1)
self.grid_layout.addWidget(QLabel(trans._('face color:')), 4, 0)
self.grid_layout.addWidget(self.faceColorEdit, 4, 1)
self.grid_layout.addWidget(QLabel(trans._('edge color:')), 5, 0)
self.grid_layout.addWidget(self.edgeColorEdit, 5, 1)
self.grid_layout.addWidget(QLabel(trans._('display text:')), 6, 0)
self.grid_layout.addWidget(self.textDispCheckBox, 6, 1)
self.grid_layout.addWidget(QLabel(trans._('text color:')), 7, 0)
self.grid_layout.addWidget(self.textColorEdit, 7, 1)
self.grid_layout.addWidget(QLabel(trans._('text size:')), 8, 0)
self.grid_layout.addWidget(self.textSlider, 8, 1)
self.grid_layout.setRowStretch(9, 1)
self.grid_layout.setColumnStretch(1, 1)
self.grid_layout.setSpacing(4)
if napari.__version__ == "0.4.15":
# grid_layout created in QtLayerControls
# addWidget(widget, row, column, [row_span, column_span])
self.grid_layout.addLayout(button_row, 0, 1)
self.grid_layout.addWidget(QLabel(trans._('opacity:')), 1, 0)
self.grid_layout.addWidget(self.opacitySlider, 1, 1)
self.grid_layout.addWidget(QLabel(trans._('edge width:')), 2, 0)
self.grid_layout.addWidget(self.widthSlider, 2, 1)
self.grid_layout.addWidget(QLabel(trans._('blending:')), 3, 0)
self.grid_layout.addWidget(self.blendComboBox, 3, 1)
self.grid_layout.addWidget(QLabel(trans._('face color:')), 4, 0)
self.grid_layout.addWidget(self.faceColorEdit, 4, 1)
self.grid_layout.addWidget(QLabel(trans._('edge color:')), 5, 0)
self.grid_layout.addWidget(self.edgeColorEdit, 5, 1)
self.grid_layout.addWidget(QLabel(trans._('display text:')), 6, 0)
self.grid_layout.addWidget(self.textDispCheckBox, 6, 1)
self.grid_layout.addWidget(QLabel(trans._('text color:')), 7, 0)
self.grid_layout.addWidget(self.textColorEdit, 7, 1)
self.grid_layout.addWidget(QLabel(trans._('text size:')), 8, 0)
self.grid_layout.addWidget(self.textSlider, 8, 1)
self.grid_layout.setRowStretch(9, 1)
self.grid_layout.setColumnStretch(1, 1)
self.grid_layout.setSpacing(4)
else:
self.layout().addRow(button_row)
self.layout().addRow(trans._('opacity:'), self.opacitySlider)
self.layout().addRow(trans._('edge width:'), self.widthSlider)
self.layout().addRow(trans._('blending:'), self.blendComboBox)
self.layout().addRow(trans._('face color:'), self.faceColorEdit)
self.layout().addRow(trans._('edge color:'), self.edgeColorEdit)
self.layout().addRow(trans._('display text:'), self.textDispCheckBox)
self.layout().addRow(trans._('text color:'), self.textColorEdit)
self.layout().addRow(trans._('text size:'), self.textSlider)

def _on_mode_change(self, event):
"""Update ticks in checkbox widgets when bounding boxes layer mode changed.
Expand Down

0 comments on commit da82a5f

Please sign in to comment.