haesleinhuepf / napari-tools-menu

BSD 3-Clause "New" or "Revised" License
9 stars 2 forks source link

Tools menu does not register dock widget with only napari.viewer.Viewer type annotation #3

Closed tdmorello closed 2 years ago

tdmorello commented 2 years ago

Hey Robert @haesleinhuepf

If a dock widget is initialized with only the napari.viewer.Viewer type annotation and not the napari_viewer variable name, it throws an error. If I rename the viewer variable napari_viewer the napari-tools-menu plugin works as expected.

I am using napari-tools-menu v0.1.7 and napari v0.4.12.

# Class that does not work
@register_dock_widget(menu="Utilities > Tiler")
class TilerWidget(QWidget):
    """The main Tiler widget."""

    def __init__(self, viewer: "napari.viewer.Viewer") -> None:
        """Init the Tiler widget."""
        super().__init__()

        self.viewer = viewer
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/Library/Caches/pypoetry/virtualenvs/napari-tiler-OQqB0NQD-py3.10/lib/python3.10/site-packages/napari_tools_menu/__init__.py in func(whatever=False)
     60                         break
     61                     if param.annotation in ('napari.viewer.Viewer', napari.Viewer):
---> 62                         kwargs[param.name] = self.qt_viewer.viewer
        kwargs = {}
        param.name = 'viewer'
        global self.qt_viewer.viewer = undefined
     63                         break
     64                     # cannot look for param.kind == param.VAR_KEYWORD because

AttributeError: 'ToolsMenu' object has no attribute 'qt_viewer'
tdmorello commented 2 years ago

Forgot to check with v0.1.8 -- same issue.

haesleinhuepf commented 2 years ago

Hi Tim @tdmorello ,

thanks for reporting this! I think I just fixed it on the main branch. Would you mind trying it out? I can't upload it to pypi right now because of a server issue... :-)

tdmorello commented 2 years ago

Fixed for me! Thank you 😊

haesleinhuepf commented 2 years ago

Thank you for reporting! 🌞