Description
Describe the issue
Currently the MEP22 ToolToggleBase API is that toggle-tool implementers should
implement an enable()
method and a disable()
method, which Matplotlib
arranges to be called when the tool is toggled. I think it would be nicer to
instead have a single on_toggle(state: bool)
method.
-
Having a single method avoids duplicating logic between
enable()
and
disable()
, given that both are often quite similar (seeToolFullScreen
,
AxisScaleBase
, orGroupHideTool
from thetoolmanager_sgskip
example). -
Using a non-verb method name makes it clearer that this is not something that
end users can call themselves and expect to work (indeed it would cause
problems, given that the widget state wouldn't get updated). Compare e.g.
with Qt's approach, which is also based on implementing special method names
in subclasses (yes, Qt also lets you bind arbitrary callables (slots) but
that's not the MEP22 design): these overridable methods are typically named
fooEvent()
(mouseMouveEvent()
), rather thando_foo()
. I don't have a
very strong preference between e.g.on_toggle(state: bool)
and
toggle_event(state: bool)
, although the latter may be confused with string
event names?
This can relatively easily be implemented with a transition period using
_deprecate_method_override
, I think.