Skip to content

Commit

Permalink
Merge branch 'main' into kb-impl
Browse files Browse the repository at this point in the history
* main: (26 commits)
  Fix some typing in napari.components (napari#6203)
  Use class name for object that does not have qt name (napari#6222)
  test: [Automatic] Constraints upgrades: `hypothesis`, `magicgui`, `psygnal`, `tensorstore`, `tifffile`, `tqdm`, `virtualenv` (napari#6143)
  Replace more np.all( ... = ...) with np.array_equal (napari#6213)
  remove np.all(... == ...) in test_surface.py (napari#6218)
  Ensure pandas Series is initialized with a list as data (napari#6226)
  Stop using temporary directory for store array for paint test (napari#6191)
  Bugfix: ensure thumbnail represents canvas when multiscale (napari#6200)
  cleanup np.all(... == ...) from test_points.py (napari#6217)
  [pre-commit.ci] pre-commit autoupdate (napari#6221)
  use app-model for file menu (napari#4865)
  Add tests to cover slicing behavior when changing layers and data (napari#4819)
  [pre-commit.ci] pre-commit autoupdate (napari#6128)
  Add test coverage for async slicing of labels (napari#5325)
  Add collision check when set colors for labels layer (napari#6193)
  Update "toggle ndview" text (napari#6192)
  Prevent layer controls buttons changing layout while taking screenshots with flash effect on (napari#6194)
  Fix typing in napari.utils.perf (napari#6132)
  Add GUI test coverage for changes to Labels.show_selected_label (napari#5372)
  Fix types in 'napari.utils.colormaps.categorical_colormap' (napari#6154)
  ...
  • Loading branch information
kne42 committed Sep 19, 2023
2 parents b184d5d + 7099b18 commit a26d848
Show file tree
Hide file tree
Showing 81 changed files with 2,111 additions and 1,372 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test_pull_requests.yml
Expand Up @@ -165,6 +165,7 @@ jobs:
test_pip_install:
name: ubuntu-latest 3.9 pip install
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -196,6 +197,7 @@ jobs:
test_examples:
name: test examples
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/upgrade_test_constraints.yml
Expand Up @@ -9,6 +9,10 @@ on:
issue_comment:
types: [ created ]

pull_request:
paths:
- '.github/workflows/upgrade_test_constraints.yml'

concurrency:
group: test-${{ github.ref }}
cancel-in-progress: true
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
@@ -1,21 +1,21 @@
repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.7.0
rev: 23.9.1
hooks:
- id: black
pass_filenames: true
exclude: _vendor|vendored|examples
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.281
rev: v0.0.288
hooks:
- id: ruff
exclude: _vendor|vendored
- repo: https://github.com/seddonym/import-linter
rev: v1.10.0
rev: v1.11.1
hooks:
- id: import-linter
stages: [manual]
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.23.3
rev: 0.26.3
hooks:
- id: check-github-workflows
2 changes: 1 addition & 1 deletion examples/dev/slicing/janelia_s3_n5_multiscale.py
Expand Up @@ -18,7 +18,7 @@

# s0 (highest resolution) through s5 (lowest resolution) are available
data = []
for i in range(0, 5):
for i in range(5):
zarr_array = group[f'em/fibsem-uint16/s{i}']
data.append(da.from_zarr(zarr_array, chunks=zarr_array.chunks))

Expand Down
18 changes: 18 additions & 0 deletions napari/_app_model/_submenus.py
Expand Up @@ -25,6 +25,24 @@
enablement=LLSCK.active_layer_is_image_3d,
),
),
(
MenuId.MENUBAR_FILE,
SubmenuItem(
submenu=MenuId.FILE_OPEN_WITH_PLUGIN,
title=trans._('Open with Plugin'),
group=MenuGroup.NAVIGATION,
order=99,
),
),
(
MenuId.MENUBAR_FILE,
SubmenuItem(
submenu=MenuId.FILE_SAMPLES,
title=trans._('Open Sample'),
group=MenuGroup.NAVIGATION,
order=100,
),
),
(
MenuId.MENUBAR_VIEW,
SubmenuItem(submenu=MenuId.VIEW_AXES, title=trans._('Axes')),
Expand Down
30 changes: 19 additions & 11 deletions napari/_app_model/actions/_view_actions.py
Expand Up @@ -10,7 +10,7 @@
from app_model.types import Action, ToggleRule

from napari._app_model.actions._toggle_action import ViewerToggleAction
from napari.constants import CommandId, MenuId
from napari.constants import CommandId, MenuGroup, MenuId
from napari.settings import get_settings

VIEW_ACTIONS: List[Action] = []
Expand Down Expand Up @@ -46,14 +46,22 @@ def _get_current_tooltip_visibility():
return get_settings().appearance.layer_tooltip_visibility


VIEW_ACTIONS.append(
# TODO: this could be made into a toggle setting Action subclass
# using a similar pattern to the above ViewerToggleAction classes
Action(
id=CommandId.TOGGLE_LAYER_TOOLTIPS,
title=CommandId.TOGGLE_LAYER_TOOLTIPS.title,
menus=[{'id': MenuId.MENUBAR_VIEW, 'group': '1_render', 'order': 10}],
callback=_tooltip_visibility_toggle,
toggled=ToggleRule(get_current=_get_current_tooltip_visibility),
),
VIEW_ACTIONS.extend(
[
# TODO: this could be made into a toggle setting Action subclass
# using a similar pattern to the above ViewerToggleAction classes
Action(
id=CommandId.TOGGLE_LAYER_TOOLTIPS,
title=CommandId.TOGGLE_LAYER_TOOLTIPS.title,
menus=[
{
'id': MenuId.MENUBAR_VIEW,
'group': MenuGroup.RENDER,
'order': 10,
}
],
callback=_tooltip_visibility_toggle,
toggled=ToggleRule(get_current=_get_current_tooltip_visibility),
),
]
)
75 changes: 56 additions & 19 deletions napari/_qt/_qapp_model/_tests/test_qapp_model_menus.py
@@ -1,28 +1,65 @@
from unittest.mock import MagicMock

import numpy as np
import pytest
from app_model.types import Action

from napari import viewer
from napari._app_model import constants, get_app
from napari._app_model import get_app
from napari._app_model.constants import MenuId
from napari._app_model.context import LayerListContextKeys as LLCK
from napari._qt._qapp_model import build_qmodel_menu
from napari._qt._qapp_model.qactions import init_qactions
from napari._qt.qt_main_window import Window
from napari.layers import Image


@pytest.mark.parametrize('menu_id', list(constants.MenuId))
def test_build_qmodel_menu(qtbot, menu_id):
"""Test that we can build qmenus for all registered menu IDs"""
# `builtins` required so there are samples registered, so samples menu exists
@pytest.mark.parametrize('menu_id', list(MenuId))
def test_build_qmodel_menu(builtins, make_napari_viewer, qtbot, menu_id):
"""Test that we can build qmenus for all registered menu IDs."""
app = get_app()

mock = MagicMock()
with app.injection_store.register(
providers={viewer.Viewer: lambda: mock, Window: lambda: mock}
):
init_qactions.cache_clear()
init_qactions()
# Configures `app`, registers actions and initializes plugins
make_napari_viewer()

menu = build_qmodel_menu(menu_id)
qtbot.addWidget(menu)

# `>=` because separator bars count as actions
assert len(menu.actions()) >= len(app.menus.get_menu(menu_id))


def test_update_menu_state_context(make_napari_viewer):
"""Test `_update_menu_state` correctly updates enabled/visible state."""
app = get_app()
viewer = make_napari_viewer()

action = Action(
id='dummy_id',
title='dummy title',
callback=lambda: None,
menus=[{'id': MenuId.MENUBAR_FILE, 'when': (LLCK.num_layers > 0)}],
enablement=(LLCK.num_layers == 2),
)
app.register_action(action)

dummy_action = viewer.window.file_menu.findAction('dummy_id')

assert 'dummy_id' in app.commands
assert len(viewer.layers) == 0
# `dummy_action` should be disabled & not visible as num layers == 0
viewer.window._update_menu_state('file_menu')
assert not dummy_action.isVisible()
assert not dummy_action.isEnabled()

menu = build_qmodel_menu(menu_id)
qtbot.addWidget(menu)
layer_a = Image(np.random.random((10, 10)))
viewer.layers.append(layer_a)
assert len(viewer.layers) == 1
viewer.window._update_menu_state('file_menu')
# `dummy_action` should be visible but not enabled after adding layer
assert dummy_action.isVisible()
assert not dummy_action.isEnabled()

# `>=` because separator bars count as actions
assert len(menu.actions()) >= len(app.menus.get_menu(menu_id))
layer_b = Image(np.random.random((10, 10)))
viewer.layers.append(layer_b)
assert len(viewer.layers) == 2
# `dummy_action` should be enabled and visible after adding second layer
viewer.window._update_menu_state('file_menu')
assert dummy_action.isVisible()
assert dummy_action.isEnabled()
4 changes: 2 additions & 2 deletions napari/_qt/_qapp_model/qactions/__init__.py
Expand Up @@ -23,6 +23,7 @@ def init_qactions() -> None:
"""

from napari._app_model import get_app
from napari._qt._qapp_model.qactions._file import Q_FILE_ACTIONS
from napari._qt._qapp_model.qactions._help import Q_HELP_ACTIONS
from napari._qt._qapp_model.qactions._view import Q_VIEW_ACTIONS
from napari._qt.qt_main_window import Window, _QtMainWindow
Expand Down Expand Up @@ -51,5 +52,4 @@ def _provide_qt_viewer() -> Optional[QtViewer]:
return None

# register actions
for action in chain(Q_VIEW_ACTIONS, Q_HELP_ACTIONS):
app.register_action(action)
app.register_actions(chain(Q_FILE_ACTIONS, Q_HELP_ACTIONS, Q_VIEW_ACTIONS))

0 comments on commit a26d848

Please sign in to comment.