Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 94f8421

Browse files
authored
Merge pull request #15224 from anntzer/qtactions
Avoid infinite loop when switching actions in qt backend.
2 parents 289130d + 4eb188a commit 94f8421

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/matplotlib/backends/backend_qt5.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,6 @@ def _icon(self, name, color=None):
678678

679679
def _init_toolbar(self):
680680
self.basedir = str(cbook._get_data_path('images'))
681-
# Ensure that zoom and pan are mutually exclusive.
682-
self._button_group = QtWidgets.QButtonGroup()
683681

684682
background_color = self.palette().color(self.backgroundRole())
685683
foreground_color = self.palette().color(self.foregroundRole())
@@ -695,7 +693,6 @@ def _init_toolbar(self):
695693
self._actions[callback] = a
696694
if callback in ['zoom', 'pan']:
697695
a.setCheckable(True)
698-
self._button_group.addButton(self.widgetForAction(a))
699696
if tooltip_text is not None:
700697
a.setToolTip(tooltip_text)
701698
if text == 'Subplots':
@@ -754,13 +751,20 @@ def edit_parameters(self):
754751
ax = axes[titles.index(item)]
755752
figureoptions.figure_edit(ax, self)
756753

754+
def _update_buttons_checked(self):
755+
# sync button checkstates to match active mode
756+
if 'pan' in self._actions:
757+
self._actions['pan'].setChecked(self._active == 'PAN')
758+
if 'zoom' in self._actions:
759+
self._actions['zoom'].setChecked(self._active == 'ZOOM')
760+
757761
def pan(self, *args):
758762
super().pan(*args)
759-
self._actions['pan'].setChecked(self._active == 'PAN')
763+
self._update_buttons_checked()
760764

761765
def zoom(self, *args):
762766
super().zoom(*args)
763-
self._actions['zoom'].setChecked(self._active == 'ZOOM')
767+
self._update_buttons_checked()
764768

765769
def set_message(self, s):
766770
self.message.emit(s)

0 commit comments

Comments
 (0)