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

Add option to toggle toolbars visibility #2426

Merged
merged 5 commits into from
Jul 21, 2015
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
4 changes: 3 additions & 1 deletion spyderlib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ def is_ubuntu():
'use_custom_margin': True,
'custom_margin': 0,
'show_internal_console_if_traceback': True,
'check_updates_on_startup': True
'check_updates_on_startup': True,
'toolbars_visible': True,
}),
('quick_layouts',
{
Expand Down Expand Up @@ -484,6 +485,7 @@ def is_ubuntu():
'_/save current layout': "Shift+Alt+S",
'_/toggle default layout': "Shift+Alt+Home",
'_/layout preferences': "Shift+Alt+P",
'_/show toolbars': "Alt+Shift+T",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@goanpeca, can you confirm that this working for you? I remember you told me there was some problem with this change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked, it works

'_/restart': "Shift+Alt+R",
'_/quit': "Ctrl+Q",
# -- In plugins/editor
Expand Down
77 changes: 77 additions & 0 deletions spyderlib/spyder.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ def __init__(self, options=None):

# Actions
self.lock_dockwidgets_action = None
self.show_toolbars_action = None
self.close_dockwidget_action = None
self.find_action = None
self.find_next_action = None
Expand Down Expand Up @@ -396,6 +397,7 @@ def __init__(self, options=None):
self.cpu_status = None

# Toolbars
self.visible_toolbars = []
self.toolbarslist = []
self.main_toolbar = None
self.main_toolbar_actions = []
Expand Down Expand Up @@ -1125,7 +1127,13 @@ def add_xydoc(text, pathlist):
self.close_dockwidget_action,
self.maximize_action,
None))
self.show_toolbars_action = create_action(self,
_("Show toolbars"),
triggered=self.show_toolbars)
self.register_shortcut(self.show_toolbars_action, "_",
"Show toolbars")
self.view_menu.addMenu(self.toolbars_menu)
self.view_menu.addAction(self.show_toolbars_action)
add_actions(self.view_menu, (None,
self.quick_layout_menu,
self.toggle_previous_layout_action,
Expand Down Expand Up @@ -1249,6 +1257,10 @@ def post_visible_setup(self):
self.extconsole.setMinimumHeight(0)

if not self.light:
# Update toolbar visibility status
self.toolbars_visible = CONF.get('main', 'toolbars_visible')
self.load_last_visible_toolbars()

# Update lock status of dockidgets (panes)
self.lock_dockwidgets_action.setChecked(self.dockwidgets_locked)
self.apply_panes_settings()
Expand Down Expand Up @@ -1382,6 +1394,7 @@ def tabify_plugins(self, first, second):
"""Tabify plugin dockwigdets"""
self.tabifyDockWidget(first.dockwidget, second.dockwidget)

# --- Layouts
def setup_layout(self, default=False):
"""Setup window layout"""
prefix = ('lightwindow' if self.light else 'window') + '/'
Expand Down Expand Up @@ -1909,6 +1922,68 @@ def quick_layout_switch(self, index):
action = plugin.toggle_view_action
action.setChecked(plugin.dockwidget.isVisible())

# --- Show/Hide toolbars
def _update_show_toolbars_action(self):
"""Update the text displayed in the menu entry."""
if self.toolbars_visible:
text = _("Hide toolbars")
tip = _("Hide toolbars")
else:
text = _("Show toolbars")
tip = _("Show toolbars")
self.show_toolbars_action.setText(text)
self.show_toolbars_action.setToolTip(tip)

def save_visible_toolbars(self):
"""Saves the name of the visible toolbars in the .ini file."""
toolbars = []
for toolbar in self.visible_toolbars:
toolbars.append(toolbar.objectName())
CONF.set('main', 'last_visible_toolbars', toolbars)

def get_visible_toolbars(self):
"""Collects the visible toolbars."""
toolbars = []
for toolbar in self.toolbarslist:
if toolbar.toggleViewAction().isChecked():
toolbars.append(toolbar)
self.visible_toolbars = toolbars

def load_last_visible_toolbars(self):
"""Loads the last visible toolbars from the .ini file."""
toolbars_names = CONF.get('main', 'last_visible_toolbars', default=[])

if toolbars_names:
dic = {}
for toolbar in self.toolbarslist:
dic[toolbar.objectName()] = toolbar

toolbars = []
for name in toolbars_names:
if name in dic:
toolbars.append(dic[name])
self.visible_toolbars = toolbars
else:
self.get_visible_toolbars()
self._update_show_toolbars_action()

def show_toolbars(self):
"""Show/Hides toolbars."""
value = not self.toolbars_visible
CONF.set('main', 'toolbars_visible', value)
if value:
self.save_visible_toolbars()
else:
self.get_visible_toolbars()

for toolbar in self.visible_toolbars:
toolbar.toggleViewAction().setChecked(value)
toolbar.setVisible(value)

self.toolbars_visible = value
self._update_show_toolbars_action()

# --- Other
def plugin_focus_changed(self):
"""Focus has changed from one plugin to another"""
if self.light:
Expand Down Expand Up @@ -2143,6 +2218,8 @@ def closing(self, cancelable=False):
if not widget.closing_plugin(cancelable):
return False
self.dialog_manager.close_all()
if self.toolbars_visible:
self.save_visible_toolbars()
self.already_closed = True
return True

Expand Down