Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Improve the ToolToggleBase API #18331

Copy link
Copy link
Open
@anntzer

Description

@anntzer
Issue body actions

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 (see ToolFullScreen,
    AxisScaleBase, or GroupHideTool from the toolmanager_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 than do_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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.