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