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

Skip to content

Commit 16b18ea

Browse files
authored
Merge pull request #6718 from anntzer/backport-qt-editor-improvements
ENH: Backport qt editor improvements
2 parents 76fd818 + 90aeeeb commit 16b18ea

File tree

8 files changed

+303
-169
lines changed

8 files changed

+303
-169
lines changed

INSTALL

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ backends and the capabilities they provide.
233233
Versions 8.6.0 and 8.6.1 are known to have issues that may result
234234
in segfaults when closing multiple windows in the wrong order.
235235

236-
:term:`pyqt` 4.0 or later
236+
:term:`pyqt` 4.4 or later
237237
The Qt4 widgets library python wrappers for the Qt4Agg backend
238238

239239
:term:`pygtk` 2.4 or later

doc/conf.py

Lines changed: 93 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -306,17 +306,99 @@ class Frame(object):
306306

307307
class MyPyQt4(MagicMock):
308308
class QtGui(object):
309-
class QToolBar(object):
310-
pass
311-
312-
class QDialog(object):
313-
pass
314-
315-
class QWidget(object):
316-
pass
317-
318-
class QMainWindow(object):
319-
pass
309+
# PyQt4.QtGui public classes.
310+
# Generated with
311+
# textwrap.fill([name for name in dir(PyQt4.QtGui)
312+
# if isinstance(getattr(PyQt4.QtGui, name), type)])
313+
_QtGui_public_classes = """\
314+
Display QAbstractButton QAbstractGraphicsShapeItem
315+
QAbstractItemDelegate QAbstractItemView QAbstractPrintDialog
316+
QAbstractProxyModel QAbstractScrollArea QAbstractSlider
317+
QAbstractSpinBox QAbstractTextDocumentLayout QAction QActionEvent
318+
QActionGroup QApplication QBitmap QBoxLayout QBrush QButtonGroup
319+
QCalendarWidget QCheckBox QClipboard QCloseEvent QColor QColorDialog
320+
QColumnView QComboBox QCommandLinkButton QCommonStyle QCompleter
321+
QConicalGradient QContextMenuEvent QCursor QDataWidgetMapper QDateEdit
322+
QDateTimeEdit QDesktopServices QDesktopWidget QDial QDialog
323+
QDialogButtonBox QDirModel QDockWidget QDoubleSpinBox QDoubleValidator
324+
QDrag QDragEnterEvent QDragLeaveEvent QDragMoveEvent QDropEvent
325+
QErrorMessage QFileDialog QFileIconProvider QFileOpenEvent
326+
QFileSystemModel QFocusEvent QFocusFrame QFont QFontComboBox
327+
QFontDatabase QFontDialog QFontInfo QFontMetrics QFontMetricsF
328+
QFormLayout QFrame QGesture QGestureEvent QGestureRecognizer QGlyphRun
329+
QGradient QGraphicsAnchor QGraphicsAnchorLayout QGraphicsBlurEffect
330+
QGraphicsColorizeEffect QGraphicsDropShadowEffect QGraphicsEffect
331+
QGraphicsEllipseItem QGraphicsGridLayout QGraphicsItem
332+
QGraphicsItemAnimation QGraphicsItemGroup QGraphicsLayout
333+
QGraphicsLayoutItem QGraphicsLineItem QGraphicsLinearLayout
334+
QGraphicsObject QGraphicsOpacityEffect QGraphicsPathItem
335+
QGraphicsPixmapItem QGraphicsPolygonItem QGraphicsProxyWidget
336+
QGraphicsRectItem QGraphicsRotation QGraphicsScale QGraphicsScene
337+
QGraphicsSceneContextMenuEvent QGraphicsSceneDragDropEvent
338+
QGraphicsSceneEvent QGraphicsSceneHelpEvent QGraphicsSceneHoverEvent
339+
QGraphicsSceneMouseEvent QGraphicsSceneMoveEvent
340+
QGraphicsSceneResizeEvent QGraphicsSceneWheelEvent
341+
QGraphicsSimpleTextItem QGraphicsTextItem QGraphicsTransform
342+
QGraphicsView QGraphicsWidget QGridLayout QGroupBox QHBoxLayout
343+
QHeaderView QHelpEvent QHideEvent QHoverEvent QIcon QIconDragEvent
344+
QIconEngine QIconEngineV2 QIdentityProxyModel QImage QImageIOHandler
345+
QImageReader QImageWriter QInputContext QInputContextFactory
346+
QInputDialog QInputEvent QInputMethodEvent QIntValidator QItemDelegate
347+
QItemEditorCreatorBase QItemEditorFactory QItemSelection
348+
QItemSelectionModel QItemSelectionRange QKeyEvent QKeyEventTransition
349+
QKeySequence QLCDNumber QLabel QLayout QLayoutItem QLineEdit
350+
QLinearGradient QListView QListWidget QListWidgetItem QMainWindow
351+
QMatrix QMatrix2x2 QMatrix2x3 QMatrix2x4 QMatrix3x2 QMatrix3x3
352+
QMatrix3x4 QMatrix4x2 QMatrix4x3 QMatrix4x4 QMdiArea QMdiSubWindow
353+
QMenu QMenuBar QMessageBox QMimeSource QMouseEvent
354+
QMouseEventTransition QMoveEvent QMovie QPageSetupDialog QPaintDevice
355+
QPaintEngine QPaintEngineState QPaintEvent QPainter QPainterPath
356+
QPainterPathStroker QPalette QPanGesture QPen QPicture QPictureIO
357+
QPinchGesture QPixmap QPixmapCache QPlainTextDocumentLayout
358+
QPlainTextEdit QPolygon QPolygonF QPrintDialog QPrintEngine
359+
QPrintPreviewDialog QPrintPreviewWidget QPrinter QPrinterInfo
360+
QProgressBar QProgressDialog QProxyModel QPushButton QPyTextObject
361+
QQuaternion QRadialGradient QRadioButton QRawFont QRegExpValidator
362+
QRegion QResizeEvent QRubberBand QScrollArea QScrollBar
363+
QSessionManager QShortcut QShortcutEvent QShowEvent QSizeGrip
364+
QSizePolicy QSlider QSortFilterProxyModel QSound QSpacerItem QSpinBox
365+
QSplashScreen QSplitter QSplitterHandle QStackedLayout QStackedWidget
366+
QStandardItem QStandardItemModel QStaticText QStatusBar
367+
QStatusTipEvent QStringListModel QStyle QStyleFactory QStyleHintReturn
368+
QStyleHintReturnMask QStyleHintReturnVariant QStyleOption
369+
QStyleOptionButton QStyleOptionComboBox QStyleOptionComplex
370+
QStyleOptionDockWidget QStyleOptionDockWidgetV2 QStyleOptionFocusRect
371+
QStyleOptionFrame QStyleOptionFrameV2 QStyleOptionFrameV3
372+
QStyleOptionGraphicsItem QStyleOptionGroupBox QStyleOptionHeader
373+
QStyleOptionMenuItem QStyleOptionProgressBar QStyleOptionProgressBarV2
374+
QStyleOptionRubberBand QStyleOptionSizeGrip QStyleOptionSlider
375+
QStyleOptionSpinBox QStyleOptionTab QStyleOptionTabBarBase
376+
QStyleOptionTabBarBaseV2 QStyleOptionTabV2 QStyleOptionTabV3
377+
QStyleOptionTabWidgetFrame QStyleOptionTabWidgetFrameV2
378+
QStyleOptionTitleBar QStyleOptionToolBar QStyleOptionToolBox
379+
QStyleOptionToolBoxV2 QStyleOptionToolButton QStyleOptionViewItem
380+
QStyleOptionViewItemV2 QStyleOptionViewItemV3 QStyleOptionViewItemV4
381+
QStylePainter QStyledItemDelegate QSwipeGesture QSyntaxHighlighter
382+
QSystemTrayIcon QTabBar QTabWidget QTableView QTableWidget
383+
QTableWidgetItem QTableWidgetSelectionRange QTabletEvent
384+
QTapAndHoldGesture QTapGesture QTextBlock QTextBlockFormat
385+
QTextBlockGroup QTextBlockUserData QTextBrowser QTextCharFormat
386+
QTextCursor QTextDocument QTextDocumentFragment QTextDocumentWriter
387+
QTextEdit QTextFormat QTextFragment QTextFrame QTextFrameFormat
388+
QTextImageFormat QTextInlineObject QTextItem QTextLayout QTextLength
389+
QTextLine QTextList QTextListFormat QTextObject QTextObjectInterface
390+
QTextOption QTextTable QTextTableCell QTextTableCellFormat
391+
QTextTableFormat QTimeEdit QToolBar QToolBox QToolButton QToolTip
392+
QTouchEvent QTransform QTreeView QTreeWidget QTreeWidgetItem
393+
QTreeWidgetItemIterator QUndoCommand QUndoGroup QUndoStack QUndoView
394+
QVBoxLayout QValidator QVector2D QVector3D QVector4D QWhatsThis
395+
QWhatsThisClickedEvent QWheelEvent QWidget QWidgetAction QWidgetItem
396+
QWindowStateChangeEvent QWizard QWizardPage QWorkspace
397+
QX11EmbedContainer QX11EmbedWidget QX11Info
398+
"""
399+
for _name in _QtGui_public_classes.split():
400+
locals()[_name] = type(_name, (), {})
401+
del _name
320402

321403

322404
class MySip(MagicMock):
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Improvements for the Qt figure options editor
2+
---------------------------------------------
3+
4+
Various usability improvements were implemented for the Qt figure options
5+
editor, among which:
6+
- Line style entries are now sorted without duplicates.
7+
- The colormap and normalization limits can now be set for images.
8+
- Line edits for floating values now display only as many digits as necessary
9+
to avoid precision loss. An important bug was also fixed regarding input
10+
validation using Qt5 and a locale where the decimal separator is ",".
11+
- The axes selector now uses shorter, more user-friendly names for axes, and
12+
does not crash if there are no axes.
13+
- Line and image entries using the default labels ("_lineX", "_imageX") are now
14+
sorted numerically even when there are more than 10 entries.

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,8 @@ def add_image(self, image):
17321732
Returns the image.
17331733
"""
17341734
self._set_artist_props(image)
1735+
if not image.get_label():
1736+
image.set_label('_image%d' % len(self.images))
17351737
self.images.append(image)
17361738
image._remove_method = lambda h: self.images.remove(h)
17371739
self.stale = True

lib/matplotlib/backends/backend_qt4.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@
2222
from matplotlib._pylab_helpers import Gcf
2323
from matplotlib.figure import Figure
2424

25-
2625
from matplotlib.widgets import SubplotTool
27-
try:
28-
import matplotlib.backends.qt_editor.figureoptions as figureoptions
29-
except ImportError:
30-
figureoptions = None
3126

3227
from .qt_compat import QtCore, QtWidgets, _getSaveFileName, __version__
3328
from matplotlib.backends.qt_editor.formsubplottool import UiSubplotTool

lib/matplotlib/backends/backend_qt5.py

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
from matplotlib.figure import Figure
2424

2525
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
3027

3128
from .qt_compat import (QtCore, QtGui, QtWidgets, _getSaveFileName,
3229
__version__, is_pyqt5)
@@ -589,7 +586,7 @@ def _init_toolbar(self):
589586
a.setCheckable(True)
590587
if tooltip_text is not None:
591588
a.setToolTip(tooltip_text)
592-
if figureoptions is not None and text == 'Subplots':
589+
if text == 'Subplots':
593590
a = self.addAction(self._icon("qt4_editor_options.png"),
594591
'Customize', self.edit_parameters)
595592
a.setToolTip('Edit axis, curve and image parameters')
@@ -620,43 +617,31 @@ def _init_toolbar(self):
620617
self.layout().setSpacing(12)
621618
self.setMinimumHeight(48)
622619

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))]
632641
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)
660645

661646
def _update_buttons_checked(self):
662647
# sync button checkstates to match active mode

0 commit comments

Comments
 (0)