diff --git a/src/napari_micromanager/_gui_objects/_toolbar.py b/src/napari_micromanager/_gui_objects/_toolbar.py index 3270cb00..debf4a28 100644 --- a/src/napari_micromanager/_gui_objects/_toolbar.py +++ b/src/napari_micromanager/_gui_objects/_toolbar.py @@ -211,6 +211,7 @@ def _show_dock_widget(self, key: str = "") -> None: wdg = ScrollableWidget(self, title=key, widget=wdg) dock_wdg = self._add_dock_widget(wdg, key, floating=floating, tabify=tabify) self._connect_dock_widget(dock_wdg) + dock_wdg.destroyed.connect(self._disconnect_dock_widget) self._dock_widgets[key] = dock_wdg def _add_dock_widget( @@ -239,6 +240,13 @@ def _connect_dock_widget(self, dock_wdg: QDockWidget) -> None: dock_wdg.topLevelChanged.connect(self._save_layout) dock_wdg.dockLocationChanged.connect(self._save_layout) + def _disconnect_dock_widget(self) -> None: + """Disconnect the dock widget from the main window.""" + dock_wdg = cast(QDockWidget, self.sender()) + dock_wdg.visibilityChanged.disconnect(self._save_layout) + dock_wdg.topLevelChanged.disconnect(self._save_layout) + dock_wdg.dockLocationChanged.disconnect(self._save_layout) + def _on_dock_widget_changed(self) -> None: """Start a saving threrad to save the layout if the thread is not running."""