Copyright © 2017 Syncplay
" + getMessage("about-dialog-license-text") + "
")
aboutIconPixmap = QtGui.QPixmap(resourcespath + u"syncplay.png")
aboutIconLabel = QtWidgets.QLabel()
- aboutIconLabel.setPixmap(aboutIconPixmap.scaled(120, 120, Qt.KeepAspectRatio))
+ aboutIconLabel.setPixmap(aboutIconPixmap.scaled(120, 120, Qt.KeepAspectRatio))
aboutLayout = QtWidgets.QGridLayout()
aboutLayout.addWidget(aboutIconLabel, 0, 0, 4, 2)
aboutLayout.addWidget(nameLabel, 0, 2, 1, 2)
@@ -115,22 +131,22 @@ class AboutDialog(QtWidgets.QDialog):
dependenciesButton = QtWidgets.QPushButton(getMessage("about-dialog-dependencies"))
dependenciesButton.setAutoDefault(False)
dependenciesButton.clicked.connect(self.openDependencies)
- aboutLayout.addWidget(dependenciesButton, 4, 3)
+ aboutLayout.addWidget(dependenciesButton, 4, 3)
aboutLayout.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
- self.setSizeGripEnabled(False)
+ self.setSizeGripEnabled(False)
self.setLayout(aboutLayout)
- def openLicense(self):
- if isWindows():
- QtGui.QDesktopServices.openUrl(QUrl("file:///" + resourcespath + u"license.rtf"))
- else:
- QtGui.QDesktopServices.openUrl(QUrl("file://" + resourcespath + u"license.rtf"))
+ def openLicense(self):
+ if isWindows():
+ QtGui.QDesktopServices.openUrl(QUrl("file:///" + resourcespath + u"license.rtf"))
+ else:
+ QtGui.QDesktopServices.openUrl(QUrl("file://" + resourcespath + u"license.rtf"))
- def openDependencies(self):
+ def openDependencies(self):
if isWindows():
- QtGui.QDesktopServices.openUrl(QUrl("file:///" + resourcespath + u"third-party-notices.rtf"))
+ QtGui.QDesktopServices.openUrl(QUrl("file:///" + resourcespath + u"third-party-notices.rtf"))
else:
- QtGui.QDesktopServices.openUrl(QUrl("file://" + resourcespath + u"third-party-notices.rtf"))
+ QtGui.QDesktopServices.openUrl(QUrl("file://" + resourcespath + u"third-party-notices.rtf"))
class MainWindow(QtWidgets.QMainWindow):
insertPosition = None
@@ -347,6 +363,8 @@ class MainWindow(QtWidgets.QMainWindow):
def addClient(self, client):
self._syncplayClient = client
+ if self.console:
+ self.console.addClient(client)
self.roomInput.setText(self._syncplayClient.getRoom())
self.config = self._syncplayClient.getConfig()
try:
@@ -385,6 +403,8 @@ class MainWindow(QtWidgets.QMainWindow):
self.chatInput.setReadOnly(True)
if not featureList["sharedPlaylists"]:
self.playlistGroup.setEnabled(False)
+ self.chatInput.setMaxLength(constants.MAX_CHAT_MESSAGE_LENGTH)
+ self.roomInput.setMaxLength(constants.MAX_ROOM_NAME_LENGTH)
def showMessage(self, message, noTimestamp=False):
message = unicode(message)
@@ -1126,10 +1146,22 @@ class MainWindow(QtWidgets.QMainWindow):
self._syncplayClient.playlist.changePlaylist(newPlaylist)
self._syncplayClient.fileSwitch.updateInfo()
+ def executeCommand(self, command):
+ self.showMessage(u"/{}".format(command))
+ self.console.executeCommand(command)
+
def sendChatMessage(self):
- if self.chatInput.text() <> "":
- self._syncplayClient.sendChat(self.chatInput.text())
- self.chatInput.setText("")
+ chatText = self.chatInput.text()
+ self.chatInput.setText("")
+ if chatText <> "":
+ if chatText[:1] == "/" and chatText <> "/":
+ command = chatText[1:]
+ if command and command[:1] == "/":
+ chatText = chatText[1:]
+ else:
+ self.executeCommand(command)
+ return
+ self._syncplayClient.sendChat(chatText)
def addTopLayout(self, window):
window.topSplit = self.topSplitter(Qt.Horizontal, self)
@@ -1705,6 +1737,8 @@ class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
+ self.console = ConsoleInGUI()
+ self.console.setDaemon(True)
self.newWatchlist = []
self.publicServerList = []
self.lastCheckedForUpdates = None
diff --git a/syncplay/utils.py b/syncplay/utils.py
index 402a44d..72fa947 100644
--- a/syncplay/utils.py
+++ b/syncplay/utils.py
@@ -130,6 +130,13 @@ def formatSize (bytes, precise=False):
def isASCII(s):
return all(ord(c) < 128 for c in s)
+def findResourcePath(resourceName):
+ if resourceName == "syncplay.lua":
+ resourcePath = os.path.join(findWorkingDir(), "lua", "intf" , "resources", resourceName)
+ else:
+ resourcePath = os.path.join(findWorkingDir(),"resources", resourceName)
+ return resourcePath
+
def findWorkingDir():
frozen = getattr(sys, 'frozen', '')
if not frozen:
@@ -152,6 +159,14 @@ def getResourcesPath():
resourcespath = getResourcesPath()
posixresourcespath = findWorkingDir().replace(u"\\","/") + u"/resources/"
+def getDefaultMonospaceFont():
+ if platform.system() == "Windows":
+ return constants.DEFAULT_WINDOWS_MONOSPACE_FONT
+ elif platform.system() == "Darwin":
+ return constants.DEFAULT_OSX_MONOSPACE_FONT
+ else:
+ return constants.FALLBACK_MONOSPACE_FONT
+
def limitedPowerset(s, minLength):
return itertools.chain.from_iterable(itertools.combinations(s, r) for r in xrange(len(s), minLength, -1))
@@ -189,20 +204,28 @@ def blackholeStdoutForFrozenWindow():
def truncateText(unicodeText, maxLength):
try:
- unicodeText = unicodedata.normalize('NFC', unicodeText)
+ unicodeText = unicodeText.decode('utf-8')
except:
pass
try:
- maxSaneLength= maxLength*5
- if len(unicodeText) > maxSaneLength:
- unicodeText = unicode(unicodeText.encode("utf-8")[:maxSaneLength], "utf-8", errors="ignore")
- while len(unicodeText) > maxLength:
- unicodeText = unicode(unicodeText.encode("utf-8")[:-1], "utf-8", errors="ignore")
- return unicodeText
+ return(unicode(unicodeText.encode("utf-8"), "utf-8", errors="ignore")[:maxLength])
except:
pass
return ""
+def splitText(unicodeText, maxLength):
+ try:
+ unicodeText = unicodeText.decode('utf-8')
+ except:
+ pass
+ try:
+ unicodeText = unicode(unicodeText.encode("utf-8"), "utf-8", errors="ignore")
+ unicodeArray = [unicodeText[i:i + maxLength] for i in range(0, len(unicodeText), maxLength)]
+ return(unicodeArray)
+ except:
+ pass
+ return [""]
+
# Relate to file hashing / difference checking:
def stripfilename(filename, stripURL):