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

Skip to content

Commit c8b3a81

Browse files
committed
Implement Qt4 backend by fully reexporting Qt5 backend.
1 parent 39575ed commit c8b3a81

3 files changed

Lines changed: 27 additions & 61 deletions

File tree

lib/matplotlib/backends/backend_qt4.py

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,14 @@
22
unicode_literals)
33

44
import six
5-
from six import unichr
6-
import os
7-
import re
8-
import signal
9-
import sys
10-
11-
from matplotlib._pylab_helpers import Gcf
12-
from matplotlib.backend_bases import (
13-
FigureCanvasBase, FigureManagerBase, NavigationToolbar2, TimerBase,
14-
cursors)
15-
from matplotlib.figure import Figure
16-
from matplotlib.widgets import SubplotTool
17-
18-
from .qt_compat import QtCore, QtWidgets, _getSaveFileName, __version__
195

206
from .backend_qt5 import (
217
backend_version, SPECIAL_KEYS, SUPER, ALT, CTRL, SHIFT, MODIFIER_KEYS,
228
cursord, _create_qApp, _BackendQT5, TimerQT, MainWindow, FigureManagerQT,
239
NavigationToolbar2QT, SubplotToolQt, error_msg_qt, exception_handler)
2410
from .backend_qt5 import FigureCanvasQT as FigureCanvasQT5
2511

26-
DEBUG = False
27-
28-
29-
class FigureCanvasQT(FigureCanvasQT5):
30-
31-
def wheelEvent(self, event):
32-
x = event.x()
33-
# flipy so y=0 is bottom of canvas
34-
y = self.figure.bbox.height - event.y()
35-
# from QWheelEvent::delta doc
36-
steps = event.delta()/120
37-
if (event.orientation() == QtCore.Qt.Vertical):
38-
FigureCanvasBase.scroll_event(self, x, y, steps)
39-
if DEBUG:
40-
print('scroll event: delta = %i, '
41-
'steps = %i ' % (event.delta(), steps))
42-
4312

4413
@_BackendQT5.export
4514
class _BackendQT4(_BackendQT5):
46-
FigureCanvas = FigureCanvasQT
15+
pass

lib/matplotlib/backends/backend_qt4agg.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,10 @@
66

77
import six
88

9-
from .backend_agg import FigureCanvasAgg
10-
from .backend_qt4 import (
11-
QtCore, _BackendQT4, FigureCanvasQT, FigureManagerQT, NavigationToolbar2QT)
12-
from .backend_qt5agg import FigureCanvasQTAggBase
9+
from .backend_qt5agg import (
10+
_BackendQT5Agg, FigureCanvasQTAgg, FigureManagerQT, NavigationToolbar2QT)
1311

1412

15-
class FigureCanvasQTAgg(FigureCanvasQTAggBase, FigureCanvasQT):
16-
"""
17-
The canvas the figure renders into. Calls the draw and print fig
18-
methods, creates the renderers, etc...
19-
20-
Attributes
21-
----------
22-
figure : `matplotlib.figure.Figure`
23-
A high-level Figure instance
24-
25-
"""
26-
27-
28-
@_BackendQT4.export
29-
class _BackendQT4Agg(_BackendQT4):
30-
FigureCanvas = FigureCanvasQTAgg
13+
@_BackendQT5Agg.export
14+
class _BackendQT4Agg(_BackendQT5Agg):
15+
pass

lib/matplotlib/backends/backend_qt5.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,27 @@ def mouseReleaseEvent(self, event):
317317
FigureCanvasBase.button_release_event(self, x, y, button,
318318
guiEvent=event)
319319

320-
def wheelEvent(self, event):
321-
x, y = self.mouseEventCoords(event)
322-
# from QWheelEvent::delta doc
323-
if event.pixelDelta().x() == 0 and event.pixelDelta().y() == 0:
324-
steps = event.angleDelta().y() / 120
325-
else:
326-
steps = event.pixelDelta().y()
327-
if steps:
328-
FigureCanvasBase.scroll_event(self, x, y, steps, guiEvent=event)
320+
if is_pyqt5():
321+
def wheelEvent(self, event):
322+
x, y = self.mouseEventCoords(event)
323+
# from QWheelEvent::delta doc
324+
if event.pixelDelta().x() == 0 and event.pixelDelta().y() == 0:
325+
steps = event.angleDelta().y() / 120
326+
else:
327+
steps = event.pixelDelta().y()
328+
if steps:
329+
FigureCanvasBase.scroll_event(
330+
self, x, y, steps, guiEvent=event)
331+
else:
332+
def wheelEvent(self, event):
333+
x = event.x()
334+
# flipy so y=0 is bottom of canvas
335+
y = self.figure.bbox.height - event.y()
336+
# from QWheelEvent::delta doc
337+
steps = event.delta() / 120
338+
if event.orientation() == QtCore.Qt.Vertical:
339+
FigureCanvasBase.scroll_event(
340+
self, x, y, steps, guiEvent=event)
329341

330342
def keyPressEvent(self, event):
331343
key = self._get_key(event)

0 commit comments

Comments
 (0)