@@ -381,6 +381,32 @@ def get_children(self):
381381 r"""Return a list of the child `.Artist`\s of this `.Artist`."""
382382 return []
383383
384+ def _default_contains (self , mouseevent , figure = None ):
385+ """
386+ Base impl. for checking whether a mouseevent happened in an artist.
387+
388+ 1. If the artist defines a custom checker, use it.
389+ 2. If the artist figure is known and the event did not occur in that
390+ figure (by checking its ``canvas`` attribute), reject it.
391+ 3. Otherwise, return `None, {}`, indicating that the subclass'
392+ implementation should be used.
393+
394+ Subclasses should start their definition of `contains` as follows:
395+
396+ inside, info = self._default_contains(mouseevent)
397+ if inside is not None:
398+ return inside, info
399+ # subclass-specific implementation follows
400+
401+ The `canvas` kwarg is provided for the implementation of
402+ `Figure.contains`.
403+ """
404+ if callable (self ._contains ):
405+ return self ._contains (self , mouseevent )
406+ if figure is not None and mouseevent .canvas is not figure .canvas :
407+ return False , {}
408+ return None , {}
409+
384410 def contains (self , mouseevent ):
385411 """Test whether the artist contains the mouse event.
386412
@@ -401,8 +427,9 @@ def contains(self, mouseevent):
401427 --------
402428 set_contains, get_contains
403429 """
404- if self ._contains is not None :
405- return self ._contains (self , mouseevent )
430+ inside , info = self ._default_contains (mouseevent )
431+ if inside is not None :
432+ return inside , info
406433 _log .warning ("%r needs 'contains' method" , self .__class__ .__name__ )
407434 return False , {}
408435
0 commit comments