File: magic_viewer.py

package info (click to toggle)
napari 0.6.6-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,036 kB
  • sloc: python: 112,264; xml: 72; makefile: 44; sh: 5
file content (25 lines) | stat: -rw-r--r-- 582 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""
magicgui viewer
===============

Example showing how to access the current viewer from a function widget.

.. tags:: gui
"""

import napari


# annotating a parameter as `napari.Viewer` will automatically provide
# the viewer that the function is embedded in, when the function is added to
# the viewer with add_function_widget.
def my_function(viewer: napari.Viewer):
    print(viewer, f'with {len(viewer.layers)} layers')


viewer = napari.Viewer()
# Add our magic function to napari
viewer.window.add_function_widget(my_function)

if __name__ == '__main__':
    napari.run()