Skip to content

Commit 0a03061

Browse files
committed
Move layout setup
1 parent cb1d31a commit 0a03061

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

src/napari_matplotlib/features.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
from typing import List
1+
from typing import Dict, List
22

3+
import napari
34
import napari.layers
5+
from qtpy.QtWidgets import QComboBox, QLabel, QVBoxLayout
46

57
from napari_matplotlib.base import NapariMPLWidget
68
from napari_matplotlib.util import Interval
@@ -10,6 +12,12 @@ class FeaturesMixin(NapariMPLWidget):
1012
"""
1113
Mixin to help with widgets that plot data from a features table stored
1214
on a single layer.
15+
16+
Notes
17+
-----
18+
This currently only works for widgets that plot two quatities against each other
19+
e.g., scatter plots. It is intended to be generalised in the future for widgets
20+
that plot one quantity e.g., histograms.
1321
"""
1422

1523
n_layers_input = Interval(1, 1)
@@ -22,6 +30,19 @@ class FeaturesMixin(NapariMPLWidget):
2230
napari.layers.Vectors,
2331
)
2432

33+
def __init__(self) -> None:
34+
# Set up selection boxes
35+
self.layout().addLayout(QVBoxLayout())
36+
37+
self._selectors: Dict[str, QComboBox] = {}
38+
for dim in ["x", "y"]:
39+
self._selectors[dim] = QComboBox()
40+
# Re-draw when combo boxes are updated
41+
self._selectors[dim].currentTextChanged.connect(self._draw)
42+
43+
self.layout().addWidget(QLabel(f"{dim}-axis:"))
44+
self.layout().addWidget(self._selectors[dim])
45+
2546
def _get_valid_axis_keys(self) -> List[str]:
2647
"""
2748
Get the valid axis keys from the layer FeatureTable.

src/napari_matplotlib/scatter.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from typing import Any, Dict, Optional, Tuple, Union
1+
from typing import Any, Optional, Tuple, Union
22

33
import napari
44
import numpy.typing as npt
5-
from qtpy.QtWidgets import QComboBox, QLabel, QVBoxLayout, QWidget
5+
from qtpy.QtWidgets import QWidget
66

77
from .base import NapariMPLWidget
88
from .features import FeaturesMixin
@@ -25,7 +25,7 @@ def __init__(
2525
napari_viewer: napari.viewer.Viewer,
2626
parent: Optional[QWidget] = None,
2727
):
28-
super().__init__(napari_viewer, parent=parent)
28+
NapariMPLWidget.__init__(self, napari_viewer, parent=parent)
2929
self.add_single_axes()
3030

3131
def clear(self) -> None:
@@ -110,19 +110,8 @@ def __init__(
110110
napari_viewer: napari.viewer.Viewer,
111111
parent: Optional[QWidget] = None,
112112
):
113-
super().__init__(napari_viewer, parent=parent)
114-
115-
self.layout().addLayout(QVBoxLayout())
116-
117-
self._selectors: Dict[str, QComboBox] = {}
118-
for dim in ["x", "y"]:
119-
self._selectors[dim] = QComboBox()
120-
# Re-draw when combo boxes are updated
121-
self._selectors[dim].currentTextChanged.connect(self._draw)
122-
123-
self.layout().addWidget(QLabel(f"{dim}-axis:"))
124-
self.layout().addWidget(self._selectors[dim])
125-
113+
ScatterBaseWidget.__init__(self, napari_viewer, parent=parent)
114+
FeaturesMixin.__init__(self)
126115
self._update_layers(None)
127116

128117
@property

0 commit comments

Comments
 (0)