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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/matplotlib/backends/backend_webagg_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ class FigureManagerWebAgg(backend_bases.FigureManagerBase):
# This must be None to not break ipympl
_toolbar2_class = None
ToolbarCls = NavigationToolbar2WebAgg
_window_title = "Matplotlib"

def __init__(self, canvas, num):
self.web_sockets = set()
Expand All @@ -444,6 +445,10 @@ def resize(self, w, h, forward=True):

def set_window_title(self, title):
self._send_event('figure_label', label=title)
self._window_title = title

def get_window_title(self):
return self._window_title

# The following methods are specific to FigureManagerWebAgg

Expand Down
2 changes: 0 additions & 2 deletions lib/matplotlib/tests/test_backend_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ def target():
thread.join()


@pytest.mark.backend('TkAgg', skip_on_importerror=True)
@pytest.mark.flaky(reruns=3)
@_isolated_tk_test(success_count=0)
def test_never_update():
Expand Down Expand Up @@ -199,7 +198,6 @@ class Toolbar(NavigationToolbar2Tk):
print("success")


@pytest.mark.backend('TkAgg', skip_on_importerror=True)
@_isolated_tk_test(success_count=1)
def test_canvas_focus():
import tkinter as tk
Expand Down
22 changes: 10 additions & 12 deletions lib/matplotlib/tests/test_backends_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def _test_interactive_impl():
import io
import json
import sys
from unittest import TestCase

import pytest

import matplotlib as mpl
from matplotlib import pyplot as plt
Expand All @@ -119,8 +120,6 @@ def _test_interactive_impl():

mpl.rcParams.update(json.loads(sys.argv[1]))
backend = plt.rcParams["backend"].lower()
assert_equal = TestCase().assertEqual
assert_raises = TestCase().assertRaises

if backend.endswith("agg") and not backend.startswith(("gtk", "web")):
# Force interactive framework setup.
Expand All @@ -135,25 +134,24 @@ def _test_interactive_impl():
# uses no interactive framework).

if backend != "tkagg":
with assert_raises(ImportError):
with pytest.raises(ImportError):
mpl.use("tkagg", force=True)

def check_alt_backend(alt_backend):
mpl.use(alt_backend, force=True)
fig = plt.figure()
assert_equal(
type(fig.canvas).__module__,
f"matplotlib.backends.backend_{alt_backend}")
assert (type(fig.canvas).__module__ ==
f"matplotlib.backends.backend_{alt_backend}")

if importlib.util.find_spec("cairocffi"):
check_alt_backend(backend[:-3] + "cairo")
check_alt_backend("svg")
mpl.use(backend, force=True)

fig, ax = plt.subplots()
assert_equal(
type(fig.canvas).__module__,
f"matplotlib.backends.backend_{backend}")
assert type(fig.canvas).__module__ == f"matplotlib.backends.backend_{backend}"

assert fig.canvas.manager.get_window_title() == "Figure 1"

if mpl.rcParams["toolbar"] == "toolmanager":
# test toolbar button icon LA mode see GH issue 25174
Expand Down Expand Up @@ -189,7 +187,7 @@ def check_alt_backend(alt_backend):
if not backend.startswith('qt5') and sys.platform == 'darwin':
# FIXME: This should be enabled everywhere once Qt5 is fixed on macOS
# to not resize incorrectly.
assert_equal(result.getvalue(), result_after.getvalue())
assert result.getvalue() == result_after.getvalue()


@pytest.mark.parametrize("env", _get_testable_interactive_backends())
Expand Down Expand Up @@ -241,7 +239,7 @@ def _test_thread_impl():
future.result() # Joins the thread; rethrows any exception.
plt.close() # backend is responsible for flushing any events here
if plt.rcParams["backend"].startswith("WX"):
# TODO: debug why WX needs this only on py3.8
# TODO: debug why WX needs this only on py >= 3.8
fig.canvas.flush_events()


Expand Down