| 124 | |
| 125 | |
| 126 | class BlitManager: |
| 127 | def __init__(self, canvas, animated_artists=()): |
| 128 | """ |
| 129 | Parameters |
| 130 | ---------- |
| 131 | canvas : FigureCanvasAgg |
| 132 | The canvas to work with, this only works for subclasses of the Agg |
| 133 | canvas which have the `~FigureCanvasAgg.copy_from_bbox` and |
| 134 | `~FigureCanvasAgg.restore_region` methods. |
| 135 | |
| 136 | animated_artists : Iterable[Artist] |
| 137 | List of the artists to manage |
| 138 | """ |
| 139 | self.canvas = canvas |
| 140 | self._bg = None |
| 141 | self._artists = [] |
| 142 | |
| 143 | for a in animated_artists: |
| 144 | self.add_artist(a) |
| 145 | # grab the background on every draw |
| 146 | self.cid = canvas.mpl_connect("draw_event", self.on_draw) |
| 147 | |
| 148 | def on_draw(self, event): |
| 149 | """Callback to register with 'draw_event'.""" |
| 150 | cv = self.canvas |
| 151 | if event is not None: |
| 152 | if event.canvas != cv: |
| 153 | raise RuntimeError |
| 154 | self._bg = cv.copy_from_bbox(cv.figure.bbox) |
| 155 | self._draw_animated() |
| 156 | |
| 157 | def add_artist(self, art): |
| 158 | """ |
| 159 | Add an artist to be managed. |
| 160 | |
| 161 | Parameters |
| 162 | ---------- |
| 163 | art : Artist |
| 164 | |
| 165 | The artist to be added. Will be set to 'animated' (just |
| 166 | to be safe). *art* must be in the figure associated with |
| 167 | the canvas this class is managing. |
| 168 | |
| 169 | """ |
| 170 | if art.figure != self.canvas.figure: |
| 171 | raise RuntimeError |
| 172 | art.set_animated(True) |
| 173 | self._artists.append(art) |
| 174 | |
| 175 | def _draw_animated(self): |
| 176 | """Draw all of the animated artists.""" |
| 177 | fig = self.canvas.figure |
| 178 | for a in self._artists: |
| 179 | fig.draw_artist(a) |
| 180 | |
| 181 | def update(self): |
| 182 | """Update the screen with animated artists.""" |
| 183 | cv = self.canvas |
no outgoing calls
no test coverage detected
searching dependent graphs…