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

Skip to content

Commit ad63b35

Browse files
committed
dynamically finding the backend preferred format for button images
1 parent 793635c commit ad63b35

4 files changed

Lines changed: 35 additions & 14 deletions

File tree

lib/matplotlib/backend_bases.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,14 +3266,29 @@ def _remove_tool_cbk(self, event):
32663266

32673267
def _get_image_filename(self, image):
32683268
"""Find the image based on its name."""
3269-
# TODO: better search for images, they are not always in the
3270-
# datapath
3269+
if not image:
3270+
return None
3271+
32713272
basedir = os.path.join(rcParams['datapath'], 'images')
3272-
if image is not None:
3273-
fname = os.path.join(basedir, image)
3274-
else:
3275-
fname = None
3276-
return fname
3273+
possible_images = [
3274+
image,
3275+
image + self.btn_image_extension(),
3276+
os.path.join(basedir, image) + self.btn_image_extension()]
3277+
3278+
for fname in possible_images:
3279+
if os.path.isfile(fname):
3280+
return fname
3281+
3282+
def btn_image_extension(self):
3283+
"""
3284+
Get the preferred image extension
3285+
3286+
Return
3287+
======
3288+
str: Image extension
3289+
"""
3290+
raise NotImplementedError
3291+
32773292

32783293
def trigger_tool(self, name):
32793294
"""

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,9 @@ def _add_separator(self):
786786
self._toolarea.pack_start(sep, False, True, 0)
787787
sep.show_all()
788788

789+
def btn_image_extension(self):
790+
return '.png'
791+
789792

790793
class StatusbarGTK3(StatusbarBase, Gtk.Statusbar):
791794
def __init__(self, *args, **kwargs):

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,9 @@ def remove_toolitem(self, name):
935935
toolitem.pack_forget()
936936
del self._toolitems[name]
937937

938+
def btn_image_extension(self):
939+
return '.gif'
940+
938941

939942
class StatusbarTk(StatusbarBase, Tk.Frame):
940943
def __init__(self, window, *args, **kwargs):

0 commit comments

Comments
 (0)