Skip to main content

Attaches a customizable Tools menu to napari

Project description

napari-tools-menu

License PyPI Python Version tests codecov

Attaches a customizable Tools menu to napari

img.png

Usage

Just add napari-tools-menu to the dependencies of your napari-plugin. Afterwards, you can annotate your functions and dock widgets using the following syntax. The specified menu path will be used to put your tool in the right place in the tools menu. All menus and sub-menus will be listed alphabetically.

from napari_tools_menu import register_function, register_action, register_dock_widget


@register_action(menu="Utilities > Action")
def test_function(viewer):
    print("hello")


@register_function(menu="Utilities > Function")
def test_function_with_params(sigma: float = 0.5):
    print("sigma", sigma)


@register_dock_widget(menu="Utilities > Widget")
class ExampleQWidget(QWidget):
    def __init__(self, napari_viewer):

The register_function and register_dock_widget annotations are made for analysis functions and graphical user interfaces as explained in the napari-plugin tutorial. The register_action annotation is made for functions with a single parameter: the napari viewer. This function is executed when the user clicks the menu. This might for example be useful for applying a certain operation to all currently selected layers.

Note: This implementation is based on a monkey patch of napari, tested with napari 0.4.11. Thus, it might stop working with a future version of napari, e.g. when the new plugin engine is finished. For now it is a nice workaround to ease the life of end-users.

Menu name suggestions

To keep the Tools menu clean and organized, some suggestions should be made. Create category menus that classify your tool in a way such that a broad audience knows what it's doing. Examples:

  • Filtering / noise removal
  • Filtering / background removal
  • Filtering / edge enhancement
  • Filtering / deconvolution
  • Image math
  • Registration
  • Segmentation / binarization
  • Segmentation / labeling
  • Segmentation post-processing
  • Measurement
  • Visualization
  • Utilities

Put a descriptive function name in the menu name first and the implementation behind. Examples:

  • Segmentation / Binarization > Threshold (Otsu et al 1979)
  • Segmentation / Binarization > Threshold (my algorithm)
  • Segmentation / Labeling > Cell labeling (CellLab)
  • Segmentation / Labeling > Nuclei segmentation (Nuc-Seg)

Example code:

@register_action(menu="Segmentation > Threshold (Otsu et al 1979)")
def threshold_otsu(viewer):
    pass
@register_action(menu="Segmentation > Threshold (my algorithm)")
def my_algorithm(viewer):
    pass
@register_action(menu="Segmentation > Cell labeling (CellLab)")
def celllab(viewer):
    pass
@register_action(menu="Segmentation > Nuclei segmentation (Nuc-Dect)")
def nucl_dect(viewer):
    pass

The menu would then look like this: img.png

Again, there are no constraints. However, please make the life of (y)our users easy by keeping this menu well organized.

Installation

You can install napari-tools-menu via pip:

pip install napari-tools-menu

Contributing

Contributions are very welcome. Tests can be run with [pytest], please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the BSD-3 license, "napari-tools-menu" is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

napari-tools-menu-0.1.15.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

napari_tools_menu-0.1.15-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file napari-tools-menu-0.1.15.tar.gz.

File metadata

  • Download URL: napari-tools-menu-0.1.15.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/29.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.6.4 keyring/23.0.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.12

File hashes

Hashes for napari-tools-menu-0.1.15.tar.gz
Algorithm Hash digest
SHA256 cfd4111ef399f20f6f0b6736187fa69df523d0f6571d7c57b57f3e495fd615c7
MD5 17c26df270e78f49a5c3752cedecb504
BLAKE2b-256 5d5fc50683ab59025f8767c3c38a8632ed644b05fa8f6aff88febf609c63fad1

See more details on using hashes here.

File details

Details for the file napari_tools_menu-0.1.15-py3-none-any.whl.

File metadata

  • Download URL: napari_tools_menu-0.1.15-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/29.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.6.4 keyring/23.0.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.12

File hashes

Hashes for napari_tools_menu-0.1.15-py3-none-any.whl
Algorithm Hash digest
SHA256 705c0db19d6bde35aaaa03687e7ca6cf700cbbfb5daecdac6155fd97e63e861b
MD5 b155375da6bd1d00d113a588ca520c22
BLAKE2b-256 d082fff5d61ebbcc49a0ee66b00a7e2518c0f0eecc698ce0e4c1bb37d17084e9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page