Skip to content

Commit 5bd30bd

Browse files
committed
Move layout setup
1 parent 68275f4 commit 5bd30bd

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

Diff for: src/napari_matplotlib/features.py

+22-1
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.

Diff for: src/napari_matplotlib/scatter.py

+4-15
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 SingleAxesWidget
88
from .features import FeaturesMixin
@@ -96,19 +96,8 @@ def __init__(
9696
napari_viewer: napari.viewer.Viewer,
9797
parent: Optional[QWidget] = None,
9898
):
99-
super().__init__(napari_viewer, parent=parent)
100-
101-
self.layout().addLayout(QVBoxLayout())
102-
103-
self._selectors: Dict[str, QComboBox] = {}
104-
for dim in ["x", "y"]:
105-
self._selectors[dim] = QComboBox()
106-
# Re-draw when combo boxes are updated
107-
self._selectors[dim].currentTextChanged.connect(self._draw)
108-
109-
self.layout().addWidget(QLabel(f"{dim}-axis:"))
110-
self.layout().addWidget(self._selectors[dim])
111-
99+
ScatterBaseWidget.__init__(self, napari_viewer, parent=parent)
100+
FeaturesMixin.__init__(self)
112101
self._update_layers(None)
113102

114103
@property

0 commit comments

Comments
 (0)