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

Skip to content

Commit 3c83fac

Browse files
committed
commit patch 1599876, fixes to qt4agg backend and qt4 blitting demo.
Thanks to Phil Thompson. svn path=/trunk/matplotlib/; revision=4096
1 parent 51087e9 commit 3c83fac

3 files changed

Lines changed: 35 additions & 26 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2007-11-02 Commited Phil Thompson's patch 1599876, fixes to Qt4Agg
2+
backend and qt4 blitting demo - DSD
3+
14
2007-10-31 Made log color scale easier to use with contourf;
25
automatic level generation now works. - EF
36

examples/animation_blit_qt4.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,29 @@
1515

1616
class BlitQT(QtCore.QObject):
1717
def __init__(self):
18-
QtCore.QObject.__init__(self, None)
19-
2018
self.ax = p.subplot(111)
2119
self.canvas = self.ax.figure.canvas
20+
21+
# By making this a child of the canvas we make sure that it is
22+
# destroyed first and avoids a possible exception when the user clicks
23+
# on the window's close box.
24+
QtCore.QObject.__init__(self, self.canvas)
25+
2226
self.cnt = 0
2327

2428
# create the initial line
2529
self.x = npy.arange(0,2*npy.pi,0.01)
2630
self.line, = p.plot(self.x, npy.sin(self.x), animated=True, lw=2)
2731

2832
self.background = None
33+
self.old_size = 0, 0
2934

3035
def timerEvent(self, evt):
31-
if self.background is None:
36+
# See if the size has changed since last time round.
37+
current_size = self.ax.bbox.width(), self.ax.bbox.height()
38+
39+
if self.old_size != current_size:
40+
self.old_size = current_size
3241
self.background = self.canvas.copy_from_bbox(self.ax.bbox)
3342

3443
# restore the clean slate background

lib/matplotlib/backends/backend_qt4agg.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import os, sys
77

88
import matplotlib
9-
from matplotlib import verbose
10-
from matplotlib.cbook import enumerate
119
from matplotlib.figure import Figure
1210

1311
from backend_agg import FigureCanvasAgg
@@ -61,7 +59,7 @@ def __init__( self, figure ):
6159
self.drawRect = False
6260
self.rect = []
6361
self.replot = True
64-
self.pixmap = QtGui.QPixmap()
62+
self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent)
6563

6664
def resizeEvent( self, e ):
6765
FigureCanvasQT.resizeEvent( self, e )
@@ -86,26 +84,25 @@ def paintEvent( self, e ):
8684

8785
# only replot data when needed
8886
if type(self.replot) is bool: # might be a bbox for blitting
89-
if ( self.replot ):
90-
#stringBuffer = str( self.buffer_rgba(0,0) )
91-
FigureCanvasAgg.draw( self )
92-
93-
# matplotlib is in rgba byte order.
94-
# qImage wants to put the bytes into argb format and
95-
# is in a 4 byte unsigned int. little endian system is LSB first
96-
# and expects the bytes in reverse order (bgra).
97-
if ( QtCore.QSysInfo.ByteOrder == QtCore.QSysInfo.LittleEndian ):
98-
stringBuffer = self.renderer._renderer.tostring_bgra()
99-
else:
100-
stringBuffer = self.renderer._renderer.tostring_argb()
101-
qImage = QtGui.QImage( stringBuffer, self.renderer.width,
102-
self.renderer.height,
103-
QtGui.QImage.Format_ARGB32)
104-
self.pixmap = self.pixmap.fromImage( qImage )
105-
p.drawPixmap( QtCore.QPoint( 0, 0 ), self.pixmap )
87+
if self.replot:
88+
FigureCanvasAgg.draw(self)
89+
90+
# matplotlib is in rgba byte order. QImage wants to put the bytes
91+
# into argb format and is in a 4 byte unsigned int. Little endian
92+
# system is LSB first and expects the bytes in reverse order
93+
# (bgra).
94+
if QtCore.QSysInfo.ByteOrder == QtCore.QSysInfo.LittleEndian:
95+
stringBuffer = self.renderer._renderer.tostring_bgra()
96+
else:
97+
stringBuffer = self.renderer._renderer.tostring_argb()
98+
99+
qImage = QtGui.QImage(stringBuffer, self.renderer.width,
100+
self.renderer.height,
101+
QtGui.QImage.Format_ARGB32)
102+
p.drawPixmap(QtCore.QPoint(0, 0), QtGui.QPixmap.fromImage(qImage))
106103

107104
# draw the zoom rectangle to the QPainter
108-
if ( self.drawRect ):
105+
if self.drawRect:
109106
p.setPen( QtGui.QPen( QtCore.Qt.black, 1, QtCore.Qt.DotLine ) )
110107
p.drawRect( self.rect[0], self.rect[1], self.rect[2], self.rect[3] )
111108

@@ -117,8 +114,8 @@ def paintEvent( self, e ):
117114
reg = self.copy_from_bbox(bbox)
118115
stringBuffer = reg.to_string()
119116
qImage = QtGui.QImage(stringBuffer, w, h, QtGui.QImage.Format_ARGB32)
120-
self.pixmap = self.pixmap.fromImage( qImage )
121-
p.drawPixmap(QtCore.QPoint(l, self.renderer.height-t), self.pixmap)
117+
pixmap = QtGui.QPixmap.fromImage(qImage)
118+
p.drawPixmap(QtCore.QPoint(l, self.renderer.height-t), pixmap)
122119

123120
p.end()
124121
self.replot = False

0 commit comments

Comments
 (0)