Ported GUI to PySide 2

This commit is contained in:
alby128 2017-09-07 19:37:03 +02:00
parent 65e51c201d
commit 89b4df7a4a
7 changed files with 456 additions and 375 deletions

32
buildPy2app.py Normal file
View File

@ -0,0 +1,32 @@
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
from glob import glob
import syncplay
APP = ['syncplayClient.py']
DATA_FILES = [
('resources', glob('resources/*.png')),
]
OPTIONS = {
'iconfile':'resources/icon.icns',
'plist': {
'CFBundleName':'Syncplay',
'CFBundleShortVersionString':syncplay.version,
'CFBundleIdentifier':'pl.syncplay.Syncplay',
'NSHumanReadableCopyright': '@ 2017 Syncplay All Rights Reserved'
}
}
setup(
app=APP,
name='Syncplay',
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)

BIN
resources/icon.icns Normal file

Binary file not shown.

View File

@ -401,15 +401,15 @@ class ConfigurationGetter(object):
self._overrideConfigWithArgs(args) self._overrideConfigWithArgs(args)
if not self._config['noGui']: if not self._config['noGui']:
try: try:
from PySide import QtGui # @UnresolvedImport from PySide2 import QtWidgets
from PySide.QtCore import QCoreApplication from PySide2.QtCore import QCoreApplication
from syncplay.vendor import qt4reactor from syncplay.vendor import qt5reactor
if QCoreApplication.instance() is None: if QCoreApplication.instance() is None:
self.app = QtGui.QApplication(sys.argv) self.app = QtWidgets.QApplication(sys.argv)
qt4reactor.install() qt5reactor.install()
if sys.platform.startswith('darwin'): if sys.platform.startswith('darwin'):
import appnope import appnope
appnope.nope() appnope.nope()
except ImportError: except ImportError:
print getMessage("unable-import-gui-error") print getMessage("unable-import-gui-error")
self._config['noGui'] = True self._config['noGui'] = True

View File

@ -1,6 +1,7 @@
from PySide import QtCore, QtGui from PySide2 import QtCore, QtWidgets, QtGui
from PySide.QtCore import QSettings, Qt, QCoreApplication, QUrl from PySide2.QtCore import Qt, QSettings, QCoreApplication, QSize, QPoint, QUrl, QLine
from PySide.QtGui import QApplication, QLineEdit, QCursor, QLabel, QCheckBox, QDesktopServices, QIcon, QImage, QButtonGroup, QRadioButton, QDoubleSpinBox, QPlainTextEdit from PySide2.QtWidgets import QApplication, QLineEdit, QLabel, QCheckBox, QButtonGroup, QRadioButton, QDoubleSpinBox, QPlainTextEdit
from PySide2.QtGui import QCursor, QIcon, QImage, QDesktopServices
from syncplay.players.playerFactory import PlayerFactory from syncplay.players.playerFactory import PlayerFactory
from datetime import datetime from datetime import datetime
from syncplay import utils from syncplay import utils
@ -19,7 +20,7 @@ class GuiConfiguration:
def run(self): def run(self):
if QCoreApplication.instance() is None: if QCoreApplication.instance() is None:
self.app = QtGui.QApplication(sys.argv) self.app = QtWidgets.QApplication(sys.argv)
dialog = ConfigDialog(self.config, self._availablePlayerPaths, self.error, self.defaultConfig) dialog = ConfigDialog(self.config, self._availablePlayerPaths, self.error, self.defaultConfig)
dialog.exec_() dialog.exec_()
@ -65,22 +66,22 @@ class GetPlayerIconThread(threading.Thread, QtCore.QObject):
self.done.emit(iconpath, playerpath) self.done.emit(iconpath, playerpath)
class ConfigDialog(QtGui.QDialog): class ConfigDialog(QtWidgets.QDialog):
pressedclosebutton = True pressedclosebutton = True
moreToggling = False moreToggling = False
def automaticUpdatePromptCheck(self): def automaticUpdatePromptCheck(self):
if self.automaticupdatesCheckbox.checkState() == Qt.PartiallyChecked: if self.automaticupdatesCheckbox.checkState() == Qt.PartiallyChecked:
reply = QtGui.QMessageBox.question(self, "Syncplay", reply = QtWidgets.QMessageBox.question(self, "Syncplay",
getMessage("promptforupdate-label"), QtGui.QMessageBox.StandardButton.Yes | QtGui.QMessageBox.StandardButton.No) getMessage("promptforupdate-label"), QtWidgets.QMessageBox.StandardButton.Yes | QtWidgets.QMessageBox.StandardButton.No)
if reply == QtGui.QMessageBox.Yes: if reply == QtWidgets.QMessageBox.Yes:
self.automaticupdatesCheckbox.setChecked(True) self.automaticupdatesCheckbox.setChecked(True)
else: else:
self.automaticupdatesCheckbox.setChecked(False) self.automaticupdatesCheckbox.setChecked(False)
def moreToggled(self): def moreToggled(self):
self.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) self.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
if self.moreToggling == False: if self.moreToggling == False:
self.moreToggling = True self.moreToggling = True
@ -113,7 +114,7 @@ class ConfigDialog(QtGui.QDialog):
self.executablepathCombobox.setFixedWidth(self.mediapathTextbox.width()) self.executablepathCombobox.setFixedWidth(self.mediapathTextbox.width())
def openHelp(self): def openHelp(self):
self.QtGui.QDesktopServices.openUrl(QUrl("http://syncplay.pl/guide/client/")) self.QtWidgets.QDesktopServices.openUrl(QUrl("http://syncplay.pl/guide/client/"))
def safenormcaseandpath(self, path): def safenormcaseandpath(self, path):
if utils.isURL(path): if utils.isURL(path):
@ -210,10 +211,10 @@ class ConfigDialog(QtGui.QDialog):
def languageChanged(self): def languageChanged(self):
setLanguage(unicode(self.languageCombobox.itemData(self.languageCombobox.currentIndex()))) setLanguage(unicode(self.languageCombobox.itemData(self.languageCombobox.currentIndex())))
QtGui.QMessageBox.information(self, "Syncplay", getMessage("language-changed-msgbox-label")) QtWidgets.QMessageBox.information(self, "Syncplay", getMessage("language-changed-msgbox-label"))
def browsePlayerpath(self): def browsePlayerpath(self):
options = QtGui.QFileDialog.Options() options = QtWidgets.QFileDialog.Options()
defaultdirectory = "" defaultdirectory = ""
browserfilter = "All files (*)" browserfilter = "All files (*)"
@ -232,7 +233,7 @@ class ConfigDialog(QtGui.QDialog):
elif "bsd" in sys.platform or sys.platform.startswith('dragonfly'): elif "bsd" in sys.platform or sys.platform.startswith('dragonfly'):
defaultdirectory = "/usr/local/bin" defaultdirectory = "/usr/local/bin"
fileName, filtr = QtGui.QFileDialog.getOpenFileName(self, fileName, filtr = QtWidgets.QFileDialog.getOpenFileName(self,
"Browse for media player executable", "Browse for media player executable",
defaultdirectory, defaultdirectory,
browserfilter, "", options) browserfilter, "", options)
@ -336,11 +337,11 @@ class ConfigDialog(QtGui.QDialog):
self.hostCombobox.setEditText(currentServer) self.hostCombobox.setEditText(currentServer)
def showErrorMessage(self, errorMessage): def showErrorMessage(self, errorMessage):
QtGui.QMessageBox.warning(self, "Syncplay", errorMessage) QtWidgets.QMessageBox.warning(self, "Syncplay", errorMessage)
def browseMediapath(self): def browseMediapath(self):
self.loadMediaBrowseSettings() self.loadMediaBrowseSettings()
options = QtGui.QFileDialog.Options() options = QtWidgets.QFileDialog.Options()
if self.config["mediaSearchDirectories"] and os.path.isdir(self.config["mediaSearchDirectories"][0]): if self.config["mediaSearchDirectories"] and os.path.isdir(self.config["mediaSearchDirectories"][0]):
defaultdirectory = self.config["mediaSearchDirectories"][0] defaultdirectory = self.config["mediaSearchDirectories"][0]
elif os.path.isdir(self.mediadirectory): elif os.path.isdir(self.mediadirectory):
@ -352,7 +353,7 @@ class ConfigDialog(QtGui.QDialog):
else: else:
defaultdirectory = "" defaultdirectory = ""
browserfilter = "All files (*)" browserfilter = "All files (*)"
fileName, filtr = QtGui.QFileDialog.getOpenFileName(self, "Browse for media files", defaultdirectory, fileName, filtr = QtWidgets.QFileDialog.getOpenFileName(self, "Browse for media files", defaultdirectory,
browserfilter, "", options) browserfilter, "", options)
if fileName: if fileName:
self.mediapathTextbox.setText(os.path.normpath(fileName)) self.mediapathTextbox.setText(os.path.normpath(fileName))
@ -508,9 +509,9 @@ class ConfigDialog(QtGui.QDialog):
self.mediaSearchDirectories = self.config["mediaSearchDirectories"] self.mediaSearchDirectories = self.config["mediaSearchDirectories"]
self.trustedDomains = self.config["trustedDomains"] self.trustedDomains = self.config["trustedDomains"]
self.connectionSettingsGroup = QtGui.QGroupBox(getMessage("connection-group-title")) self.connectionSettingsGroup = QtWidgets.QGroupBox(getMessage("connection-group-title"))
self.loadSavedPublicServerList() self.loadSavedPublicServerList()
self.hostCombobox = QtGui.QComboBox(self) self.hostCombobox = QtWidgets.QComboBox(self)
if self.publicServers: if self.publicServers:
i = 0 i = 0
for publicServer in self.publicServers: for publicServer in self.publicServers:
@ -521,7 +522,7 @@ class ConfigDialog(QtGui.QDialog):
self.hostCombobox.setEditText(host) self.hostCombobox.setEditText(host)
self.hostCombobox.setFixedWidth(165) self.hostCombobox.setFixedWidth(165)
self.hostLabel = QLabel(getMessage("host-label"), self) self.hostLabel = QLabel(getMessage("host-label"), self)
self.findServerButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'arrow_refresh.png'), getMessage("update-server-list-label")) self.findServerButton = QtWidgets.QPushButton(QtGui.QIcon(resourcespath + 'arrow_refresh.png'), getMessage("update-server-list-label"))
self.findServerButton.clicked.connect(self.updateServerList) self.findServerButton.clicked.connect(self.updateServerList)
self.findServerButton.setToolTip(getMessage("update-server-list-tooltip")) self.findServerButton.setToolTip(getMessage("update-server-list-tooltip"))
self.usernameTextbox = QLineEdit(self) self.usernameTextbox = QLineEdit(self)
@ -545,7 +546,7 @@ class ConfigDialog(QtGui.QDialog):
self.usernameTextbox.setMaxLength(constants.MAX_USERNAME_LENGTH) self.usernameTextbox.setMaxLength(constants.MAX_USERNAME_LENGTH)
self.defaultroomTextbox.setMaxLength(constants.MAX_ROOM_NAME_LENGTH) self.defaultroomTextbox.setMaxLength(constants.MAX_ROOM_NAME_LENGTH)
self.connectionSettingsLayout = QtGui.QGridLayout() self.connectionSettingsLayout = QtWidgets.QGridLayout()
self.connectionSettingsLayout.addWidget(self.hostLabel, 0, 0) self.connectionSettingsLayout.addWidget(self.hostLabel, 0, 0)
self.connectionSettingsLayout.addWidget(self.hostCombobox, 0, 1) self.connectionSettingsLayout.addWidget(self.hostCombobox, 0, 1)
self.connectionSettingsLayout.addWidget(self.findServerButton, 0, 2) self.connectionSettingsLayout.addWidget(self.findServerButton, 0, 2)
@ -562,11 +563,11 @@ class ConfigDialog(QtGui.QDialog):
self.playerargsTextbox.textEdited.connect(self.changedPlayerArgs) self.playerargsTextbox.textEdited.connect(self.changedPlayerArgs)
self.playerargsLabel = QLabel(getMessage("player-arguments-label"), self) self.playerargsLabel = QLabel(getMessage("player-arguments-label"), self)
self.mediaplayerSettingsGroup = QtGui.QGroupBox(getMessage("media-setting-title")) self.mediaplayerSettingsGroup = QtWidgets.QGroupBox(getMessage("media-setting-title"))
self.executableiconImage = QtGui.QImage() self.executableiconImage = QtGui.QImage()
self.executableiconLabel = QLabel(self) self.executableiconLabel = QLabel(self)
self.executableiconLabel.setMinimumWidth(16) self.executableiconLabel.setMinimumWidth(16)
self.executablepathCombobox = QtGui.QComboBox(self) self.executablepathCombobox = QtWidgets.QComboBox(self)
self.executablepathCombobox.setEditable(True) self.executablepathCombobox.setEditable(True)
self.executablepathCombobox.currentIndexChanged.connect(self.updateExecutableIcon) self.executablepathCombobox.currentIndexChanged.connect(self.updateExecutableIcon)
self.executablepathCombobox.setEditText(self._tryToFillPlayerPath(config['playerPath'], playerpaths)) self.executablepathCombobox.setEditText(self._tryToFillPlayerPath(config['playerPath'], playerpaths))
@ -574,11 +575,11 @@ class ConfigDialog(QtGui.QDialog):
self.executablepathCombobox.editTextChanged.connect(self.updateExecutableIcon) self.executablepathCombobox.editTextChanged.connect(self.updateExecutableIcon)
self.executablepathLabel = QLabel(getMessage("executable-path-label"), self) self.executablepathLabel = QLabel(getMessage("executable-path-label"), self)
self.executablebrowseButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'folder_explore.png'), getMessage("browse-label")) self.executablebrowseButton = QtWidgets.QPushButton(QtGui.QIcon(resourcespath + 'folder_explore.png'), getMessage("browse-label"))
self.executablebrowseButton.clicked.connect(self.browsePlayerpath) self.executablebrowseButton.clicked.connect(self.browsePlayerpath)
self.mediapathTextbox = QLineEdit(config['file'], self) self.mediapathTextbox = QLineEdit(config['file'], self)
self.mediapathLabel = QLabel(getMessage("media-path-label"), self) self.mediapathLabel = QLabel(getMessage("media-path-label"), self)
self.mediabrowseButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + 'folder_explore.png'), getMessage("browse-label")) self.mediabrowseButton = QtWidgets.QPushButton(QtGui.QIcon(resourcespath + 'folder_explore.png'), getMessage("browse-label"))
self.mediabrowseButton.clicked.connect(self.browseMediapath) self.mediabrowseButton.clicked.connect(self.browseMediapath)
self.executablepathLabel.setObjectName("executable-path") self.executablepathLabel.setObjectName("executable-path")
@ -588,7 +589,7 @@ class ConfigDialog(QtGui.QDialog):
self.playerargsLabel.setObjectName("player-arguments") self.playerargsLabel.setObjectName("player-arguments")
self.playerargsTextbox.setObjectName(constants.LOAD_SAVE_MANUALLY_MARKER + "player-arguments") self.playerargsTextbox.setObjectName(constants.LOAD_SAVE_MANUALLY_MARKER + "player-arguments")
self.mediaplayerSettingsLayout = QtGui.QGridLayout() self.mediaplayerSettingsLayout = QtWidgets.QGridLayout()
self.mediaplayerSettingsLayout.addWidget(self.executablepathLabel, 0, 0) self.mediaplayerSettingsLayout.addWidget(self.executablepathLabel, 0, 0)
self.mediaplayerSettingsLayout.addWidget(self.executableiconLabel, 0, 1) self.mediaplayerSettingsLayout.addWidget(self.executableiconLabel, 0, 1)
self.mediaplayerSettingsLayout.addWidget(self.executablepathCombobox, 0, 2) self.mediaplayerSettingsLayout.addWidget(self.executablepathCombobox, 0, 2)
@ -603,8 +604,8 @@ class ConfigDialog(QtGui.QDialog):
self.showmoreCheckbox = QCheckBox(getMessage("more-title")) self.showmoreCheckbox = QCheckBox(getMessage("more-title"))
self.showmoreCheckbox.setObjectName(constants.LOAD_SAVE_MANUALLY_MARKER + "more") self.showmoreCheckbox.setObjectName(constants.LOAD_SAVE_MANUALLY_MARKER + "more")
self.basicOptionsFrame = QtGui.QFrame() self.basicOptionsFrame = QtWidgets.QFrame()
self.basicOptionsLayout = QtGui.QVBoxLayout() self.basicOptionsLayout = QtWidgets.QVBoxLayout()
if error: if error:
self.errorLabel = QLabel(self) self.errorLabel = QLabel(self)
if error[:1] != constants.ERROR_MESSAGE_MARKER: if error[:1] != constants.ERROR_MESSAGE_MARKER:
@ -620,19 +621,19 @@ class ConfigDialog(QtGui.QDialog):
self.basicOptionsLayout.addWidget(self.connectionSettingsGroup) self.basicOptionsLayout.addWidget(self.connectionSettingsGroup)
self.basicOptionsLayout.addSpacing(5) self.basicOptionsLayout.addSpacing(5)
self.basicOptionsLayout.addWidget(self.mediaplayerSettingsGroup) self.basicOptionsLayout.addWidget(self.mediaplayerSettingsGroup)
self.basicOptionsFrame.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) self.basicOptionsFrame.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
self.basicOptionsFrame.setLayout(self.basicOptionsLayout) self.basicOptionsFrame.setLayout(self.basicOptionsLayout)
self.stackedLayout.addWidget(self.basicOptionsFrame) self.stackedLayout.addWidget(self.basicOptionsFrame)
def addReadinessTab(self): def addReadinessTab(self):
self.readyFrame = QtGui.QFrame() self.readyFrame = QtWidgets.QFrame()
self.readyLayout = QtGui.QVBoxLayout() self.readyLayout = QtWidgets.QVBoxLayout()
self.readyFrame.setLayout(self.readyLayout) self.readyFrame.setLayout(self.readyLayout)
# Initial state # Initial state
self.readyInitialGroup = QtGui.QGroupBox(getMessage("readiness-title")) self.readyInitialGroup = QtWidgets.QGroupBox(getMessage("readiness-title"))
self.readyInitialLayout = QtGui.QVBoxLayout() self.readyInitialLayout = QtWidgets.QVBoxLayout()
self.readyInitialGroup.setLayout(self.readyInitialLayout) self.readyInitialGroup.setLayout(self.readyInitialLayout)
self.readyatstartCheckbox = QCheckBox(getMessage("readyatstart-label")) self.readyatstartCheckbox = QCheckBox(getMessage("readyatstart-label"))
self.readyatstartCheckbox.setObjectName("readyAtStart") self.readyatstartCheckbox.setObjectName("readyAtStart")
@ -640,8 +641,8 @@ class ConfigDialog(QtGui.QDialog):
self.readyLayout.addWidget(self.readyInitialGroup) self.readyLayout.addWidget(self.readyInitialGroup)
# Automatically pausing # Automatically pausing
self.readyPauseGroup = QtGui.QGroupBox(getMessage("pausing-title")) self.readyPauseGroup = QtWidgets.QGroupBox(getMessage("pausing-title"))
self.readyPauseLayout = QtGui.QVBoxLayout() self.readyPauseLayout = QtWidgets.QVBoxLayout()
self.readyPauseGroup.setLayout(self.readyPauseLayout) self.readyPauseGroup.setLayout(self.readyPauseLayout)
self.pauseonleaveCheckbox = QCheckBox(getMessage("pauseonleave-label")) self.pauseonleaveCheckbox = QCheckBox(getMessage("pauseonleave-label"))
self.pauseonleaveCheckbox.setObjectName("pauseOnLeave") self.pauseonleaveCheckbox.setObjectName("pauseOnLeave")
@ -649,8 +650,8 @@ class ConfigDialog(QtGui.QDialog):
self.readyLayout.addWidget(self.readyPauseGroup) self.readyLayout.addWidget(self.readyPauseGroup)
# Unpausing # Unpausing
self.readyUnpauseGroup = QtGui.QGroupBox(getMessage("unpause-title")) self.readyUnpauseGroup = QtWidgets.QGroupBox(getMessage("unpause-title"))
self.readyUnpauseLayout = QtGui.QVBoxLayout() self.readyUnpauseLayout = QtWidgets.QVBoxLayout()
self.readyUnpauseGroup.setLayout(self.readyUnpauseLayout) self.readyUnpauseGroup.setLayout(self.readyUnpauseLayout)
self.readyUnpauseButtonGroup = QButtonGroup() self.readyUnpauseButtonGroup = QButtonGroup()
self.unpauseIfAlreadyReadyOption = QRadioButton(getMessage("unpause-ifalreadyready-option")) self.unpauseIfAlreadyReadyOption = QRadioButton(getMessage("unpause-ifalreadyready-option"))
@ -679,12 +680,12 @@ class ConfigDialog(QtGui.QDialog):
self.stackedLayout.addWidget(self.readyFrame) self.stackedLayout.addWidget(self.readyFrame)
def addMiscTab(self): def addMiscTab(self):
self.miscFrame = QtGui.QFrame() self.miscFrame = QtWidgets.QFrame()
self.miscLayout = QtGui.QVBoxLayout() self.miscLayout = QtWidgets.QVBoxLayout()
self.miscFrame.setLayout(self.miscLayout) self.miscFrame.setLayout(self.miscLayout)
self.coreSettingsGroup = QtGui.QGroupBox(getMessage("core-behaviour-title")) self.coreSettingsGroup = QtWidgets.QGroupBox(getMessage("core-behaviour-title"))
self.coreSettingsLayout = QtGui.QGridLayout() self.coreSettingsLayout = QtWidgets.QGridLayout()
self.coreSettingsGroup.setLayout(self.coreSettingsLayout) self.coreSettingsGroup.setLayout(self.coreSettingsLayout)
### Privacy: ### Privacy:
@ -727,8 +728,8 @@ class ConfigDialog(QtGui.QDialog):
## Syncplay internals ## Syncplay internals
self.internalSettingsGroup = QtGui.QGroupBox(getMessage("syncplay-internals-title")) self.internalSettingsGroup = QtWidgets.QGroupBox(getMessage("syncplay-internals-title"))
self.internalSettingsLayout = QtGui.QVBoxLayout() self.internalSettingsLayout = QtWidgets.QVBoxLayout()
self.internalSettingsGroup.setLayout(self.internalSettingsLayout) self.internalSettingsGroup.setLayout(self.internalSettingsLayout)
self.alwaysshowCheckbox = QCheckBox(getMessage("forceguiprompt-label")) self.alwaysshowCheckbox = QCheckBox(getMessage("forceguiprompt-label"))
@ -741,13 +742,13 @@ class ConfigDialog(QtGui.QDialog):
## Media path directories ## Media path directories
self.mediasearchSettingsGroup = QtGui.QGroupBox(getMessage("syncplay-mediasearchdirectories-title")) self.mediasearchSettingsGroup = QtWidgets.QGroupBox(getMessage("syncplay-mediasearchdirectories-title"))
self.mediasearchSettingsLayout = QtGui.QVBoxLayout() self.mediasearchSettingsLayout = QtWidgets.QVBoxLayout()
self.mediasearchSettingsGroup.setLayout(self.mediasearchSettingsLayout) self.mediasearchSettingsGroup.setLayout(self.mediasearchSettingsLayout)
self.mediasearchTextEdit = QPlainTextEdit(utils.getListAsMultilineString(self.mediaSearchDirectories)) self.mediasearchTextEdit = QPlainTextEdit(utils.getListAsMultilineString(self.mediaSearchDirectories))
self.mediasearchTextEdit.setObjectName(constants.LOAD_SAVE_MANUALLY_MARKER + "mediasearcdirectories-arguments") self.mediasearchTextEdit.setObjectName(constants.LOAD_SAVE_MANUALLY_MARKER + "mediasearcdirectories-arguments")
self.mediasearchTextEdit.setLineWrapMode(QtGui.QPlainTextEdit.NoWrap) self.mediasearchTextEdit.setLineWrapMode(QtWidgets.QPlainTextEdit.NoWrap)
self.mediasearchSettingsLayout.addWidget(self.mediasearchTextEdit) self.mediasearchSettingsLayout.addWidget(self.mediasearchTextEdit)
self.mediasearchSettingsGroup.setMaximumHeight(self.mediasearchSettingsGroup.minimumSizeHint().height()) self.mediasearchSettingsGroup.setMaximumHeight(self.mediasearchSettingsGroup.minimumSizeHint().height())
@ -758,12 +759,12 @@ class ConfigDialog(QtGui.QDialog):
self.stackedLayout.addWidget(self.miscFrame) self.stackedLayout.addWidget(self.miscFrame)
def addSyncTab(self): def addSyncTab(self):
self.syncSettingsFrame = QtGui.QFrame() self.syncSettingsFrame = QtWidgets.QFrame()
self.syncSettingsLayout = QtGui.QVBoxLayout() self.syncSettingsLayout = QtWidgets.QVBoxLayout()
self.desyncSettingsGroup = QtGui.QGroupBox(getMessage("sync-otherslagging-title")) self.desyncSettingsGroup = QtWidgets.QGroupBox(getMessage("sync-otherslagging-title"))
self.desyncOptionsFrame = QtGui.QFrame() self.desyncOptionsFrame = QtWidgets.QFrame()
self.desyncSettingsOptionsLayout = QtGui.QHBoxLayout() self.desyncSettingsOptionsLayout = QtWidgets.QHBoxLayout()
config = self.config config = self.config
self.slowdownCheckbox = QCheckBox(getMessage("slowondesync-label")) self.slowdownCheckbox = QCheckBox(getMessage("slowondesync-label"))
@ -773,9 +774,9 @@ class ConfigDialog(QtGui.QDialog):
self.fastforwardCheckbox = QCheckBox(getMessage("fastforwardondesync-label")) self.fastforwardCheckbox = QCheckBox(getMessage("fastforwardondesync-label"))
self.fastforwardCheckbox.setObjectName("fastforwardOnDesync") self.fastforwardCheckbox.setObjectName("fastforwardOnDesync")
self.desyncSettingsLayout = QtGui.QGridLayout() self.desyncSettingsLayout = QtWidgets.QGridLayout()
self.desyncSettingsLayout.setSpacing(2) self.desyncSettingsLayout.setSpacing(2)
self.desyncFrame = QtGui.QFrame() self.desyncFrame = QtWidgets.QFrame()
self.desyncFrame.setLineWidth(0) self.desyncFrame.setLineWidth(0)
self.desyncFrame.setMidLineWidth(0) self.desyncFrame.setMidLineWidth(0)
@ -788,9 +789,9 @@ class ConfigDialog(QtGui.QDialog):
self.desyncFrame.setLayout(self.syncSettingsLayout) self.desyncFrame.setLayout(self.syncSettingsLayout)
self.othersyncSettingsGroup = QtGui.QGroupBox(getMessage("sync-youlaggging-title")) self.othersyncSettingsGroup = QtWidgets.QGroupBox(getMessage("sync-youlaggging-title"))
self.othersyncOptionsFrame = QtGui.QFrame() self.othersyncOptionsFrame = QtWidgets.QFrame()
self.othersyncSettingsLayout = QtGui.QGridLayout() self.othersyncSettingsLayout = QtWidgets.QGridLayout()
self.dontslowwithmeCheckbox = QCheckBox(getMessage("dontslowdownwithme-label")) self.dontslowwithmeCheckbox = QCheckBox(getMessage("dontslowdownwithme-label"))
self.dontslowwithmeCheckbox.setObjectName("dontSlowDownWithMe") self.dontslowwithmeCheckbox.setObjectName("dontSlowDownWithMe")
@ -803,13 +804,13 @@ class ConfigDialog(QtGui.QDialog):
## Trusted domains ## Trusted domains
self.trusteddomainsSettingsGroup = QtGui.QGroupBox(getMessage("syncplay-trusteddomains-title")) self.trusteddomainsSettingsGroup = QtWidgets.QGroupBox(getMessage("syncplay-trusteddomains-title"))
self.trusteddomainsSettingsLayout = QtGui.QVBoxLayout() self.trusteddomainsSettingsLayout = QtWidgets.QVBoxLayout()
self.trusteddomainsSettingsGroup.setLayout(self.trusteddomainsSettingsLayout) self.trusteddomainsSettingsGroup.setLayout(self.trusteddomainsSettingsLayout)
self.trusteddomainsTextEdit = QPlainTextEdit(utils.getListAsMultilineString(self.trustedDomains)) self.trusteddomainsTextEdit = QPlainTextEdit(utils.getListAsMultilineString(self.trustedDomains))
self.trusteddomainsTextEdit.setObjectName(constants.LOAD_SAVE_MANUALLY_MARKER + "trusteddomains-arguments") self.trusteddomainsTextEdit.setObjectName(constants.LOAD_SAVE_MANUALLY_MARKER + "trusteddomains-arguments")
self.trusteddomainsTextEdit.setLineWrapMode(QtGui.QPlainTextEdit.NoWrap) self.trusteddomainsTextEdit.setLineWrapMode(QtWidgets.QPlainTextEdit.NoWrap)
self.trusteddomainsSettingsLayout.addWidget(self.trusteddomainsTextEdit) self.trusteddomainsSettingsLayout.addWidget(self.trusteddomainsTextEdit)
self.trusteddomainsSettingsGroup.setMaximumHeight(self.trusteddomainsSettingsGroup.minimumSizeHint().height()) self.trusteddomainsSettingsGroup.setMaximumHeight(self.trusteddomainsSettingsGroup.minimumSizeHint().height())
@ -824,14 +825,14 @@ class ConfigDialog(QtGui.QDialog):
self.stackedLayout.addWidget(self.syncSettingsFrame) self.stackedLayout.addWidget(self.syncSettingsFrame)
def addMessageTab(self): def addMessageTab(self):
self.messageFrame = QtGui.QFrame() self.messageFrame = QtWidgets.QFrame()
self.messageLayout = QtGui.QVBoxLayout() self.messageLayout = QtWidgets.QVBoxLayout()
self.messageLayout.setAlignment(Qt.AlignTop) self.messageLayout.setAlignment(Qt.AlignTop)
# OSD # OSD
self.osdSettingsGroup = QtGui.QGroupBox(getMessage("messages-osd-title")) self.osdSettingsGroup = QtWidgets.QGroupBox(getMessage("messages-osd-title"))
self.osdSettingsLayout = QtGui.QVBoxLayout() self.osdSettingsLayout = QtWidgets.QVBoxLayout()
self.osdSettingsFrame = QtGui.QFrame() self.osdSettingsFrame = QtWidgets.QFrame()
self.showOSDCheckbox = QCheckBox(getMessage("showosd-label")) self.showOSDCheckbox = QCheckBox(getMessage("showosd-label"))
self.showOSDCheckbox.setObjectName("showOSD") self.showOSDCheckbox.setObjectName("showOSD")
@ -871,23 +872,23 @@ class ConfigDialog(QtGui.QDialog):
# Other display # Other display
self.displaySettingsGroup = QtGui.QGroupBox(getMessage("messages-other-title")) self.displaySettingsGroup = QtWidgets.QGroupBox(getMessage("messages-other-title"))
self.displaySettingsLayout = QtGui.QVBoxLayout() self.displaySettingsLayout = QtWidgets.QVBoxLayout()
self.displaySettingsLayout.setAlignment(Qt.AlignTop & Qt.AlignLeft) self.displaySettingsLayout.setAlignment(Qt.AlignTop & Qt.AlignLeft)
self.displaySettingsFrame = QtGui.QFrame() self.displaySettingsFrame = QtWidgets.QFrame()
self.showDurationNotificationCheckbox = QCheckBox(getMessage("showdurationnotification-label")) self.showDurationNotificationCheckbox = QCheckBox(getMessage("showdurationnotification-label"))
self.showDurationNotificationCheckbox.setObjectName("showDurationNotification") self.showDurationNotificationCheckbox.setObjectName("showDurationNotification")
self.displaySettingsLayout.addWidget(self.showDurationNotificationCheckbox) self.displaySettingsLayout.addWidget(self.showDurationNotificationCheckbox)
self.languageFrame = QtGui.QFrame() self.languageFrame = QtWidgets.QFrame()
self.languageLayout = QtGui.QHBoxLayout() self.languageLayout = QtWidgets.QHBoxLayout()
self.languageLayout.setContentsMargins(0, 0, 0, 0) self.languageLayout.setContentsMargins(0, 0, 0, 0)
self.languageFrame.setLayout(self.languageLayout) self.languageFrame.setLayout(self.languageLayout)
self.languageFrame.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) self.languageFrame.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
self.languageLayout.setAlignment(Qt.AlignTop & Qt.AlignLeft) self.languageLayout.setAlignment(Qt.AlignTop & Qt.AlignLeft)
self.languageLabel = QLabel(getMessage("language-label"), self) self.languageLabel = QLabel(getMessage("language-label"), self)
self.languageCombobox = QtGui.QComboBox(self) self.languageCombobox = QtWidgets.QComboBox(self)
self.languageCombobox.addItem(getMessage("automatic-language").format(getMessage("LANGUAGE", getInitialLanguage()))) self.languageCombobox.addItem(getMessage("automatic-language").format(getMessage("LANGUAGE", getInitialLanguage())))
self.languages = getLanguages() self.languages = getLanguages()
@ -917,22 +918,22 @@ class ConfigDialog(QtGui.QDialog):
config = self.config config = self.config
resourcespath = self.resourcespath resourcespath = self.resourcespath
self.bottomButtonFrame = QtGui.QFrame() self.bottomButtonFrame = QtWidgets.QFrame()
self.bottomButtonLayout = QtGui.QHBoxLayout() self.bottomButtonLayout = QtWidgets.QHBoxLayout()
self.helpButton = QtGui.QPushButton(QtGui.QIcon(self.resourcespath + u'help.png'), getMessage("help-label")) self.helpButton = QtWidgets.QPushButton(QtGui.QIcon(self.resourcespath + u'help.png'), getMessage("help-label"))
self.helpButton.setObjectName("help") self.helpButton.setObjectName("help")
self.helpButton.setMaximumSize(self.helpButton.sizeHint()) self.helpButton.setMaximumSize(self.helpButton.sizeHint())
self.helpButton.pressed.connect(self.openHelp) self.helpButton.pressed.connect(self.openHelp)
self.resetButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + u'cog_delete.png'),getMessage("reset-label")) self.resetButton = QtWidgets.QPushButton(QtGui.QIcon(resourcespath + u'cog_delete.png'),getMessage("reset-label"))
self.resetButton.setMaximumSize(self.resetButton.sizeHint()) self.resetButton.setMaximumSize(self.resetButton.sizeHint())
self.resetButton.setObjectName("reset") self.resetButton.setObjectName("reset")
self.resetButton.pressed.connect(self.resetSettings) self.resetButton.pressed.connect(self.resetSettings)
self.runButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + u'accept.png'), getMessage("run-label")) self.runButton = QtWidgets.QPushButton(QtGui.QIcon(resourcespath + u'accept.png'), getMessage("run-label"))
self.runButton.pressed.connect(self._runWithoutStoringConfig) self.runButton.pressed.connect(self._runWithoutStoringConfig)
self.runButton.setToolTip(getMessage("nostore-tooltip")) self.runButton.setToolTip(getMessage("nostore-tooltip"))
self.storeAndRunButton = QtGui.QPushButton(QtGui.QIcon(resourcespath + u'accept.png'), getMessage("storeandrun-label")) self.storeAndRunButton = QtWidgets.QPushButton(QtGui.QIcon(resourcespath + u'accept.png'), getMessage("storeandrun-label"))
self.storeAndRunButton.pressed.connect(self._saveDataAndLeave) self.storeAndRunButton.pressed.connect(self._saveDataAndLeave)
self.bottomButtonLayout.addWidget(self.helpButton) self.bottomButtonLayout.addWidget(self.helpButton)
self.bottomButtonLayout.addWidget(self.resetButton) self.bottomButtonLayout.addWidget(self.resetButton)
@ -942,9 +943,9 @@ class ConfigDialog(QtGui.QDialog):
self.bottomButtonLayout.setContentsMargins(5,0,5,0) self.bottomButtonLayout.setContentsMargins(5,0,5,0)
self.mainLayout.addWidget(self.bottomButtonFrame, 1, 0, 1, 2) self.mainLayout.addWidget(self.bottomButtonFrame, 1, 0, 1, 2)
self.bottomCheckboxFrame = QtGui.QFrame() self.bottomCheckboxFrame = QtWidgets.QFrame()
self.bottomCheckboxFrame.setContentsMargins(0,0,0,0) self.bottomCheckboxFrame.setContentsMargins(0,0,0,0)
self.bottomCheckboxLayout = QtGui.QGridLayout() self.bottomCheckboxLayout = QtWidgets.QGridLayout()
self.alwaysshowCheckbox = QCheckBox(getMessage("forceguiprompt-label")) self.alwaysshowCheckbox = QCheckBox(getMessage("forceguiprompt-label"))
self.enableplaylistsCheckbox = QCheckBox(getMessage("sharedplaylistenabled-label")) self.enableplaylistsCheckbox = QCheckBox(getMessage("sharedplaylistenabled-label"))
@ -957,14 +958,14 @@ class ConfigDialog(QtGui.QDialog):
self.mainLayout.addWidget(self.bottomCheckboxFrame, 2, 0, 1, 2) self.mainLayout.addWidget(self.bottomCheckboxFrame, 2, 0, 1, 2)
def tabList(self): def tabList(self):
self.tabListLayout = QtGui.QHBoxLayout() self.tabListLayout = QtWidgets.QHBoxLayout()
self.tabListFrame = QtGui.QFrame() self.tabListFrame = QtWidgets.QFrame()
self.tabListWidget = QtGui.QListWidget() self.tabListWidget = QtWidgets.QListWidget()
self.tabListWidget.addItem(QtGui.QListWidgetItem(QtGui.QIcon(self.resourcespath + u"house.png"),getMessage("basics-label"))) self.tabListWidget.addItem(QtWidgets.QListWidgetItem(QtGui.QIcon(self.resourcespath + u"house.png"),getMessage("basics-label")))
self.tabListWidget.addItem(QtGui.QListWidgetItem(QtGui.QIcon(self.resourcespath + u"control_pause_blue.png"),getMessage("readiness-label"))) self.tabListWidget.addItem(QtWidgets.QListWidgetItem(QtGui.QIcon(self.resourcespath + u"control_pause_blue.png"),getMessage("readiness-label")))
self.tabListWidget.addItem(QtGui.QListWidgetItem(QtGui.QIcon(self.resourcespath + u"film_link.png"),getMessage("sync-label"))) self.tabListWidget.addItem(QtWidgets.QListWidgetItem(QtGui.QIcon(self.resourcespath + u"film_link.png"),getMessage("sync-label")))
self.tabListWidget.addItem(QtGui.QListWidgetItem(QtGui.QIcon(self.resourcespath + u"comments.png"),getMessage("messages-label"))) self.tabListWidget.addItem(QtWidgets.QListWidgetItem(QtGui.QIcon(self.resourcespath + u"comments.png"),getMessage("messages-label")))
self.tabListWidget.addItem(QtGui.QListWidgetItem(QtGui.QIcon(self.resourcespath + u"cog.png"),getMessage("misc-label"))) self.tabListWidget.addItem(QtWidgets.QListWidgetItem(QtGui.QIcon(self.resourcespath + u"cog.png"),getMessage("misc-label")))
self.tabListLayout.addWidget(self.tabListWidget) self.tabListLayout.addWidget(self.tabListWidget)
self.tabListFrame.setLayout(self.tabListLayout) self.tabListFrame.setLayout(self.tabListLayout)
self.tabListFrame.setFixedWidth(self.tabListFrame.minimumSizeHint().width()) self.tabListFrame.setFixedWidth(self.tabListFrame.minimumSizeHint().width())
@ -1045,6 +1046,7 @@ class ConfigDialog(QtGui.QDialog):
self.config['clearGUIData'] = False self.config['clearGUIData'] = False
self.clearGUIData() self.clearGUIData()
self.QtWidgets = QtWidgets
self.QtGui = QtGui self.QtGui = QtGui
self.error = error self.error = error
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
@ -1060,11 +1062,11 @@ class ConfigDialog(QtGui.QDialog):
self.setWindowFlags(self.windowFlags() & Qt.WindowCloseButtonHint & ~Qt.WindowContextHelpButtonHint) self.setWindowFlags(self.windowFlags() & Qt.WindowCloseButtonHint & ~Qt.WindowContextHelpButtonHint)
self.setWindowIcon(QtGui.QIcon(resourcespath + u"syncplay.png")) self.setWindowIcon(QtGui.QIcon(resourcespath + u"syncplay.png"))
self.stackedLayout = QtGui.QStackedLayout() self.stackedLayout = QtWidgets.QStackedLayout()
self.stackedFrame = QtGui.QFrame() self.stackedFrame = QtWidgets.QFrame()
self.stackedFrame.setLayout(self.stackedLayout) self.stackedFrame.setLayout(self.stackedLayout)
self.mainLayout = QtGui.QGridLayout() self.mainLayout = QtWidgets.QGridLayout()
self.mainLayout.setSpacing(0) self.mainLayout.setSpacing(0)
self.mainLayout.setContentsMargins(0,0,0,0) self.mainLayout.setContentsMargins(0,0,0,0)

View File

@ -1,5 +1,5 @@
from PySide import QtGui from PySide2 import QtWidgets, QtGui
from PySide.QtCore import Qt, QSettings, QSize, QPoint, QUrl, QLine from PySide2.QtCore import Qt, QSettings, QSize, QPoint, QUrl, QLine, QStandardPaths
from syncplay import utils, constants, version from syncplay import utils, constants, version
from syncplay.messages import getMessage from syncplay.messages import getMessage
import sys import sys
@ -13,12 +13,12 @@ from functools import wraps
from twisted.internet import task from twisted.internet import task
lastCheckedForUpdates = None lastCheckedForUpdates = None
class UserlistItemDelegate(QtGui.QStyledItemDelegate): class UserlistItemDelegate(QtWidgets.QStyledItemDelegate):
def __init__(self): def __init__(self):
QtGui.QStyledItemDelegate.__init__(self) QtWidgets.QStyledItemDelegate.__init__(self)
def sizeHint(self, option, index): def sizeHint(self, option, index):
size = QtGui.QStyledItemDelegate.sizeHint(self, option, index) size = QtWidgets.QStyledItemDelegate.sizeHint(self, option, index)
if (index.column() == constants.USERLIST_GUI_USERNAME_COLUMN): if (index.column() == constants.USERLIST_GUI_USERNAME_COLUMN):
size.setWidth(size.width() + constants.USERLIST_GUI_USERNAME_OFFSET) size.setWidth(size.width() + constants.USERLIST_GUI_USERNAME_OFFSET)
return size return size
@ -82,9 +82,9 @@ class UserlistItemDelegate(QtGui.QStyledItemDelegate):
midY - 8, midY - 8,
streamSwitchIconQPixmap.scaled(16, 16, Qt.KeepAspectRatio)) streamSwitchIconQPixmap.scaled(16, 16, Qt.KeepAspectRatio))
optionQStyleOptionViewItem.rect.setX(optionQStyleOptionViewItem.rect.x()+16) optionQStyleOptionViewItem.rect.setX(optionQStyleOptionViewItem.rect.x()+16)
QtGui.QStyledItemDelegate.paint(self, itemQPainter, optionQStyleOptionViewItem, indexQModelIndex) QtWidgets.QStyledItemDelegate.paint(self, itemQPainter, optionQStyleOptionViewItem, indexQModelIndex)
class MainWindow(QtGui.QMainWindow): class MainWindow(QtWidgets.QMainWindow):
insertPosition = None insertPosition = None
playlistState = [] playlistState = []
updatingPlaylist = False updatingPlaylist = False
@ -97,7 +97,7 @@ class MainWindow(QtGui.QMainWindow):
MainWindow.insertPosition = newPosition MainWindow.insertPosition = newPosition
self.playlist.forceUpdate() self.playlist.forceUpdate()
class PlaylistItemDelegate(QtGui.QStyledItemDelegate): class PlaylistItemDelegate(QtWidgets.QStyledItemDelegate):
def paint(self, itemQPainter, optionQStyleOptionViewItem, indexQModelIndex): def paint(self, itemQPainter, optionQStyleOptionViewItem, indexQModelIndex):
itemQPainter.save() itemQPainter.save()
currentQAbstractItemModel = indexQModelIndex.model() currentQAbstractItemModel = indexQModelIndex.model()
@ -115,7 +115,7 @@ class MainWindow(QtGui.QMainWindow):
currentlyplayingIconQPixmap.scaled(6, 16, Qt.KeepAspectRatio)) currentlyplayingIconQPixmap.scaled(6, 16, Qt.KeepAspectRatio))
optionQStyleOptionViewItem.rect.setX(optionQStyleOptionViewItem.rect.x()+10) optionQStyleOptionViewItem.rect.setX(optionQStyleOptionViewItem.rect.x()+10)
QtGui.QStyledItemDelegate.paint(self, itemQPainter, optionQStyleOptionViewItem, indexQModelIndex) QtWidgets.QStyledItemDelegate.paint(self, itemQPainter, optionQStyleOptionViewItem, indexQModelIndex)
lineAbove = False lineAbove = False
lineBelow = False lineBelow = False
@ -131,7 +131,7 @@ class MainWindow(QtGui.QMainWindow):
itemQPainter.drawLine(line) itemQPainter.drawLine(line)
itemQPainter.restore() itemQPainter.restore()
class PlaylistGroupBox(QtGui.QGroupBox): class PlaylistGroupBox(QtWidgets.QGroupBox):
def dragEnterEvent(self, event): def dragEnterEvent(self, event):
data = event.mimeData() data = event.mimeData()
@ -152,8 +152,8 @@ class MainWindow(QtGui.QMainWindow):
if not window.playlist.isEnabled(): if not window.playlist.isEnabled():
return return
window.setPlaylistInsertPosition(None) window.setPlaylistInsertPosition(None)
if QtGui.QDropEvent.proposedAction(event) == Qt.MoveAction: if QtWidgets.QDropEvent.proposedAction(event) == Qt.MoveAction:
QtGui.QDropEvent.setDropAction(event, Qt.CopyAction) # Avoids file being deleted QtWidgets.QDropEvent.setDropAction(event, Qt.CopyAction) # Avoids file being deleted
data = event.mimeData() data = event.mimeData()
urls = data.urls() urls = data.urls()
@ -169,7 +169,7 @@ class MainWindow(QtGui.QMainWindow):
else: else:
super(MainWindow.PlaylistWidget, self).dropEvent(event) super(MainWindow.PlaylistWidget, self).dropEvent(event)
class PlaylistWidget(QtGui.QListWidget): class PlaylistWidget(QtWidgets.QListWidget):
selfWindow = None selfWindow = None
playlistIndexFilename = None playlistIndexFilename = None
@ -188,7 +188,7 @@ class MainWindow(QtGui.QMainWindow):
if fileIsUntrusted: if fileIsUntrusted:
self.item(item).setForeground(QtGui.QBrush(QtGui.QColor(constants.STYLE_UNTRUSTEDITEM_COLOR))) self.item(item).setForeground(QtGui.QBrush(QtGui.QColor(constants.STYLE_UNTRUSTEDITEM_COLOR)))
elif fileIsAvailable: elif fileIsAvailable:
self.item(item).setForeground(QtGui.QBrush(QtGui.QColor(QtGui.QPalette.ColorRole(QtGui.QPalette.Text)))) self.item(item).setForeground(QtGui.QBrush(QtGui.QColor(QtWidgets.QPalette.ColorRole(QtWidgets.QPalette.Text))))
else: else:
self.item(item).setForeground(QtGui.QBrush(QtGui.QColor(constants.STYLE_DIFFERENTITEM_COLOR))) self.item(item).setForeground(QtGui.QBrush(QtGui.QColor(constants.STYLE_DIFFERENTITEM_COLOR)))
self.selfWindow._syncplayClient.fileSwitch.setFilenameWatchlist(self.selfWindow.newWatchlist) self.selfWindow._syncplayClient.fileSwitch.setFilenameWatchlist(self.selfWindow.newWatchlist)
@ -251,8 +251,8 @@ class MainWindow(QtGui.QMainWindow):
if not window.playlist.isEnabled(): if not window.playlist.isEnabled():
return return
window.setPlaylistInsertPosition(None) window.setPlaylistInsertPosition(None)
if QtGui.QDropEvent.proposedAction(event) == Qt.MoveAction: if QtWidgets.QDropEvent.proposedAction(event) == Qt.MoveAction:
QtGui.QDropEvent.setDropAction(event, Qt.CopyAction) # Avoids file being deleted QtWidgets.QDropEvent.setDropAction(event, Qt.CopyAction) # Avoids file being deleted
data = event.mimeData() data = event.mimeData()
urls = data.urls() urls = data.urls()
@ -273,17 +273,17 @@ class MainWindow(QtGui.QMainWindow):
class topSplitter(QtGui.QSplitter): class topSplitter(QtWidgets.QSplitter):
def createHandle(self): def createHandle(self):
return self.topSplitterHandle(self.orientation(), self) return self.topSplitterHandle(self.orientation(), self)
class topSplitterHandle(QtGui.QSplitterHandle): class topSplitterHandle(QtWidgets.QSplitterHandle):
def mouseReleaseEvent(self, event): def mouseReleaseEvent(self, event):
QtGui.QSplitterHandle.mouseReleaseEvent(self, event) QtWidgets.QSplitterHandle.mouseReleaseEvent(self, event)
self.parent().parent().parent().updateListGeometry() self.parent().parent().parent().updateListGeometry()
def mouseMoveEvent(self, event): def mouseMoveEvent(self, event):
QtGui.QSplitterHandle.mouseMoveEvent(self, event) QtWidgets.QSplitterHandle.mouseMoveEvent(self, event)
self.parent().parent().parent().updateListGeometry() self.parent().parent().parent().updateListGeometry()
def needsClient(f): # @NoSelf def needsClient(f): # @NoSelf
@ -408,11 +408,11 @@ class MainWindow(QtGui.QMainWindow):
if isControlledRoom: if isControlledRoom:
if room == currentUser.room and currentUser.isController(): if room == currentUser.room and currentUser.isController():
roomitem.setIcon(QtGui.QIcon(self.resourcespath + 'lock_open.png')) roomitem.setIcon(QtGui.QPixmap(self.resourcespath + 'lock_open.png'))
else: else:
roomitem.setIcon(QtGui.QIcon(self.resourcespath + 'lock.png')) roomitem.setIcon(QtGui.QPixmap(self.resourcespath + 'lock.png'))
else: else:
roomitem.setIcon(QtGui.QIcon(self.resourcespath + 'chevrons_right.png')) roomitem.setIcon(QtGui.QPixmap(self.resourcespath + 'chevrons_right.png'))
for user in rooms[room]: for user in rooms[room]:
useritem = QtGui.QStandardItem(user.username) useritem = QtGui.QStandardItem(user.username)
@ -506,7 +506,7 @@ class MainWindow(QtGui.QMainWindow):
item = self.playlist.selectedIndexes()[0] item = self.playlist.selectedIndexes()[0]
else: else:
item = None item = None
menu = QtGui.QMenu() menu = QtWidgets.QMenu()
if item: if item:
firstFile = item.sibling(item.row(), 0).data() firstFile = item.sibling(item.row(), 0).data()
@ -548,7 +548,7 @@ class MainWindow(QtGui.QMainWindow):
else: else:
return return
menu = QtGui.QMenu() menu = QtWidgets.QMenu()
username = item.sibling(item.row(), 0).data() username = item.sibling(item.row(), 0).data()
if username == self._syncplayClient.userlist.currentUser.username: if username == self._syncplayClient.userlist.currentUser.username:
shortUsername = getMessage("item-is-yours-indicator") shortUsername = getMessage("item-is-yours-indicator")
@ -596,15 +596,15 @@ class MainWindow(QtGui.QMainWindow):
self.listTreeView.setFirstColumnSpanned(roomtocheck, self.listTreeView.rootIndex(), True) self.listTreeView.setFirstColumnSpanned(roomtocheck, self.listTreeView.rootIndex(), True)
roomtocheck += 1 roomtocheck += 1
self.listTreeView.header().setStretchLastSection(False) self.listTreeView.header().setStretchLastSection(False)
self.listTreeView.header().setResizeMode(0, QtGui.QHeaderView.ResizeToContents) self.listTreeView.header().setResizeMode(0, QtWidgets.QHeaderView.ResizeToContents)
self.listTreeView.header().setResizeMode(1, QtGui.QHeaderView.ResizeToContents) self.listTreeView.header().setResizeMode(1, QtWidgets.QHeaderView.ResizeToContents)
self.listTreeView.header().setResizeMode(2, QtGui.QHeaderView.ResizeToContents) self.listTreeView.header().setResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
self.listTreeView.header().setResizeMode(3, QtGui.QHeaderView.ResizeToContents) self.listTreeView.header().setResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)
NarrowTabsWidth = self.listTreeView.header().sectionSize(0)+self.listTreeView.header().sectionSize(1)+self.listTreeView.header().sectionSize(2) NarrowTabsWidth = self.listTreeView.header().sectionSize(0)+self.listTreeView.header().sectionSize(1)+self.listTreeView.header().sectionSize(2)
if self.listTreeView.header().width() < (NarrowTabsWidth+self.listTreeView.header().sectionSize(3)): if self.listTreeView.header().width() < (NarrowTabsWidth+self.listTreeView.header().sectionSize(3)):
self.listTreeView.header().resizeSection(3,self.listTreeView.header().width()-NarrowTabsWidth) self.listTreeView.header().resizeSection(3,self.listTreeView.header().width()-NarrowTabsWidth)
else: else:
self.listTreeView.header().setResizeMode(3, QtGui.QHeaderView.Stretch) self.listTreeView.header().setResizeMode(3, QtWidgets.QHeaderView.Stretch)
self.listTreeView.expandAll() self.listTreeView.expandAll()
except: except:
pass pass
@ -677,7 +677,7 @@ class MainWindow(QtGui.QMainWindow):
def showErrorMessage(self, message, criticalerror=False): def showErrorMessage(self, message, criticalerror=False):
message = unicode(message) message = unicode(message)
if criticalerror: if criticalerror:
QtGui.QMessageBox.critical(self, "Syncplay", message) QtWidgets.QMessageBox.critical(self, "Syncplay", message)
message = message.replace(u"&", u"&amp;").replace(u'"', u"&quot;").replace(u"<", u"&lt;").replace(u">", u"&gt;") message = message.replace(u"&", u"&amp;").replace(u'"', u"&quot;").replace(u"<", u"&lt;").replace(u">", u"&gt;")
message = message.replace(u"\n", u"<br />") message = message.replace(u"\n", u"<br />")
message = u"<span style=\"{}\">".format(constants.STYLE_ERRORNOTIFICATION) + message + u"</span>" message = u"<span style=\"{}\">".format(constants.STYLE_ERRORNOTIFICATION) + message + u"</span>"
@ -698,8 +698,8 @@ class MainWindow(QtGui.QMainWindow):
self._syncplayClient.sendRoom() self._syncplayClient.sendRoom()
def seekPositionDialog(self): def seekPositionDialog(self):
seekTime, ok = QtGui.QInputDialog.getText(self, getMessage("seektime-menu-label"), seekTime, ok = QtWidgets.QInputDialog.getText(self, getMessage("seektime-menu-label"),
getMessage("seektime-msgbox-label"), QtGui.QLineEdit.Normal, getMessage("seektime-msgbox-label"), QtWidgets.QLineEdit.Normal,
u"0:00") u"0:00")
if ok and seekTime != '': if ok and seekTime != '':
self.seekPosition(seekTime) self.seekPosition(seekTime)
@ -766,10 +766,10 @@ class MainWindow(QtGui.QMainWindow):
defaultdirectory = self.config["mediaSearchDirectories"][0] defaultdirectory = self.config["mediaSearchDirectories"][0]
elif includeUserSpecifiedDirectories and os.path.isdir(self.mediadirectory): elif includeUserSpecifiedDirectories and os.path.isdir(self.mediadirectory):
defaultdirectory = self.mediadirectory defaultdirectory = self.mediadirectory
elif os.path.isdir(QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.MoviesLocation)): elif os.path.isdir(QStandardPaths.standardLocations(QStandardPaths.MoviesLocation)[0]):
defaultdirectory = QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.MoviesLocation) defaultdirectory = QStandardPaths.standardLocations(QStandardPaths.MoviesLocation)[0]
elif os.path.isdir(QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.HomeLocation)): elif os.path.isdir(QStandardPaths.standardLocations(QStandardPaths.HomeLocation)[0]):
defaultdirectory = QtGui.QDesktopServices.storageLocation(QtGui.QDesktopServices.HomeLocation) defaultdirectory = QStandardPaths.standardLocations(QStandardPaths.HomeLocation)[0]
else: else:
defaultdirectory = "" defaultdirectory = ""
return defaultdirectory return defaultdirectory
@ -781,7 +781,7 @@ class MainWindow(QtGui.QMainWindow):
return return
self.loadMediaBrowseSettings() self.loadMediaBrowseSettings()
options = QtGui.QFileDialog.Options() options = QtWidgets.QFileDialog.Options()
self.mediadirectory = "" self.mediadirectory = ""
currentdirectory = os.path.dirname(self._syncplayClient.userlist.currentUser.file["path"]) if self._syncplayClient.userlist.currentUser.file else None currentdirectory = os.path.dirname(self._syncplayClient.userlist.currentUser.file["path"]) if self._syncplayClient.userlist.currentUser.file else None
if currentdirectory and os.path.isdir(currentdirectory): if currentdirectory and os.path.isdir(currentdirectory):
@ -789,7 +789,7 @@ class MainWindow(QtGui.QMainWindow):
else: else:
defaultdirectory = self.getInitialMediaDirectory() defaultdirectory = self.getInitialMediaDirectory()
browserfilter = "All files (*)" browserfilter = "All files (*)"
fileName, filtr = QtGui.QFileDialog.getOpenFileName(self, getMessage("browseformedia-label"), defaultdirectory, fileName, filtr = QtWidgets.QFileDialog.getOpenFileName(self, getMessage("browseformedia-label"), defaultdirectory,
browserfilter, "", options) browserfilter, "", options)
if fileName: if fileName:
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
@ -806,7 +806,7 @@ class MainWindow(QtGui.QMainWindow):
return return
self.loadMediaBrowseSettings() self.loadMediaBrowseSettings()
options = QtGui.QFileDialog.Options() options = QtWidgets.QFileDialog.Options()
self.mediadirectory = "" self.mediadirectory = ""
currentdirectory = os.path.dirname(self._syncplayClient.userlist.currentUser.file["path"]) if self._syncplayClient.userlist.currentUser.file else None currentdirectory = os.path.dirname(self._syncplayClient.userlist.currentUser.file["path"]) if self._syncplayClient.userlist.currentUser.file else None
if currentdirectory and os.path.isdir(currentdirectory): if currentdirectory and os.path.isdir(currentdirectory):
@ -814,7 +814,7 @@ class MainWindow(QtGui.QMainWindow):
else: else:
defaultdirectory = self.getInitialMediaDirectory() defaultdirectory = self.getInitialMediaDirectory()
browserfilter = "All files (*)" browserfilter = "All files (*)"
fileNames, filtr = QtGui.QFileDialog.getOpenFileNames(self, getMessage("browseformedia-label"), defaultdirectory, fileNames, filtr = QtWidgets.QFileDialog.getOpenFileNames(self, getMessage("browseformedia-label"), defaultdirectory,
browserfilter, "", options) browserfilter, "", options)
self.updatingPlaylist = True self.updatingPlaylist = True
if fileNames: if fileNames:
@ -830,17 +830,17 @@ class MainWindow(QtGui.QMainWindow):
@needsClient @needsClient
def OpenAddURIsToPlaylistDialog(self): def OpenAddURIsToPlaylistDialog(self):
URIsDialog = QtGui.QDialog() URIsDialog = QtWidgets.QDialog()
URIsDialog.setWindowTitle(getMessage("adduris-msgbox-label")) URIsDialog.setWindowTitle(getMessage("adduris-msgbox-label"))
URIsLayout = QtGui.QGridLayout() URIsLayout = QtWidgets.QGridLayout()
URIsLabel = QtGui.QLabel(getMessage("adduris-msgbox-label")) URIsLabel = QtWidgets.QLabel(getMessage("adduris-msgbox-label"))
URIsLayout.addWidget(URIsLabel, 0, 0, 1, 1) URIsLayout.addWidget(URIsLabel, 0, 0, 1, 1)
URIsTextbox = QtGui.QPlainTextEdit() URIsTextbox = QtWidgets.QPlainTextEdit()
URIsTextbox.setLineWrapMode(QtGui.QPlainTextEdit.NoWrap) URIsTextbox.setLineWrapMode(QtWidgets.QPlainTextEdit.NoWrap)
URIsLayout.addWidget(URIsTextbox, 1, 0, 1, 1) URIsLayout.addWidget(URIsTextbox, 1, 0, 1, 1)
URIsButtonBox = QtGui.QDialogButtonBox() URIsButtonBox = QtWidgets.QDialogButtonBox()
URIsButtonBox.setOrientation(Qt.Horizontal) URIsButtonBox.setOrientation(Qt.Horizontal)
URIsButtonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel) URIsButtonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Ok|QtWidgets.QDialogButtonBox.Cancel)
URIsButtonBox.accepted.connect(URIsDialog.accept) URIsButtonBox.accepted.connect(URIsDialog.accept)
URIsButtonBox.rejected.connect(URIsDialog.reject) URIsButtonBox.rejected.connect(URIsDialog.reject)
URIsLayout.addWidget(URIsButtonBox, 2, 0, 1, 1) URIsLayout.addWidget(URIsButtonBox, 2, 0, 1, 1)
@ -848,7 +848,7 @@ class MainWindow(QtGui.QMainWindow):
URIsDialog.setModal(True) URIsDialog.setModal(True)
URIsDialog.show() URIsDialog.show()
result = URIsDialog.exec_() result = URIsDialog.exec_()
if result == QtGui.QDialog.Accepted: if result == QtWidgets.QDialog.Accepted:
URIsToAdd = utils.convertMultilineStringToList(URIsTextbox.toPlainText()) URIsToAdd = utils.convertMultilineStringToList(URIsTextbox.toPlainText())
self.updatingPlaylist = True self.updatingPlaylist = True
for URI in URIsToAdd: for URI in URIsToAdd:
@ -866,17 +866,17 @@ class MainWindow(QtGui.QMainWindow):
@needsClient @needsClient
def openEditPlaylistDialog(self): def openEditPlaylistDialog(self):
oldPlaylist = utils.getListAsMultilineString(self.getPlaylistState()) oldPlaylist = utils.getListAsMultilineString(self.getPlaylistState())
editPlaylistDialog = QtGui.QDialog() editPlaylistDialog = QtWidgets.QDialog()
editPlaylistDialog.setWindowTitle(getMessage("editplaylist-msgbox-label")) editPlaylistDialog.setWindowTitle(getMessage("editplaylist-msgbox-label"))
editPlaylistLayout = QtGui.QGridLayout() editPlaylistLayout = QtWidgets.QGridLayout()
editPlaylistLabel = QtGui.QLabel(getMessage("editplaylist-msgbox-label")) editPlaylistLabel = QtWidgets.QLabel(getMessage("editplaylist-msgbox-label"))
editPlaylistLayout.addWidget(editPlaylistLabel, 0, 0, 1, 1) editPlaylistLayout.addWidget(editPlaylistLabel, 0, 0, 1, 1)
editPlaylistTextbox = QtGui.QPlainTextEdit(oldPlaylist) editPlaylistTextbox = QtWidgets.QPlainTextEdit(oldPlaylist)
editPlaylistTextbox.setLineWrapMode(QtGui.QPlainTextEdit.NoWrap) editPlaylistTextbox.setLineWrapMode(QtWidgets.QPlainTextEdit.NoWrap)
editPlaylistLayout.addWidget(editPlaylistTextbox, 1, 0, 1, 1) editPlaylistLayout.addWidget(editPlaylistTextbox, 1, 0, 1, 1)
editPlaylistButtonBox = QtGui.QDialogButtonBox() editPlaylistButtonBox = QtWidgets.QDialogButtonBox()
editPlaylistButtonBox.setOrientation(Qt.Horizontal) editPlaylistButtonBox.setOrientation(Qt.Horizontal)
editPlaylistButtonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel) editPlaylistButtonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Ok|QtWidgets.QDialogButtonBox.Cancel)
editPlaylistButtonBox.accepted.connect(editPlaylistDialog.accept) editPlaylistButtonBox.accepted.connect(editPlaylistDialog.accept)
editPlaylistButtonBox.rejected.connect(editPlaylistDialog.reject) editPlaylistButtonBox.rejected.connect(editPlaylistDialog.reject)
editPlaylistLayout.addWidget(editPlaylistButtonBox, 2, 0, 1, 1) editPlaylistLayout.addWidget(editPlaylistButtonBox, 2, 0, 1, 1)
@ -886,7 +886,7 @@ class MainWindow(QtGui.QMainWindow):
editPlaylistDialog.setMinimumHeight(500) editPlaylistDialog.setMinimumHeight(500)
editPlaylistDialog.show() editPlaylistDialog.show()
result = editPlaylistDialog.exec_() result = editPlaylistDialog.exec_()
if result == QtGui.QDialog.Accepted: if result == QtWidgets.QDialog.Accepted:
newPlaylist = utils.convertMultilineStringToList(editPlaylistTextbox.toPlainText()) newPlaylist = utils.convertMultilineStringToList(editPlaylistTextbox.toPlainText())
if newPlaylist <> self.playlistState and self._syncplayClient and not self.updatingPlaylist: if newPlaylist <> self.playlistState and self._syncplayClient and not self.updatingPlaylist:
self.setPlaylist(newPlaylist) self.setPlaylist(newPlaylist)
@ -895,46 +895,46 @@ class MainWindow(QtGui.QMainWindow):
@needsClient @needsClient
def openSetMediaDirectoriesDialog(self): def openSetMediaDirectoriesDialog(self):
MediaDirectoriesDialog = QtGui.QDialog() MediaDirectoriesDialog = QtWidgets.QDialog()
MediaDirectoriesDialog.setWindowTitle(getMessage("syncplay-mediasearchdirectories-title")) # TODO: Move to messages_*.py MediaDirectoriesDialog.setWindowTitle(getMessage("syncplay-mediasearchdirectories-title")) # TODO: Move to messages_*.py
MediaDirectoriesLayout = QtGui.QGridLayout() MediaDirectoriesLayout = QtWidgets.QGridLayout()
MediaDirectoriesLabel = QtGui.QLabel(getMessage("syncplay-mediasearchdirectories-title")) MediaDirectoriesLabel = QtWidgets.QLabel(getMessage("syncplay-mediasearchdirectories-title"))
MediaDirectoriesLayout.addWidget(MediaDirectoriesLabel, 0, 0, 1, 2) MediaDirectoriesLayout.addWidget(MediaDirectoriesLabel, 0, 0, 1, 2)
MediaDirectoriesTextbox = QtGui.QPlainTextEdit() MediaDirectoriesTextbox = QtWidgets.QPlainTextEdit()
MediaDirectoriesTextbox.setLineWrapMode(QtGui.QPlainTextEdit.NoWrap) MediaDirectoriesTextbox.setLineWrapMode(QtWidgets.QPlainTextEdit.NoWrap)
MediaDirectoriesTextbox.setPlainText(utils.getListAsMultilineString(self.config["mediaSearchDirectories"])) MediaDirectoriesTextbox.setPlainText(utils.getListAsMultilineString(self.config["mediaSearchDirectories"]))
MediaDirectoriesLayout.addWidget(MediaDirectoriesTextbox, 1, 0, 1, 1) MediaDirectoriesLayout.addWidget(MediaDirectoriesTextbox, 1, 0, 1, 1)
MediaDirectoriesButtonBox = QtGui.QDialogButtonBox() MediaDirectoriesButtonBox = QtWidgets.QDialogButtonBox()
MediaDirectoriesButtonBox.setOrientation(Qt.Horizontal) MediaDirectoriesButtonBox.setOrientation(Qt.Horizontal)
MediaDirectoriesButtonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel) MediaDirectoriesButtonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Ok|QtWidgets.QDialogButtonBox.Cancel)
MediaDirectoriesButtonBox.accepted.connect(MediaDirectoriesDialog.accept) MediaDirectoriesButtonBox.accepted.connect(MediaDirectoriesDialog.accept)
MediaDirectoriesButtonBox.rejected.connect(MediaDirectoriesDialog.reject) MediaDirectoriesButtonBox.rejected.connect(MediaDirectoriesDialog.reject)
MediaDirectoriesLayout.addWidget(MediaDirectoriesButtonBox, 2, 0, 1, 1) MediaDirectoriesLayout.addWidget(MediaDirectoriesButtonBox, 2, 0, 1, 1)
MediaDirectoriesAddFolderButton = QtGui.QPushButton(getMessage("addfolder-label")) MediaDirectoriesAddFolderButton = QtWidgets.QPushButton(getMessage("addfolder-label"))
MediaDirectoriesAddFolderButton.pressed.connect(lambda: self.openAddMediaDirectoryDialog(MediaDirectoriesTextbox, MediaDirectoriesDialog)) MediaDirectoriesAddFolderButton.pressed.connect(lambda: self.openAddMediaDirectoryDialog(MediaDirectoriesTextbox, MediaDirectoriesDialog))
MediaDirectoriesLayout.addWidget(MediaDirectoriesAddFolderButton, 1, 1, 1, 1, Qt.AlignTop) MediaDirectoriesLayout.addWidget(MediaDirectoriesAddFolderButton, 1, 1, 1, 1, Qt.AlignTop)
MediaDirectoriesDialog.setLayout(MediaDirectoriesLayout) MediaDirectoriesDialog.setLayout(MediaDirectoriesLayout)
MediaDirectoriesDialog.setModal(True) MediaDirectoriesDialog.setModal(True)
MediaDirectoriesDialog.show() MediaDirectoriesDialog.show()
result = MediaDirectoriesDialog.exec_() result = MediaDirectoriesDialog.exec_()
if result == QtGui.QDialog.Accepted: if result == QtWidgets.QDialog.Accepted:
newMediaDirectories = utils.convertMultilineStringToList(MediaDirectoriesTextbox.toPlainText()) newMediaDirectories = utils.convertMultilineStringToList(MediaDirectoriesTextbox.toPlainText())
self._syncplayClient.fileSwitch.changeMediaDirectories(newMediaDirectories) self._syncplayClient.fileSwitch.changeMediaDirectories(newMediaDirectories)
@needsClient @needsClient
def openSetTrustedDomainsDialog(self): def openSetTrustedDomainsDialog(self):
TrustedDomainsDialog = QtGui.QDialog() TrustedDomainsDialog = QtWidgets.QDialog()
TrustedDomainsDialog.setWindowTitle(getMessage("syncplay-trusteddomains-title")) TrustedDomainsDialog.setWindowTitle(getMessage("syncplay-trusteddomains-title"))
TrustedDomainsLayout = QtGui.QGridLayout() TrustedDomainsLayout = QtWidgets.QGridLayout()
TrustedDomainsLabel = QtGui.QLabel(getMessage("trusteddomains-msgbox-label")) TrustedDomainsLabel = QtWidgets.QLabel(getMessage("trusteddomains-msgbox-label"))
TrustedDomainsLayout.addWidget(TrustedDomainsLabel, 0, 0, 1, 1) TrustedDomainsLayout.addWidget(TrustedDomainsLabel, 0, 0, 1, 1)
TrustedDomainsTextbox = QtGui.QPlainTextEdit() TrustedDomainsTextbox = QtWidgets.QPlainTextEdit()
TrustedDomainsTextbox.setLineWrapMode(QtGui.QPlainTextEdit.NoWrap) TrustedDomainsTextbox.setLineWrapMode(QtWidgets.QPlainTextEdit.NoWrap)
TrustedDomainsTextbox.setPlainText(utils.getListAsMultilineString(self.config["trustedDomains"])) TrustedDomainsTextbox.setPlainText(utils.getListAsMultilineString(self.config["trustedDomains"]))
TrustedDomainsLayout.addWidget(TrustedDomainsTextbox, 1, 0, 1, 1) TrustedDomainsLayout.addWidget(TrustedDomainsTextbox, 1, 0, 1, 1)
TrustedDomainsButtonBox = QtGui.QDialogButtonBox() TrustedDomainsButtonBox = QtWidgets.QDialogButtonBox()
TrustedDomainsButtonBox.setOrientation(Qt.Horizontal) TrustedDomainsButtonBox.setOrientation(Qt.Horizontal)
TrustedDomainsButtonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel) TrustedDomainsButtonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Ok|QtWidgets.QDialogButtonBox.Cancel)
TrustedDomainsButtonBox.accepted.connect(TrustedDomainsDialog.accept) TrustedDomainsButtonBox.accepted.connect(TrustedDomainsDialog.accept)
TrustedDomainsButtonBox.rejected.connect(TrustedDomainsDialog.reject) TrustedDomainsButtonBox.rejected.connect(TrustedDomainsDialog.reject)
TrustedDomainsLayout.addWidget(TrustedDomainsButtonBox, 2, 0, 1, 1) TrustedDomainsLayout.addWidget(TrustedDomainsButtonBox, 2, 0, 1, 1)
@ -942,7 +942,7 @@ class MainWindow(QtGui.QMainWindow):
TrustedDomainsDialog.setModal(True) TrustedDomainsDialog.setModal(True)
TrustedDomainsDialog.show() TrustedDomainsDialog.show()
result = TrustedDomainsDialog.exec_() result = TrustedDomainsDialog.exec_()
if result == QtGui.QDialog.Accepted: if result == QtWidgets.QDialog.Accepted:
newTrustedDomains = utils.convertMultilineStringToList(TrustedDomainsTextbox.toPlainText()) newTrustedDomains = utils.convertMultilineStringToList(TrustedDomainsTextbox.toPlainText())
self._syncplayClient.setTrustedDomains(newTrustedDomains) self._syncplayClient.setTrustedDomains(newTrustedDomains)
@needsClient @needsClient
@ -954,7 +954,7 @@ class MainWindow(QtGui.QMainWindow):
@needsClient @needsClient
def openAddMediaDirectoryDialog(self, MediaDirectoriesTextbox, MediaDirectoriesDialog): def openAddMediaDirectoryDialog(self, MediaDirectoriesTextbox, MediaDirectoriesDialog):
folderName = unicode(QtGui.QFileDialog.getExistingDirectory(self,None,self.getInitialMediaDirectory(includeUserSpecifiedDirectories=False),QtGui.QFileDialog.ShowDirsOnly)) folderName = unicode(QtWidgets.QFileDialog.getExistingDirectory(self,None,self.getInitialMediaDirectory(includeUserSpecifiedDirectories=False),QtWidgets.QFileDialog.ShowDirsOnly))
if folderName: if folderName:
existingMediaDirs = MediaDirectoriesTextbox.toPlainText() existingMediaDirs = MediaDirectoriesTextbox.toPlainText()
if existingMediaDirs == "": if existingMediaDirs == "":
@ -967,16 +967,16 @@ class MainWindow(QtGui.QMainWindow):
@needsClient @needsClient
def promptForStreamURL(self): def promptForStreamURL(self):
streamURL, ok = QtGui.QInputDialog.getText(self, getMessage("promptforstreamurl-msgbox-label"), streamURL, ok = QtWidgets.QInputDialog.getText(self, getMessage("promptforstreamurl-msgbox-label"),
getMessage("promptforstreamurlinfo-msgbox-label"), QtGui.QLineEdit.Normal, getMessage("promptforstreamurlinfo-msgbox-label"), QtWidgets.QLineEdit.Normal,
"") "")
if ok and streamURL != '': if ok and streamURL != '':
self._syncplayClient._player.openFile(streamURL) self._syncplayClient._player.openFile(streamURL)
@needsClient @needsClient
def createControlledRoom(self): def createControlledRoom(self):
controlroom, ok = QtGui.QInputDialog.getText(self, getMessage("createcontrolledroom-msgbox-label"), controlroom, ok = QtWidgets.QInputDialog.getText(self, getMessage("createcontrolledroom-msgbox-label"),
getMessage("controlledroominfo-msgbox-label"), QtGui.QLineEdit.Normal, getMessage("controlledroominfo-msgbox-label"), QtWidgets.QLineEdit.Normal,
utils.stripRoomName(self._syncplayClient.getRoom())) utils.stripRoomName(self._syncplayClient.getRoom()))
if ok and controlroom != '': if ok and controlroom != '':
self._syncplayClient.createControlledRoom(controlroom) self._syncplayClient.createControlledRoom(controlroom)
@ -985,7 +985,7 @@ class MainWindow(QtGui.QMainWindow):
def identifyAsController(self): def identifyAsController(self):
msgboxtitle = getMessage("identifyascontroller-msgbox-label") msgboxtitle = getMessage("identifyascontroller-msgbox-label")
msgboxtext = getMessage("identifyinfo-msgbox-label") msgboxtext = getMessage("identifyinfo-msgbox-label")
controlpassword, ok = QtGui.QInputDialog.getText(self, msgboxtitle, msgboxtext, QtGui.QLineEdit.Normal, "") controlpassword, ok = QtWidgets.QInputDialog.getText(self, msgboxtitle, msgboxtext, QtWidgets.QLineEdit.Normal, "")
if ok and controlpassword != '': if ok and controlpassword != '':
self._syncplayClient.identifyAsController(controlpassword) self._syncplayClient.identifyAsController(controlpassword)
@ -1000,8 +1000,8 @@ class MainWindow(QtGui.QMainWindow):
@needsClient @needsClient
def setOffset(self): def setOffset(self):
newoffset, ok = QtGui.QInputDialog.getText(self, getMessage("setoffset-msgbox-label"), newoffset, ok = QtWidgets.QInputDialog.getText(self, getMessage("setoffset-msgbox-label"),
getMessage("offsetinfo-msgbox-label"), QtGui.QLineEdit.Normal, getMessage("offsetinfo-msgbox-label"), QtWidgets.QLineEdit.Normal,
"") "")
if ok and newoffset != '': if ok and newoffset != '':
o = re.match(constants.UI_OFFSET_REGEX, "o " + newoffset) o = re.match(constants.UI_OFFSET_REGEX, "o " + newoffset)
@ -1054,8 +1054,8 @@ class MainWindow(QtGui.QMainWindow):
def addTopLayout(self, window): def addTopLayout(self, window):
window.topSplit = self.topSplitter(Qt.Horizontal, self) window.topSplit = self.topSplitter(Qt.Horizontal, self)
window.outputLayout = QtGui.QVBoxLayout() window.outputLayout = QtWidgets.QVBoxLayout()
window.outputbox = QtGui.QTextBrowser() window.outputbox = QtWidgets.QTextBrowser()
window.outputbox.setReadOnly(True) window.outputbox.setReadOnly(True)
window.outputbox.setTextInteractionFlags(window.outputbox.textInteractionFlags() | Qt.TextSelectableByKeyboard) window.outputbox.setTextInteractionFlags(window.outputbox.textInteractionFlags() | Qt.TextSelectableByKeyboard)
window.outputbox.setOpenExternalLinks(True) window.outputbox.setOpenExternalLinks(True)
@ -1065,24 +1065,24 @@ class MainWindow(QtGui.QMainWindow):
window.outputbox.moveCursor(QtGui.QTextCursor.End) window.outputbox.moveCursor(QtGui.QTextCursor.End)
window.outputbox.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) window.outputbox.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
window.outputlabel = QtGui.QLabel(getMessage("notifications-heading-label")) window.outputlabel = QtWidgets.QLabel(getMessage("notifications-heading-label"))
window.chatInput = QtGui.QLineEdit() window.chatInput = QtWidgets.QLineEdit()
window.chatInput.setMaxLength(constants.MAX_CHAT_MESSAGE_LENGTH) window.chatInput.setMaxLength(constants.MAX_CHAT_MESSAGE_LENGTH)
window.chatInput.returnPressed.connect(self.sendChatMessage) window.chatInput.returnPressed.connect(self.sendChatMessage)
window.chatButton = QtGui.QPushButton(QtGui.QIcon(self.resourcespath + 'email_go.png'), window.chatButton = QtWidgets.QPushButton(QtGui.QPixmap(self.resourcespath + 'email_go.png'),
getMessage("sendmessage-label")) getMessage("sendmessage-label"))
window.chatButton.pressed.connect(self.sendChatMessage) window.chatButton.pressed.connect(self.sendChatMessage)
window.chatLayout = QtGui.QHBoxLayout() window.chatLayout = QtWidgets.QHBoxLayout()
window.chatFrame = QtGui.QFrame() window.chatFrame = QtWidgets.QFrame()
window.chatFrame.setLayout(self.chatLayout) window.chatFrame.setLayout(self.chatLayout)
window.chatFrame.setContentsMargins(0,0,0,0) window.chatFrame.setContentsMargins(0,0,0,0)
window.chatFrame.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) window.chatFrame.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
window.chatLayout.setContentsMargins(0,0,0,0) window.chatLayout.setContentsMargins(0,0,0,0)
self.chatButton.setToolTip(getMessage("sendmessage-tooltip")) self.chatButton.setToolTip(getMessage("sendmessage-tooltip"))
window.chatLayout.addWidget(window.chatInput) window.chatLayout.addWidget(window.chatInput)
window.chatLayout.addWidget(window.chatButton) window.chatLayout.addWidget(window.chatButton)
window.chatFrame.setMaximumHeight(window.chatFrame.sizeHint().height()) window.chatFrame.setMaximumHeight(window.chatFrame.sizeHint().height())
window.outputFrame = QtGui.QFrame() window.outputFrame = QtWidgets.QFrame()
window.outputFrame.setLineWidth(0) window.outputFrame.setLineWidth(0)
window.outputFrame.setMidLineWidth(0) window.outputFrame.setMidLineWidth(0)
window.outputLayout.setContentsMargins(0, 0, 0, 0) window.outputLayout.setContentsMargins(0, 0, 0, 0)
@ -1091,47 +1091,47 @@ class MainWindow(QtGui.QMainWindow):
window.outputLayout.addWidget(window.chatFrame) window.outputLayout.addWidget(window.chatFrame)
window.outputFrame.setLayout(window.outputLayout) window.outputFrame.setLayout(window.outputLayout)
window.listLayout = QtGui.QVBoxLayout() window.listLayout = QtWidgets.QVBoxLayout()
window.listTreeModel = QtGui.QStandardItemModel() window.listTreeModel = QtGui.QStandardItemModel()
window.listTreeView = QtGui.QTreeView() window.listTreeView = QtWidgets.QTreeView()
window.listTreeView.setModel(window.listTreeModel) window.listTreeView.setModel(window.listTreeModel)
window.listTreeView.setIndentation(21) window.listTreeView.setIndentation(21)
window.listTreeView.doubleClicked.connect(self.roomClicked) window.listTreeView.doubleClicked.connect(self.roomClicked)
self.listTreeView.setContextMenuPolicy(Qt.CustomContextMenu) self.listTreeView.setContextMenuPolicy(Qt.CustomContextMenu)
self.listTreeView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) self.listTreeView.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
self.listTreeView.customContextMenuRequested.connect(self.openRoomMenu) self.listTreeView.customContextMenuRequested.connect(self.openRoomMenu)
window.listlabel = QtGui.QLabel(getMessage("userlist-heading-label")) window.listlabel = QtWidgets.QLabel(getMessage("userlist-heading-label"))
window.listFrame = QtGui.QFrame() window.listFrame = QtWidgets.QFrame()
window.listFrame.setLineWidth(0) window.listFrame.setLineWidth(0)
window.listFrame.setMidLineWidth(0) window.listFrame.setMidLineWidth(0)
window.listFrame.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred) window.listFrame.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
window.listLayout.setContentsMargins(0, 0, 0, 0) window.listLayout.setContentsMargins(0, 0, 0, 0)
window.userlistLayout = QtGui.QVBoxLayout() window.userlistLayout = QtWidgets.QVBoxLayout()
window.userlistFrame = QtGui.QFrame() window.userlistFrame = QtWidgets.QFrame()
window.userlistFrame.setLineWidth(0) window.userlistFrame.setLineWidth(0)
window.userlistFrame.setMidLineWidth(0) window.userlistFrame.setMidLineWidth(0)
window.userlistFrame.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred) window.userlistFrame.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
window.userlistLayout.setContentsMargins(0, 0, 0, 0) window.userlistLayout.setContentsMargins(0, 0, 0, 0)
window.userlistFrame.setLayout(window.userlistLayout) window.userlistFrame.setLayout(window.userlistLayout)
window.userlistLayout.addWidget(window.listlabel) window.userlistLayout.addWidget(window.listlabel)
window.userlistLayout.addWidget(window.listTreeView) window.userlistLayout.addWidget(window.listTreeView)
window.listSplit = QtGui.QSplitter(Qt.Vertical, self) window.listSplit = QtWidgets.QSplitter(Qt.Vertical, self)
window.listSplit.addWidget(window.userlistFrame) window.listSplit.addWidget(window.userlistFrame)
window.listLayout.addWidget(window.listSplit) window.listLayout.addWidget(window.listSplit)
window.roomInput = QtGui.QLineEdit() window.roomInput = QtWidgets.QLineEdit()
window.roomInput.setMaxLength(constants.MAX_ROOM_NAME_LENGTH) window.roomInput.setMaxLength(constants.MAX_ROOM_NAME_LENGTH)
window.roomInput.returnPressed.connect(self.joinRoom) window.roomInput.returnPressed.connect(self.joinRoom)
window.roomButton = QtGui.QPushButton(QtGui.QIcon(self.resourcespath + 'door_in.png'), window.roomButton = QtWidgets.QPushButton(QtGui.QPixmap(self.resourcespath + 'door_in.png'),
getMessage("joinroom-label")) getMessage("joinroom-label"))
window.roomButton.pressed.connect(self.joinRoom) window.roomButton.pressed.connect(self.joinRoom)
window.roomLayout = QtGui.QHBoxLayout() window.roomLayout = QtWidgets.QHBoxLayout()
window.roomFrame = QtGui.QFrame() window.roomFrame = QtWidgets.QFrame()
window.roomFrame.setLayout(self.roomLayout) window.roomFrame.setLayout(self.roomLayout)
window.roomFrame.setContentsMargins(0,0,0,0) window.roomFrame.setContentsMargins(0,0,0,0)
window.roomFrame.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) window.roomFrame.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
window.roomLayout.setContentsMargins(0,0,0,0) window.roomLayout.setContentsMargins(0,0,0,0)
self.roomButton.setToolTip(getMessage("joinroom-tooltip")) self.roomButton.setToolTip(getMessage("joinroom-tooltip"))
window.roomLayout.addWidget(window.roomInput) window.roomLayout.addWidget(window.roomInput)
@ -1146,11 +1146,11 @@ class MainWindow(QtGui.QMainWindow):
window.topSplit.setStretchFactor(0,4) window.topSplit.setStretchFactor(0,4)
window.topSplit.setStretchFactor(1,5) window.topSplit.setStretchFactor(1,5)
window.mainLayout.addWidget(window.topSplit) window.mainLayout.addWidget(window.topSplit)
window.topSplit.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding) window.topSplit.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Expanding)
def addBottomLayout(self, window): def addBottomLayout(self, window):
window.bottomLayout = QtGui.QHBoxLayout() window.bottomLayout = QtWidgets.QHBoxLayout()
window.bottomFrame = QtGui.QFrame() window.bottomFrame = QtWidgets.QFrame()
window.bottomFrame.setLayout(window.bottomLayout) window.bottomFrame.setLayout(window.bottomLayout)
window.bottomLayout.setContentsMargins(0,0,0,0) window.bottomLayout.setContentsMargins(0,0,0,0)
@ -1159,8 +1159,8 @@ class MainWindow(QtGui.QMainWindow):
window.playlistGroup = self.PlaylistGroupBox(getMessage("sharedplaylistenabled-label")) window.playlistGroup = self.PlaylistGroupBox(getMessage("sharedplaylistenabled-label"))
window.playlistGroup.setCheckable(True) window.playlistGroup.setCheckable(True)
window.playlistGroup.toggled.connect(self.changePlaylistEnabledState) window.playlistGroup.toggled.connect(self.changePlaylistEnabledState)
window.playlistLayout = QtGui.QHBoxLayout() window.playlistLayout = QtWidgets.QHBoxLayout()
window.playlistGroup.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred) window.playlistGroup.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
window.playlistGroup.setAcceptDrops(True) window.playlistGroup.setAcceptDrops(True)
window.playlist = self.PlaylistWidget() window.playlist = self.PlaylistWidget()
window.playlist.setWindow(window) window.playlist.setWindow(window)
@ -1168,18 +1168,18 @@ class MainWindow(QtGui.QMainWindow):
window.playlist.setDragEnabled(True) window.playlist.setDragEnabled(True)
window.playlist.setAcceptDrops(True) window.playlist.setAcceptDrops(True)
window.playlist.setDropIndicatorShown(True) window.playlist.setDropIndicatorShown(True)
window.playlist.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) window.playlist.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
window.playlist.setDefaultDropAction(Qt.MoveAction) window.playlist.setDefaultDropAction(Qt.MoveAction)
window.playlist.setDragDropMode(QtGui.QAbstractItemView.InternalMove) window.playlist.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove)
window.playlist.doubleClicked.connect(self.playlistItemClicked) window.playlist.doubleClicked.connect(self.playlistItemClicked)
window.playlist.setContextMenuPolicy(Qt.CustomContextMenu) window.playlist.setContextMenuPolicy(Qt.CustomContextMenu)
window.playlist.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) window.playlist.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
window.playlist.customContextMenuRequested.connect(self.openPlaylistMenu) window.playlist.customContextMenuRequested.connect(self.openPlaylistMenu)
self.playlistUpdateTimer = task.LoopingCall(self.playlistChangeCheck) self.playlistUpdateTimer = task.LoopingCall(self.playlistChangeCheck)
self.playlistUpdateTimer.start(0.1, True) self.playlistUpdateTimer.start(0.1, True)
noteFont = QtGui.QFont() noteFont = QtGui.QFont()
noteFont.setItalic(True) noteFont.setItalic(True)
playlistItem = QtGui.QListWidgetItem(getMessage("playlist-instruction-item-message")) playlistItem = QtWidgets.QListWidgetItem(getMessage("playlist-instruction-item-message"))
playlistItem.setFont(noteFont) playlistItem.setFont(noteFont)
window.playlist.addItem(playlistItem) window.playlist.addItem(playlistItem)
playlistItem.setFont(noteFont) playlistItem.setFont(noteFont)
@ -1189,7 +1189,7 @@ class MainWindow(QtGui.QMainWindow):
window.playlistGroup.setLayout(window.playlistLayout) window.playlistGroup.setLayout(window.playlistLayout)
window.listSplit.addWidget(window.playlistGroup) window.listSplit.addWidget(window.playlistGroup)
window.readyPushButton = QtGui.QPushButton() window.readyPushButton = QtWidgets.QPushButton()
readyFont = QtGui.QFont() readyFont = QtGui.QFont()
readyFont.setWeight(QtGui.QFont.Bold) readyFont.setWeight(QtGui.QFont.Bold)
window.readyPushButton.setText(getMessage("ready-guipushbuttonlabel")) window.readyPushButton.setText(getMessage("ready-guipushbuttonlabel"))
@ -1201,12 +1201,12 @@ class MainWindow(QtGui.QMainWindow):
window.readyPushButton.setToolTip(getMessage("ready-tooltip")) window.readyPushButton.setToolTip(getMessage("ready-tooltip"))
window.listLayout.addWidget(window.readyPushButton, Qt.AlignRight) window.listLayout.addWidget(window.readyPushButton, Qt.AlignRight)
window.autoplayLayout = QtGui.QHBoxLayout() window.autoplayLayout = QtWidgets.QHBoxLayout()
window.autoplayFrame = QtGui.QFrame() window.autoplayFrame = QtWidgets.QFrame()
window.autoplayFrame.setVisible(False) window.autoplayFrame.setVisible(False)
window.autoplayLayout.setContentsMargins(0,0,0,0) window.autoplayLayout.setContentsMargins(0,0,0,0)
window.autoplayFrame.setLayout(window.autoplayLayout) window.autoplayFrame.setLayout(window.autoplayLayout)
window.autoplayPushButton = QtGui.QPushButton() window.autoplayPushButton = QtWidgets.QPushButton()
autoPlayFont = QtGui.QFont() autoPlayFont = QtGui.QFont()
autoPlayFont.setWeight(QtGui.QFont.Bold) autoPlayFont.setWeight(QtGui.QFont.Bold)
window.autoplayPushButton.setText(getMessage("autoplay-guipushbuttonlabel")) window.autoplayPushButton.setText(getMessage("autoplay-guipushbuttonlabel"))
@ -1215,13 +1215,13 @@ class MainWindow(QtGui.QMainWindow):
window.autoplayPushButton.toggled.connect(self.changeAutoplayState) window.autoplayPushButton.toggled.connect(self.changeAutoplayState)
window.autoplayPushButton.setFont(autoPlayFont) window.autoplayPushButton.setFont(autoPlayFont)
window.autoplayPushButton.setStyleSheet(constants.STYLE_AUTO_PLAY_PUSHBUTTON) window.autoplayPushButton.setStyleSheet(constants.STYLE_AUTO_PLAY_PUSHBUTTON)
window.autoplayPushButton.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) window.autoplayPushButton.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
window.autoplayPushButton.setToolTip(getMessage("autoplay-tooltip")) window.autoplayPushButton.setToolTip(getMessage("autoplay-tooltip"))
window.autoplayLabel = QtGui.QLabel(getMessage("autoplay-minimum-label")) window.autoplayLabel = QtWidgets.QLabel(getMessage("autoplay-minimum-label"))
window.autoplayLabel.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) window.autoplayLabel.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
window.autoplayLabel.setMaximumWidth(window.autoplayLabel.minimumSizeHint().width()) window.autoplayLabel.setMaximumWidth(window.autoplayLabel.minimumSizeHint().width())
window.autoplayLabel.setToolTip(getMessage("autoplay-tooltip")) window.autoplayLabel.setToolTip(getMessage("autoplay-tooltip"))
window.autoplayThresholdSpinbox = QtGui.QSpinBox() window.autoplayThresholdSpinbox = QtWidgets.QSpinBox()
window.autoplayThresholdSpinbox.setMaximumWidth(window.autoplayThresholdSpinbox.minimumSizeHint().width()) window.autoplayThresholdSpinbox.setMaximumWidth(window.autoplayThresholdSpinbox.minimumSizeHint().width())
window.autoplayThresholdSpinbox.setMinimum(2) window.autoplayThresholdSpinbox.setMinimum(2)
window.autoplayThresholdSpinbox.setMaximum(99) window.autoplayThresholdSpinbox.setMaximum(99)
@ -1237,33 +1237,33 @@ class MainWindow(QtGui.QMainWindow):
window.bottomFrame.setMaximumHeight(window.bottomFrame.minimumSizeHint().height()) window.bottomFrame.setMaximumHeight(window.bottomFrame.minimumSizeHint().height())
def addPlaybackLayout(self, window): def addPlaybackLayout(self, window):
window.playbackFrame = QtGui.QFrame() window.playbackFrame = QtWidgets.QFrame()
window.playbackFrame.setVisible(False) window.playbackFrame.setVisible(False)
window.playbackFrame.setContentsMargins(0,0,0,0) window.playbackFrame.setContentsMargins(0,0,0,0)
window.playbackLayout = QtGui.QHBoxLayout() window.playbackLayout = QtWidgets.QHBoxLayout()
window.playbackLayout.setAlignment(Qt.AlignLeft) window.playbackLayout.setAlignment(Qt.AlignLeft)
window.playbackLayout.setContentsMargins(0,0,0,0) window.playbackLayout.setContentsMargins(0,0,0,0)
window.playbackFrame.setLayout(window.playbackLayout) window.playbackFrame.setLayout(window.playbackLayout)
window.seekInput = QtGui.QLineEdit() window.seekInput = QtWidgets.QLineEdit()
window.seekInput.returnPressed.connect(self.seekFromButton) window.seekInput.returnPressed.connect(self.seekFromButton)
window.seekButton = QtGui.QPushButton(QtGui.QIcon(self.resourcespath + u'clock_go.png'), "") window.seekButton = QtWidgets.QPushButton(QtGui.QPixmap(self.resourcespath + u'clock_go.png'), "")
window.seekButton.setToolTip(getMessage("seektime-menu-label")) window.seekButton.setToolTip(getMessage("seektime-menu-label"))
window.seekButton.pressed.connect(self.seekFromButton) window.seekButton.pressed.connect(self.seekFromButton)
window.seekInput.setText("0:00") window.seekInput.setText("0:00")
window.seekInput.setFixedWidth(60) window.seekInput.setFixedWidth(60)
window.playbackLayout.addWidget(window.seekInput) window.playbackLayout.addWidget(window.seekInput)
window.playbackLayout.addWidget(window.seekButton) window.playbackLayout.addWidget(window.seekButton)
window.unseekButton = QtGui.QPushButton(QtGui.QIcon(self.resourcespath + u'arrow_undo.png'), "") window.unseekButton = QtWidgets.QPushButton(QtGui.QPixmap(self.resourcespath + u'arrow_undo.png'), "")
window.unseekButton.setToolTip(getMessage("undoseek-menu-label")) window.unseekButton.setToolTip(getMessage("undoseek-menu-label"))
window.unseekButton.pressed.connect(self.undoSeek) window.unseekButton.pressed.connect(self.undoSeek)
window.miscLayout = QtGui.QHBoxLayout() window.miscLayout = QtWidgets.QHBoxLayout()
window.playbackLayout.addWidget(window.unseekButton) window.playbackLayout.addWidget(window.unseekButton)
window.playButton = QtGui.QPushButton(QtGui.QIcon(self.resourcespath + u'control_play_blue.png'), "") window.playButton = QtWidgets.QPushButton(QtGui.QPixmap(self.resourcespath + u'control_play_blue.png'), "")
window.playButton.setToolTip(getMessage("play-menu-label")) window.playButton.setToolTip(getMessage("play-menu-label"))
window.playButton.pressed.connect(self.play) window.playButton.pressed.connect(self.play)
window.playbackLayout.addWidget(window.playButton) window.playbackLayout.addWidget(window.playButton)
window.pauseButton = QtGui.QPushButton(QtGui.QIcon(self.resourcespath + 'control_pause_blue.png'), "") window.pauseButton = QtWidgets.QPushButton(QtGui.QPixmap(self.resourcespath + 'control_pause_blue.png'), "")
window.pauseButton.setToolTip(getMessage("pause-menu-label")) window.pauseButton.setToolTip(getMessage("pause-menu-label"))
window.pauseButton.pressed.connect(self.pause) window.pauseButton.pressed.connect(self.pause)
window.playbackLayout.addWidget(window.pauseButton) window.playbackLayout.addWidget(window.pauseButton)
@ -1272,54 +1272,54 @@ class MainWindow(QtGui.QMainWindow):
window.outputLayout.addWidget(window.playbackFrame) window.outputLayout.addWidget(window.playbackFrame)
def addMenubar(self, window): def addMenubar(self, window):
window.menuBar = QtGui.QMenuBar() window.menuBar = QtWidgets.QMenuBar()
# File menu # File menu
window.fileMenu = QtGui.QMenu(getMessage("file-menu-label"), self) window.fileMenu = QtWidgets.QMenu(getMessage("file-menu-label"), self)
window.openAction = window.fileMenu.addAction(QtGui.QIcon(self.resourcespath + 'folder_explore.png'), window.openAction = window.fileMenu.addAction(QtGui.QPixmap(self.resourcespath + 'folder_explore.png'),
getMessage("openmedia-menu-label")) getMessage("openmedia-menu-label"))
window.openAction.triggered.connect(self.browseMediapath) window.openAction.triggered.connect(self.browseMediapath)
window.openAction = window.fileMenu.addAction(QtGui.QIcon(self.resourcespath + 'world_explore.png'), window.openAction = window.fileMenu.addAction(QtGui.QPixmap(self.resourcespath + 'world_explore.png'),
getMessage("openstreamurl-menu-label")) getMessage("openstreamurl-menu-label"))
window.openAction.triggered.connect(self.promptForStreamURL) window.openAction.triggered.connect(self.promptForStreamURL)
window.openAction = window.fileMenu.addAction(QtGui.QIcon(self.resourcespath + 'film_folder_edit.png'), window.openAction = window.fileMenu.addAction(QtGui.QPixmap(self.resourcespath + 'film_folder_edit.png'),
getMessage("setmediadirectories-menu-label")) getMessage("setmediadirectories-menu-label"))
window.openAction.triggered.connect(self.openSetMediaDirectoriesDialog) window.openAction.triggered.connect(self.openSetMediaDirectoriesDialog)
window.exitAction = window.fileMenu.addAction(QtGui.QIcon(self.resourcespath + 'cross.png'), window.exitAction = window.fileMenu.addAction(QtGui.QPixmap(self.resourcespath + 'cross.png'),
getMessage("exit-menu-label")) getMessage("exit-menu-label"))
window.exitAction.triggered.connect(self.exitSyncplay) window.exitAction.triggered.connect(self.exitSyncplay)
window.menuBar.addMenu(window.fileMenu) window.menuBar.addMenu(window.fileMenu)
# Playback menu # Playback menu
window.playbackMenu = QtGui.QMenu(getMessage("playback-menu-label"), self) window.playbackMenu = QtWidgets.QMenu(getMessage("playback-menu-label"), self)
window.playAction = window.playbackMenu.addAction(QtGui.QIcon(self.resourcespath + 'control_play_blue.png'), getMessage("play-menu-label")) window.playAction = window.playbackMenu.addAction(QtGui.QPixmap(self.resourcespath + 'control_play_blue.png'), getMessage("play-menu-label"))
window.playAction.triggered.connect(self.play) window.playAction.triggered.connect(self.play)
window.pauseAction = window.playbackMenu.addAction(QtGui.QIcon(self.resourcespath + 'control_pause_blue.png'), getMessage("pause-menu-label")) window.pauseAction = window.playbackMenu.addAction(QtGui.QPixmap(self.resourcespath + 'control_pause_blue.png'), getMessage("pause-menu-label"))
window.pauseAction.triggered.connect(self.pause) window.pauseAction.triggered.connect(self.pause)
window.seekAction = window.playbackMenu.addAction(QtGui.QIcon(self.resourcespath + 'clock_go.png'), getMessage("seektime-menu-label")) window.seekAction = window.playbackMenu.addAction(QtGui.QPixmap(self.resourcespath + 'clock_go.png'), getMessage("seektime-menu-label"))
window.seekAction.triggered.connect(self.seekPositionDialog) window.seekAction.triggered.connect(self.seekPositionDialog)
window.unseekAction = window.playbackMenu.addAction(QtGui.QIcon(self.resourcespath + 'arrow_undo.png'), getMessage("undoseek-menu-label")) window.unseekAction = window.playbackMenu.addAction(QtGui.QPixmap(self.resourcespath + 'arrow_undo.png'), getMessage("undoseek-menu-label"))
window.unseekAction.triggered.connect(self.undoSeek) window.unseekAction.triggered.connect(self.undoSeek)
window.menuBar.addMenu(window.playbackMenu) window.menuBar.addMenu(window.playbackMenu)
# Advanced menu # Advanced menu
window.advancedMenu = QtGui.QMenu(getMessage("advanced-menu-label"), self) window.advancedMenu = QtWidgets.QMenu(getMessage("advanced-menu-label"), self)
window.setoffsetAction = window.advancedMenu.addAction(QtGui.QIcon(self.resourcespath + 'timeline_marker.png'), window.setoffsetAction = window.advancedMenu.addAction(QtGui.QPixmap(self.resourcespath + 'timeline_marker.png'),
getMessage("setoffset-menu-label")) getMessage("setoffset-menu-label"))
window.setoffsetAction.triggered.connect(self.setOffset) window.setoffsetAction.triggered.connect(self.setOffset)
window.setTrustedDomainsAction = window.advancedMenu.addAction(QtGui.QIcon(self.resourcespath + 'shield_edit.png'), window.setTrustedDomainsAction = window.advancedMenu.addAction(QtGui.QPixmap(self.resourcespath + 'shield_edit.png'),
getMessage("settrusteddomains-menu-label")) getMessage("settrusteddomains-menu-label"))
window.setTrustedDomainsAction.triggered.connect(self.openSetTrustedDomainsDialog) window.setTrustedDomainsAction.triggered.connect(self.openSetTrustedDomainsDialog)
window.createcontrolledroomAction = window.advancedMenu.addAction( window.createcontrolledroomAction = window.advancedMenu.addAction(
QtGui.QIcon(self.resourcespath + 'page_white_key.png'), getMessage("createcontrolledroom-menu-label")) QtGui.QPixmap(self.resourcespath + 'page_white_key.png'), getMessage("createcontrolledroom-menu-label"))
window.createcontrolledroomAction.triggered.connect(self.createControlledRoom) window.createcontrolledroomAction.triggered.connect(self.createControlledRoom)
window.identifyascontroller = window.advancedMenu.addAction(QtGui.QIcon(self.resourcespath + 'key_go.png'), window.identifyascontroller = window.advancedMenu.addAction(QtGui.QPixmap(self.resourcespath + 'key_go.png'),
getMessage("identifyascontroller-menu-label")) getMessage("identifyascontroller-menu-label"))
window.identifyascontroller.triggered.connect(self.identifyAsController) window.identifyascontroller.triggered.connect(self.identifyAsController)
@ -1327,7 +1327,7 @@ class MainWindow(QtGui.QMainWindow):
# Window menu # Window menu
window.windowMenu = QtGui.QMenu(getMessage("window-menu-label"), self) window.windowMenu = QtWidgets.QMenu(getMessage("window-menu-label"), self)
window.playbackAction = window.windowMenu.addAction(getMessage("playbackbuttons-menu-label")) window.playbackAction = window.windowMenu.addAction(getMessage("playbackbuttons-menu-label"))
window.playbackAction.setCheckable(True) window.playbackAction.setCheckable(True)
@ -1341,11 +1341,15 @@ class MainWindow(QtGui.QMainWindow):
# Help menu # Help menu
window.helpMenu = QtGui.QMenu(getMessage("help-menu-label"), self) window.helpMenu = QtWidgets.QMenu(getMessage("help-menu-label"), self)
window.userguideAction = window.helpMenu.addAction(QtGui.QIcon(self.resourcespath + 'help.png'), if sys.platform.startswith('darwin'):
window.about = window.helpMenu.addAction("&About")
window.about.triggered.connect(self.openAbout)
window.userguideAction = window.helpMenu.addAction(QtGui.QPixmap(self.resourcespath + 'help.png'),
getMessage("userguide-menu-label")) getMessage("userguide-menu-label"))
window.userguideAction.triggered.connect(self.openUserGuide) window.userguideAction.triggered.connect(self.openUserGuide)
window.updateAction = window.helpMenu.addAction(QtGui.QIcon(self.resourcespath + 'application_get.png'), window.updateAction = window.helpMenu.addAction(QtGui.QPixmap(self.resourcespath + 'application_get.png'),
getMessage("update-menu-label")) getMessage("update-menu-label"))
window.updateAction.triggered.connect(self.userCheckForUpdates) window.updateAction.triggered.connect(self.userCheckForUpdates)
@ -1353,8 +1357,11 @@ class MainWindow(QtGui.QMainWindow):
if not sys.platform.startswith('darwin'): if not sys.platform.startswith('darwin'):
window.mainLayout.setMenuBar(window.menuBar) window.mainLayout.setMenuBar(window.menuBar)
def openAbout(self):
AboutMsgBox = QtGui.QMessageBox.about(self,"Syncplay","Syncplay v" + version)
def addMainFrame(self, window): def addMainFrame(self, window):
window.mainFrame = QtGui.QFrame() window.mainFrame = QtWidgets.QFrame()
window.mainFrame.setLineWidth(0) window.mainFrame.setLineWidth(0)
window.mainFrame.setMidLineWidth(0) window.mainFrame.setMidLineWidth(0)
window.mainFrame.setContentsMargins(0, 0, 0, 0) window.mainFrame.setContentsMargins(0, 0, 0, 0)
@ -1414,16 +1421,16 @@ class MainWindow(QtGui.QMainWindow):
def updateReadyIcon(self): def updateReadyIcon(self):
ready = self.readyPushButton.isChecked() ready = self.readyPushButton.isChecked()
if ready: if ready:
self.readyPushButton.setIcon(QtGui.QIcon(self.resourcespath + 'tick_checkbox.png')) self.readyPushButton.setIcon(QtGui.QPixmap(self.resourcespath + 'tick_checkbox.png'))
else: else:
self.readyPushButton.setIcon(QtGui.QIcon(self.resourcespath + 'empty_checkbox.png')) self.readyPushButton.setIcon(QtGui.QPixmap(self.resourcespath + 'empty_checkbox.png'))
def updateAutoPlayIcon(self): def updateAutoPlayIcon(self):
ready = self.autoplayPushButton.isChecked() ready = self.autoplayPushButton.isChecked()
if ready: if ready:
self.autoplayPushButton.setIcon(QtGui.QIcon(self.resourcespath + 'tick_checkbox.png')) self.autoplayPushButton.setIcon(QtGui.QPixmap(self.resourcespath + 'tick_checkbox.png'))
else: else:
self.autoplayPushButton.setIcon(QtGui.QIcon(self.resourcespath + 'empty_checkbox.png')) self.autoplayPushButton.setIcon(QtGui.QPixmap(self.resourcespath + 'empty_checkbox.png'))
def automaticUpdateCheck(self): def automaticUpdateCheck(self):
currentDateTime = datetime.utcnow() currentDateTime = datetime.utcnow()
@ -1459,12 +1466,12 @@ class MainWindow(QtGui.QMainWindow):
if userInitiated == True: if userInitiated == True:
updateURL = constants.SYNCPLAY_DOWNLOAD_URL updateURL = constants.SYNCPLAY_DOWNLOAD_URL
if updateURL is not None: if updateURL is not None:
reply = QtGui.QMessageBox.question(self, "Syncplay", reply = QtWidgets.QMessageBox.question(self, "Syncplay",
updateMessage, QtGui.QMessageBox.StandardButton.Yes | QtGui.QMessageBox.StandardButton.No) updateMessage, QtWidgets.QMessageBox.StandardButton.Yes | QtWidgets.QMessageBox.StandardButton.No)
if reply == QtGui.QMessageBox.Yes: if reply == QtWidgets.QMessageBox.Yes:
self.QtGui.QDesktopServices.openUrl(QUrl(updateURL)) self.QtGui.QDesktopServices.openUrl(QUrl(updateURL))
elif userInitiated: elif userInitiated:
QtGui.QMessageBox.information(self, "Syncplay", updateMessage) QtWidgets.QMessageBox.information(self, "Syncplay", updateMessage)
else: else:
self.showMessage(updateMessage) self.showMessage(updateMessage)
@ -1476,8 +1483,8 @@ class MainWindow(QtGui.QMainWindow):
def dropEvent(self, event): def dropEvent(self, event):
rewindFile = False rewindFile = False
if QtGui.QDropEvent.proposedAction(event) == Qt.MoveAction: if QtWidgets.QDropEvent.proposedAction(event) == Qt.MoveAction:
QtGui.QDropEvent.setDropAction(event, Qt.CopyAction) # Avoids file being deleted QtWidgets.QDropEvent.setDropAction(event, Qt.CopyAction) # Avoids file being deleted
rewindFile = True rewindFile = True
data = event.mimeData() data = event.mimeData()
urls = data.urls() urls = data.urls()
@ -1618,15 +1625,18 @@ class MainWindow(QtGui.QMainWindow):
self.resourcespath = utils.findWorkingDir() + u"\\resources\\" self.resourcespath = utils.findWorkingDir() + u"\\resources\\"
else: else:
self.resourcespath = utils.findWorkingDir() + u"/resources/" self.resourcespath = utils.findWorkingDir() + u"/resources/"
self.setWindowFlags(self.windowFlags() & Qt.AA_DontUseNativeMenuBar) if sys.platform.startswith('darwin'):
self.setWindowFlags(self.windowFlags())
else:
self.setWindowFlags(self.windowFlags() & Qt.AA_DontUseNativeMenuBar)
self.setWindowTitle("Syncplay v" + version) self.setWindowTitle("Syncplay v" + version)
self.mainLayout = QtGui.QVBoxLayout() self.mainLayout = QtWidgets.QVBoxLayout()
self.addTopLayout(self) self.addTopLayout(self)
self.addBottomLayout(self) self.addBottomLayout(self)
self.addMenubar(self) self.addMenubar(self)
self.addMainFrame(self) self.addMainFrame(self)
self.loadSettings() self.loadSettings()
self.setWindowIcon(QtGui.QIcon(self.resourcespath + u"syncplay.png")) self.setWindowIcon(QtGui.QPixmap(self.resourcespath + u"syncplay.png"))
self.setWindowFlags(self.windowFlags() & Qt.WindowCloseButtonHint & Qt.AA_DontUseNativeMenuBar & Qt.WindowMinimizeButtonHint & ~Qt.WindowContextHelpButtonHint) self.setWindowFlags(self.windowFlags() & Qt.WindowCloseButtonHint & Qt.AA_DontUseNativeMenuBar & Qt.WindowMinimizeButtonHint & ~Qt.WindowContextHelpButtonHint)
self.show() self.show()
self.setAcceptDrops(True) self.setAcceptDrops(True)

View File

@ -124,6 +124,8 @@ def findWorkingDir():
path = os.path.dirname(os.path.dirname(__file__)) path = os.path.dirname(os.path.dirname(__file__))
elif frozen in ('dll', 'console_exe', 'windows_exe'): elif frozen in ('dll', 'console_exe', 'windows_exe'):
path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
elif frozen in ('macosx_app'):
path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))))
else: else:
path = "" path = ""
return path return path

View File

@ -1,5 +1,76 @@
# Copyright (c) 2001-2011 Twisted Matrix Laboratories. # -*- coding: utf-8 -*-
# See LICENSE for details. # Copyright (c) 2001-2017
# Allen Short
# Andy Gayton
# Andrew Bennetts
# Antoine Pitrou
# Apple Computer, Inc.
# Ashwini Oruganti
# bakbuk
# Benjamin Bruheim
# Bob Ippolito
# Burak Nehbit
# Canonical Limited
# Christopher Armstrong
# Christopher R. Wood
# David Reid
# Donovan Preston
# Elvis Stansvik
# Eric Mangold
# Eyal Lotem
# Glenn Tarbox
# Google Inc.
# Hybrid Logic Ltd.
# Hynek Schlawack
# Itamar Turner-Trauring
# James Knight
# Jason A. Mobarak
# Jean-Paul Calderone
# Jessica McKellar
# Jonathan Jacobs
# Jonathan Lange
# Jonathan D. Simms
# Jürgen Hermann
# Julian Berman
# Kevin Horn
# Kevin Turner
# Kyle Altendorf
# Laurens Van Houtven
# Mary Gardiner
# Matthew Lefkowitz
# Massachusetts Institute of Technology
# Moshe Zadka
# Paul Swartz
# Pavel Pergamenshchik
# Ralph Meijer
# Richard Wall
# Sean Riley
# Software Freedom Conservancy
# Tarashish Mishra
# Travis B. Hartwell
# Thijs Triemstra
# Thomas Herve
# Timothy Allen
# Tom Prince
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
""" """
@ -7,13 +78,8 @@ This module provides support for Twisted to be driven by the Qt mainloop.
In order to use this support, simply do the following:: In order to use this support, simply do the following::
| app = QApplication(sys.argv) # your code to init Qt | app = QApplication(sys.argv) # your code to init Qt
| import qt4reactor | import qt5reactor
| qt4reactor.install() | qt5reactor.install()
alternatively:
| from twisted.application import reactors
| reactors.installReactor('qt4')
Then use twisted.internet APIs as usual. The other methods here are not Then use twisted.internet APIs as usual. The other methods here are not
intended to be called directly. intended to be called directly.
@ -27,65 +93,61 @@ Twisted can be initialized after QApplication.exec_() with a call to
reactor.runReturn(). calling reactor.stop() will unhook twisted but reactor.runReturn(). calling reactor.stop() will unhook twisted but
leave your Qt application running leave your Qt application running
API Stability: stable Qt5 Port: U{Burak Nehbit<mailto:burak@nehbit.net>}
Maintainer: U{Glenn H Tarbox, PhD<mailto:glenn@tarbox.org>} Current maintainer: U{Christopher R. Wood<mailto:chris@leastauthority.com>}
Previous maintainer: U{Tarashish Mishra<mailto:sunu@sunu.in>}
Previous maintainer: U{Glenn H Tarbox, PhD<mailto:glenn@tarbox.org>}
Previous maintainer: U{Itamar Shtull-Trauring<mailto:twisted@itamarst.org>} Previous maintainer: U{Itamar Shtull-Trauring<mailto:twisted@itamarst.org>}
Original port to QT4: U{Gabe Rudy<mailto:rudy@goldenhelix.com>} Original port to QT4: U{Gabe Rudy<mailto:rudy@goldenhelix.com>}
Subsequent port by therve Subsequent port by therve
""" """
import sys import sys
import time
from zope.interface import implements from PySide2.QtCore import (
QCoreApplication, QEventLoop, QObject, QSocketNotifier, QTimer, Signal)
from twisted.internet import posixbase
from twisted.internet.interfaces import IReactorFDSet from twisted.internet.interfaces import IReactorFDSet
from twisted.python import log, runtime from twisted.python import log, runtime
from twisted.internet import posixbase from zope.interface import implementer
from twisted.python.runtime import platformType, platform
try:
from PyQt4.QtCore import QSocketNotifier, QObject, SIGNAL, QTimer, QCoreApplication
from PyQt4.QtCore import QEventLoop
except ImportError:
from PySide.QtCore import QSocketNotifier, QObject, SIGNAL, QTimer, QCoreApplication
from PySide.QtCore import QEventLoop
class TwistedSocketNotifier(QObject): class TwistedSocketNotifier(QObject):
""" """Connection between an fd event and reader/writer callbacks."""
Connection between an fd event and reader/writer callbacks.
""" activated = Signal(int)
def __init__(self, parent, reactor, watcher, socketType): def __init__(self, parent, reactor, watcher, socketType):
QObject.__init__(self, parent) QObject.__init__(self, parent)
self.reactor = reactor self.reactor = reactor
self.watcher = watcher self.watcher = watcher
fd = watcher.fileno() fd = self.watcher.fileno()
self.notifier = QSocketNotifier(fd, socketType, parent) self.notifier = QSocketNotifier(watcher, socketType, parent)
self.notifier.setEnabled(True) self.notifier.setEnabled(True)
if socketType == QSocketNotifier.Read: if socketType == QSocketNotifier.Read:
self.fn = self.read self.fn = self.read
else: else:
self.fn = self.write self.fn = self.write
QObject.connect(self.notifier, SIGNAL("activated(int)"), self.fn) self.notifier.activated.connect(self.fn)
def shutdown(self): def shutdown(self):
self.notifier.setEnabled(False) self.notifier.setEnabled(False)
self.disconnect(self.notifier, SIGNAL("activated(int)"), self.fn) self.notifier.activated.disconnect(self.fn)
self.fn = self.watcher = None self.fn = self.watcher = None
self.notifier.deleteLater() self.notifier.deleteLater()
self.deleteLater() self.deleteLater()
def read(self, fd): def read(self, fd):
if not self.watcher: if not self.watcher:
return return
w = self.watcher w = self.watcher
# doRead can cause self.shutdown to be called so keep a reference to self.watcher # doRead can cause self.shutdown to be called so keep
# a reference to self.watcher
def _read(): def _read():
#Don't call me again, until the data has been read # Don't call me again, until the data has been read
self.notifier.setEnabled(False) self.notifier.setEnabled(False)
why = None why = None
try: try:
@ -98,18 +160,20 @@ class TwistedSocketNotifier(QObject):
if why: if why:
self.reactor._disconnectSelectable(w, why, inRead) self.reactor._disconnectSelectable(w, why, inRead)
elif self.watcher: elif self.watcher:
self.notifier.setEnabled(True) # Re enable notification following sucessfull read self.notifier.setEnabled(True)
# Re enable notification following sucessfull read
self.reactor._iterate(fromqt=True) self.reactor._iterate(fromqt=True)
log.callWithLogger(w, _read) log.callWithLogger(w, _read)
def write(self, sock): def write(self, sock):
if not self.watcher: if not self.watcher:
return return
w = self.watcher w = self.watcher
def _write(): def _write():
why = None why = None
self.notifier.setEnabled(False) self.notifier.setEnabled(False)
try: try:
why = w.doWrite() why = w.doWrite()
except: except:
@ -120,12 +184,13 @@ class TwistedSocketNotifier(QObject):
elif self.watcher: elif self.watcher:
self.notifier.setEnabled(True) self.notifier.setEnabled(True)
self.reactor._iterate(fromqt=True) self.reactor._iterate(fromqt=True)
log.callWithLogger(w, _write) log.callWithLogger(w, _write)
@implementer(IReactorFDSet)
class QtReactor(posixbase.PosixReactorBase): class QtReactor(posixbase.PosixReactorBase):
implements(IReactorFDSet) # implements(IReactorFDSet)
def __init__(self): def __init__(self):
self._reads = {} self._reads = {}
@ -133,19 +198,17 @@ class QtReactor(posixbase.PosixReactorBase):
self._notifiers = {} self._notifiers = {}
self._timer = QTimer() self._timer = QTimer()
self._timer.setSingleShot(True) self._timer.setSingleShot(True)
QObject.connect(self._timer, SIGNAL("timeout()"), self.iterate) self._timer.timeout.connect(self.iterate_qt)
if QCoreApplication.instance() is None: if QCoreApplication.instance() is None:
# Application Object has not been started yet # Application Object has not been started yet
self.qApp=QCoreApplication([]) self.qApp = QCoreApplication([])
self._ownApp=True self._ownApp = True
else: else:
self.qApp = QCoreApplication.instance() self.qApp = QCoreApplication.instance()
self._ownApp=False self._ownApp = False
self._blockApp = None self._blockApp = None
posixbase.PosixReactorBase.__init__(self) posixbase.PosixReactorBase.__init__(self)
def _add(self, xer, primary, type): def _add(self, xer, primary, type):
""" """
Private method for adding a descriptor from the event loop. Private method for adding a descriptor from the event loop.
@ -156,21 +219,14 @@ class QtReactor(posixbase.PosixReactorBase):
if xer not in primary: if xer not in primary:
primary[xer] = TwistedSocketNotifier(None, self, xer, type) primary[xer] = TwistedSocketNotifier(None, self, xer, type)
def addReader(self, reader): def addReader(self, reader):
""" """Add a FileDescriptor for notification of data available to read."""
Add a FileDescriptor for notification of data available to read.
"""
self._add(reader, self._reads, QSocketNotifier.Read) self._add(reader, self._reads, QSocketNotifier.Read)
def addWriter(self, writer): def addWriter(self, writer):
""" """Add a FileDescriptor for notification of data available to write."""
Add a FileDescriptor for notification of data available to write.
"""
self._add(writer, self._writes, QSocketNotifier.Write) self._add(writer, self._writes, QSocketNotifier.Write)
def _remove(self, xer, primary): def _remove(self, xer, primary):
""" """
Private method for removing a descriptor from the event loop. Private method for removing a descriptor from the event loop.
@ -182,81 +238,66 @@ class QtReactor(posixbase.PosixReactorBase):
notifier = primary.pop(xer) notifier = primary.pop(xer)
notifier.shutdown() notifier.shutdown()
def removeReader(self, reader): def removeReader(self, reader):
""" """Remove a Selectable for notification of data available to read."""
Remove a Selectable for notification of data available to read.
"""
self._remove(reader, self._reads) self._remove(reader, self._reads)
def removeWriter(self, writer): def removeWriter(self, writer):
""" """Remove a Selectable for notification of data available to write."""
Remove a Selectable for notification of data available to write.
"""
self._remove(writer, self._writes) self._remove(writer, self._writes)
def removeAll(self): def removeAll(self):
""" """Remove all selectables, and return a list of them."""
Remove all selectables, and return a list of them. return self._removeAll(self._reads, self._writes)
"""
rv = self._removeAll(self._reads, self._writes)
return rv
def getReaders(self): def getReaders(self):
return self._reads.keys() return self._reads.keys()
def getWriters(self): def getWriters(self):
return self._writes.keys() return self._writes.keys()
def callLater(self, howlong, *args, **kargs):
def callLater(self,howlong, *args, **kargs): rval = super(QtReactor, self).callLater(howlong, *args, **kargs)
rval = super(QtReactor,self).callLater(howlong, *args, **kargs)
self.reactorInvocation() self.reactorInvocation()
return rval return rval
def reactorInvocation(self): def reactorInvocation(self):
self._timer.stop() self._timer.stop()
self._timer.setInterval(0) self._timer.setInterval(0)
self._timer.start() self._timer.start()
def _iterate(self, delay=None, fromqt=False): def _iterate(self, delay=None, fromqt=False):
"""See twisted.internet.interfaces.IReactorCore.iterate. """See twisted.internet.interfaces.IReactorCore.iterate."""
"""
self.runUntilCurrent() self.runUntilCurrent()
self.doIteration(delay, fromqt) self.doIteration(delay, fromqt=fromqt)
iterate = _iterate iterate = _iterate
def iterate_qt(self, delay=None):
self.iterate(delay=delay, fromqt=True)
def doIteration(self, delay=None, fromqt=False): def doIteration(self, delay=None, fromqt=False):
'This method is called by a Qt timer or by network activity on a file descriptor' """This method is called by a Qt timer or by network activity on a file descriptor"""
if not self.running and self._blockApp: if not self.running and self._blockApp:
self._blockApp.quit() self._blockApp.quit()
self._timer.stop() self._timer.stop()
if delay is None:
delay = 0
delay = max(delay, 1) delay = max(delay, 1)
if not fromqt: if not fromqt:
self.qApp.processEvents(QEventLoop.AllEvents, delay * 1000) self.qApp.processEvents(QEventLoop.AllEvents, delay * 1000)
if self.timeout() is None: t = self.timeout()
timeout = 0.1 if t is None:
elif self.timeout() == 0: timeout = 0.01
timeout = 0
else: else:
timeout = self.timeout() timeout = min(t, 0.01)
self._timer.setInterval(timeout * 1000) self._timer.setInterval(timeout * 1000)
self._timer.start() self._timer.start()
def runReturn(self, installSignalHandlers=True): def runReturn(self, installSignalHandlers=True):
self.startRunning(installSignalHandlers=installSignalHandlers) self.startRunning(installSignalHandlers=installSignalHandlers)
self.reactorInvocation() self.reactorInvocation()
def run(self, installSignalHandlers=True): def run(self, installSignalHandlers=True):
if self._ownApp: if self._ownApp:
self._blockApp = self.qApp self._blockApp = self.qApp
@ -264,6 +305,21 @@ class QtReactor(posixbase.PosixReactorBase):
self._blockApp = QEventLoop() self._blockApp = QEventLoop()
self.runReturn() self.runReturn()
self._blockApp.exec_() self._blockApp.exec_()
if self.running:
self.stop()
self.runUntilCurrent()
# def sigInt(self, *args):
# print('I received a sigint. BAIBAI')
# posixbase.PosixReactorBase.sigInt()
#
# def sigTerm(self, *args):
# print('I received a sigterm. BAIBAI')
# posixbase.PosixReactorBase.sigTerm()
#
# def sigBreak(self, *args):
# print('I received a sigbreak. BAIBAI')
# posixbase.PosixReactorBase.sigBreak()
class QtEventReactor(QtReactor): class QtEventReactor(QtReactor):
@ -271,22 +327,15 @@ class QtEventReactor(QtReactor):
self._events = {} self._events = {}
super(QtEventReactor, self).__init__() super(QtEventReactor, self).__init__()
def addEvent(self, event, fd, action): def addEvent(self, event, fd, action):
""" """Add a new win32 event to the event loop."""
Add a new win32 event to the event loop.
"""
self._events[event] = (fd, action) self._events[event] = (fd, action)
def removeEvent(self, event): def removeEvent(self, event):
""" """Remove an event."""
Remove an event.
"""
if event in self._events: if event in self._events:
del self._events[event] del self._events[event]
def doEvents(self): def doEvents(self):
handles = self._events.keys() handles = self._events.keys()
if len(handles) > 0: if len(handles) > 0:
@ -304,46 +353,33 @@ class QtEventReactor(QtReactor):
#print 'Got an unexpected return of %r' % val #print 'Got an unexpected return of %r' % val
return return
def _runAction(self, action, fd): def _runAction(self, action, fd):
try: try:
closed = getattr(fd, action)() closed = getattr(fd, action)()
except: except:
closed = sys.exc_info()[1] closed = sys.exc_info()[1]
log.deferr() log.deferr()
if closed: if closed:
self._disconnectSelectable(fd, closed, action == 'doRead') self._disconnectSelectable(fd, closed, action == 'doRead')
def iterate(self, delay=None, fromqt=False):
def timeout(self): """See twisted.internet.interfaces.IReactorCore.iterate."""
t = super(QtEventReactor, self).timeout()
return min(t, 0.01)
def iterate(self, delay=None):
"""See twisted.internet.interfaces.IReactorCore.iterate.
"""
self.runUntilCurrent() self.runUntilCurrent()
self.doEvents() self.doEvents()
self.doIteration(delay) self.doIteration(delay, fromqt=fromqt)
def posixinstall(): def posixinstall():
""" """Install the Qt reactor."""
Install the Qt reactor.
"""
p = QtReactor()
from twisted.internet.main import installReactor from twisted.internet.main import installReactor
p = QtReactor()
installReactor(p) installReactor(p)
def win32install(): def win32install():
""" """Install the Qt reactor."""
Install the Qt reactor.
"""
p = QtEventReactor()
from twisted.internet.main import installReactor from twisted.internet.main import installReactor
p = QtEventReactor()
installReactor(p) installReactor(p)
@ -356,4 +392,3 @@ else:
__all__ = ["install"] __all__ = ["install"]