Skip to content

Commit ba4142a

Browse files
authored
Merge pull request #9811 from fariza/button-prefered-extension
dynamically finding the backend preferred format for button images
2 parents 982254c + 02818c9 commit ba4142a

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3218,6 +3218,13 @@ class ToolContainerBase(object):
32183218
The tools with which this `ToolContainer` wants to communicate.
32193219
"""
32203220

3221+
_icon_extension = '.png'
3222+
"""
3223+
Toolcontainer button icon image format extension
3224+
3225+
**String**: Image extension
3226+
"""
3227+
32213228
def __init__(self, toolmanager):
32223229
self.toolmanager = toolmanager
32233230
self.toolmanager.toolmanager_connect('tool_removed_event',
@@ -3262,14 +3269,19 @@ def _remove_tool_cbk(self, event):
32623269

32633270
def _get_image_filename(self, image):
32643271
"""Find the image based on its name."""
3265-
# TODO: better search for images, they are not always in the
3266-
# datapath
3272+
if not image:
3273+
return None
3274+
32673275
basedir = os.path.join(rcParams['datapath'], 'images')
3268-
if image is not None:
3269-
fname = os.path.join(basedir, image)
3270-
else:
3271-
fname = None
3272-
return fname
3276+
possible_images = (
3277+
image,
3278+
image + self._icon_extension,
3279+
os.path.join(basedir, image),
3280+
os.path.join(basedir, image) + self._icon_extension)
3281+
3282+
for fname in possible_images:
3283+
if os.path.isfile(fname):
3284+
return fname
32733285

32743286
def trigger_tool(self, name):
32753287
"""

lib/matplotlib/backend_tools.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ class ToolHome(ViewsPositionsBase):
724724
"""Restore the original view lim"""
725725

726726
description = 'Reset original view'
727-
image = 'home.png'
727+
image = 'home'
728728
default_keymap = rcParams['keymap.home']
729729
_on_trigger = 'home'
730730

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

735735
description = 'Back to previous view'
736-
image = 'back.png'
736+
image = 'back'
737737
default_keymap = rcParams['keymap.back']
738738
_on_trigger = 'back'
739739

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

744744
description = 'Forward to next view'
745-
image = 'forward.png'
745+
image = 'forward'
746746
default_keymap = rcParams['keymap.forward']
747747
_on_trigger = 'forward'
748748

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

753753
description = 'Configure subplots'
754-
image = 'subplots.png'
754+
image = 'subplots'
755755

756756

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

760760
description = 'Save the figure'
761-
image = 'filesave.png'
761+
image = 'filesave'
762762
default_keymap = rcParams['keymap.save']
763763

764764

@@ -830,7 +830,7 @@ class ToolZoom(ZoomPanBase):
830830
"""Zoom to rectangle"""
831831

832832
description = 'Zoom to rectangle'
833-
image = 'zoom_to_rect.png'
833+
image = 'zoom_to_rect'
834834
default_keymap = rcParams['keymap.zoom']
835835
cursor = cursors.SELECT_REGION
836836
radio_group = 'default'
@@ -957,7 +957,7 @@ class ToolPan(ZoomPanBase):
957957

958958
default_keymap = rcParams['keymap.pan']
959959
description = 'Pan axes with left mouse, zoom with right'
960-
image = 'move.png'
960+
image = 'move'
961961
cursor = cursors.MOVE
962962
radio_group = 'default'
963963

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ def draw_rubberband(self, x0, y0, x1, y1):
716716

717717

718718
class ToolbarGTK3(ToolContainerBase, Gtk.Box):
719+
_icon_extension = '.png'
719720
def __init__(self, toolmanager):
720721
ToolContainerBase.__init__(self, toolmanager)
721722
Gtk.Box.__init__(self)

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@ def set_cursor(self, cursor):
868868

869869

870870
class ToolbarTk(ToolContainerBase, Tk.Frame):
871+
_icon_extension = '.gif'
871872
def __init__(self, toolmanager, window):
872873
ToolContainerBase.__init__(self, toolmanager)
873874
xmin, xmax = self.toolmanager.canvas.figure.bbox.intervalx

0 commit comments

Comments
 (0)