From 4dd72b971c9e6f368e7a12f7da5141ce87bb89a8 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sat, 4 Sep 2021 15:46:35 +0200 Subject: [PATCH] Deprecate some backend_gtk3 helper globals. It is nicer to just define them at the point of use rather than ~400 lines later. --- .../deprecations/20995-AL.rst | 3 +++ lib/matplotlib/backends/backend_gtk3.py | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 doc/api/next_api_changes/deprecations/20995-AL.rst diff --git a/doc/api/next_api_changes/deprecations/20995-AL.rst b/doc/api/next_api_changes/deprecations/20995-AL.rst new file mode 100644 index 000000000000..bdccd8f5d333 --- /dev/null +++ b/doc/api/next_api_changes/deprecations/20995-AL.rst @@ -0,0 +1,3 @@ +``backend_gtk3.icon_filename`` and ``backend_gtk3.window_icon`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +... are deprecated with no replacement. diff --git a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py index 7701d7742bf0..efbbbb387238 100644 --- a/lib/matplotlib/backends/backend_gtk3.py +++ b/lib/matplotlib/backends/backend_gtk3.py @@ -59,6 +59,13 @@ def cursord(self): except TypeError as exc: return {} + icon_filename = _api.deprecated("3.6", obj_type="")(property( + lambda self: + "matplotlib.png" if sys.platform == "win32" else "matplotlib.svg")) + window_icon = _api.deprecated("3.6", obj_type="")(property( + lambda self: + str(cbook._get_data_path("images", __getattr__("icon_filename"))))) + @functools.lru_cache() def _mpl_to_gtk_cursor(mpl_cursor): @@ -307,7 +314,9 @@ def __init__(self, canvas, num): super().__init__(canvas, num) self.window.set_wmclass("matplotlib", "Matplotlib") - self.window.set_icon_from_file(window_icon) + icon_ext = "png" if sys.platform == "win32" else "svg" + self.window.set_icon_from_file( + str(cbook._get_data_path(f"images/matplotlib.{icon_ext}"))) self.vbox = Gtk.Box() self.vbox.set_property("orientation", Gtk.Orientation.VERTICAL) @@ -698,14 +707,6 @@ def trigger(self, *args, **kwargs): clipboard.set_image(pb) -# Define the file to use as the GTk icon -if sys.platform == 'win32': - icon_filename = 'matplotlib.png' -else: - icon_filename = 'matplotlib.svg' -window_icon = str(cbook._get_data_path('images', icon_filename)) - - def error_msg_gtk(msg, parent=None): if parent is not None: # find the toplevel Gtk.Window parent = parent.get_toplevel()