Thanks to visit codestin.com
Credit goes to github.com

Skip to content

dynamically finding the backend preferred format for button images #9811

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

Merged
merged 5 commits into from
Nov 25, 2017
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
26 changes: 19 additions & 7 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3222,6 +3222,13 @@ class ToolContainerBase(object):
The tools with which this `ToolContainer` wants to communicate.
"""

_icon_extension = '.png'
"""
Toolcontainer button icon image format extension

**String**: Image extension
"""

def __init__(self, toolmanager):
self.toolmanager = toolmanager
self.toolmanager.toolmanager_connect('tool_removed_event',
Expand Down Expand Up @@ -3266,14 +3273,19 @@ def _remove_tool_cbk(self, event):

def _get_image_filename(self, image):
"""Find the image based on its name."""
# TODO: better search for images, they are not always in the
# datapath
if not image:
return None

basedir = os.path.join(rcParams['datapath'], 'images')
if image is not None:
fname = os.path.join(basedir, image)
else:
fname = None
return fname
possible_images = (
image,
image + self._icon_extension,
os.path.join(basedir, image),
os.path.join(basedir, image) + self._icon_extension)

for fname in possible_images:
if os.path.isfile(fname):
return fname

def trigger_tool(self, name):
"""
Expand Down
14 changes: 7 additions & 7 deletions lib/matplotlib/backend_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ class ToolHome(ViewsPositionsBase):
"""Restore the original view lim"""

description = 'Reset original view'
image = 'home.png'
image = 'home'
default_keymap = rcParams['keymap.home']
_on_trigger = 'home'

Expand All @@ -733,7 +733,7 @@ class ToolBack(ViewsPositionsBase):
"""Move back up the view lim stack"""

description = 'Back to previous view'
image = 'back.png'
image = 'back'
default_keymap = rcParams['keymap.back']
_on_trigger = 'back'

Expand All @@ -742,7 +742,7 @@ class ToolForward(ViewsPositionsBase):
"""Move forward in the view lim stack"""

description = 'Forward to next view'
image = 'forward.png'
image = 'forward'
default_keymap = rcParams['keymap.forward']
_on_trigger = 'forward'

Expand All @@ -751,14 +751,14 @@ class ConfigureSubplotsBase(ToolBase):
"""Base tool for the configuration of subplots"""

description = 'Configure subplots'
image = 'subplots.png'
image = 'subplots'


class SaveFigureBase(ToolBase):
"""Base tool for figure saving"""

description = 'Save the figure'
image = 'filesave.png'
image = 'filesave'
default_keymap = rcParams['keymap.save']


Expand Down Expand Up @@ -830,7 +830,7 @@ class ToolZoom(ZoomPanBase):
"""Zoom to rectangle"""

description = 'Zoom to rectangle'
image = 'zoom_to_rect.png'
image = 'zoom_to_rect'
default_keymap = rcParams['keymap.zoom']
cursor = cursors.SELECT_REGION
radio_group = 'default'
Expand Down Expand Up @@ -957,7 +957,7 @@ class ToolPan(ZoomPanBase):

default_keymap = rcParams['keymap.pan']
description = 'Pan axes with left mouse, zoom with right'
image = 'move.png'
image = 'move'
cursor = cursors.MOVE
radio_group = 'default'

Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ def draw_rubberband(self, x0, y0, x1, y1):


class ToolbarGTK3(ToolContainerBase, Gtk.Box):
_icon_extension = '.png'
def __init__(self, toolmanager):
ToolContainerBase.__init__(self, toolmanager)
Gtk.Box.__init__(self)
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/backends/backend_tkagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@ def set_cursor(self, cursor):


class ToolbarTk(ToolContainerBase, Tk.Frame):
_icon_extension = '.gif'
def __init__(self, toolmanager, window):
ToolContainerBase.__init__(self, toolmanager)
xmin, xmax = self.toolmanager.canvas.figure.bbox.intervalx
Expand Down