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

Skip to content

Commit 25df1bb

Browse files
Phil Elsonpelson
Phil Elson
authored and
pelson
committed
Checked gtk backend & simplified some icon related code.
1 parent 6256889 commit 25df1bb

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,17 @@ def __init__(self, canvas, num):
359359

360360
self.window = Gtk.Window()
361361
self.set_window_title("Figure %d" % num)
362-
if (window_icon):
363-
try:
364-
self.window.set_icon_from_file(window_icon)
365-
except:
366-
# some versions of gtk throw a glib.GError but not
367-
# all, so I am not sure how to catch it. I am unhappy
368-
# diong a blanket catch here, but an not sure what a
369-
# better way is - JDH
370-
verbose.report('Could not load matplotlib icon: %s' % sys.exc_info()[1])
362+
try:
363+
self.window.set_icon_from_file(window_icon)
364+
except (SystemExit, KeyboardInterrupt):
365+
# re-raise exit type Exceptions
366+
raise
367+
except:
368+
# some versions of gtk throw a glib.GError but not
369+
# all, so I am not sure how to catch it. I am unhappy
370+
# doing a blanket catch here, but an not sure what a
371+
# better way is - JDH
372+
verbose.report('Could not load matplotlib icon: %s' % sys.exc_info()[1])
371373

372374
self.vbox = Gtk.Box()
373375
self.vbox.set_property("orientation", Gtk.Orientation.VERTICAL)
@@ -562,12 +564,15 @@ def configure_subplots(self, button):
562564

563565

564566
window = Gtk.Window()
565-
if (window_icon):
566-
try: window.set_icon_from_file(window_icon)
567-
except:
568-
# we presumably already logged a message on the
569-
# failure of the main plot, don't keep reporting
570-
pass
567+
try:
568+
window.set_icon_from_file(window_icon)
569+
except (SystemExit, KeyboardInterrupt):
570+
# re-raise exit type Exceptions
571+
raise
572+
except:
573+
# we presumably already logged a message on the
574+
# failure of the main plot, don't keep reporting
575+
pass
571576
window.set_title("Subplot Configuration Tool")
572577
window.set_default_size(w, h)
573578
vbox = Gtk.Box()
@@ -963,7 +968,6 @@ def get_active_line(self):
963968
line = self.lines[ind]
964969
return line
965970

966-
967971
def get_active_linestyle(self):
968972
'get the active lineinestyle'
969973
ind = self.cbox_linestyles.get_active()
@@ -997,8 +1001,6 @@ def _update(self):
9971001

9981002
line.figure.canvas.draw()
9991003

1000-
1001-
10021004
def on_combobox_lineprops_changed(self, item):
10031005
'update the widgets from the active line'
10041006
if not self._inited: return
@@ -1044,17 +1046,14 @@ def on_dialog_lineprops_okbutton_clicked(self, button):
10441046
def on_dialog_lineprops_cancelbutton_clicked(self, button):
10451047
self.dlg.hide()
10461048

1047-
# set icon used when windows are minimized
1048-
try:
10491049

1050-
if sys.platform == 'win32':
1051-
icon_filename = 'matplotlib.png'
1052-
else:
1053-
icon_filename = 'matplotlib.svg'
1054-
window_icon = os.path.join(rcParams['datapath'], 'images', icon_filename)
1055-
except:
1056-
window_icon = None
1057-
verbose.report('Could not load matplotlib icon: %s' % sys.exc_info()[1])
1050+
# Define the file to use as the GTk icon
1051+
if sys.platform == 'win32':
1052+
icon_filename = 'matplotlib.png'
1053+
else:
1054+
icon_filename = 'matplotlib.svg'
1055+
window_icon = os.path.join(matplotlib.rcParams['datapath'], 'images', icon_filename)
1056+
10581057

10591058
def error_msg_gtk(msg, parent=None):
10601059
if parent is not None: # find the toplevel Gtk.Window

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,14 @@ def new_figure_manager(num, *args, **kwargs):
7979
figure = FigureClass(*args, **kwargs)
8080
window = Tk.Tk()
8181

82-
# put a mpl icon on the window rather than the default tk icon. Tkinter
83-
# doesn't allow colour icons on linux systems, but tk >=8.5 has a iconphoto
84-
# command which we call directly. Source:
85-
# http://mail.python.org/pipermail/tkinter-discuss/2006-November/000954.html
86-
icon_fname = os.path.join(rcParams['datapath'], 'images', 'logo.gif')
87-
icon_img = Tk.PhotoImage(file=icon_fname)
88-
window.tk.call('wm', 'iconphoto', window._w, icon_img)
82+
if Tk.TkVersion >= 8.5:
83+
# put a mpl icon on the window rather than the default tk icon. Tkinter
84+
# doesn't allow colour icons on linux systems, but tk >=8.5 has a iconphoto
85+
# command which we call directly. Source:
86+
# http://mail.python.org/pipermail/tkinter-discuss/2006-November/000954.html
87+
icon_fname = os.path.join(rcParams['datapath'], 'images', 'matplotlib.gif')
88+
icon_img = Tk.PhotoImage(file=icon_fname)
89+
window.tk.call('wm', 'iconphoto', window._w, icon_img)
8990

9091
canvas = FigureCanvasTkAgg(figure, master=window)
9192
figManager = FigureManagerTkAgg(canvas, num, window)

0 commit comments

Comments
 (0)