From: <ds...@us...> - 2007-11-02 16:37:38
|
Revision: 4096 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4096&view=rev Author: dsdale Date: 2007-11-02 09:37:37 -0700 (Fri, 02 Nov 2007) Log Message: ----------- commit patch 1599876, fixes to qt4agg backend and qt4 blitting demo. Thanks to Phil Thompson. Modified Paths: -------------- trunk/matplotlib/CHANGELOG trunk/matplotlib/examples/animation_blit_qt4.py trunk/matplotlib/lib/matplotlib/backends/backend_qt4agg.py Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2007-11-02 13:13:40 UTC (rev 4095) +++ trunk/matplotlib/CHANGELOG 2007-11-02 16:37:37 UTC (rev 4096) @@ -1,3 +1,6 @@ +2007-11-02 Commited Phil Thompson's patch 1599876, fixes to Qt4Agg + backend and qt4 blitting demo - DSD + 2007-10-31 Made log color scale easier to use with contourf; automatic level generation now works. - EF Modified: trunk/matplotlib/examples/animation_blit_qt4.py =================================================================== --- trunk/matplotlib/examples/animation_blit_qt4.py 2007-11-02 13:13:40 UTC (rev 4095) +++ trunk/matplotlib/examples/animation_blit_qt4.py 2007-11-02 16:37:37 UTC (rev 4096) @@ -15,10 +15,14 @@ class BlitQT(QtCore.QObject): def __init__(self): - QtCore.QObject.__init__(self, None) - self.ax = p.subplot(111) self.canvas = self.ax.figure.canvas + + # By making this a child of the canvas we make sure that it is + # destroyed first and avoids a possible exception when the user clicks + # on the window's close box. + QtCore.QObject.__init__(self, self.canvas) + self.cnt = 0 # create the initial line @@ -26,9 +30,14 @@ self.line, = p.plot(self.x, npy.sin(self.x), animated=True, lw=2) self.background = None + self.old_size = 0, 0 def timerEvent(self, evt): - if self.background is None: + # See if the size has changed since last time round. + current_size = self.ax.bbox.width(), self.ax.bbox.height() + + if self.old_size != current_size: + self.old_size = current_size self.background = self.canvas.copy_from_bbox(self.ax.bbox) # restore the clean slate background Modified: trunk/matplotlib/lib/matplotlib/backends/backend_qt4agg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_qt4agg.py 2007-11-02 13:13:40 UTC (rev 4095) +++ trunk/matplotlib/lib/matplotlib/backends/backend_qt4agg.py 2007-11-02 16:37:37 UTC (rev 4096) @@ -6,8 +6,6 @@ import os, sys import matplotlib -from matplotlib import verbose -from matplotlib.cbook import enumerate from matplotlib.figure import Figure from backend_agg import FigureCanvasAgg @@ -61,7 +59,7 @@ self.drawRect = False self.rect = [] self.replot = True - self.pixmap = QtGui.QPixmap() + self.setAttribute(QtCore.Qt.WA_OpaquePaintEvent) def resizeEvent( self, e ): FigureCanvasQT.resizeEvent( self, e ) @@ -86,26 +84,25 @@ # only replot data when needed if type(self.replot) is bool: # might be a bbox for blitting - if ( self.replot ): - #stringBuffer = str( self.buffer_rgba(0,0) ) - FigureCanvasAgg.draw( self ) + if self.replot: + FigureCanvasAgg.draw(self) - # matplotlib is in rgba byte order. - # qImage wants to put the bytes into argb format and - # is in a 4 byte unsigned int. little endian system is LSB first - # and expects the bytes in reverse order (bgra). - if ( QtCore.QSysInfo.ByteOrder == QtCore.QSysInfo.LittleEndian ): - stringBuffer = self.renderer._renderer.tostring_bgra() - else: - stringBuffer = self.renderer._renderer.tostring_argb() - qImage = QtGui.QImage( stringBuffer, self.renderer.width, - self.renderer.height, - QtGui.QImage.Format_ARGB32) - self.pixmap = self.pixmap.fromImage( qImage ) - p.drawPixmap( QtCore.QPoint( 0, 0 ), self.pixmap ) + # matplotlib is in rgba byte order. QImage wants to put the bytes + # into argb format and is in a 4 byte unsigned int. Little endian + # system is LSB first and expects the bytes in reverse order + # (bgra). + if QtCore.QSysInfo.ByteOrder == QtCore.QSysInfo.LittleEndian: + stringBuffer = self.renderer._renderer.tostring_bgra() + else: + stringBuffer = self.renderer._renderer.tostring_argb() + qImage = QtGui.QImage(stringBuffer, self.renderer.width, + self.renderer.height, + QtGui.QImage.Format_ARGB32) + p.drawPixmap(QtCore.QPoint(0, 0), QtGui.QPixmap.fromImage(qImage)) + # draw the zoom rectangle to the QPainter - if ( self.drawRect ): + if self.drawRect: p.setPen( QtGui.QPen( QtCore.Qt.black, 1, QtCore.Qt.DotLine ) ) p.drawRect( self.rect[0], self.rect[1], self.rect[2], self.rect[3] ) @@ -117,8 +114,8 @@ reg = self.copy_from_bbox(bbox) stringBuffer = reg.to_string() qImage = QtGui.QImage(stringBuffer, w, h, QtGui.QImage.Format_ARGB32) - self.pixmap = self.pixmap.fromImage( qImage ) - p.drawPixmap(QtCore.QPoint(l, self.renderer.height-t), self.pixmap) + pixmap = QtGui.QPixmap.fromImage(qImage) + p.drawPixmap(QtCore.QPoint(l, self.renderer.height-t), pixmap) p.end() self.replot = False This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |