Don't animate smilies that aren't animated.

Revert back to animation memory leak (didn't slow down as much) but now with slightly less memory leak.
This commit is contained in:
Kiooeht 2011-05-18 21:38:30 -07:00
parent c6342f5305
commit 5228d35f9a

View file

@ -229,30 +229,21 @@ class PesterText(QtGui.QTextEdit):
def addAnimation(self, url, fileName): def addAnimation(self, url, fileName):
movie = QtGui.QMovie(self) movie = QtGui.QMovie(self)
movie.setFileName(fileName) movie.setFileName(fileName)
self.urls[movie] = url if movie.frameCount() > 1:
self.urls[movie] = url
for f in range(movie.frameCount()): self.connect(movie, QtCore.SIGNAL('frameChanged(int)'),
yes = movie.jumpToFrame(f) self, QtCore.SLOT('animate(int)'))
if yes: movie.start()
url = "%s_%s" % (self.urls[movie].toString(), f)
self.document().addResource(QtGui.QTextDocument.ImageResource,
QtCore.QUrl(url), movie.currentPixmap())
self.connect(movie, QtCore.SIGNAL('frameChanged(int)'),
self, QtCore.SLOT('animate(int)'))
movie.start()
@QtCore.pyqtSlot(int) @QtCore.pyqtSlot(int)
def animate(self, frame): def animate(self, frame):
if self.mainwindow.config.animations(): if self.mainwindow.config.animations():
scrollPos = self.verticalScrollBar().sliderPosition()
movie = self.sender() movie = self.sender()
url = self.urls[movie].toString() url = self.urls[movie].toString()
def stuff(mo): html = unicode(self.toHtml())
return '<img src="%s_%s" />' % (url, frame) if html.find(url) != -1:
html = re.sub(r'<img src="%s\S{0,3}" />' % (url), stuff, unicode(self.toHtml())) self.document().addResource(QtGui.QTextDocument.ImageResource,
self.setHtml(html) self.urls[movie], movie.currentPixmap())
self.setLineWrapColumnOrWidth(self.lineWrapColumnOrWidth()) self.setLineWrapColumnOrWidth(self.lineWrapColumnOrWidth())
self.verticalScrollBar().setSliderPosition(scrollPos)
@QtCore.pyqtSlot(bool) @QtCore.pyqtSlot(bool)