|
1 | | -""" |
2 | | -This module is an example of a barebones QWidget plugin for napari |
3 | | -
|
4 | | -It implements the Widget specification. |
5 | | -see: https://napari.org/plugins/stable/guides.html#widgets |
6 | | -
|
7 | | -Replace code below according to your needs. |
8 | | -""" |
9 | | -from magicgui import magic_factory |
10 | | -from qtpy.QtWidgets import QHBoxLayout, QPushButton, QWidget |
| 1 | +import napari |
| 2 | +from matplotlib.backends.backend_qt5agg import FigureCanvas |
| 3 | +from matplotlib.figure import Figure |
| 4 | +from qtpy.QtWidgets import QHBoxLayout, QWidget |
11 | 5 |
|
12 | 6 |
|
13 | 7 | class ExampleQWidget(QWidget): |
14 | 8 | # your QWidget.__init__ can optionally request the napari viewer instance |
15 | 9 | # in one of two ways: |
16 | 10 | # 1. use a parameter called `napari_viewer`, as done here |
17 | 11 | # 2. use a type annotation of 'napari.viewer.Viewer' for any parameter |
18 | | - def __init__(self, napari_viewer): |
| 12 | + def __init__(self, napari_viewer: napari.viewer.Viewer): |
19 | 13 | super().__init__() |
20 | 14 | self.viewer = napari_viewer |
21 | 15 |
|
22 | | - btn = QPushButton("Click me!") |
23 | | - btn.clicked.connect(self._on_click) |
24 | | - |
25 | 16 | self.setLayout(QHBoxLayout()) |
26 | | - self.layout().addWidget(btn) |
27 | | - |
28 | | - def _on_click(self): |
29 | | - print("napari has", len(self.viewer.layers), "layers") |
30 | | - |
31 | | - |
32 | | -@magic_factory |
33 | | -def example_magic_widget(img_layer: "napari.layers.Image"): |
34 | | - print(f"you have selected {img_layer}") |
35 | 17 |
|
| 18 | + static_canvas = FigureCanvas(Figure(figsize=(5, 3))) |
| 19 | + axes = static_canvas.figure.subplots() |
36 | 20 |
|
37 | | -# Uses the `autogenerate: true` flag in the plugin manifest |
38 | | -# to indicate it should be wrapped as a magicgui to autogenerate |
39 | | -# a widget. |
40 | | -def example_function_widget(img_layer: "napari.layers.Image"): |
41 | | - print(f"you have selected {img_layer}") |
| 21 | + self.layout().addWidget(static_canvas) |
0 commit comments