-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
GUI icon in Tkinter #897
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
GUI icon in Tkinter #897
Changes from 1 commit
6256889
25df1bb
c382f60
427ce52
c156ce3
1706dd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -359,15 +359,17 @@ def __init__(self, canvas, num): | |
|
||
self.window = Gtk.Window() | ||
self.set_window_title("Figure %d" % num) | ||
if (window_icon): | ||
try: | ||
self.window.set_icon_from_file(window_icon) | ||
except: | ||
# some versions of gtk throw a glib.GError but not | ||
# all, so I am not sure how to catch it. I am unhappy | ||
# diong a blanket catch here, but an not sure what a | ||
# better way is - JDH | ||
verbose.report('Could not load matplotlib icon: %s' % sys.exc_info()[1]) | ||
try: | ||
self.window.set_icon_from_file(window_icon) | ||
except (SystemExit, KeyboardInterrupt): | ||
# re-raise exit type Exceptions | ||
raise | ||
except: | ||
# some versions of gtk throw a glib.GError but not | ||
# all, so I am not sure how to catch it. I am unhappy | ||
# doing a blanket catch here, but an not sure what a | ||
# better way is - JDH | ||
verbose.report('Could not load matplotlib icon: %s' % sys.exc_info()[1]) | ||
|
||
self.vbox = Gtk.Box() | ||
self.vbox.set_property("orientation", Gtk.Orientation.VERTICAL) | ||
|
@@ -562,12 +564,15 @@ def configure_subplots(self, button): | |
|
||
|
||
window = Gtk.Window() | ||
if (window_icon): | ||
try: window.set_icon_from_file(window_icon) | ||
except: | ||
# we presumably already logged a message on the | ||
# failure of the main plot, don't keep reporting | ||
pass | ||
try: | ||
window.set_icon_from_file(window_icon) | ||
except (SystemExit, KeyboardInterrupt): | ||
# re-raise exit type Exceptions | ||
raise | ||
except: | ||
# we presumably already logged a message on the | ||
# failure of the main plot, don't keep reporting | ||
pass | ||
window.set_title("Subplot Configuration Tool") | ||
window.set_default_size(w, h) | ||
vbox = Gtk.Box() | ||
|
@@ -963,7 +968,6 @@ def get_active_line(self): | |
line = self.lines[ind] | ||
return line | ||
|
||
|
||
def get_active_linestyle(self): | ||
'get the active lineinestyle' | ||
ind = self.cbox_linestyles.get_active() | ||
|
@@ -997,8 +1001,6 @@ def _update(self): | |
|
||
line.figure.canvas.draw() | ||
|
||
|
||
|
||
def on_combobox_lineprops_changed(self, item): | ||
'update the widgets from the active line' | ||
if not self._inited: return | ||
|
@@ -1044,17 +1046,14 @@ def on_dialog_lineprops_okbutton_clicked(self, button): | |
def on_dialog_lineprops_cancelbutton_clicked(self, button): | ||
self.dlg.hide() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why remove this exception handling? At the very least we could use the verbose.report() there to provide us information and then re-raise (or maybe add a message to the exception and let it bubble up?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment needs removing, as far as I can see, this try block will never fail. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually agree that this exception handling is unnecessary -- it really shouldn't fail here, unless something is seriously wrong. This is different from the try/excepts above where if the icon can't be set we should continue along without an icon. |
||
# set icon used when windows are minimized | ||
try: | ||
|
||
if sys.platform == 'win32': | ||
icon_filename = 'matplotlib.png' | ||
else: | ||
icon_filename = 'matplotlib.svg' | ||
window_icon = os.path.join(rcParams['datapath'], 'images', icon_filename) | ||
except: | ||
window_icon = None | ||
verbose.report('Could not load matplotlib icon: %s' % sys.exc_info()[1]) | ||
# Define the file to use as the GTk icon | ||
if sys.platform == 'win32': | ||
icon_filename = 'matplotlib.png' | ||
else: | ||
icon_filename = 'matplotlib.svg' | ||
window_icon = os.path.join(matplotlib.rcParams['datapath'], 'images', icon_filename) | ||
|
||
|
||
def error_msg_gtk(msg, parent=None): | ||
if parent is not None: # find the toplevel Gtk.Window | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,13 +79,14 @@ def new_figure_manager(num, *args, **kwargs): | |
figure = FigureClass(*args, **kwargs) | ||
window = Tk.Tk() | ||
|
||
# put a mpl icon on the window rather than the default tk icon. Tkinter | ||
# doesn't allow colour icons on linux systems, but tk >=8.5 has a iconphoto | ||
# command which we call directly. Source: | ||
# http://mail.python.org/pipermail/tkinter-discuss/2006-November/000954.html | ||
icon_fname = os.path.join(rcParams['datapath'], 'images', 'logo.gif') | ||
icon_img = Tk.PhotoImage(file=icon_fname) | ||
window.tk.call('wm', 'iconphoto', window._w, icon_img) | ||
if Tk.TkVersion >= 8.5: | ||
# put a mpl icon on the window rather than the default tk icon. Tkinter | ||
# doesn't allow colour icons on linux systems, but tk >=8.5 has a iconphoto | ||
# command which we call directly. Source: | ||
# http://mail.python.org/pipermail/tkinter-discuss/2006-November/000954.html | ||
icon_fname = os.path.join(rcParams['datapath'], 'images', 'matplotlib.gif') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like matplotlib.gif didn't get committed. I tried changing this to .png -- it appears that Tkinter doesn't support png, so we'll need to include a gif version of the regular matplotlib icon. |
||
icon_img = Tk.PhotoImage(file=icon_fname) | ||
window.tk.call('wm', 'iconphoto', window._w, icon_img) | ||
|
||
canvas = FigureCanvasTkAgg(figure, master=window) | ||
figManager = FigureManagerTkAgg(canvas, num, window) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"an" --> "am"