Skip to content

Keyboard shortcuts work when toolbar not displayed #1830

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

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 8 additions & 2 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,7 @@ def key_press_handler(event, canvas, toolbar=None):
# saving current figure (default key 's')
elif event.key in save_keys:
toolbar.save_figure()
toolbar.display_cursor(event)

if event.inaxes is None:
return
Expand Down Expand Up @@ -2676,7 +2677,7 @@ class implementation.
"""
raise NotImplementedError

def mouse_move(self, event):
def display_cursor(self, event):
if not event.inaxes or not self._active:
if self._lastCursor != cursors.POINTER:
self.set_cursor(cursors.POINTER)
Expand All @@ -2692,8 +2693,9 @@ def mouse_move(self, event):

self._lastCursor = cursors.MOVE

def mouse_move(self, event):
self.display_cursor(event)
if event.inaxes and event.inaxes.get_navigate():

try:
s = event.inaxes.format_coord(event.xdata, event.ydata)
except (ValueError, OverflowError):
Expand Down Expand Up @@ -3096,3 +3098,7 @@ def zoom(self, *args):
def set_history_buttons(self):
"""Enable or disable back/forward button"""
pass

def set_hidden(self, is_hidden):
"""Set the toolbars visibility."""
pass
3 changes: 3 additions & 0 deletions lib/matplotlib/backends/backend_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,9 @@ def configure_subplots(self, button):
def _get_canvas(self, fig):
return FigureCanvasGTK(fig)

def set_hidden(self, hidden):
self.set_visible(hidden)


class NavigationToolbar(gtk.Toolbar):
"""
Expand Down
3 changes: 3 additions & 0 deletions lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,9 @@ def configure_subplots(self, button):
def _get_canvas(self, fig):
return self.canvas.__class__(fig)

def set_hidden(self, hidden):
self.set_visible(hidden)


class NavigationToolbar(Gtk.Toolbar):
"""
Expand Down
3 changes: 3 additions & 0 deletions lib/matplotlib/backends/backend_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@ def set_history_buttons( self ):
self.buttons[ 'Back' ].setEnabled( canBackward )
self.buttons[ 'Forward' ].setEnabled( canForward )

def set_hidden(self, hidden):
self.setVisible(hidden)

# set icon used when windows are minimized
try:
# TODO: This is badly broken
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/backends/backend_qt4.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,8 @@ def save_figure(self, *args):
self, "Error saving file", str(e),
QtGui.QMessageBox.Ok, QtGui.QMessageBox.NoButton)


def set_hidden(self, hidden):
self.setVisible(hidden)

class SubplotToolQt( SubplotTool, QtGui.QWidget ):
def __init__(self, targetfig, parent):
Expand Down
14 changes: 14 additions & 0 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,16 @@ class that will be passed on to :meth:`new_figure_manager` in the
if figManager is None:
if get_backend().lower() == 'ps': dpi = 72

# If toolbar is set to 'None', it should still be instantiated if
# the backend supports setting it's visibility, so that keyboard
# shortcut logic is preserved
invisible_toolbar = False
if rcParams['toolbar'] not in ('toolbar2', 'classic'):
if get_backend().lower() in ('qt4agg', 'qtagg', 'gtk', 'gtkagg',
'gtkcairo'):
rcParams['toolbar'] = 'toolbar2'
invisible_toolbar = True

figManager = new_figure_manager(num, figsize=figsize,
dpi=dpi,
facecolor=facecolor,
Expand All @@ -347,6 +357,10 @@ class that will be passed on to :meth:`new_figure_manager` in the
FigureClass=FigureClass,
**kwargs)

if invisible_toolbar:
figManager.toolbar.set_hidden(False)
rcParams['toolbar'] = 'None'

if figLabel:
figManager.set_window_title(figLabel)
figManager.canvas.figure.set_label(figLabel)
Expand Down