Fixed smiley-related file descriptor/handle leak ( hopefully. . . . ;w; )

This commit is contained in:
Dpeta 2022-03-23 05:10:06 +01:00
parent f43394b4af
commit a82d460da4
3 changed files with 19 additions and 11 deletions

View file

@ -324,6 +324,7 @@ class PesterMovie(QtGui.QMovie):
text.urls[movie], movie.currentPixmap())
text.setLineWrapColumnOrWidth(text.lineWrapColumnOrWidth())
class PesterText(QtWidgets.QTextEdit):
def __init__(self, theme, parent=None):
super(PesterText, self).__init__(parent)
@ -344,17 +345,25 @@ class PesterText(QtWidgets.QTextEdit):
self.urls = {}
for k in smiledict:
self.addAnimation(QtCore.QUrl("smilies/%s" % (smiledict[k])), "smilies/%s" % (smiledict[k]))
self.mainwindow.animationSetting[bool].connect(self.animateChanged)
#self.mainwindow.animationSetting[bool].connect(self.animateChanged)
def addAnimation(self, url, fileName):
# We don't need to treat images formats like .png as animation,
# this always opens a file handler otherwise, "movie.frameCount() > 1" isn't sufficient.
# Might be useful to use QImageReader's supportsAnimation function for this?
# As long as we're only using gifs there's no advantage to that though.
if not fileName.endswith(".gif"):
return
movie = PesterMovie(self)
movie.setFileName(fileName)
movie.setCacheMode(QtGui.QMovie.CacheAll)
if movie.frameCount() > 1:
self.urls[movie] = url
movie.frameChanged[int].connect(movie.animate)
#movie.start()
"""
@QtCore.pyqtSlot(bool)
def animateChanged(self, animate):
PchumLog.warning("aaa")
if animate:
for m in self.urls:
html = str(self.toHtml())
@ -367,6 +376,7 @@ class PesterText(QtWidgets.QTextEdit):
if html.find(self.urls[m].toString()) != -1:
if m.frameCount() > 1:
m.stop()
"""
@QtCore.pyqtSlot(bool)
def textReady(self, ready):
@ -807,6 +817,7 @@ class PesterConvo(QtWidgets.QFrame):
def closeEvent(self, event):
self.mainwindow.waitingMessages.messageAnswered(self.title())
for movie in self.textArea.urls:
movie.setFileName("") # Required, sometimes, for some reason. . .
movie.stop()
del movie
self.windowClosed.emit(self.title())

View file

@ -278,7 +278,7 @@ class MemoText(PesterText):
self.urls = {}
for k in smiledict:
self.addAnimation(QtCore.QUrl("smilies/%s" % (smiledict[k])), "smilies/%s" % (smiledict[k]))
self.mainwindow.animationSetting[bool].connect(self.animateChanged)
#self.mainwindow.animationSetting[bool].connect(self.animateChanged)
def initTheme(self, theme):
if "memos/scrollbar" in theme:

View file

@ -2865,9 +2865,6 @@ class PesterWindow(MovingWindow):
if opvmesssetting != curopvmess:
self.config.set('opvMessages', opvmesssetting)
# animated smiles
if ostools.isOSXBundle():
animatesetting = False;
else:
animatesetting = self.optionmenu.animationscheck.isChecked()
curanimate = self.config.animations()
if animatesetting != curanimate: