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 = {}
for k in smiledict:
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):
movie = QtGui.QMovie(self)
movie.setFileName(fileName)
@ -233,7 +235,7 @@ class PesterText(QtGui.QTextEdit):
self.urls[movie] = url
self.connect(movie, QtCore.SIGNAL('frameChanged(int)'),
self, QtCore.SLOT('animate(int)'))
movie.start()
#movie.start()
@QtCore.pyqtSlot(int)
def animate(self, frame):
if self.mainwindow.config.animations():
@ -244,7 +246,20 @@ class PesterText(QtGui.QTextEdit):
self.document().addResource(QtGui.QTextDocument.ImageResource,
self.urls[movie], movie.currentPixmap())
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)
def textReady(self, ready):
@ -263,6 +278,11 @@ class PesterText(QtGui.QTextEdit):
parent = self.parent()
window = parent.mainwindow
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.time12Format():
time = strftime("[%I:%M")

View file

@ -739,9 +739,9 @@ class chumArea(RightClickTree):
# create mime data object
mime = QtCore.QMimeData()
mime.setData('application/x-item', '???')
# start drag
# start drag
drag = QtGui.QDrag(self)
drag.setMimeData(mime)
drag.setMimeData(mime)
drag.start(QtCore.Qt.MoveAction)
def dragMoveEvent(self, event):
@ -755,7 +755,7 @@ class chumArea(RightClickTree):
if (event.mimeData().hasFormat('application/x-item')):
event.accept()
else:
event.ignore()
event.ignore()
def dropEvent(self, event):
if (event.mimeData().hasFormat('application/x-item')):
@ -2627,6 +2627,7 @@ class PesterWindow(MovingWindow):
curanimate = self.config.animations()
if animatesetting != curanimate:
self.config.set('animations', animatesetting)
self.animationSetting.emit(animatesetting)
# update checked
updatechecksetting = self.optionmenu.updatecheck.isChecked()
curupdatecheck = self.config.checkForUpdates()
@ -2817,6 +2818,7 @@ class PesterWindow(MovingWindow):
sendNotice = QtCore.pyqtSignal(QtCore.QString, QtCore.QString)
convoClosed = QtCore.pyqtSignal(QtCore.QString)
profileChanged = QtCore.pyqtSignal()
animationSetting = QtCore.pyqtSignal(bool)
moodRequest = QtCore.pyqtSignal(PesterProfile)
moodsRequest = QtCore.pyqtSignal(PesterList)
moodUpdated = QtCore.pyqtSignal()