Skip to content

Commit

Permalink
Merge pull request #5207 from matplotlib/v1.5.x
Browse files Browse the repository at this point in the history
Merge V1.5.x into matter
  • Loading branch information
tacaswell committed Oct 7, 2015
2 parents fef412e + c4b9f4e commit 912c813
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 31 deletions.
Binary file removed doc/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions lib/matplotlib/__init__.py
Expand Up @@ -1429,6 +1429,7 @@ def tk_window_focus():
'matplotlib.tests.test_backend_pgf',
'matplotlib.tests.test_backend_ps',
'matplotlib.tests.test_backend_qt4',
'matplotlib.tests.test_backend_qt5',
'matplotlib.tests.test_backend_svg',
'matplotlib.tests.test_basic',
'matplotlib.tests.test_bbox_tight',
Expand Down
7 changes: 6 additions & 1 deletion lib/matplotlib/backends/backend_qt4agg.py
Expand Up @@ -15,7 +15,7 @@
from matplotlib.figure import Figure


from .backend_qt5agg import FigureCanvasQTAggBase
from .backend_qt5agg import FigureCanvasQTAggBase as _FigureCanvasQTAggBase

from .backend_agg import FigureCanvasAgg
from .backend_qt4 import QtCore
Expand Down Expand Up @@ -54,6 +54,11 @@ def new_figure_manager_given_figure(num, figure):
return FigureManagerQT(canvas, num)


class FigureCanvasQTAggBase(_FigureCanvasQTAggBase):
def __init__(self, figure):
self._agg_draw_pending = False


class FigureCanvasQTAgg(FigureCanvasQTAggBase,
FigureCanvasQT, FigureCanvasAgg):
"""
Expand Down
30 changes: 14 additions & 16 deletions lib/matplotlib/backends/qt_compat.py
Expand Up @@ -139,24 +139,22 @@ def _getSaveFileName(*args, **kwargs):
# call to getapi() can fail in older versions of sip
def _getSaveFileName(*args, **kwargs):
return QtGui.QFileDialog.getSaveFileName(*args, **kwargs), None

else:
raise RuntimeError("PyQt{4,5} bindings found despite sip importing\n"
"Please install PyQt4 or PyQt5, uninstall sip or "
"explicitly set the pyside backend.")

# Alias PyQt-specific functions for PySide compatibility.
QtCore.Signal = QtCore.pyqtSignal
try:
QtCore.Slot = QtCore.pyqtSlot
except AttributeError:
# Not a perfect match but works in simple cases
QtCore.Slot = QtCore.pyqtSignature

QtCore.Property = QtCore.pyqtProperty
__version__ = QtCore.PYQT_VERSION_STR
# Alias PyQt-specific functions for PySide compatibility.
QtCore.Signal = QtCore.pyqtSignal
try:
QtCore.Slot = QtCore.pyqtSlot
except AttributeError:
# Not a perfect match but works in simple cases
QtCore.Slot = QtCore.pyqtSignature

QtCore.Property = QtCore.pyqtProperty
__version__ = QtCore.PYQT_VERSION_STR
except NameError:
# QtCore did not get imported, fall back to pyside
QT_API = QT_API_PYSIDE

else: # try importing pyside
if QT_API == QT_API_PYSIDE: # try importing pyside
try:
from PySide import QtCore, QtGui, __version__, __version_info__
except ImportError:
Expand Down
16 changes: 13 additions & 3 deletions lib/matplotlib/tests/test_backend_qt4.py
Expand Up @@ -7,6 +7,7 @@
from matplotlib.testing.decorators import cleanup, switch_backend
from matplotlib.testing.decorators import knownfailureif
from matplotlib._pylab_helpers import Gcf
import matplotlib.style as mstyle
import copy

try:
Expand All @@ -16,15 +17,24 @@
import mock

try:
from matplotlib.backends.qt_compat import QtCore
with mstyle.context({'backend': 'Qt4Agg'}):
from matplotlib.backends.qt_compat import QtCore

from matplotlib.backends.backend_qt4 import (MODIFIER_KEYS,
SUPER, ALT, CTRL, SHIFT)

_, ControlModifier, ControlKey = MODIFIER_KEYS[CTRL]
_, AltModifier, AltKey = MODIFIER_KEYS[ALT]
_, SuperModifier, SuperKey = MODIFIER_KEYS[SUPER]
_, ShiftModifier, ShiftKey = MODIFIER_KEYS[SHIFT]
HAS_QT = True

try:
py_qt_ver = int(QtCore.PYQT_VERSION_STR.split('.')[0])
except AttributeError:
py_qt_ver = QtCore.__version_info__[0]
print(py_qt_ver)
HAS_QT = py_qt_ver == 4

except ImportError:
HAS_QT = False

Expand All @@ -33,7 +43,7 @@
@knownfailureif(not HAS_QT)
@switch_backend('Qt4Agg')
def test_fig_close():
#save the state of Gcf.figs
# save the state of Gcf.figs
init_figs = copy.copy(Gcf.figs)

# make a figure using pyplot interface
Expand Down
24 changes: 13 additions & 11 deletions lib/matplotlib/tests/test_backend_qt5.py
@@ -1,12 +1,12 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

from matplotlib.externals import six

from matplotlib import pyplot as plt
from matplotlib.testing.decorators import cleanup
from matplotlib.testing.decorators import cleanup, switch_backend
from matplotlib.testing.decorators import knownfailureif
from matplotlib._pylab_helpers import Gcf
import matplotlib.style as mstyle
import copy

try:
Expand All @@ -16,25 +16,27 @@
import mock

try:
from matplotlib.backends.qt_compat import QtCore
with mstyle.context({'backend': 'Qt5Agg'}):
from matplotlib.backends.qt_compat import QtCore, __version__
from matplotlib.backends.backend_qt5 import (MODIFIER_KEYS,
SUPER, ALT, CTRL, SHIFT)

_, ControlModifier, ControlKey = MODIFIER_KEYS[CTRL]
_, AltModifier, AltKey = MODIFIER_KEYS[ALT]
_, SuperModifier, SuperKey = MODIFIER_KEYS[SUPER]
_, ShiftModifier, ShiftKey = MODIFIER_KEYS[SHIFT]
HAS_QT = True

py_qt_ver = int(__version__.split('.')[0])
HAS_QT = py_qt_ver == 5

except ImportError:
HAS_QT = False


@cleanup
@knownfailureif(not HAS_QT)
@switch_backend('Qt5Agg')
def test_fig_close():
# force switch to the Qt5 backend
plt.switch_backend('Qt5Agg')

# save the state of Gcf.figs
init_figs = copy.copy(Gcf.figs)

Expand All @@ -50,14 +52,14 @@ def test_fig_close():
assert(init_figs == Gcf.figs)


@switch_backend('Qt5Agg')
def assert_correct_key(qt_key, qt_mods, answer):
"""
Make a figure
Send a key_press_event event (using non-public, qt5 backend specific api)
Catch the event
Assert sent and caught keys are the same
"""
plt.switch_backend('Qt5Agg')
qt_canvas = plt.figure().canvas

event = mock.Mock()
Expand Down Expand Up @@ -101,15 +103,15 @@ def test_control():
def test_unicode_upper():
assert_correct_key(QtCore.Qt.Key_Aacute,
ShiftModifier,
unichr(193))
six.unichr(193))


@cleanup
@knownfailureif(not HAS_QT)
def test_unicode_lower():
assert_correct_key(QtCore.Qt.Key_Aacute,
QtCore.Qt.NoModifier,
unichr(225))
six.unichr(225))


@cleanup
Expand All @@ -133,7 +135,7 @@ def test_control_alt():
def test_modifier_order():
assert_correct_key(QtCore.Qt.Key_Aacute,
(ControlModifier | AltModifier | SuperModifier),
'ctrl+alt+super+' + unichr(225))
'ctrl+alt+super+' + six.unichr(225))


@cleanup
Expand Down

0 comments on commit 912c813

Please sign in to comment.