Skip to content

Commit

Permalink
add dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Schorb committed Mar 14, 2024
1 parent a1133c5 commit 7b45076
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 47 deletions.
20 changes: 10 additions & 10 deletions src/debug_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ def get_widgetname():
with open(os.path.join(os.getcwd(), "src", module, "napari.yaml")) as f:
mod_settings = yaml.safe_load(f)

for cmd in mod_settings['contributions']['commands']:
if selection not in cmd['python_name']:
continue
else:
w_id = cmd['id']
for widget in mod_settings['contributions']['widgets']:
if w_id not in widget['command']:
continue
else:
widget_name = widget['display_name']
for cmd in mod_settings['contributions']['commands']:
if selection not in cmd['python_name']:
continue
else:
w_id = cmd['id']
for widget in mod_settings['contributions']['widgets']:
if w_id not in widget['command']:
continue
else:
widget_name = widget['display_name']

return widget_name

Expand Down
4 changes: 2 additions & 2 deletions src/mobie_napari_bridge/_tests/test_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def test_browse_q_widget(make_napari_viewer, capsys):
my_widget = TestBrowse(viewer)

# call our widget method
my_widget._on_click()
my_widget._button_click()

# read captured output and check that it's as we expected
captured = capsys.readouterr()
assert captured.out == "napari has 1 layers\n"

51 changes: 16 additions & 35 deletions src/mobie_napari_bridge/_widget.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,17 @@
"""
This module contains four napari widgets declared in
different ways:
- a pure Python function flagged with `autogenerate: true`
in the plugin manifest. Type annotations are used by
magicgui to generate widgets for each parameter. Best
suited for simple processing tasks - usually taking
in and/or returning a layer.
- a `magic_factory` decorated function. The `magic_factory`
decorator allows us to customize aspects of the resulting
GUI, including the widgets associated with each parameter.
Best used when you have a very simple processing task,
but want some control over the autogenerated widgets. If you
find yourself needing to define lots of nested functions to achieve
your functionality, maybe look at the `Container` widget!
- a `magicgui.widgets.Container` subclass. This provides lots
of flexibility and customization options while still supporting
`magicgui` widgets and convenience methods for creating widgets
from type annotations. If you want to customize your widgets and
connect callbacks, this is the best widget option for you.
- a `QWidget` subclass. This provides maximal flexibility but requires
full specification of widget layouts, callbacks, events, etc.
References:
- Widget specification: https://napari.org/stable/plugins/guides.html?#widgets
- magicgui docs: https://pyapp-kit.github.io/magicgui/
Replace code below according to your needs.
"""
from typing import TYPE_CHECKING

from magicgui import magic_factory
from magicgui.widgets import CheckBox, Container, create_widget
from qtpy.QtWidgets import QFileDialog, QHBoxLayout, QPushButton, QWidget
from qtpy.QtWidgets import QFileDialog, QHBoxLayout, QPushButton, QWidget, QComboBox
from skimage.util import img_as_float

if TYPE_CHECKING:
import napari


class ExampleQWidget(QWidget):
# your QWidget.__init__ can optionally request the napari viewer instance
# use a type annotation of 'napari.viewer.Viewer' for any parameter
Expand All @@ -54,21 +28,28 @@ def __init__(self, viewer: "napari.viewer.Viewer"):
def _on_click(self):
print("napari has", len(self.viewer.layers), "layers")


class TestBrowse(QWidget):
# your QWidget.__init__ can optionally request the napari viewer instance
# use a type annotation of 'napari.viewer.Viewer' for any parameter
def __init__(self, viewer: "napari.viewer.Viewer"):
super().__init__()
self.viewer = viewer
self.project_root = None

btn = QPushButton("Load this!")
btn.clicked.connect(self._button_click)
self.loadproj_btn = QPushButton("Select MoBIE project Folder")
self.loadproj_btn.clicked.connect(self._button_click)

dlg1 = QFileDialog(caption="123")
self.ds_dropdown = QComboBox()

self.setLayout(QHBoxLayout())
self.layout().addWidget(dlg1)
self.layout().addWidget(btn)
self.layout().addWidget(self.loadproj_btn)

def _button_click(self):
print("resxdcfghjj")
dlg1 = QFileDialog()
self.project_root = dlg1.getExistingDirectory(None)

self.ds_dropdown.addItems(['1', '2'])
self.layout().addWidget(self.ds_dropdown)

print(self.project_root)

0 comments on commit 7b45076

Please sign in to comment.