Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b0dc1d5

Browse filesBrowse files
committed
Merge branch 'backend-pyqt5'
2 parents c906f13 + 1889c04 commit b0dc1d5
Copy full SHA for b0dc1d5
Expand file treeCollapse file tree

16 files changed

+1501
-1029
lines changed

‎lib/matplotlib/backends/backend_qt4.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_qt4.py
+14-762Lines changed: 14 additions & 762 deletions
Large diffs are not rendered by default.

‎lib/matplotlib/backends/backend_qt4agg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_qt4agg.py
+5-118Lines changed: 5 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
import matplotlib
1515
from matplotlib.figure import Figure
1616

17+
from .backend_qt5agg import new_figure_manager, NavigationToolbar2QTAgg
18+
from .backend_qt5agg import FigureCanvasQTAggBase
19+
1720
from .backend_agg import FigureCanvasAgg
1821
from .backend_qt4 import QtCore
19-
from .backend_qt4 import QtGui
2022
from .backend_qt4 import FigureManagerQT
2123
from .backend_qt4 import FigureCanvasQT
2224
from .backend_qt4 import NavigationToolbar2QT
@@ -34,17 +36,6 @@
3436
_decref.restype = None
3537

3638

37-
def new_figure_manager(num, *args, **kwargs):
38-
"""
39-
Create a new figure manager instance
40-
"""
41-
if DEBUG:
42-
print('backend_qtagg.new_figure_manager')
43-
FigureClass = kwargs.pop('FigureClass', Figure)
44-
thisFig = FigureClass(*args, **kwargs)
45-
return new_figure_manager_given_figure(num, thisFig)
46-
47-
4839
def new_figure_manager_given_figure(num, figure):
4940
"""
5041
Create a new figure manager instance for the given figure.
@@ -53,7 +44,8 @@ def new_figure_manager_given_figure(num, figure):
5344
return FigureManagerQT(canvas, num)
5445

5546

56-
class FigureCanvasQTAgg(FigureCanvasQT, FigureCanvasAgg):
47+
class FigureCanvasQTAgg(FigureCanvasQTAggBase,
48+
FigureCanvasQT, FigureCanvasAgg):
5749
"""
5850
The canvas the figure renders into. Calls the draw and print fig
5951
methods, creates the renderers, etc...
@@ -88,111 +80,6 @@ def __init__(self, figure):
8880
else:
8981
self._priv_update = self.update
9082

91-
def drawRectangle(self, rect):
92-
self._drawRect = rect
93-
self.repaint()
94-
95-
def paintEvent(self, e):
96-
"""
97-
Copy the image from the Agg canvas to the qt.drawable.
98-
In Qt, all drawing should be done inside of here when a widget is
99-
shown onscreen.
100-
"""
101-
102-
#FigureCanvasQT.paintEvent(self, e)
103-
if DEBUG:
104-
print('FigureCanvasQtAgg.paintEvent: ', self,
105-
self.get_width_height())
106-
107-
if self.blitbox is None:
108-
# matplotlib is in rgba byte order. QImage wants to put the bytes
109-
# into argb format and is in a 4 byte unsigned int. Little endian
110-
# system is LSB first and expects the bytes in reverse order
111-
# (bgra).
112-
if QtCore.QSysInfo.ByteOrder == QtCore.QSysInfo.LittleEndian:
113-
stringBuffer = self.renderer._renderer.tostring_bgra()
114-
else:
115-
stringBuffer = self.renderer._renderer.tostring_argb()
116-
117-
refcnt = sys.getrefcount(stringBuffer)
118-
119-
# convert the Agg rendered image -> qImage
120-
qImage = QtGui.QImage(stringBuffer, self.renderer.width,
121-
self.renderer.height,
122-
QtGui.QImage.Format_ARGB32)
123-
# get the rectangle for the image
124-
rect = qImage.rect()
125-
p = QtGui.QPainter(self)
126-
# reset the image area of the canvas to be the back-ground color
127-
p.eraseRect(rect)
128-
# draw the rendered image on to the canvas
129-
p.drawPixmap(QtCore.QPoint(0, 0), QtGui.QPixmap.fromImage(qImage))
130-
131-
# draw the zoom rectangle to the QPainter
132-
if self._drawRect is not None:
133-
p.setPen(QtGui.QPen(QtCore.Qt.black, 1, QtCore.Qt.DotLine))
134-
x, y, w, h = self._drawRect
135-
p.drawRect(x, y, w, h)
136-
p.end()
137-
138-
# This works around a bug in PySide 1.1.2 on Python 3.x,
139-
# where the reference count of stringBuffer is incremented
140-
# but never decremented by QImage.
141-
# TODO: revert PR #1323 once the issue is fixed in PySide.
142-
del qImage
143-
if refcnt != sys.getrefcount(stringBuffer):
144-
_decref(stringBuffer)
145-
else:
146-
bbox = self.blitbox
147-
l, b, r, t = bbox.extents
148-
w = int(r) - int(l)
149-
h = int(t) - int(b)
150-
t = int(b) + h
151-
reg = self.copy_from_bbox(bbox)
152-
stringBuffer = reg.to_string_argb()
153-
qImage = QtGui.QImage(stringBuffer, w, h,
154-
QtGui.QImage.Format_ARGB32)
155-
pixmap = QtGui.QPixmap.fromImage(qImage)
156-
p = QtGui.QPainter(self)
157-
p.drawPixmap(QtCore.QPoint(l, self.renderer.height-t), pixmap)
158-
p.end()
159-
self.blitbox = None
160-
self._drawRect = None
161-
162-
def draw(self):
163-
"""
164-
Draw the figure with Agg, and queue a request
165-
for a Qt draw.
166-
"""
167-
# The Agg draw is done here; delaying it until the paintEvent
168-
# causes problems with code that uses the result of the
169-
# draw() to update plot elements.
170-
FigureCanvasAgg.draw(self)
171-
self._priv_update()
172-
173-
def blit(self, bbox=None):
174-
"""
175-
Blit the region in bbox
176-
"""
177-
self.blitbox = bbox
178-
l, b, w, h = bbox.bounds
179-
t = b + h
180-
self.repaint(l, self.renderer.height-t, w, h)
181-
182-
def print_figure(self, *args, **kwargs):
183-
FigureCanvasAgg.print_figure(self, *args, **kwargs)
184-
self.draw()
185-
186-
187-
class NavigationToolbar2QTAgg(NavigationToolbar2QT):
188-
def __init__(*args, **kwargs):
189-
warnings.warn('This class has been deprecated in 1.4 ' +
190-
'as it has no additional functionality over ' +
191-
'`NavigationToolbar2QT`. Please change your code to '
192-
'use `NavigationToolbar2QT` instead',
193-
mplDeprecation)
194-
NavigationToolbar2QT.__init__(*args, **kwargs)
195-
19683

19784
FigureCanvas = FigureCanvasQTAgg
19885
FigureManager = FigureManagerQT

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.