Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain how to add new examples to the gallery #137

Merged
merged 5 commits into from Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 57 additions & 0 deletions docs/developers/contributing.md
Expand Up @@ -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 on a Jupyter notebook (or in the
IPython console), the block
melissawm marked this conversation as resolved.
Show resolved Hide resolved

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

is not necessary, but it is required when running the examples as scripts.
melissawm marked this conversation as resolved.
Show resolved Hide resolved
Because our example gallery is built from Python scripts, you will see this
block in all examples.
melissawm marked this conversation as resolved.
Show resolved Hide resolved
````
## Adding icons

If you want to add a new icon to the app, make the icon in whatever program you
Expand Down
3 changes: 2 additions & 1 deletion docs/developers/documentation/index.md
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions docs/gallery.md
Expand Up @@ -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

Expand Down