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

Skip to content

Commit 76ecdca

Browse files
authored
Merge pull request #14795 from anntzer/supports_blit
Autodetect whether a canvas class supports blitting.
2 parents 507bd38 + e4efe88 commit 76ecdca

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

lib/matplotlib/backend_bases.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,6 @@ class FigureCanvasBase:
15811581
'close_event'
15821582
]
15831583

1584-
supports_blit = True
15851584
fixed_dpi = None
15861585

15871586
filetypes = _default_filetypes
@@ -1597,6 +1596,11 @@ class FigureCanvasBase:
15971596
register_backend('tiff', 'matplotlib.backends.backend_agg',
15981597
'Tagged Image File Format')
15991598

1599+
@cbook._classproperty
1600+
def supports_blit(cls):
1601+
return (hasattr(cls, "copy_from_bbox")
1602+
and hasattr(cls, "restore_region"))
1603+
16001604
def __init__(self, figure):
16011605
self._fix_ipython_backend2gui()
16021606
self._is_idle_drawing = True

lib/matplotlib/backends/backend_cairo.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ def set_linewidth(self, w):
390390

391391

392392
class FigureCanvasCairo(FigureCanvasBase):
393-
supports_blit = False
394393

395394
def print_png(self, fobj, *args, **kwargs):
396395
self._get_printed_image_surface().write_to_png(fobj)

lib/matplotlib/cbook/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,3 +2131,26 @@ def _check_getitem(_mapping, **kwargs):
21312131
raise ValueError(
21322132
"{!r} is not a valid value for {}; supported values are {}"
21332133
.format(v, k, ', '.join(map(repr, mapping)))) from None
2134+
2135+
2136+
class _classproperty:
2137+
"""
2138+
Like `property`, but also triggers on access via the class, and it is the
2139+
*class* that's passed as argument.
2140+
2141+
Examples
2142+
--------
2143+
::
2144+
class C:
2145+
@classproperty
2146+
def foo(cls):
2147+
return cls.__name__
2148+
2149+
assert C.foo == "C"
2150+
"""
2151+
2152+
def __init__(self, fget):
2153+
self._fget = fget
2154+
2155+
def __get__(self, instance, owner):
2156+
return self._fget(owner)

0 commit comments

Comments
 (0)