An event that has a screen location. A LocationEvent has a number of special attributes in addition to those defined by the parent `Event` class. Attributes ---------- x, y : int or None Event location in pixels from bottom left of canvas. inaxes : `~matplotlib
| 1255 | |
| 1256 | |
| 1257 | class LocationEvent(Event): |
| 1258 | """ |
| 1259 | An event that has a screen location. |
| 1260 | |
| 1261 | A LocationEvent has a number of special attributes in addition to those |
| 1262 | defined by the parent `Event` class. |
| 1263 | |
| 1264 | Attributes |
| 1265 | ---------- |
| 1266 | x, y : int or None |
| 1267 | Event location in pixels from bottom left of canvas. |
| 1268 | inaxes : `~matplotlib.axes.Axes` or None |
| 1269 | The `~.axes.Axes` instance over which the mouse is, if any. |
| 1270 | xdata, ydata : float or None |
| 1271 | Data coordinates of the mouse within *inaxes*, or *None* if the mouse |
| 1272 | is not over an Axes. |
| 1273 | modifiers : frozenset[str] |
| 1274 | The keyboard modifiers currently being pressed (except for KeyEvent). |
| 1275 | """ |
| 1276 | |
| 1277 | _last_axes_ref = None |
| 1278 | |
| 1279 | def __init__(self, name, canvas, x, y, guiEvent=None, *, modifiers=None): |
| 1280 | super().__init__(name, canvas, guiEvent=guiEvent) |
| 1281 | # x position - pixels from left of canvas |
| 1282 | self.x = int(x) if x is not None else x |
| 1283 | # y position - pixels from right of canvas |
| 1284 | self.y = int(y) if y is not None else y |
| 1285 | self.inaxes = None # the Axes instance the mouse is over |
| 1286 | self.xdata = None # x coord of mouse in data coords |
| 1287 | self.ydata = None # y coord of mouse in data coords |
| 1288 | self.modifiers = frozenset(modifiers if modifiers is not None else []) |
| 1289 | |
| 1290 | if x is None or y is None: |
| 1291 | # cannot check if event was in Axes if no (x, y) info |
| 1292 | return |
| 1293 | |
| 1294 | self._set_inaxes(self.canvas.inaxes((x, y)) |
| 1295 | if self.canvas.mouse_grabber is None else |
| 1296 | self.canvas.mouse_grabber, |
| 1297 | (x, y)) |
| 1298 | |
| 1299 | # Splitting _set_inaxes out is useful for the axes_leave_event handler: it |
| 1300 | # needs to generate synthetic LocationEvents with manually-set inaxes. In |
| 1301 | # that latter case, xy has already been cast to int so it can directly be |
| 1302 | # read from self.x, self.y; in the normal case, however, it is more |
| 1303 | # accurate to pass the untruncated float x, y values passed to the ctor. |
| 1304 | |
| 1305 | def _set_inaxes(self, inaxes, xy=None): |
| 1306 | self.inaxes = inaxes |
| 1307 | if inaxes is not None: |
| 1308 | try: |
| 1309 | self.xdata, self.ydata = inaxes.transData.inverted().transform( |
| 1310 | xy if xy is not None else (self.x, self.y)) |
| 1311 | except ValueError: |
| 1312 | pass |
| 1313 | |
| 1314 |
no outgoing calls
searching dependent graphs…