diff --git a/docs/developers/contributing.md b/docs/developers/contributing.md index d2658f96..600f9ec9 100644 --- a/docs/developers/contributing.md +++ b/docs/developers/contributing.md @@ -112,6 +112,63 @@ Now you are all set to start developing with napari. If you wish to contribute documentation changes to napari, please read the [guide on contributing documentation](documentation/index.md). +(add-examples)= +## Adding examples to the [Gallery](gallery) + +All of the examples in the [examples Gallery](gallery) are Python scripts that +live under [the `examples` folder of the napari repository](https://github.com/napari/napari/tree/main/examples). +Because of how this gallery is built, every such Python script needs a docstring +containing at least a title (following the `.rst` format of docstrings in +Python) and one or more _tags_. This ensures the example will be shown in the +correct place in the table of contents for the gallery (see, for example, the +[](tagoverview) page.) + +Here's an example of what that means. The example file +[add_image.py](https://github.com/napari/napari/blob/main/examples/add_image.py) +contains the following: + +```python +""" +Add image +========= + +Display one image using the :func:`view_image` API. + +.. tags:: visualization-basic +""" + +from skimage import data +import napari + +# create the viewer with an image +viewer = napari.view_image(data.astronaut(), rgb=True) + +if __name__ == '__main__': + napari.run() +``` + +The equals signs under "Add image" mark this as the example title. The text +below is a short description of the example, and the tags are assigned by the +use of the `.. tags::` directive. In this case, the only tag associated with +this example is `visualization-basic`. Multiple tags can be separated with a +comma. + +Note that the examples are `.py` source files, and any outputs and images will +be autogenerated when the documentation site is built. + +````{note} +If you are running any of these examples in an interactive environment (e.g. a Jupyter notebook or +IPython console), the block + +``` +if __name__ == '__main__': + napari.run() +``` + +is not necessary—you can copy-paste the code above it. However, it is required when running examples as scripts, using for example `python add_image.py`. +Because our example gallery is built from Python scripts, you need to ensure this +block is present in all contributed examples. +```` ## Adding icons If you want to add a new icon to the app, make the icon in whatever program you diff --git a/docs/developers/documentation/index.md b/docs/developers/documentation/index.md index ebe82a6e..bcf57c9a 100644 --- a/docs/developers/documentation/index.md +++ b/docs/developers/documentation/index.md @@ -11,7 +11,8 @@ The napari documentation is built from sources located at the repository is where all the narrative documentation (e.g. tutorials, how-to guides) pull requests should be made. Meanwhile, changes to docstrings or to the [examples gallery](https://napari.org/gallery) should be made to the -[napari/napari](https://github.com/napari/napari) repository. +[napari/napari](https://github.com/napari/napari) repository (see also +[](add-examples)). ## Prerequisites diff --git a/docs/gallery.md b/docs/gallery.md index fa0b1fef..e3d857c9 100644 --- a/docs/gallery.md +++ b/docs/gallery.md @@ -3,6 +3,12 @@ Examples of napari usage. +```{note} + +If you want to submit a new example to this gallery, check out our +[contribution guide](add-examples)! +``` + ```{toctree} :maxdepth: 1