Skip to content
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

PR: Change icon and text of 'Lock Interface Action' when clicked #12527

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,11 @@ def setup(self):
"Close pane")
self.lock_interface_action = create_action(
self,
_("Lock panes and toolbars"),
toggled=self.toggle_lock,
(_("Unlock panes and toolbars") if self.interface_locked else
_("Lock panes and toolbars")),
icon=ima.icon('lock' if self.interface_locked else 'lock_open'),
triggered=lambda checked:
self.toggle_lock(not self.interface_locked),
context=Qt.ApplicationShortcut)
self.register_shortcut(self.lock_interface_action, "_",
"Lock unlock panes")
Expand Down Expand Up @@ -1332,7 +1335,7 @@ def post_visible_setup(self):
self.load_last_visible_toolbars()

# Update lock status
self.lock_interface_action.setChecked(self.interface_locked)
self.toggle_lock(self.interface_locked)

# Hide Internal Console so that people don't use it instead of
# the External or IPython ones
Expand Down Expand Up @@ -2524,6 +2527,11 @@ def toggle_lock(self, value):
"""Lock/Unlock dockwidgets and toolbars"""
self.interface_locked = value
CONF.set('main', 'panes_locked', value)
self.lock_interface_action.setIcon(
ima.icon('lock' if self.interface_locked else 'lock_open'))
self.lock_interface_action.setText(
_("Unlock panes and toolbars") if self.interface_locked else
_("Lock panes and toolbars"))

# Apply lock to panes
for plugin in (self.widgetlist + self.thirdparty_plugins):
Expand Down
12 changes: 7 additions & 5 deletions spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ def test_lock_action(main_window):
action = main_window.lock_interface_action
plugins = main_window.widgetlist

# By default the action is checked
assert action.isChecked()
# By default the interface is locked.
assert main_window.interface_locked

# In this state the title bar is an empty QWidget
for plugin in plugins:
Expand All @@ -294,14 +294,16 @@ def test_lock_action(main_window):
assert isinstance(title_bar, QWidget)

# Test that our custom title bar is shown when the action
# is unchecked
action.setChecked(False)
# is triggered.
action.trigger()
for plugin in plugins:
title_bar = plugin.dockwidget.titleBarWidget()
assert isinstance(title_bar, DockTitleBar)
assert not main_window.interface_locked

# Restore default state
action.setChecked(True)
action.trigger()
assert main_window.interface_locked


@pytest.mark.slow
Expand Down