|
23 | 23 | from matplotlib.figure import Figure
|
24 | 24 |
|
25 | 25 | from matplotlib.widgets import SubplotTool
|
26 |
| -try: |
27 |
| - import matplotlib.backends.qt_editor.figureoptions as figureoptions |
28 |
| -except ImportError: |
29 |
| - figureoptions = None |
| 26 | +import matplotlib.backends.qt_editor.figureoptions as figureoptions |
30 | 27 |
|
31 | 28 | from .qt_compat import (QtCore, QtGui, QtWidgets, _getSaveFileName,
|
32 | 29 | __version__, is_pyqt5)
|
@@ -589,7 +586,7 @@ def _init_toolbar(self):
|
589 | 586 | a.setCheckable(True)
|
590 | 587 | if tooltip_text is not None:
|
591 | 588 | a.setToolTip(tooltip_text)
|
592 |
| - if figureoptions is not None and text == 'Subplots': |
| 589 | + if text == 'Subplots': |
593 | 590 | a = self.addAction(self._icon("qt4_editor_options.png"),
|
594 | 591 | 'Customize', self.edit_parameters)
|
595 | 592 | a.setToolTip('Edit axis, curve and image parameters')
|
@@ -620,43 +617,31 @@ def _init_toolbar(self):
|
620 | 617 | self.layout().setSpacing(12)
|
621 | 618 | self.setMinimumHeight(48)
|
622 | 619 |
|
623 |
| - if figureoptions is not None: |
624 |
| - def edit_parameters(self): |
625 |
| - allaxes = self.canvas.figure.get_axes() |
626 |
| - if not allaxes: |
627 |
| - QtWidgets.QMessageBox.warning( |
628 |
| - self.parent, "Error", "There are no axes to edit.") |
629 |
| - return |
630 |
| - if len(allaxes) == 1: |
631 |
| - axes = allaxes[0] |
| 620 | + def edit_parameters(self): |
| 621 | + allaxes = self.canvas.figure.get_axes() |
| 622 | + if not allaxes: |
| 623 | + QtWidgets.QMessageBox.warning( |
| 624 | + self.parent, "Error", "There are no axes to edit.") |
| 625 | + return |
| 626 | + if len(allaxes) == 1: |
| 627 | + axes = allaxes[0] |
| 628 | + else: |
| 629 | + titles = [] |
| 630 | + for axes in allaxes: |
| 631 | + name = (axes.get_title() or |
| 632 | + " - ".join(filter(None, [axes.get_xlabel(), |
| 633 | + axes.get_ylabel()])) or |
| 634 | + "<anonymous {} (id: {:#x})>".format( |
| 635 | + type(axes).__name__, id(axes))) |
| 636 | + titles.append(name) |
| 637 | + item, ok = QtWidgets.QInputDialog.getItem( |
| 638 | + self.parent, 'Customize', 'Select axes:', titles, 0, False) |
| 639 | + if ok: |
| 640 | + axes = allaxes[titles.index(six.text_type(item))] |
632 | 641 | else:
|
633 |
| - titles = [] |
634 |
| - for axes in allaxes: |
635 |
| - title = axes.get_title() |
636 |
| - ylabel = axes.get_ylabel() |
637 |
| - label = axes.get_label() |
638 |
| - if title: |
639 |
| - fmt = "%(title)s" |
640 |
| - if ylabel: |
641 |
| - fmt += ": %(ylabel)s" |
642 |
| - fmt += " (%(axes_repr)s)" |
643 |
| - elif ylabel: |
644 |
| - fmt = "%(axes_repr)s (%(ylabel)s)" |
645 |
| - elif label: |
646 |
| - fmt = "%(axes_repr)s (%(label)s)" |
647 |
| - else: |
648 |
| - fmt = "%(axes_repr)s" |
649 |
| - titles.append(fmt % dict(title=title, |
650 |
| - ylabel=ylabel, label=label, |
651 |
| - axes_repr=repr(axes))) |
652 |
| - item, ok = QtWidgets.QInputDialog.getItem( |
653 |
| - self.parent, 'Customize', 'Select axes:', titles, 0, False) |
654 |
| - if ok: |
655 |
| - axes = allaxes[titles.index(six.text_type(item))] |
656 |
| - else: |
657 |
| - return |
658 |
| - |
659 |
| - figureoptions.figure_edit(axes, self) |
| 642 | + return |
| 643 | + |
| 644 | + figureoptions.figure_edit(axes, self) |
660 | 645 |
|
661 | 646 | def _update_buttons_checked(self):
|
662 | 647 | # sync button checkstates to match active mode
|
|
0 commit comments