mirror of
https://github.com/Syncplay/syncplay
synced 2024-12-16 11:55:11 +00:00
Merge pull request #78 from tari/playerpath-background
Probe player paths in a non-UI thread
This commit is contained in:
commit
af526177e7
@ -654,7 +654,8 @@ guiIcons = ['resources/accept.png', 'resources/arrow_undo.png', 'resources/clock
|
|||||||
'resources/user_key.png', 'resources/lock.png', 'resources/key_go.png', 'resources/page_white_key.png',
|
'resources/user_key.png', 'resources/lock.png', 'resources/key_go.png', 'resources/page_white_key.png',
|
||||||
'resources/tick.png', 'resources/lock_open.png', 'resources/empty_checkbox.png', 'resources/tick_checkbox.png',
|
'resources/tick.png', 'resources/lock_open.png', 'resources/empty_checkbox.png', 'resources/tick_checkbox.png',
|
||||||
'resources/world_explore.png', 'resources/application_get.png', 'resources/cog.png',
|
'resources/world_explore.png', 'resources/application_get.png', 'resources/cog.png',
|
||||||
'resources/film_go.png', 'resources/world_go.png', 'resources/arrow_refresh.png'
|
'resources/film_go.png', 'resources/world_go.png',
|
||||||
|
'resources/arrow_refresh.png', 'resources/spinner.mng'
|
||||||
]
|
]
|
||||||
resources = ["resources/icon.ico", "resources/syncplay.png"]
|
resources = ["resources/icon.ico", "resources/syncplay.png"]
|
||||||
resources.extend(guiIcons)
|
resources.extend(guiIcons)
|
||||||
|
BIN
resources/spinner.mng
Executable file
BIN
resources/spinner.mng
Executable file
Binary file not shown.
@ -6,6 +6,7 @@ from datetime import datetime
|
|||||||
from syncplay import utils
|
from syncplay import utils
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import threading
|
||||||
from syncplay.messages import getMessage, getLanguages, setLanguage, getInitialLanguage
|
from syncplay.messages import getMessage, getLanguages, setLanguage, getInitialLanguage
|
||||||
from syncplay import constants
|
from syncplay import constants
|
||||||
|
|
||||||
@ -31,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
|
||||||
@ -140,15 +174,32 @@ class ConfigDialog(QtGui.QDialog):
|
|||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
return foundpath
|
return foundpath
|
||||||
|
|
||||||
def updateExecutableIcon(self):
|
@QtCore.Slot(str, str)
|
||||||
currentplayerpath = unicode(self.executablepathCombobox.currentText())
|
def _updateExecutableIcon(self, iconpath, playerpath):
|
||||||
iconpath = PlayerFactory().getPlayerIconByPath(currentplayerpath)
|
if iconpath is not None and iconpath != "":
|
||||||
if iconpath != None and iconpath != "":
|
if iconpath.endswith('.mng'):
|
||||||
self.executableiconImage.load(self.resourcespath + iconpath)
|
movie = QtGui.QMovie(self.resourcespath + iconpath)
|
||||||
self.executableiconLabel.setPixmap(QtGui.QPixmap.fromImage(self.executableiconImage))
|
movie.setCacheMode(QtGui.QMovie.CacheMode.CacheAll)
|
||||||
|
self.executableiconLabel.setMovie(movie)
|
||||||
|
movie.start()
|
||||||
|
else:
|
||||||
|
self.executableiconImage.load(self.resourcespath + iconpath)
|
||||||
|
self.executableiconLabel.setPixmap(QtGui.QPixmap.fromImage(self.executableiconImage))
|
||||||
else:
|
else:
|
||||||
self.executableiconLabel.setPixmap(QtGui.QPixmap.fromImage(QtGui.QImage()))
|
self.executableiconLabel.setPixmap(QtGui.QPixmap.fromImage(QtGui.QImage()))
|
||||||
self.updatePlayerArguments(currentplayerpath)
|
self.updatePlayerArguments(playerpath)
|
||||||
|
|
||||||
|
def updateExecutableIcon(self):
|
||||||
|
"""
|
||||||
|
Start getting the icon path in another thread, which will set the GUI
|
||||||
|
icon if valid.
|
||||||
|
|
||||||
|
This is performed outside the main thread because networked players may
|
||||||
|
take a long time to perform their checks and hang the GUI while doing
|
||||||
|
so.
|
||||||
|
"""
|
||||||
|
currentplayerpath = unicode(self.executablepathCombobox.currentText())
|
||||||
|
self._playerProbeThread.setPlayerPath(currentplayerpath)
|
||||||
|
|
||||||
def updatePlayerArguments(self, currentplayerpath):
|
def updatePlayerArguments(self, currentplayerpath):
|
||||||
argumentsForPath = utils.getPlayerArgumentsByPathAsText(self.perPlayerArgs, currentplayerpath)
|
argumentsForPath = utils.getPlayerArgumentsByPathAsText(self.perPlayerArgs, currentplayerpath)
|
||||||
@ -924,7 +975,6 @@ class ConfigDialog(QtGui.QDialog):
|
|||||||
self.hostCombobox.setEditText(currentServer)
|
self.hostCombobox.setEditText(currentServer)
|
||||||
|
|
||||||
def __init__(self, config, playerpaths, error, defaultConfig):
|
def __init__(self, config, playerpaths, error, defaultConfig):
|
||||||
|
|
||||||
self.config = config
|
self.config = config
|
||||||
self.defaultConfig = defaultConfig
|
self.defaultConfig = defaultConfig
|
||||||
self.playerpaths = playerpaths
|
self.playerpaths = playerpaths
|
||||||
@ -933,6 +983,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()
|
||||||
|
Loading…
Reference in New Issue
Block a user