question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:open
  • Created 2 years ago
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
brisvagcommented, Jul 9, 2021

That’s reasonable! Might be worth considering in #2995 then, which was prompted by similar issues.

0reactions
sofroniewncommented, Jul 22, 2022

but this requires removing all information about the current render state

the layer specific render state should be on the layer model. i’m not sure i understand this

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found