From 36392ce85a2162d84f790465e091c2ea985bea23 Mon Sep 17 00:00:00 2001 From: Kiooeht Date: Mon, 13 Jun 2011 23:00:51 -0700 Subject: [PATCH] Start and stop QMovie objects when enabling/disabling animations. Hopefully cuts down on memory leak a bit --- convo.py | 24 ++++++++++++++++++++++-- pesterchum.py | 8 +++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/convo.py b/convo.py index 375528d..c221a1e 100644 --- a/convo.py +++ b/convo.py @@ -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") diff --git a/pesterchum.py b/pesterchum.py index a1d4dda..53bac1b 100644 --- a/pesterchum.py +++ b/pesterchum.py @@ -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()