Use a single icon worker thread.
Spawning a lot of threads tends to be inefficient and they often get serialized, so have a single thread that always looks at the latest path only.
This commit is contained in:
parent
c23fe6ad8f
commit
f06a1dc18a
@ -32,6 +32,39 @@ class GuiConfiguration:
|
|||||||
class WindowClosed(Exception):
|
class WindowClosed(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class GetPlayerIconThread(threading.Thread, QtCore.QObject):
|
||||||
|
daemon = True
|
||||||
|
done = QtCore.Signal(str, str)
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
threading.Thread.__init__(self, name='GetPlayerIcon')
|
||||||
|
QtCore.QObject.__init__(self)
|
||||||
|
self.condvar = threading.Condition()
|
||||||
|
self.playerpath = None
|
||||||
|
|
||||||
|
def setPlayerPath(self, playerpath):
|
||||||
|
self.condvar.acquire()
|
||||||
|
was_none = self.playerpath is None
|
||||||
|
self.playerpath = playerpath
|
||||||
|
if was_none:
|
||||||
|
self.condvar.notify()
|
||||||
|
self.condvar.release()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
while True:
|
||||||
|
self.condvar.acquire()
|
||||||
|
if self.playerpath is None:
|
||||||
|
self.condvar.wait()
|
||||||
|
playerpath = self.playerpath
|
||||||
|
self.playerpath = None
|
||||||
|
self.condvar.release()
|
||||||
|
|
||||||
|
self.done.emit('spinner.mng', '')
|
||||||
|
iconpath = PlayerFactory().getPlayerIconByPath(playerpath)
|
||||||
|
self.done.emit(iconpath, playerpath)
|
||||||
|
|
||||||
|
|
||||||
class ConfigDialog(QtGui.QDialog):
|
class ConfigDialog(QtGui.QDialog):
|
||||||
|
|
||||||
pressedclosebutton = False
|
pressedclosebutton = False
|
||||||
@ -141,25 +174,9 @@ class ConfigDialog(QtGui.QDialog):
|
|||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
return foundpath
|
return foundpath
|
||||||
|
|
||||||
class _GetIconPath(threading.Thread, QtCore.QObject):
|
@QtCore.Slot(str, str)
|
||||||
daemon = True
|
def _updateExecutableIcon(self, iconpath, playerpath):
|
||||||
done = QtCore.Signal(int, str, str)
|
if iconpath is not None and iconpath != "":
|
||||||
|
|
||||||
def __init__(self, playerpath, seqnum):
|
|
||||||
threading.Thread.__init__(self)
|
|
||||||
QtCore.QObject.__init__(self)
|
|
||||||
self.playerpath = playerpath
|
|
||||||
self.seqnum = seqnum
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
iconpath = PlayerFactory().getPlayerIconByPath(self.playerpath)
|
|
||||||
self.done.emit(self.seqnum, iconpath, self.playerpath)
|
|
||||||
|
|
||||||
@QtCore.Slot(int, str, str)
|
|
||||||
def _updateExecutableIcon(self, seqnum, iconpath, playerpath):
|
|
||||||
if seqnum < self._lastThreadSeqnum:
|
|
||||||
return
|
|
||||||
if iconpath != None and iconpath != "":
|
|
||||||
if iconpath.endswith('.mng'):
|
if iconpath.endswith('.mng'):
|
||||||
movie = QtGui.QMovie(self.resourcespath + iconpath)
|
movie = QtGui.QMovie(self.resourcespath + iconpath)
|
||||||
movie.setCacheMode(QtGui.QMovie.CacheMode.CacheAll)
|
movie.setCacheMode(QtGui.QMovie.CacheMode.CacheAll)
|
||||||
@ -182,11 +199,7 @@ class ConfigDialog(QtGui.QDialog):
|
|||||||
so.
|
so.
|
||||||
"""
|
"""
|
||||||
currentplayerpath = unicode(self.executablepathCombobox.currentText())
|
currentplayerpath = unicode(self.executablepathCombobox.currentText())
|
||||||
self._lastThreadSeqnum += 1
|
self._playerProbeThread.setPlayerPath(currentplayerpath)
|
||||||
thread = self._GetIconPath(currentplayerpath, self._lastThreadSeqnum)
|
|
||||||
thread.done.connect(self._updateExecutableIcon)
|
|
||||||
thread.done.emit(self._lastThreadSeqnum, 'spinner.mng', '')
|
|
||||||
thread.start()
|
|
||||||
|
|
||||||
def updatePlayerArguments(self, currentplayerpath):
|
def updatePlayerArguments(self, currentplayerpath):
|
||||||
argumentsForPath = utils.getPlayerArgumentsByPathAsText(self.perPlayerArgs, currentplayerpath)
|
argumentsForPath = utils.getPlayerArgumentsByPathAsText(self.perPlayerArgs, currentplayerpath)
|
||||||
@ -972,6 +985,10 @@ class ConfigDialog(QtGui.QDialog):
|
|||||||
self.subitems = {}
|
self.subitems = {}
|
||||||
self.publicServers = None
|
self.publicServers = None
|
||||||
|
|
||||||
|
self._playerProbeThread = GetPlayerIconThread()
|
||||||
|
self._playerProbeThread.done.connect(self._updateExecutableIcon)
|
||||||
|
self._playerProbeThread.start()
|
||||||
|
|
||||||
if self.config['clearGUIData'] == True:
|
if self.config['clearGUIData'] == True:
|
||||||
self.config['clearGUIData'] = False
|
self.config['clearGUIData'] = False
|
||||||
self.clearGUIData()
|
self.clearGUIData()
|
||||||
@ -1035,4 +1052,4 @@ class ConfigDialog(QtGui.QDialog):
|
|||||||
self.processWidget(self, lambda w: self.loadTooltips(w))
|
self.processWidget(self, lambda w: self.loadTooltips(w))
|
||||||
self.processWidget(self, lambda w: self.loadValues(w))
|
self.processWidget(self, lambda w: self.loadValues(w))
|
||||||
self.processWidget(self, lambda w: self.connectChildren(w))
|
self.processWidget(self, lambda w: self.connectChildren(w))
|
||||||
self.populateEmptyServerList()
|
self.populateEmptyServerList()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user