feat(dock_area): add restore user profile from default functionality with optional confirmation dialog

This commit is contained in:
2026-04-24 17:07:21 +02:00
parent 3f1aa80756
commit d94e32782a
3 changed files with 71 additions and 12 deletions
+28
View File
@@ -369,6 +369,20 @@ class BECDockArea(RPCBase):
name (str | None): The name of the profile to load. If None, prompts the user.
"""
@rpc_timeout(None)
@rpc_call
def restore_user_profile_from_default(
self, name: "str | None" = None, show_dialog: "bool" = True
):
"""
Overwrite the user copy of *name* with the default baseline.
If *name* is None, target the currently active profile.
Args:
name (str | None): Profile to restore. If None, uses the current profile.
show_dialog (bool): If True, ask for confirmation before restoring.
"""
@rpc_call
def delete_profile(self, name: "str | None" = None, show_dialog: "bool" = False) -> "bool":
"""
@@ -1377,6 +1391,20 @@ class DockAreaView(RPCBase):
name (str | None): The name of the profile to load. If None, prompts the user.
"""
@rpc_timeout(None)
@rpc_call
def restore_user_profile_from_default(
self, name: "str | None" = None, show_dialog: "bool" = True
):
"""
Overwrite the user copy of *name* with the default baseline.
If *name* is None, target the currently active profile.
Args:
name (str | None): Profile to restore. If None, uses the current profile.
show_dialog (bool): If True, ask for confirmation before restoring.
"""
@rpc_call
def delete_profile(self, name: "str | None" = None, show_dialog: "bool" = False) -> "bool":
"""
@@ -108,6 +108,7 @@ class BECDockArea(DockAreaWidget):
"list_profiles",
"save_profile",
"load_profile",
"restore_user_profile_from_default",
"delete_profile",
]
@@ -893,30 +894,34 @@ class BECDockArea(DockAreaWidget):
@SafeSlot()
@SafeSlot(str)
def restore_user_profile_from_default(self, name: str | None = None):
@SafeSlot(str, bool)
@rpc_timeout(None)
def restore_user_profile_from_default(self, name: str | None = None, show_dialog: bool = True):
"""
Overwrite the user copy of *name* with the default baseline.
If *name* is None, target the currently active profile.
Args:
name (str | None): The name of the profile to restore. If None, uses the current profile.
name (str | None): Profile to restore. If None, uses the current profile.
show_dialog (bool): If True, ask for confirmation before restoring.
"""
target = name or getattr(self, "_current_profile_name", None)
if not target:
return
namespace = self.profile_namespace
current_pixmap = None
if self.isVisible():
current_pixmap = QPixmap()
ba = bytes(self.screenshot_bytes())
current_pixmap.loadFromData(ba)
if current_pixmap is None or current_pixmap.isNull():
current_pixmap = load_user_profile_screenshot(target, namespace=namespace)
default_pixmap = load_default_profile_screenshot(target, namespace=namespace)
if show_dialog:
current_pixmap = None
if self.isVisible():
current_pixmap = QPixmap()
ba = bytes(self.screenshot_bytes())
current_pixmap.loadFromData(ba)
if current_pixmap is None or current_pixmap.isNull():
current_pixmap = load_user_profile_screenshot(target, namespace=namespace)
default_pixmap = load_default_profile_screenshot(target, namespace=namespace)
if not RestoreProfileDialog.confirm(self, current_pixmap, default_pixmap):
return
if not RestoreProfileDialog.confirm(self, current_pixmap, default_pixmap):
return
restore_user_from_default(target, namespace=namespace)
self.delete_all()
+26
View File
@@ -639,6 +639,7 @@ class TestAdvancedDockAreaInit:
"workspace_is_locked",
"attach_all",
"delete_all",
"restore_user_profile_from_default",
]
for method in expected_methods:
assert method in BECDockArea.USER_ACCESS
@@ -1506,6 +1507,31 @@ class TestAdvancedDockAreaRestoreAndDialogs:
mock_restore.assert_not_called()
def test_restore_user_profile_from_default_without_dialog(self, advanced_dock_area):
profile_name = "alignment_scan"
helper = profile_helper(advanced_dock_area)
helper.open_default(profile_name).sync()
helper.open_user(profile_name).sync()
with (
patch(
"bec_widgets.widgets.containers.dock_area.dock_area.RestoreProfileDialog.confirm"
) as mock_confirm,
patch(
"bec_widgets.widgets.containers.dock_area.dock_area.restore_user_from_default"
) as mock_restore,
patch.object(advanced_dock_area, "delete_all") as mock_delete_all,
patch.object(advanced_dock_area, "load_profile") as mock_load_profile,
):
advanced_dock_area.restore_user_profile_from_default(profile_name, show_dialog=False)
mock_confirm.assert_not_called()
mock_restore.assert_called_once_with(
profile_name, namespace=advanced_dock_area.profile_namespace
)
mock_delete_all.assert_called_once()
mock_load_profile.assert_called_once_with(profile_name)
def test_restore_user_profile_from_default_no_target(self, advanced_dock_area, monkeypatch):
advanced_dock_area._current_profile_name = None
with patch(