Unsettable attributes and magicgui LayerDataTuple are incompatible
See original GitHub issue🐛 Bug
To update inplace a result layer with a @magicgui
decorated function, one should return a LayerDataTuple
. However, this breaks if any of the attributes passed in the dictionary are not settable, such as ndim
for Points.
To Reproduce
import napari
from napari.types import LayerDataTuple
from napari.layers import Points
from magicgui import magicgui
@magicgui()
def func(points: Points) -> LayerDataTuple:
return (), dict(name='result', ndim=3), 'points'
v = napari.Viewer()
v.add_points()
v.window.add_dock_widget(func)
func()
func()
This fails with
~/git/napari/napari/utils/_magicgui.py in add_layer_data_tuples_to_viewer(gui, result, return_type)
148 layer.data = layer_datum[0]
149 for k, v in layer_datum[1].items():
--> 150 setattr(layer, k, v)
151 continue
152 except KeyError: # layer not in the viewer
AttributeError: can't set attribute
Expected behavior
I’m not sure about the best approach, but I feel like there should be no failure when the attribute (even if not settable) is already correct. In this case, ndim was 3, so setting it to 3 should just be a noop.
Environment
napari: 0.4.9rc1.dev12+gbf03a0d4
Platform: Linux-5.12.14-arch1-1-x86_64-with-glibc2.33
System: Arch Linux
Python: 3.9.6 (default, Jun 30 2021, 10:22:16) [GCC 11.1.0]
Qt: 5.15.2
PyQt5: 5.15.4
NumPy: 1.20.3
SciPy: 1.7.0
Dask: 2020.12.0
VisPy: 0.6.5.dev716+g91430ea4.d20210629
OpenGL:
- GL version: 4.6.0 NVIDIA 465.31
- MAX_TEXTURE_SIZE: 16384
Screens:
- screen 1: resolution 1920x1080, scale 1.0
- screen 2: resolution 1920x1200, scale 1.0
Plugins:
- animation: 0.0.2
- console: 0.0.3
- mrcfile-reader: 0.1.2
- napari-em-reader: 0.1.0
- napari-properties-plotter: 0.2.0
- ndtiffs: 0.1.1
- scikit-image: 0.4.9
- svg: 0.1.5
Issue Analytics
- State:
- Created 2 years ago
- Comments:15 (15 by maintainers)
Top Results From Across the Web
Using magicgui in napari
magicgui ¶. magicgui is a python package that assists in building small, composable graphical user interfaces (widgets). It is a general abstraction layer...
Read more >Generate Multi-selection widget from magicgui for napari plugins
Hi everyone, I would like to know if there is a convenient way to generate a multi-selection widget with magicgui to be used...
Read more >Unsettable attributes and magicgui LayerDataTuple are ...
I'm creating a result layer that sometimes (e.g: at initialization) will have no data. If one passes no data and no ndim, it...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That’s reasonable! Might be worth considering in #2995 then, which was prompted by similar issues.
the layer specific render state should be on the layer model. i’m not sure i understand this