| 2191 | """ |
| 2192 | |
| 2193 | def __init__(self, *args, useblit=True, horizOn=False, vertOn=True, |
| 2194 | **lineprops): |
| 2195 | # Deprecation of canvas as the first attribute. When the deprecation expires: |
| 2196 | # - change the signature to __init__(self, axes, *, ...) |
| 2197 | # - delete the "Call signatures" block in the docstring |
| 2198 | # - delete this block |
| 2199 | kwargs = {k: lineprops.pop(k) |
| 2200 | for k in list(lineprops) if k in ("canvas", "axes")} |
| 2201 | params = _api.select_matching_signature( |
| 2202 | [lambda axes: locals(), lambda canvas, axes: locals()], *args, **kwargs) |
| 2203 | if "canvas" in params: |
| 2204 | _api.warn_deprecated( |
| 2205 | "3.11", |
| 2206 | message="The canvas parameter in MultiCursor is unused and deprecated " |
| 2207 | "since %(since)s. Please remove it and call MultiCursor(axes) " |
| 2208 | "instead of MultiCursor(canvas, axes). The latter will start raising " |
| 2209 | "an error in %(removal)s" |
| 2210 | ) |
| 2211 | axes = params["axes"] |
| 2212 | |
| 2213 | self.axes = axes |
| 2214 | self.horizOn = horizOn |
| 2215 | self.vertOn = vertOn |
| 2216 | |
| 2217 | self._canvas_infos = { |
| 2218 | ax.get_figure(root=True).canvas: |
| 2219 | {"cids": [], "background": None} for ax in axes} |
| 2220 | |
| 2221 | xmin, xmax = axes[-1].get_xlim() |
| 2222 | ymin, ymax = axes[-1].get_ylim() |
| 2223 | xmid = 0.5 * (xmin + xmax) |
| 2224 | ymid = 0.5 * (ymin + ymax) |
| 2225 | |
| 2226 | self.visible = True |
| 2227 | self.useblit = ( |
| 2228 | useblit |
| 2229 | and all(canvas.supports_blit for canvas in self._canvas_infos)) |
| 2230 | # TODO: make dynamic |
| 2231 | |
| 2232 | if self.useblit: |
| 2233 | lineprops['animated'] = True |
| 2234 | |
| 2235 | self.vlines = [ax.axvline(xmid, visible=False, **lineprops) |
| 2236 | for ax in axes] |
| 2237 | self.hlines = [ax.axhline(ymid, visible=False, **lineprops) |
| 2238 | for ax in axes] |
| 2239 | |
| 2240 | self.connect() |
| 2241 | |
| 2242 | def connect(self): |
| 2243 | """Connect events.""" |