Skip to content

Commit

Permalink
made a chest of widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
niksirbi committed Nov 17, 2023
1 parent 304e8c1 commit d051dc4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
17 changes: 17 additions & 0 deletions brainglobe_template_builder/napari/chest_of_widgets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from brainglobe_utils.qtpy.collapsible_widget import CollapsibleWidgetContainer
from napari.viewer import Viewer
from qtpy.QtWidgets import QPushButton

from brainglobe_template_builder.napari.mask_widget import GenerateMask


class ChestOfDrawers(CollapsibleWidgetContainer):
def __init__(self, napari_viewer: Viewer, parent=None):
super().__init__()
self.add_widget(GenerateMask(napari_viewer, parent=self))
self.add_widget(GenerateMask(napari_viewer, parent=self))

random_button = QPushButton("Random button", parent=self)
self.add_widget(random_button)

self.add_widget(GenerateMask(napari_viewer, parent=self))
21 changes: 13 additions & 8 deletions brainglobe_template_builder/napari/mask_widget.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
from brainglobe_utils.qtpy.collapsible_widget import CollapsibleWidget
from napari.layers import Image
from napari.utils.notifications import show_info
from napari.viewer import Viewer
Expand All @@ -17,28 +18,32 @@
)


class GenerateMask(QWidget):
class GenerateMask(CollapsibleWidget):
def __init__(self, napari_viewer: Viewer, parent=None):
super().__init__(parent=parent)
super().__init__(title="Generate Mask", parent=parent)
self.viewer = napari_viewer
self.setLayout(QFormLayout())

content = QWidget(parent=self)
content.setLayout(QFormLayout())

self.setContent(content)

self.gauss_sigma = QSpinBox(parent=self)
self.gauss_sigma.setRange(0, 20)
self.gauss_sigma.setValue(3)
self.layout().addRow("gauss sigma:", self.gauss_sigma)
content.layout().addRow("gauss sigma:", self.gauss_sigma)

self.threshold_method = QComboBox(parent=self)
self.threshold_method.addItems(["triangle", "otsu", "isodata"])
self.layout().addRow("threshold method:", self.threshold_method)
content.layout().addRow("threshold method:", self.threshold_method)

self.erosion_size = QSpinBox(parent=self)
self.erosion_size.setRange(0, 20)
self.erosion_size.setValue(5)
self.layout().addRow("erosion size:", self.erosion_size)
content.layout().addRow("erosion size:", self.erosion_size)

self.generate_mask_button = QPushButton("Generate mask", parent=self)
self.layout().addRow(self.generate_mask_button)
content.layout().addRow(self.generate_mask_button)
self.generate_mask_button.clicked.connect(self._on_button_click)

def _on_button_click(self):
Expand All @@ -48,7 +53,7 @@ def _on_button_click(self):
show_info("Please select exactly one image layer")
return None

image = self.viewer.layers.selection[0]
image = list(self.viewer.layers.selection)[0]

if not isinstance(image, Image):
show_info("The selected layer is not an image layer")
Expand Down
2 changes: 1 addition & 1 deletion brainglobe_template_builder/napari/napari.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ contributions:
python_name: brainglobe_template_builder.napari._reader:napari_get_reader
title: Open data with brainglobe-template-builder
- id: brainglobe-template-builder.make_mask_widget
python_name: brainglobe_template_builder.napari.mask_widget:GenerateMask
python_name: brainglobe_template_builder.napari.chest_of_widgets:ChestOfDrawers
title: Generate mask
- id: brainglobe-template-builder.make_points_widget
python_name: brainglobe_template_builder.napari._widget:points_widget
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ dependencies = [
"simpleitk",
"vtk",
"qbatch",
"imio"
"imio",
"brainglobe-utils[napari]",
]

entry-points."napari.manifest".brainglobe-template-builder = "brainglobe_template_builder.napari:napari.yaml"
Expand Down

0 comments on commit d051dc4

Please sign in to comment.