Use app model for plugins menu#4991
Conversation
for more information, see https://pre-commit.ci
|
This is ready for review, again I hope I got the action callbacks correct. |
| @@ -33,18 +31,6 @@ def __init__(self, window: 'Window'): | |||
| self._build() | |||
|
|
|||
| def _build(self, event=None): | |||
There was a problem hiding this comment.
I've kept the _build method as it is used here:
napari/napari/plugins/_npe2.py
Lines 311 to 317 in beaa98e
but not sure what the comment means with regard to how _build should change. Related: https://github.com/napari/napari/pull/4865/files#r972649032
There was a problem hiding this comment.
I see a few plugin widget tests are failing but I kept the _add_registered_widget fun - any ideas @DragaDoncila ?
There was a problem hiding this comment.
but not sure what the comment means with regard to how _build should change.
So, I think this is saying that once we build the plugin menu with app_model, it should update itself when plugins are enabled/disabled, so we shouldn't need to update them here. We should then also be adding the plugin menu actions & actions created from plugin widgets in register_manifest_actions...?
There was a problem hiding this comment.
I see a few plugin widget tests are failing but I kept the _add_registered_widget fun - any ideas @DragaDoncila ?
Yeah this is just a testing quirk but, now that we're not adding the Install/Uninstall Plugins and Plugin Errors buttons via this menu, there's no separator anymore so these few lines of code clear your action list (and are reproduced in all the failing tests lol). I feel like we don't even need to filter the actions, since we're just checking whether a given widget name is in there?
There was a problem hiding this comment.
We should then also be adding the plugin menu actions & actions created from plugin widgets in register_manifest_actions...?
Thanks for explaining. To clarify I can make this change in this PR (since we are moving plugins menu to use app-model)?
Also any thoughts on: https://github.com/napari/napari/pull/4865/files#r972649032
There was a problem hiding this comment.
I feel like we don't even need to filter the actions, since we're just checking whether a given widget name is in there
Agreed. I will update the test.
|
Click here to download the docs artifacts |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4991 +/- ##
==========================================
- Coverage 92.36% 92.29% -0.08%
==========================================
Files 605 611 +6
Lines 54469 54683 +214
==========================================
+ Hits 50312 50470 +158
- Misses 4157 4213 +56 ☔ View full report in Codecov by Sentry. |
|
Click here to download the docs artifacts |
DragaDoncila
left a comment
There was a problem hiding this comment.
I've left a few comments. Looking good in general, but when I pull the code down the Plugin menu doesn't get populated and I get a TypeError when trying to open the Install/Uninstall Plugins... dialog:
TypeError Traceback (most recent call last)
File /opt/miniconda3/envs/napari-edit/lib/python3.10/site-packages/in_n_out/_store.py:774, in Store.inject.<locals>._inner.<locals>._exec(*args=(), **kwargs={})
773 try:
--> 774 result = func(**_kwargs)
_kwargs = {}
func = <function _show_plugin_install_dialog at 0x7f7bc1e01ea0>
775 except TypeError as e:
776 # likely a required argument is still missing.
777 # show what was injected and raise
TypeError: _show_plugin_install_dialog() missing 1 required positional argument: 'window'| @@ -33,18 +31,6 @@ def __init__(self, window: 'Window'): | |||
| self._build() | |||
|
|
|||
| def _build(self, event=None): | |||
There was a problem hiding this comment.
but not sure what the comment means with regard to how _build should change.
So, I think this is saying that once we build the plugin menu with app_model, it should update itself when plugins are enabled/disabled, so we shouldn't need to update them here. We should then also be adding the plugin menu actions & actions created from plugin widgets in register_manifest_actions...?
| @@ -33,18 +31,6 @@ def __init__(self, window: 'Window'): | |||
| self._build() | |||
|
|
|||
| def _build(self, event=None): | |||
There was a problem hiding this comment.
I see a few plugin widget tests are failing but I kept the _add_registered_widget fun - any ideas @DragaDoncila ?
Yeah this is just a testing quirk but, now that we're not adding the Install/Uninstall Plugins and Plugin Errors buttons via this menu, there's no separator anymore so these few lines of code clear your action list (and are reproduced in all the failing tests lol). I feel like we don't even need to filter the actions, since we're just checking whether a given widget name is in there?
it looks like a problem with the injection process. |
|
Click here to download the docs artifacts |
|
Full traceback just for my reference: |
|
@Czaki I think I've addressed everything, just one more item waiting for your response: #4991 (comment) |
| # Check that widget removed from `_dock_widgets` dict when closed | ||
| widget.destroyOnClose() | ||
| assert 'test' not in viewer.window._dock_widgets | ||
| assert ww.parent is None |
There was a problem hiding this comment.
So in the original test this was adapted from, there was more widget clean up steps:
napari/napari/_qt/_tests/test_plugin_widgets.py
Lines 149 to 155 in 27851ee
are these needed?
Czaki
left a comment
There was a problem hiding this comment.
Based on Your promise of followup PR I think that this is ready for merge.
# References and relevant issues Follows on from #4991 # Description * Use `partial` for the npe1 sample menu build * Fix the looping, we should have one list of submenus and actions, which gets added at the end of all looping (I've tested in env with 2 npe1 plugins). This also allows us to add all actions and submenus to the `unregister` list, so actions are correct when plugin status is changed.
# References and relevant issues Follow on from #4991 see: #4991 (comment) # Description Better naming in `test_widget_hide_destroy` Adds more widget clean up steps. The tests passes fine currently but Draga suggested it was best to add these back.
# References and relevant issues Follow on from #4991 # Description Removes lambdas when updating from context during `add_menu` `_qt_main_window.py`. Each menu function just gets layerlist and does not use a helper function anymore. Prevents any use of strings now. Not 100% this is better. There is a lot of repetition but there was previously as well. Open to change.
Description
Migrate plugins menubar and widget creation to app-model. Notable changes:
_provide_viewerto usePublicOnlyProxy_add_plugin_dock_widgetprocessor, which adds the dock widget to the qt main window, to run on the output of widget callbacks._npe2.pyto underqtin_qnpe2.py. Allow importing from_qnpe2.pyin_npe2.py, see: Use app model for plugins menu #4991 (comment) for more detailsadd_plugin_dock_widgetand_add_plugin_function_widgettests as these functions are slated for removal