Skip to content

Commit

Permalink
Move help actions under _qt and remove lambdas (napari#6883)
Browse files Browse the repository at this point in the history
# References and relevant issues
Closes napari#6744
Related:
napari#6848 (comment)

# Description
Move all help actions to `_qt/` and remove lambdas and replace with
partials.
  • Loading branch information
lucyleeow authored May 20, 2024
1 parent 9836ed1 commit 2102518
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 93 deletions.
5 changes: 1 addition & 4 deletions napari/_app_model/_app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from __future__ import annotations

from functools import lru_cache
from itertools import chain

from app_model import Application

from napari._app_model._submenus import SUBMENUS
from napari._app_model.actions._help_actions import HELP_ACTIONS
from napari._app_model.actions._layer_actions import LAYER_ACTIONS

APP_NAME = 'napari'
Expand All @@ -25,8 +23,7 @@ def __init__(self, app_name=APP_NAME) -> None:

self.injection_store.namespace = _napari_names # type: ignore [assignment]

for action in chain(HELP_ACTIONS, LAYER_ACTIONS):
self.register_action(action)
self.register_actions(LAYER_ACTIONS)

self.menus.append_menu_items(SUBMENUS)

Expand Down
88 changes: 0 additions & 88 deletions napari/_app_model/actions/_help_actions.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
import requests

from napari._app_model.actions._help_actions import HELP_URLS
from napari._qt._qapp_model.qactions._help import HELP_URLS


@pytest.mark.parametrize('url', HELP_URLS.keys())
Expand Down
71 changes: 71 additions & 0 deletions napari/_qt/_qapp_model/qactions/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
"""

import sys
from functools import partial
from webbrowser import open

from app_model.types import Action, KeyBindingRule, KeyCode, KeyMod
from packaging.version import parse

from napari import __version__
from napari._app_model.constants import MenuGroup, MenuId
from napari._qt.dialogs.qt_about import QtAbout
from napari._qt.qt_main_window import Window
Expand All @@ -23,6 +27,19 @@ def _show_about(window: Window):
QtAbout.showAbout(window._qt_window)


v = parse(__version__)
VERSION = 'dev' if v.is_devrelease else str(v)

HELP_URLS: dict[str, str] = {
'getting_started': f'https://napari.org/{VERSION}/tutorials/start_index.html',
'tutorials': f'https://napari.org/{VERSION}/tutorials/index.html',
'layers_guide': f'https://napari.org/{VERSION}/howtos/layers/index.html',
'examples_gallery': f'https://napari.org/{VERSION}/gallery.html',
'release_notes': f'https://napari.org/{VERSION}/release/release_{VERSION.replace(".", "_")}.html',
'github_issue': 'https://github.com/napari/napari/issues',
'homepage': 'https://napari.org',
}

Q_HELP_ACTIONS: list[Action] = [
Action(
id='napari.window.help.info',
Expand All @@ -45,6 +62,60 @@ def _show_about(window: Window):
],
status_tip=trans._('About napari'),
),
Action(
id='napari.window.help.getting_started',
title=trans._('Getting started'),
callback=partial(open, url=HELP_URLS['getting_started']),
menus=[{'id': MenuId.MENUBAR_HELP}],
),
Action(
id='napari.window.help.tutorials',
title=trans._('Tutorials'),
callback=partial(open, url=HELP_URLS['tutorials']),
menus=[{'id': MenuId.MENUBAR_HELP}],
),
Action(
id='napari.window.help.layers_guide',
title=trans._('Using Layers Guides'),
callback=partial(open, url=HELP_URLS['layers_guide']),
menus=[{'id': MenuId.MENUBAR_HELP}],
),
Action(
id='napari.window.help.examples',
title=trans._('Examples Gallery'),
callback=partial(open, url=HELP_URLS['examples_gallery']),
menus=[{'id': MenuId.MENUBAR_HELP}],
),
Action(
id='napari.window.help.release_notes',
title=trans._('Release Notes'),
callback=partial(open, url=HELP_URLS['release_notes']),
menus=[
{
'id': MenuId.MENUBAR_HELP,
'when': VERSION != 'dev',
'group': MenuGroup.NAVIGATION,
}
],
),
Action(
id='napari.window.help.github_issue',
title=trans._('Report an issue on GitHub'),
callback=partial(open, url=HELP_URLS['github_issue']),
menus=[
{
'id': MenuId.MENUBAR_HELP,
'when': VERSION == 'dev',
'group': MenuGroup.NAVIGATION,
}
],
),
Action(
id='napari.window.help.homepage',
title=trans._('napari homepage'),
callback=partial(open, url=HELP_URLS['homepage']),
menus=[{'id': MenuId.MENUBAR_HELP, 'group': MenuGroup.NAVIGATION}],
),
]

if ask_opt_in is not None:
Expand Down

0 comments on commit 2102518

Please sign in to comment.