Skip to content

[Bug]: macOS backend UI doesn't update on 'o' and 'p' shortcuts #31933

Open

Description

@iccir

Bug summary

  1. Open a figure
  2. Press 'o' and 'p' to toggle the Pan/Zoom and Zoom-to-rect tools
  3. Notice that the buttons in the UI do not update state
  4. Click a button to toggle it, the button toggles, but is still not in sync with the currently selected tool

Code for reproduction

(Any figure)

Actual outcome

'o' and 'p' do not update the UI's button state.

Expected outcome

The button state of the Pan/Zoom and Zoom-to-rect tools always matches the actual selected tool, like it does in qtagg.

Additional information

No response

Operating system

macOS 14.7

Matplotlib Version

dev / 3.11

Matplotlib Backend

macOS

Python version

Python 3.14.5

Jupyter version

No response

Installation

None

Activity

  1. QuLogic commented on Jun 23, 2026

    @QuLogic
    Member

    It looks like Qt just checks self.mode in pan and zoom after calling the superclass method:

    def _update_buttons_checked(self):
    # sync button checkstates to match active mode
    if 'pan' in self._actions:
    self._actions['pan'].setChecked(self.mode.name == 'PAN')
    if 'zoom' in self._actions:
    self._actions['zoom'].setChecked(self.mode.name == 'ZOOM')
    def pan(self, *args):
    super().pan(*args)
    self._update_buttons_checked()
    def zoom(self, *args):
    super().zoom(*args)
    self._update_buttons_checked()

    On a related note, it looks like the macosx backend doesn't implement NavigationToolbar2.set_history_buttons.

  2. iccir commented on Jun 23, 2026

    @iccir
    ContributorAuthor

    I got it fixed in my local branch by doing something similar:

        def _update_buttons_checked(self):
            mode_names = {_Mode.PAN: 'pan', _Mode.ZOOM: 'zoom'}
            self.update_selected_item(mode_names.get(self.mode, ''))
    
        def pan(self, *args):
            super().pan(*args)
            self._update_buttons_checked()
    
        def zoom(self, *args):
            super().zoom(*args)
            self._update_buttons_checked()

    Where self.update_selected_item() eventually calls into the Objective-C layer.

    Thanks for letting me know about set_history_buttons()! I'll get that wired up!

  3. iccir commented on Jun 23, 2026

    @iccir
    ContributorAuthor

    (Ideally, I want to get rid of the hardcoded panButton and zoomButton in the Obj-C layer. I'm trying to follow the path that MEP22 lays out to make the eventual migration easier!)

  4. iccir commented on Jun 27, 2026

    @iccir
    ContributorAuthor

    Fixed in my macosx-rework branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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