magicgui icon indicating copy to clipboard operation
magicgui copied to clipboard

reset_choices with reparenting behavior can be confusing

Open tlambert03 opened this issue 3 years ago • 3 comments

this code does not result in a combobox with 1,2,3,4

import napari
from magicgui.widgets import ComboBox, Container

class MyWidget(Container):
    def __init__(self, viewer: napari.Viewer):
        super().__init__()
        self._viewer = viewer
        self._combobox = ComboBox()
        self.append(self._combobox)
        self._combobox.choices = (1, 2, 3, 4)

viewer = napari.Viewer()
widget = MyWidget(viewer)

viewer.window.add_dock_widget(widget)
napari.run()

The issue here is that when you reparent a widget, like when you add it as a dock widget to the viewer. It will reset choices. This is the thing that makes a magicgui able to update Layer combobox with the available layers in whatever viewer it's in (even though it's not necessarily in a viewer when you create the widget).

but it's obviously confusing behavior, so should be fixed

tlambert03 avatar Oct 30 '21 00:10 tlambert03

I think I just ran into this. Note to self: always check for open issues first.

I tried to assign to w.choices in a Combobox widget w that has been docked into napari. I get weird results. E.g. I assign a list of items to .choices and only some of the items appear in Combobox. However, if I print w.choices, everything that I assigned is there.

VolkerH avatar Dec 03 '21 17:12 VolkerH

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/resetting-choices-in-select-widget/63545/2

imagesc-bot avatar Feb 19 '22 13:02 imagesc-bot

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/visualizing-feature-measurements-in-napari-using-colormaps-as-luts/51567/37

imagesc-bot avatar Mar 15 '22 19:03 imagesc-bot