Start and stop QMovie objects when enabling/disabling animations. Hopefully cuts down on memory leak a bit

This commit is contained in:
Kiooeht 2011-06-13 23:00:51 -07:00
parent 98d84e7e85
commit 36392ce85a
2 changed files with 27 additions and 5 deletions

View file

@ -226,6 +226,8 @@ class PesterText(QtGui.QTextEdit):
self.urls = {} self.urls = {}
for k in smiledict: for k in smiledict:
self.addAnimation(QtCore.QUrl("smilies/%s" % (smiledict[k])), "smilies/%s" % (smiledict[k])) self.addAnimation(QtCore.QUrl("smilies/%s" % (smiledict[k])), "smilies/%s" % (smiledict[k]))
self.connect(self.mainwindow, QtCore.SIGNAL('animationSetting(bool)'),
self, QtCore.SLOT('animateChanged(bool)'))
def addAnimation(self, url, fileName): def addAnimation(self, url, fileName):
movie = QtGui.QMovie(self) movie = QtGui.QMovie(self)
movie.setFileName(fileName) movie.setFileName(fileName)
@ -233,7 +235,7 @@ class PesterText(QtGui.QTextEdit):
self.urls[movie] = url self.urls[movie] = url
self.connect(movie, QtCore.SIGNAL('frameChanged(int)'), self.connect(movie, QtCore.SIGNAL('frameChanged(int)'),
self, QtCore.SLOT('animate(int)')) self, QtCore.SLOT('animate(int)'))
movie.start() #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():
@ -244,7 +246,20 @@ class PesterText(QtGui.QTextEdit):
self.document().addResource(QtGui.QTextDocument.ImageResource, self.document().addResource(QtGui.QTextDocument.ImageResource,
self.urls[movie], movie.currentPixmap()) self.urls[movie], movie.currentPixmap())
self.setLineWrapColumnOrWidth(self.lineWrapColumnOrWidth()) self.setLineWrapColumnOrWidth(self.lineWrapColumnOrWidth())
@QtCore.pyqtSlot(bool)
def animateChanged(self, animate):
if animate:
for m in self.urls:
html = unicode(self.toHtml())
if html.find(self.urls[m].toString()) != -1:
if movie.frameCount() > 1:
m.start()
else:
for m in self.urls:
html = unicode(self.toHtml())
if html.find(self.urls[m].toString()) != -1:
if movie.frameCount() > 1:
m.stop()
@QtCore.pyqtSlot(bool) @QtCore.pyqtSlot(bool)
def textReady(self, ready): def textReady(self, ready):
@ -263,6 +278,11 @@ class PesterText(QtGui.QTextEdit):
parent = self.parent() parent = self.parent()
window = parent.mainwindow window = parent.mainwindow
me = window.profile() me = window.profile()
if self.mainwindow.config.animations():
for m in self.urls:
if convertTags(lexmsg).find(self.urls[m].toString()) != -1:
if m.state() == QtGui.QMovie.NotRunning:
m.start()
if self.parent().mainwindow.config.showTimeStamps(): if self.parent().mainwindow.config.showTimeStamps():
if self.parent().mainwindow.config.time12Format(): if self.parent().mainwindow.config.time12Format():
time = strftime("[%I:%M") time = strftime("[%I:%M")

View file

@ -2627,6 +2627,7 @@ class PesterWindow(MovingWindow):
curanimate = self.config.animations() curanimate = self.config.animations()
if animatesetting != curanimate: if animatesetting != curanimate:
self.config.set('animations', animatesetting) self.config.set('animations', animatesetting)
self.animationSetting.emit(animatesetting)
# update checked # update checked
updatechecksetting = self.optionmenu.updatecheck.isChecked() updatechecksetting = self.optionmenu.updatecheck.isChecked()
curupdatecheck = self.config.checkForUpdates() curupdatecheck = self.config.checkForUpdates()
@ -2817,6 +2818,7 @@ class PesterWindow(MovingWindow):
sendNotice = QtCore.pyqtSignal(QtCore.QString, QtCore.QString) sendNotice = QtCore.pyqtSignal(QtCore.QString, QtCore.QString)
convoClosed = QtCore.pyqtSignal(QtCore.QString) convoClosed = QtCore.pyqtSignal(QtCore.QString)
profileChanged = QtCore.pyqtSignal() profileChanged = QtCore.pyqtSignal()
animationSetting = QtCore.pyqtSignal(bool)
moodRequest = QtCore.pyqtSignal(PesterProfile) moodRequest = QtCore.pyqtSignal(PesterProfile)
moodsRequest = QtCore.pyqtSignal(PesterList) moodsRequest = QtCore.pyqtSignal(PesterList)
moodUpdated = QtCore.pyqtSignal() moodUpdated = QtCore.pyqtSignal()