-
-
Notifications
You must be signed in to change notification settings - Fork 491
use app-model for file menu #4865
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
Merged
Merged
Changes from all commits
Commits
Show all changes
174 commits
Select commit
Hold shift + click to select a range
7a7f14c
feat: use app-model WIP
tlambert03 8241dc2
partially fixed circ imports
tlambert03 6fec004
bring back some menus with lazy import
tlambert03 00ca1a6
wip
tlambert03 7073aa3
incorporate changes from app-model and ino
tlambert03 2c12cb7
remove old code
tlambert03 6e93b9b
remove more
tlambert03 197268a
add app-model dep
tlambert03 29d7e1b
remove module from typecheck
tlambert03 d81a277
Merge branch 'main' into use-app-model
tlambert03 9e42378
small changes
tlambert03 eb0958c
Merge branch 'main' into use-app-model
tlambert03 6ee215b
Merge branch 'main' into use-app-model
tlambert03 cd41480
remove not gc.collect assertion
tlambert03 adf237f
reduce test code
tlambert03 3f8978c
add comments about context objects
tlambert03 27a495f
add in-n-out to deps
tlambert03 168e890
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b0c742e
fix test
tlambert03 5832656
Merge branch 'use-app-model' of https://github.com/tlambert03/napari …
tlambert03 0cbad81
bump in-n-out min ver
tlambert03 86ab609
Merge branch 'main' into use-app-model
tlambert03 8a6bd5b
refactor: add constants module, add test for menu building
tlambert03 34fb5cb
add __all__ to constants
tlambert03 94aa8fd
add some tests
tlambert03 26b54ce
add more comments
tlambert03 543e411
bump app-model
tlambert03 dca809f
add internal documentation
tlambert03 dc5cd29
add motivations and vision
tlambert03 f496c4c
bump version, raise synchronous errors
tlambert03 9bee5d6
Merge branch 'main' into use-app-model
tlambert03 3f94e6f
Merge branch 'main' into use-app-model
tlambert03 c344b99
Merge branch 'main' into use-app-model
tlambert03 4020d12
comment navigation global
tlambert03 022c353
Merge branch 'main' into use-app-model
tlambert03 64e578f
lenient test
tlambert03 dedae8c
Update docs/guides/app_model.md
tlambert03 ee62f69
Update napari/_app/actions/_layer_actions.py
tlambert03 b144796
Update napari/_qt/widgets/_tests/test_qt_extension2reader.py
tlambert03 a7aa93c
Merge branch 'main' into use-app-model
tlambert03 e4e0541
rename module
tlambert03 941a55c
use get_app getter
tlambert03 6b712f1
bump appmodel
tlambert03 846bb01
fix comment
tlambert03 300aa7d
add comment
tlambert03 d891e7f
move layer actions constants
tlambert03 d3b0f9c
clarify expression
tlambert03 2f46b67
update docs
tlambert03 4346ce6
add tests
tlambert03 886dcf0
Merge branch 'main' into use-app-model
tlambert03 c98e847
stub out file actions
tlambert03 96bfbb2
wip
tlambert03 951bb07
mostly working file menu
tlambert03 7a78461
fix token
tlambert03 08cf2fd
Merge branch 'main' into use-app-model
tlambert03 9845504
update docs
tlambert03 8acf813
add comment to layer actions
tlambert03 2bd8231
add comment to named tuple
tlambert03 242f63c
more comments for nathan
tlambert03 9e3e248
add comment
tlambert03 83a36b0
Merge branch 'use-app-model' into appmodel-file-menu
tlambert03 69596c6
Merge branch 'main' into appmodel-file-menu
tlambert03 d2b7f9d
Merge branch 'main' into appmodel-file-menu
tlambert03 2182101
add shortcut
lucyleeow 3399e95
use Q_FILE_ACTIONS
lucyleeow 3eb254f
merge main
lucyleeow 0c01046
update rebuild_samples_menu to build app-model actions
lucyleeow 5decbc2
build samples menu in npe2
lucyleeow 2baafb9
remove comment
lucyleeow 285f1da
add comment
lucyleeow a0afb62
amend comment
lucyleeow 4b08472
merge main
lucyleeow 4a334dd
fix mypy error
lucyleeow 272b201
separate npe1 and npe2 sample menu building
lucyleeow 97d52ff
remove args in add_sample
lucyleeow 92c7863
wip action id
lucyleeow 22de88c
add _get_sample_data_id
lucyleeow b4a2c98
try fix mypy action id
lucyleeow ff0b917
fix mypy in manifest to actions
lucyleeow 6a68aee
merge main
lucyleeow 6d7c3c3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ad748ba
use display name as per 5366
lucyleeow 365797b
move show_shortcuts
lucyleeow 0916ca9
update pref keybinding
lucyleeow c467ca1
Merge branch 'main' into appmodel-file-menu
lucyleeow 6510c8d
move open with plugin, add window to commands
lucyleeow f306858
use display name for npe2 samples
lucyleeow 671f103
use menugroup
lucyleeow 549deb8
fix enablement
lucyleeow c1678bc
fix when bundle
lucyleeow 5eb3be8
fix typo command id
lucyleeow 183927c
rm file_menu.py
lucyleeow 0f0dc07
Merge branch 'main' into appmodel-file-menu
lucyleeow 2316b45
first attempt - working layerlist context
lucyleeow 2ae7e2e
clean up adding layer context
lucyleeow d58d193
add save selected layers
lucyleeow 09682cf
use ctrl alt s for save all layers
lucyleeow b3b0b55
clean up
lucyleeow b560920
fix save selected layers
lucyleeow a299f75
Merge branch 'main' into appmodel-file-menu
lucyleeow 6e9cfe5
dont use running_as_bundled_app
lucyleeow 45f3498
Merge branch 'main' into appmodel-file-menu
lucyleeow 5ef5da0
connect npe2 samples menu to plugin deactivate, fix npe1 samples menu
lucyleeow ad79b46
remove old NapariMenu file menu in window teardown
lucyleeow 95fa95e
typos
lucyleeow 99f32c1
amend variable names
lucyleeow 8202572
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b7e87f8
fix display name use;
lucyleeow 8a0b559
add npe2 sample menu test
lucyleeow 2dbbe2b
fix typing
lucyleeow 2525e2c
Merge branch 'main' into appmodel-file-menu
lucyleeow 02603e4
use register_actions
lucyleeow a8c41cd
ammend return types
lucyleeow af824b1
format, update comment
lucyleeow 23ac6c5
fix typo conftest
lucyleeow dd70d27
carry through _open_preferences_dialog name/location change
lucyleeow b3061f6
update _pref_dialog location in test
lucyleeow bf0ca5f
update multi sample test after sample menu changes
lucyleeow b5c1f05
typo
lucyleeow 1e8c5e0
update comment
lucyleeow b3c2bd9
update read test, use handle_gui_reading
lucyleeow 33a1913
add test for sample menu
lucyleeow 440b5ad
remove sample menu test from test_smaple_data
lucyleeow 77f66b3
clear cache in fixture, fix test menus
lucyleeow 8e4856d
Merge branch 'main' into appmodel-file-menu
lucyleeow 5a7a02c
try moving qt import in npe2
lucyleeow 4671be6
update note in mock app fixture
lucyleeow b6acf9a
clear cache in note in mock app fixture
lucyleeow 31f04e3
amend wording in mock app
lucyleeow 5a28f14
[skip ci] try skip
lucyleeow 2aee0a3
empty trigger ci
lucyleeow 603bfe4
improve manifest to actions
lucyleeow 44d29d8
fix handle_gui_reading
lucyleeow 5477835
use getatttr
lucyleeow 42d519b
Merge branch 'main' into appmodel-file-menu
lucyleeow aec9ac3
use new close/quit from 4820
lucyleeow 1c16bd6
revert getattr as attr can be None
lucyleeow fdc1fcb
type checking
lucyleeow 43ccced
type checking
lucyleeow c615592
amend mf iterating in npe2
lucyleeow 64bae52
add update enabled test
lucyleeow c1878e1
comment
lucyleeow c02f576
review
lucyleeow 9fdec0e
try remove lambda in update enabled
lucyleeow 0a8ba18
revert update enabled
lucyleeow 1935ddd
test save actions updated
lucyleeow 5b3b8c3
amend fun name to _update_menu_state
lucyleeow b827a44
carry through fun name change to _update_menu_state
lucyleeow 5c6b30e
add test for _update_menu_state
lucyleeow 5ad66b4
add disconnect
lucyleeow 2457634
revert disconnect
lucyleeow 91a4038
empty CI
lucyleeow a307cdc
merge main
lucyleeow f87b8b0
amend new test_open_sample_data_shows_all_readers test for app model
lucyleeow 23ceb41
use qt viewer provider
lucyleeow a7a67f4
Merge branch 'main' into appmodel-file-menu
lucyleeow 172f1ea
Merge branch 'main' into appmodel-file-menu
lucyleeow 1c990cc
try fix qt viewer leak, destroy action
lucyleeow 81bcde2
check clear instances
lucyleeow 150df7f
try action destroy
lucyleeow f695e7a
just clear qtviewer
lucyleeow 6bfacc8
try fix viewer leak: setdata None
lucyleeow 1b6dc8b
check test sample
lucyleeow 4687549
revert clear qtviewer
lucyleeow 9d0cb1a
Merge branch 'main' into appmodel-file-menu
lucyleeow df3139c
fix test
lucyleeow 19967ef
make test more unit
lucyleeow 984433a
Merge branch 'main' into appmodel-file-menu
lucyleeow 6d70692
review
lucyleeow 188dd6c
mv test file
lucyleeow e6cf923
merge main
lucyleeow d453507
Merge branch 'main' into appmodel-file-menu
lucyleeow 33ab757
move back test_file_menu
lucyleeow 729b2c9
Merge branch 'main' into appmodel-file-menu
DragaDoncila File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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} | ||
| ): | ||
|
Comment on lines
-18
to
-20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Injection not needed because we register providers in |
||
| 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() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.