22
33import napari
44import numpy as np
5- from qtpy .QtWidgets import QWidget
6- from magicgui import magicgui
5+ from qtpy .QtWidgets import QComboBox , QLabel , QVBoxLayout , QWidget
76
87from .base import SingleAxesWidget
98from .util import Interval
@@ -71,13 +70,14 @@ def __init__(
7170 parent : Optional [QWidget ] = None ,):
7271 super ().__init__ (napari_viewer , parent = parent )
7372
74- self ._key_selection_widget = magicgui (
75- x_axis_key = {"choices" : self ._get_valid_axis_keys },
76- call_button = "plot" ,
77- )
78- self .layout ().addWidget (self ._key_selection_widget .native )
73+ self .layout ().addLayout (QVBoxLayout ())
74+ self ._key_selection_widget = QComboBox ()
75+ self .layout ().addWidget (QLabel ("Key:" ))
76+ self .layout ().addWidget (self ._key_selection_widget )
7977
80- self .update_layers (None )
78+ self ._key_selection_widget .currentTextChanged .connect (self ._set_axis_keys )
79+
80+ self ._update_layers (None )
8181
8282 @property
8383 def x_axis_key (self ) -> Optional [str ]:
@@ -139,17 +139,17 @@ def _get_data(self) -> Tuple[np.ndarray, str]:
139139
140140 return data , x_axis_name
141141
142- def _on_update_layers (self ) -> None :
142+ def on_update_layers (self ) -> None :
143143 """
144- This is called when the layer selection changes by
145- ``self.update_layers()``.
144+ Called when the layer selection changes by ``self.update_layers()``.
146145 """
147- if hasattr (self , "_key_selection_widget" ):
148- self ._key_selection_widget .reset_choices ()
149-
150146 # reset the axis keys
151147 self ._x_axis_key = None
152148
149+ # Clear combobox
150+ self ._key_selection_widget .clear ()
151+ self ._key_selection_widget .addItems (self ._get_valid_axis_keys ())
152+
153153 def draw (self ) -> None :
154154 """Clear the axes and histogram the currently selected layer/slice."""
155155
@@ -159,7 +159,7 @@ def draw(self) -> None:
159159 return
160160
161161 self .axes .hist (data , bins = 50 , edgecolor = 'white' ,
162- linewidth = 0.3 )
162+ linewidth = 0.3 )
163163
164164 # set ax labels
165165 self .axes .set_xlabel (x_axis_name )
0 commit comments