ome / napari-ome-zarr

A napari plugin for zarr backed OME-NGFF images
https://www.napari-hub.org/plugins/napari-ome-zarr
BSD 3-Clause "New" or "Revised" License
28 stars 21 forks source link

Right click on any layer fails #34

Open constantinpape opened 2 years ago

constantinpape commented 2 years ago

Normally it's possible to right click on napari layers to change their properties, e.g. to change from an image layer to a label layer or group layers. E.g.: image But this fails for layers that were loaded with the napari-ome-zarr plugin, see the long traceback below.

I have tried this with the following settings (from napari info):

napari: 0.4.14
Platform: Linux-5.14.0-1027-oem-x86_64-with-glibc2.31
System: Ubuntu 20.04.4 LTS
Python: 3.10.2 | packaged by conda-forge | (main, Mar 8 2022, 15:52:01) [GCC 9.4.0]
Qt: 5.12.9
PyQt5: 5.12.3
NumPy: 1.22.3
SciPy: 1.8.0
Dask: 2022.02.1
VisPy: 0.9.6

OpenGL:
- GL version: 4.6 (Compatibility Profile) Mesa 21.2.6
- MAX_TEXTURE_SIZE: 16384

Screens:
- screen 1: resolution 2560x1440, scale 1.0

Plugins:
- console: 0.0.4
- napari-ome-zarr: 0.4.0
- scikit-image: 0.4.14
- svg: 0.1.5

Traceback:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File ~/software/conda/miniconda3/envs/napari/lib/python3.10/site-packages/napari/_qt/containers/_layer_delegate.py:153, in LayerDelegate.editorEvent(self=, event=, model=, option=, index=)
    145 """Called when an event has occured in the editor.
    146 
    147 This can be used to customize how the delegate handles mouse/key events
    148 """
    149 if (
    150     event.type() == event.MouseButtonRelease
    151     and event.button() == Qt.RightButton
    152 ):
--> 153     self.show_context_menu(
        self = 
        event = 
        model = 
        option = 
        index = 
    154         index, model, event.globalPos(), option.widget
    155     )
    157 # if the user clicks quickly on the visibility checkbox, we *don't*
    158 # want it to be interpreted as a double-click.  We want the visibilty
    159 # to simply be toggled.
    160 if event.type() == event.MouseButtonDblClick:

File ~/software/conda/miniconda3/envs/napari/lib/python3.10/site-packages/napari/_qt/containers/_layer_delegate.py:185, in LayerDelegate.show_context_menu(self=, index=, model=, pos=PyQt5.QtCore.QPoint(1439, 558), parent=)
    182     self._context_menu = QtActionContextMenu(_LAYER_ACTIONS)
    184 layer_list: LayerList = model.sourceModel()._root
--> 185 self._context_menu.update_from_context(get_context(layer_list))
        layer_list = [, , , ]
        self._context_menu = 
        self = 
    186 action = self._context_menu.exec_(pos)
    187 if action is not None and isinstance(action.data(), dict):
    188     # action.data will be a callable that accepts a layer_list instance

File ~/software/conda/miniconda3/envs/napari/lib/python3.10/site-packages/napari/_qt/widgets/qt_action_context_menu.py:117, in QtActionContextMenu.update_from_context(self=, ctx=Context({'layers_selection_count': 1, 'all_layer...same_shape': True}, {}, SettingsAwareContext({})))
    115 enable = d['enable_when']
    116 if isinstance(enable, Expr):
--> 117     enable = enable.eval(ctx)
        enable = Compare(
  left=BoolOp(
    op=And(),
    values=[
      Compare(
        left=ContextKey(id='active_layer_type', ctx=Load()),
        ops=[
          Eq()],
        comparators=[
          Constant(value='image')]),
      ContextKey(id='active_layer_ndim', ctx=Load())]),
  ops=[
    Gt()],
  comparators=[
    Constant(value=2)])
        ctx = Context({'layers_selection_count': 1, 'all_layers_linked': False, 'unselected_linked_layers': 0, 'active_layer_is_rgb': False, 'active_layer_type': 'image', 'only_images_selected': True, 'only_labels_selected': False, 'only_shapes_selected': False, 'active_layer_ndim': None, 'active_layer_shape': (6, 2048, 2048), 'active_layer_dtype': 'uint16', 'all_layers_same_shape': True}, {}, SettingsAwareContext({}))
    118 item.setEnabled(bool(enable))
    119 # if it's a menu, iterate (but don't toggle visibility)

File ~/software/conda/miniconda3/envs/napari/lib/python3.10/site-packages/napari/utils/context/_expressions.py:186, in Expr.eval(self=Compare(
  left=BoolOp(
    op=And(),
    values...   Gt()],
  comparators=[
    Constant(value=2)]), context=Context({'layers_selection_count': 1, 'all_layer...same_shape': True}, {}, SettingsAwareContext({})))
    184 code = compile(ast.Expression(body=self), '', 'eval')
    185 try:
--> 186     return eval(code, {}, context)
        code =  at 0x7f3f939ef890, file "", line 1>
        context = Context({'layers_selection_count': 1, 'all_layers_linked': False, 'unselected_linked_layers': 0, 'active_layer_is_rgb': False, 'active_layer_type': 'image', 'only_images_selected': True, 'only_labels_selected': False, 'only_shapes_selected': False, 'active_layer_ndim': None, 'active_layer_shape': (6, 2048, 2048), 'active_layer_dtype': 'uint16', 'all_layers_same_shape': True}, {}, SettingsAwareContext({}))
    187 except NameError:
    188     miss = {k for k in _iter_names(self) if k not in context}

File :1, in 

TypeError: '>' not supported between instances of 'NoneType' and 'int'
will-moore commented 2 years ago

Yes, this fails for me too (M1 Mac). The context menu doesn't get shown. But I don't know if this is an issue with napari-ome-zarr. Should it be doing something differently? cc @jni

dstansby commented 3 months ago

Using the example napari "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.3/9836842.zarr/" right click seems to work for me now. Can this be close now?

jni commented 3 months ago

If we can't reproduce it, we can probably close it. If it comes up again we can reopen and I can investigate — sorry I missed the ping last time!

psobolewskiPhD commented 3 months ago

The layer list contextual menus work just for for me as well. Even the Convert... which surprised me. I'd vote to close.