From 0691d41f45796e1662238f5a861bd58ec64f02f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Pe=C3=B1a-Castellanos?= Date: Wed, 29 May 2024 13:11:24 -0500 Subject: [PATCH 1/3] Do not destroy plugin dialog on close, just hide --- napari_plugin_manager/qt_plugin_dialog.py | 25 +++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/napari_plugin_manager/qt_plugin_dialog.py b/napari_plugin_manager/qt_plugin_dialog.py index d86762a..8704b34 100644 --- a/napari_plugin_manager/qt_plugin_dialog.py +++ b/napari_plugin_manager/qt_plugin_dialog.py @@ -697,6 +697,11 @@ class RefreshState(Enum): class QtPluginDialog(QDialog): def __init__(self, parent=None) -> None: super().__init__(parent) + + self._parent = parent + if getattr(parent, '_plugin_dialog', None) is None: + self._parent._plugin_dialog = self + self.refresh_state = RefreshState.DONE self.already_installed = set() self.available_set = set() @@ -737,11 +742,23 @@ def _on_installer_done(self, exit_code): self.close_btn.setDisabled(False) self.refresh() + def exec_(self): + plugin_dialog = getattr(self._parent, '_plugin_dialog', self) + plugin_dialog.setModal(True) + plugin_dialog.show() + + if plugin_dialog != self: + self.close() + def closeEvent(self, event): - self._add_items_timer.stop() - if self.close_btn.isEnabled(): - super().closeEvent(event) - event.ignore() + plugin_dialog = getattr(self._parent, '_plugin_dialog', self) + if plugin_dialog != self: + self._add_items_timer.stop() + if self.close_btn.isEnabled(): + super().closeEvent(event) + event.ignore() + else: + plugin_dialog.hide() def refresh(self): if self.refresh_state != RefreshState.DONE: From b26c2f5f2b595de9d325ea2002937eee8ff0274a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Pe=C3=B1a-Castellanos?= Date: Wed, 29 May 2024 13:13:51 -0500 Subject: [PATCH 2/3] Add cache on plugin summaries --- napari_plugin_manager/npe2api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/napari_plugin_manager/npe2api.py b/napari_plugin_manager/npe2api.py index 24e01f9..3913ecc 100644 --- a/napari_plugin_manager/npe2api.py +++ b/napari_plugin_manager/npe2api.py @@ -66,6 +66,7 @@ class SummaryDict(_ShortSummaryDict): conda_versions: NotRequired[list[str]] +@lru_cache def plugin_summaries() -> list[SummaryDict]: """Return PackageMetadata object for all known napari plugins.""" url = 'https://npe2api.vercel.app/api/extended_summary' From e18e841a66d4d1a2c3b76b96b01768d33fac81c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Pe=C3=B1a-Castellanos?= Date: Wed, 29 May 2024 13:29:48 -0500 Subject: [PATCH 3/3] Hanlde case for no parent --- napari_plugin_manager/qt_plugin_dialog.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/napari_plugin_manager/qt_plugin_dialog.py b/napari_plugin_manager/qt_plugin_dialog.py index 8704b34..3daa902 100644 --- a/napari_plugin_manager/qt_plugin_dialog.py +++ b/napari_plugin_manager/qt_plugin_dialog.py @@ -699,7 +699,10 @@ def __init__(self, parent=None) -> None: super().__init__(parent) self._parent = parent - if getattr(parent, '_plugin_dialog', None) is None: + if ( + getattr(parent, '_plugin_dialog', None) is None + and self._parent is not None + ): self._parent._plugin_dialog = self self.refresh_state = RefreshState.DONE @@ -751,14 +754,17 @@ def exec_(self): self.close() def closeEvent(self, event): - plugin_dialog = getattr(self._parent, '_plugin_dialog', self) - if plugin_dialog != self: - self._add_items_timer.stop() - if self.close_btn.isEnabled(): - super().closeEvent(event) - event.ignore() + if self._parent is not None: + plugin_dialog = getattr(self._parent, '_plugin_dialog', self) + if plugin_dialog != self: + self._add_items_timer.stop() + if self.close_btn.isEnabled(): + super().closeEvent(event) + event.ignore() + else: + plugin_dialog.hide() else: - plugin_dialog.hide() + super().closeEvent(event) def refresh(self): if self.refresh_state != RefreshState.DONE: