Refactor resourcespath/posixpath to utils

This commit is contained in:
Etoh 2017-12-10 14:58:39 +00:00
parent 8a082ed1cd
commit 2618a0f527
3 changed files with 64 additions and 89 deletions

View File

@ -13,7 +13,7 @@ import threading
from syncplay.messages import getMessage, getLanguages, setLanguage, getInitialLanguage from syncplay.messages import getMessage, getLanguages, setLanguage, getInitialLanguage
from syncplay import constants from syncplay import constants
from syncplay.utils import isBSD, isLinux, isWindows, isOSX from syncplay.utils import isBSD, isLinux, isWindows, isOSX
from syncplay.utils import resourcespath, posixresourcespath
class GuiConfiguration: class GuiConfiguration:
def __init__(self, config, error=None, defaultConfig=None): def __init__(self, config, error=None, defaultConfig=None):
self.defaultConfig = defaultConfig self.defaultConfig = defaultConfig
@ -186,12 +186,12 @@ class ConfigDialog(QtWidgets.QDialog):
def _updateExecutableIcon(self, iconpath, playerpath): def _updateExecutableIcon(self, iconpath, playerpath):
if iconpath is not None and iconpath != "": if iconpath is not None and iconpath != "":
if iconpath.endswith('.mng'): if iconpath.endswith('.mng'):
movie = QtGui.QMovie(self.resourcespath + iconpath) movie = QtGui.QMovie(resourcespath + iconpath)
movie.setCacheMode(QtGui.QMovie.CacheMode.CacheAll) movie.setCacheMode(QtGui.QMovie.CacheMode.CacheAll)
self.executableiconLabel.setMovie(movie) self.executableiconLabel.setMovie(movie)
movie.start() movie.start()
else: else:
self.executableiconImage.load(self.resourcespath + iconpath) self.executableiconImage.load(resourcespath + iconpath)
self.executableiconLabel.setPixmap(QtGui.QPixmap.fromImage(self.executableiconImage)) self.executableiconLabel.setPixmap(QtGui.QPixmap.fromImage(self.executableiconImage))
else: else:
self.executableiconLabel.setPixmap(QtGui.QPixmap.fromImage(QtGui.QImage())) self.executableiconLabel.setPixmap(QtGui.QPixmap.fromImage(QtGui.QImage()))
@ -531,7 +531,6 @@ class ConfigDialog(QtWidgets.QDialog):
def addBasicTab(self): def addBasicTab(self):
config = self.config config = self.config
playerpaths = self.playerpaths playerpaths = self.playerpaths
resourcespath = self.resourcespath
error = self.error error = self.error
if self.datacleared == True: if self.datacleared == True:
error = constants.ERROR_MESSAGE_MARKER + "{}".format(getMessage("gui-data-cleared-notification")) error = constants.ERROR_MESSAGE_MARKER + "{}".format(getMessage("gui-data-cleared-notification"))
@ -702,22 +701,22 @@ class ConfigDialog(QtWidgets.QDialog):
self.readyUnpauseButtonGroup = QButtonGroup() self.readyUnpauseButtonGroup = QButtonGroup()
self.unpauseIfAlreadyReadyOption = QRadioButton(getMessage("unpause-ifalreadyready-option")) self.unpauseIfAlreadyReadyOption = QRadioButton(getMessage("unpause-ifalreadyready-option"))
self.readyUnpauseButtonGroup.addButton(self.unpauseIfAlreadyReadyOption) self.readyUnpauseButtonGroup.addButton(self.unpauseIfAlreadyReadyOption)
self.unpauseIfAlreadyReadyOption.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + "chevrons_right.png")) self.unpauseIfAlreadyReadyOption.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(posixresourcespath + "chevrons_right.png"))
self.unpauseIfAlreadyReadyOption.setObjectName("unpause-ifalreadyready" + constants.CONFIG_NAME_MARKER + "unpauseAction" + constants.CONFIG_VALUE_MARKER + constants.UNPAUSE_IFALREADYREADY_MODE) self.unpauseIfAlreadyReadyOption.setObjectName("unpause-ifalreadyready" + constants.CONFIG_NAME_MARKER + "unpauseAction" + constants.CONFIG_VALUE_MARKER + constants.UNPAUSE_IFALREADYREADY_MODE)
self.readyUnpauseLayout.addWidget(self.unpauseIfAlreadyReadyOption) self.readyUnpauseLayout.addWidget(self.unpauseIfAlreadyReadyOption)
self.unpauseIfOthersReadyOption = QRadioButton(getMessage("unpause-ifothersready-option")) self.unpauseIfOthersReadyOption = QRadioButton(getMessage("unpause-ifothersready-option"))
self.readyUnpauseButtonGroup.addButton(self.unpauseIfOthersReadyOption) self.readyUnpauseButtonGroup.addButton(self.unpauseIfOthersReadyOption)
self.unpauseIfOthersReadyOption.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + "chevrons_right.png")) self.unpauseIfOthersReadyOption.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(posixresourcespath + "chevrons_right.png"))
self.unpauseIfOthersReadyOption.setObjectName("unpause-ifothersready" + constants.CONFIG_NAME_MARKER + "unpauseAction" + constants.CONFIG_VALUE_MARKER + constants.UNPAUSE_IFOTHERSREADY_MODE) self.unpauseIfOthersReadyOption.setObjectName("unpause-ifothersready" + constants.CONFIG_NAME_MARKER + "unpauseAction" + constants.CONFIG_VALUE_MARKER + constants.UNPAUSE_IFOTHERSREADY_MODE)
self.readyUnpauseLayout.addWidget(self.unpauseIfOthersReadyOption) self.readyUnpauseLayout.addWidget(self.unpauseIfOthersReadyOption)
self.unpauseIfMinUsersReadyOption = QRadioButton(getMessage("unpause-ifminusersready-option")) self.unpauseIfMinUsersReadyOption = QRadioButton(getMessage("unpause-ifminusersready-option"))
self.readyUnpauseButtonGroup.addButton(self.unpauseIfMinUsersReadyOption) self.readyUnpauseButtonGroup.addButton(self.unpauseIfMinUsersReadyOption)
self.unpauseIfMinUsersReadyOption.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + "chevrons_right.png")) self.unpauseIfMinUsersReadyOption.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(posixresourcespath + "chevrons_right.png"))
self.unpauseIfMinUsersReadyOption.setObjectName("unpause-ifminusersready" + constants.CONFIG_NAME_MARKER + "unpauseAction" + constants.CONFIG_VALUE_MARKER + constants.UNPAUSE_IFMINUSERSREADY_MODE) self.unpauseIfMinUsersReadyOption.setObjectName("unpause-ifminusersready" + constants.CONFIG_NAME_MARKER + "unpauseAction" + constants.CONFIG_VALUE_MARKER + constants.UNPAUSE_IFMINUSERSREADY_MODE)
self.readyUnpauseLayout.addWidget(self.unpauseIfMinUsersReadyOption) self.readyUnpauseLayout.addWidget(self.unpauseIfMinUsersReadyOption)
self.unpauseAlwaysUnpauseOption = QRadioButton(getMessage("unpause-always")) self.unpauseAlwaysUnpauseOption = QRadioButton(getMessage("unpause-always"))
self.readyUnpauseButtonGroup.addButton(self.unpauseAlwaysUnpauseOption) self.readyUnpauseButtonGroup.addButton(self.unpauseAlwaysUnpauseOption)
self.unpauseAlwaysUnpauseOption.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + "chevrons_right.png")) self.unpauseAlwaysUnpauseOption.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(posixresourcespath + "chevrons_right.png"))
self.unpauseAlwaysUnpauseOption.setObjectName("unpause-always" + constants.CONFIG_NAME_MARKER + "unpauseAction" + constants.CONFIG_VALUE_MARKER + constants.UNPAUSE_ALWAYS_MODE) self.unpauseAlwaysUnpauseOption.setObjectName("unpause-always" + constants.CONFIG_NAME_MARKER + "unpauseAction" + constants.CONFIG_VALUE_MARKER + constants.UNPAUSE_ALWAYS_MODE)
self.readyUnpauseLayout.addWidget(self.unpauseAlwaysUnpauseOption) self.readyUnpauseLayout.addWidget(self.unpauseAlwaysUnpauseOption)
self.readyLayout.addWidget(self.readyUnpauseGroup) self.readyLayout.addWidget(self.readyUnpauseGroup)
@ -886,27 +885,27 @@ class ConfigDialog(QtWidgets.QDialog):
self.showSameRoomOSDCheckbox = QCheckBox(getMessage("showsameroomosd-label")) self.showSameRoomOSDCheckbox = QCheckBox(getMessage("showsameroomosd-label"))
self.showSameRoomOSDCheckbox.setObjectName("showSameRoomOSD") self.showSameRoomOSDCheckbox.setObjectName("showSameRoomOSD")
self.showSameRoomOSDCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + u"chevrons_right.png")) self.showSameRoomOSDCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(posixresourcespath + u"chevrons_right.png"))
self.osdSettingsLayout.addWidget(self.showSameRoomOSDCheckbox) self.osdSettingsLayout.addWidget(self.showSameRoomOSDCheckbox)
self.showNonControllerOSDCheckbox = QCheckBox(getMessage("shownoncontrollerosd-label")) self.showNonControllerOSDCheckbox = QCheckBox(getMessage("shownoncontrollerosd-label"))
self.showNonControllerOSDCheckbox.setObjectName("showNonControllerOSD") self.showNonControllerOSDCheckbox.setObjectName("showNonControllerOSD")
self.showNonControllerOSDCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + u"chevrons_right.png")) self.showNonControllerOSDCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(posixresourcespath + u"chevrons_right.png"))
self.osdSettingsLayout.addWidget(self.showNonControllerOSDCheckbox) self.osdSettingsLayout.addWidget(self.showNonControllerOSDCheckbox)
self.showDifferentRoomOSDCheckbox = QCheckBox(getMessage("showdifferentroomosd-label")) self.showDifferentRoomOSDCheckbox = QCheckBox(getMessage("showdifferentroomosd-label"))
self.showDifferentRoomOSDCheckbox.setObjectName("showDifferentRoomOSD") self.showDifferentRoomOSDCheckbox.setObjectName("showDifferentRoomOSD")
self.showDifferentRoomOSDCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + u"chevrons_right.png")) self.showDifferentRoomOSDCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(posixresourcespath + u"chevrons_right.png"))
self.osdSettingsLayout.addWidget(self.showDifferentRoomOSDCheckbox) self.osdSettingsLayout.addWidget(self.showDifferentRoomOSDCheckbox)
self.slowdownOSDCheckbox = QCheckBox(getMessage("showslowdownosd-label")) self.slowdownOSDCheckbox = QCheckBox(getMessage("showslowdownosd-label"))
self.slowdownOSDCheckbox.setObjectName("showSlowdownOSD") self.slowdownOSDCheckbox.setObjectName("showSlowdownOSD")
self.slowdownOSDCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + u"chevrons_right.png")) self.slowdownOSDCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(posixresourcespath + u"chevrons_right.png"))
self.osdSettingsLayout.addWidget(self.slowdownOSDCheckbox) self.osdSettingsLayout.addWidget(self.slowdownOSDCheckbox)
self.showOSDWarningsCheckbox = QCheckBox(getMessage("showosdwarnings-label")) self.showOSDWarningsCheckbox = QCheckBox(getMessage("showosdwarnings-label"))
self.showOSDWarningsCheckbox.setObjectName("showOSDWarnings") self.showOSDWarningsCheckbox.setObjectName("showOSDWarnings")
self.showOSDWarningsCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + u"chevrons_right.png")) self.showOSDWarningsCheckbox.setStyleSheet(constants.STYLE_SUBCHECKBOX.format(posixresourcespath + u"chevrons_right.png"))
self.osdSettingsLayout.addWidget(self.showOSDWarningsCheckbox) self.osdSettingsLayout.addWidget(self.showOSDWarningsCheckbox)
self.subitems['showOSD'] = ["showSameRoomOSD", "showDifferentRoomOSD", "showSlowdownOSD", "showOSDWarnings", "showNonControllerOSD"] self.subitems['showOSD'] = ["showSameRoomOSD", "showDifferentRoomOSD", "showSlowdownOSD", "showOSDWarnings", "showNonControllerOSD"]
@ -962,11 +961,10 @@ class ConfigDialog(QtWidgets.QDialog):
def addBottomLayout(self): def addBottomLayout(self):
config = self.config config = self.config
resourcespath = self.resourcespath
self.bottomButtonFrame = QtWidgets.QFrame() self.bottomButtonFrame = QtWidgets.QFrame()
self.bottomButtonLayout = QtWidgets.QHBoxLayout() self.bottomButtonLayout = QtWidgets.QHBoxLayout()
self.helpButton = QtWidgets.QPushButton(QtGui.QIcon(self.resourcespath + u'help.png'), getMessage("help-label")) self.helpButton = QtWidgets.QPushButton(QtGui.QIcon(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)
@ -1007,11 +1005,11 @@ class ConfigDialog(QtWidgets.QDialog):
self.tabListLayout = QtWidgets.QHBoxLayout() self.tabListLayout = QtWidgets.QHBoxLayout()
self.tabListFrame = QtWidgets.QFrame() self.tabListFrame = QtWidgets.QFrame()
self.tabListWidget = QtWidgets.QListWidget() self.tabListWidget = QtWidgets.QListWidget()
self.tabListWidget.addItem(QtWidgets.QListWidgetItem(QtGui.QIcon(self.resourcespath + u"house.png"),getMessage("basics-label"))) self.tabListWidget.addItem(QtWidgets.QListWidgetItem(QtGui.QIcon(resourcespath + u"house.png"),getMessage("basics-label")))
self.tabListWidget.addItem(QtWidgets.QListWidgetItem(QtGui.QIcon(self.resourcespath + u"control_pause_blue.png"),getMessage("readiness-label"))) self.tabListWidget.addItem(QtWidgets.QListWidgetItem(QtGui.QIcon(resourcespath + u"control_pause_blue.png"),getMessage("readiness-label")))
self.tabListWidget.addItem(QtWidgets.QListWidgetItem(QtGui.QIcon(self.resourcespath + u"film_link.png"),getMessage("sync-label"))) self.tabListWidget.addItem(QtWidgets.QListWidgetItem(QtGui.QIcon(resourcespath + u"film_link.png"),getMessage("sync-label")))
self.tabListWidget.addItem(QtWidgets.QListWidgetItem(QtGui.QIcon(self.resourcespath + u"comments.png"),getMessage("messages-label"))) self.tabListWidget.addItem(QtWidgets.QListWidgetItem(QtGui.QIcon(resourcespath + u"comments.png"),getMessage("messages-label")))
self.tabListWidget.addItem(QtWidgets.QListWidgetItem(QtGui.QIcon(self.resourcespath + u"cog.png"),getMessage("misc-label"))) self.tabListWidget.addItem(QtWidgets.QListWidgetItem(QtGui.QIcon(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() + constants.TAB_PADDING) self.tabListFrame.setFixedWidth(self.tabListFrame.minimumSizeHint().width() + constants.TAB_PADDING)
@ -1110,12 +1108,6 @@ class ConfigDialog(QtWidgets.QDialog):
self.QtWidgets = QtWidgets self.QtWidgets = QtWidgets
self.QtGui = QtGui self.QtGui = QtGui
self.error = error self.error = error
if isWindows():
resourcespath = utils.findWorkingDir() + "\\resources\\"
else:
resourcespath = utils.findWorkingDir() + u"/resources/"
self.posixresourcespath = utils.findWorkingDir().replace(u"\\","/") + u"/resources/"
self.resourcespath = resourcespath
super(ConfigDialog, self).__init__() super(ConfigDialog, self).__init__()

View File

@ -5,6 +5,7 @@ if IsPySide2:
from PySide2.QtCore import QStandardPaths from PySide2.QtCore import QStandardPaths
from syncplay import utils, constants, version, release_number from syncplay import utils, constants, version, release_number
from syncplay.messages import getMessage from syncplay.messages import getMessage
from syncplay.utils import resourcespath
import sys import sys
import time import time
import urllib import urllib
@ -35,10 +36,6 @@ class UserlistItemDelegate(QtWidgets.QStyledItemDelegate):
if column == constants.USERLIST_GUI_USERNAME_COLUMN: if column == constants.USERLIST_GUI_USERNAME_COLUMN:
currentQAbstractItemModel = indexQModelIndex.model() currentQAbstractItemModel = indexQModelIndex.model()
itemQModelIndex = currentQAbstractItemModel.index(indexQModelIndex.row(), constants.USERLIST_GUI_USERNAME_COLUMN, indexQModelIndex.parent()) itemQModelIndex = currentQAbstractItemModel.index(indexQModelIndex.row(), constants.USERLIST_GUI_USERNAME_COLUMN, indexQModelIndex.parent())
if isWindows():
resourcespath = utils.findWorkingDir() + u"\\resources\\"
else:
resourcespath = utils.findWorkingDir() + u"/resources/"
controlIconQPixmap = QtGui.QPixmap(resourcespath + u"user_key.png") controlIconQPixmap = QtGui.QPixmap(resourcespath + u"user_key.png")
tickIconQPixmap = QtGui.QPixmap(resourcespath + u"tick.png") tickIconQPixmap = QtGui.QPixmap(resourcespath + u"tick.png")
crossIconQPixmap = QtGui.QPixmap(resourcespath + u"cross.png") crossIconQPixmap = QtGui.QPixmap(resourcespath + u"cross.png")
@ -66,10 +63,6 @@ class UserlistItemDelegate(QtWidgets.QStyledItemDelegate):
if isUserRow: if isUserRow:
optionQStyleOptionViewItem.rect.setX(optionQStyleOptionViewItem.rect.x()+constants.USERLIST_GUI_USERNAME_OFFSET) optionQStyleOptionViewItem.rect.setX(optionQStyleOptionViewItem.rect.x()+constants.USERLIST_GUI_USERNAME_OFFSET)
if column == constants.USERLIST_GUI_FILENAME_COLUMN: if column == constants.USERLIST_GUI_FILENAME_COLUMN:
if isWindows():
resourcespath = utils.findWorkingDir() + u"\\resources\\"
else:
resourcespath = utils.findWorkingDir() + u"/resources/"
currentQAbstractItemModel = indexQModelIndex.model() currentQAbstractItemModel = indexQModelIndex.model()
itemQModelIndex = currentQAbstractItemModel.index(indexQModelIndex.row(), constants.USERLIST_GUI_FILENAME_COLUMN, indexQModelIndex.parent()) itemQModelIndex = currentQAbstractItemModel.index(indexQModelIndex.row(), constants.USERLIST_GUI_FILENAME_COLUMN, indexQModelIndex.parent())
fileSwitchRole = currentQAbstractItemModel.data(itemQModelIndex, Qt.UserRole + constants.FILEITEM_SWITCH_ROLE) fileSwitchRole = currentQAbstractItemModel.data(itemQModelIndex, Qt.UserRole + constants.FILEITEM_SWITCH_ROLE)
@ -91,10 +84,6 @@ class UserlistItemDelegate(QtWidgets.QStyledItemDelegate):
QtWidgets.QStyledItemDelegate.paint(self, itemQPainter, optionQStyleOptionViewItem, indexQModelIndex) QtWidgets.QStyledItemDelegate.paint(self, itemQPainter, optionQStyleOptionViewItem, indexQModelIndex)
class AboutDialog(QtWidgets.QDialog): class AboutDialog(QtWidgets.QDialog):
if isWindows():
resourcespath = utils.findWorkingDir() + u"\\resources\\"
else:
resourcespath = utils.findWorkingDir() + u"/resources/"
def __init__(self, parent=None): def __init__(self, parent=None):
super(AboutDialog, self).__init__(parent) super(AboutDialog, self).__init__(parent)
@ -110,7 +99,7 @@ class AboutDialog(QtWidgets.QDialog):
linkLabel.setOpenExternalLinks(True) linkLabel.setOpenExternalLinks(True)
versionLabel = QtWidgets.QLabel("<center>" + getMessage("about-dialog-release").format(version, release_number, __binding__) + "</center>") versionLabel = QtWidgets.QLabel("<center>" + getMessage("about-dialog-release").format(version, release_number, __binding__) + "</center>")
licenseLabel = QtWidgets.QLabel("<center><p>Copyright &copy; 2017 Syncplay</p><p>" + getMessage("about-dialog-license-text") + "</p></center>") licenseLabel = QtWidgets.QLabel("<center><p>Copyright &copy; 2017 Syncplay</p><p>" + getMessage("about-dialog-license-text") + "</p></center>")
aboutIconPixmap = QtGui.QPixmap(self.resourcespath + u"syncplay.png") aboutIconPixmap = QtGui.QPixmap(resourcespath + u"syncplay.png")
aboutIconLabel = QtWidgets.QLabel() aboutIconLabel = QtWidgets.QLabel()
aboutIconLabel.setPixmap(aboutIconPixmap.scaled(120, 120, Qt.KeepAspectRatio)) aboutIconLabel.setPixmap(aboutIconPixmap.scaled(120, 120, Qt.KeepAspectRatio))
aboutLayout = QtWidgets.QGridLayout() aboutLayout = QtWidgets.QGridLayout()
@ -133,15 +122,15 @@ class AboutDialog(QtWidgets.QDialog):
def openLicense(self): def openLicense(self):
if isWindows(): if isWindows():
QtGui.QDesktopServices.openUrl(QUrl("file:///" + self.resourcespath + u"license.rtf")) QtGui.QDesktopServices.openUrl(QUrl("file:///" + resourcespath + u"license.rtf"))
else: else:
QtGui.QDesktopServices.openUrl(QUrl("file://" + self.resourcespath + u"license.rtf")) QtGui.QDesktopServices.openUrl(QUrl("file://" + resourcespath + u"license.rtf"))
def openDependencies(self): def openDependencies(self):
if isWindows(): if isWindows():
QtGui.QDesktopServices.openUrl(QUrl("file:///" + self.resourcespath + u"third-party-notices.rtf")) QtGui.QDesktopServices.openUrl(QUrl("file:///" + resourcespath + u"third-party-notices.rtf"))
else: else:
QtGui.QDesktopServices.openUrl(QUrl("file://" + self.resourcespath + u"third-party-notices.rtf")) QtGui.QDesktopServices.openUrl(QUrl("file://" + resourcespath + u"third-party-notices.rtf"))
class MainWindow(QtWidgets.QMainWindow): class MainWindow(QtWidgets.QMainWindow):
insertPosition = None insertPosition = None
@ -161,10 +150,6 @@ class MainWindow(QtWidgets.QMainWindow):
itemQPainter.save() itemQPainter.save()
currentQAbstractItemModel = indexQModelIndex.model() currentQAbstractItemModel = indexQModelIndex.model()
currentlyPlayingFile = currentQAbstractItemModel.data(indexQModelIndex, Qt.UserRole + constants.PLAYLISTITEM_CURRENTLYPLAYING_ROLE) currentlyPlayingFile = currentQAbstractItemModel.data(indexQModelIndex, Qt.UserRole + constants.PLAYLISTITEM_CURRENTLYPLAYING_ROLE)
if isWindows():
resourcespath = utils.findWorkingDir() + u"\\resources\\"
else:
resourcespath = utils.findWorkingDir() + u"/resources/"
if currentlyPlayingFile: if currentlyPlayingFile:
currentlyplayingIconQPixmap = QtGui.QPixmap(resourcespath + u"bullet_right_grey.png") currentlyplayingIconQPixmap = QtGui.QPixmap(resourcespath + u"bullet_right_grey.png")
midY = int((optionQStyleOptionViewItem.rect.y() + optionQStyleOptionViewItem.rect.bottomLeft().y()) / 2) midY = int((optionQStyleOptionViewItem.rect.y() + optionQStyleOptionViewItem.rect.bottomLeft().y()) / 2)
@ -474,11 +459,11 @@ class MainWindow(QtWidgets.QMainWindow):
if isControlledRoom: if isControlledRoom:
if room == currentUser.room and currentUser.isController(): if room == currentUser.room and currentUser.isController():
roomitem.setIcon(QtGui.QPixmap(self.resourcespath + 'lock_open.png')) roomitem.setIcon(QtGui.QPixmap(resourcespath + 'lock_open.png'))
else: else:
roomitem.setIcon(QtGui.QPixmap(self.resourcespath + 'lock.png')) roomitem.setIcon(QtGui.QPixmap(resourcespath + 'lock.png'))
else: else:
roomitem.setIcon(QtGui.QPixmap(self.resourcespath + 'chevrons_right.png')) roomitem.setIcon(QtGui.QPixmap(resourcespath + 'chevrons_right.png'))
for user in rooms[room]: for user in rooms[room]:
useritem = QtGui.QStandardItem(user.username) useritem = QtGui.QStandardItem(user.username)
@ -568,10 +553,6 @@ class MainWindow(QtWidgets.QMainWindow):
@needsClient @needsClient
def openPlaylistMenu(self, position): def openPlaylistMenu(self, position):
indexes = self.playlist.selectedIndexes() indexes = self.playlist.selectedIndexes()
if isWindows():
resourcespath = utils.findWorkingDir() + u"\\resources\\"
else:
resourcespath = utils.findWorkingDir() + u"/resources/"
if len(indexes) > 0: if len(indexes) > 0:
item = self.playlist.selectedIndexes()[0] item = self.playlist.selectedIndexes()[0]
else: else:
@ -610,10 +591,6 @@ class MainWindow(QtWidgets.QMainWindow):
def openRoomMenu(self, position): def openRoomMenu(self, position):
# TODO: Deselect items after right click # TODO: Deselect items after right click
indexes = self.listTreeView.selectedIndexes() indexes = self.listTreeView.selectedIndexes()
if isWindows():
resourcespath = utils.findWorkingDir() + u"\\resources\\"
else:
resourcespath = utils.findWorkingDir() + u"/resources/"
if len(indexes) > 0: if len(indexes) > 0:
item = self.listTreeView.selectedIndexes()[0] item = self.listTreeView.selectedIndexes()[0]
else: else:
@ -1172,7 +1149,7 @@ class MainWindow(QtWidgets.QMainWindow):
window.chatInput = QtWidgets.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 = QtWidgets.QPushButton(QtGui.QPixmap(self.resourcespath + 'email_go.png'), window.chatButton = QtWidgets.QPushButton(QtGui.QPixmap(resourcespath + 'email_go.png'),
getMessage("sendmessage-label")) getMessage("sendmessage-label"))
window.chatButton.pressed.connect(self.sendChatMessage) window.chatButton.pressed.connect(self.sendChatMessage)
window.chatLayout = QtWidgets.QHBoxLayout() window.chatLayout = QtWidgets.QHBoxLayout()
@ -1227,7 +1204,7 @@ class MainWindow(QtWidgets.QMainWindow):
window.roomInput = QtWidgets.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 = QtWidgets.QPushButton(QtGui.QPixmap(self.resourcespath + 'door_in.png'), window.roomButton = QtWidgets.QPushButton(QtGui.QPixmap(resourcespath + 'door_in.png'),
getMessage("joinroom-label")) getMessage("joinroom-label"))
window.roomButton.pressed.connect(self.joinRoom) window.roomButton.pressed.connect(self.joinRoom)
window.roomLayout = QtWidgets.QHBoxLayout() window.roomLayout = QtWidgets.QHBoxLayout()
@ -1349,24 +1326,24 @@ class MainWindow(QtWidgets.QMainWindow):
window.playbackFrame.setLayout(window.playbackLayout) window.playbackFrame.setLayout(window.playbackLayout)
window.seekInput = QtWidgets.QLineEdit() window.seekInput = QtWidgets.QLineEdit()
window.seekInput.returnPressed.connect(self.seekFromButton) window.seekInput.returnPressed.connect(self.seekFromButton)
window.seekButton = QtWidgets.QPushButton(QtGui.QPixmap(self.resourcespath + u'clock_go.png'), "") window.seekButton = QtWidgets.QPushButton(QtGui.QPixmap(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 = QtWidgets.QPushButton(QtGui.QPixmap(self.resourcespath + u'arrow_undo.png'), "") window.unseekButton = QtWidgets.QPushButton(QtGui.QPixmap(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 = QtWidgets.QHBoxLayout() window.miscLayout = QtWidgets.QHBoxLayout()
window.playbackLayout.addWidget(window.unseekButton) window.playbackLayout.addWidget(window.unseekButton)
window.playButton = QtWidgets.QPushButton(QtGui.QPixmap(self.resourcespath + u'control_play_blue.png'), "") window.playButton = QtWidgets.QPushButton(QtGui.QPixmap(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 = QtWidgets.QPushButton(QtGui.QPixmap(self.resourcespath + 'control_pause_blue.png'), "") window.pauseButton = QtWidgets.QPushButton(QtGui.QPixmap(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)
@ -1380,18 +1357,18 @@ class MainWindow(QtWidgets.QMainWindow):
# File menu # File menu
window.fileMenu = QtWidgets.QMenu(getMessage("file-menu-label"), self) window.fileMenu = QtWidgets.QMenu(getMessage("file-menu-label"), self)
window.openAction = window.fileMenu.addAction(QtGui.QPixmap(self.resourcespath + 'folder_explore.png'), window.openAction = window.fileMenu.addAction(QtGui.QPixmap(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.QPixmap(self.resourcespath + 'world_explore.png'), window.openAction = window.fileMenu.addAction(QtGui.QPixmap(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.QPixmap(self.resourcespath + 'film_folder_edit.png'), window.openAction = window.fileMenu.addAction(QtGui.QPixmap(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.QPixmap(self.resourcespath + 'cross.png'), window.exitAction = window.fileMenu.addAction(QtGui.QPixmap(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)
@ -1399,13 +1376,13 @@ class MainWindow(QtWidgets.QMainWindow):
# Playback menu # Playback menu
window.playbackMenu = QtWidgets.QMenu(getMessage("playback-menu-label"), self) window.playbackMenu = QtWidgets.QMenu(getMessage("playback-menu-label"), self)
window.playAction = window.playbackMenu.addAction(QtGui.QPixmap(self.resourcespath + 'control_play_blue.png'), getMessage("play-menu-label")) window.playAction = window.playbackMenu.addAction(QtGui.QPixmap(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.QPixmap(self.resourcespath + 'control_pause_blue.png'), getMessage("pause-menu-label")) window.pauseAction = window.playbackMenu.addAction(QtGui.QPixmap(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.QPixmap(self.resourcespath + 'clock_go.png'), getMessage("seektime-menu-label")) window.seekAction = window.playbackMenu.addAction(QtGui.QPixmap(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.QPixmap(self.resourcespath + 'arrow_undo.png'), getMessage("undoseek-menu-label")) window.unseekAction = window.playbackMenu.addAction(QtGui.QPixmap(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)
@ -1413,16 +1390,16 @@ class MainWindow(QtWidgets.QMainWindow):
# Advanced menu # Advanced menu
window.advancedMenu = QtWidgets.QMenu(getMessage("advanced-menu-label"), self) window.advancedMenu = QtWidgets.QMenu(getMessage("advanced-menu-label"), self)
window.setoffsetAction = window.advancedMenu.addAction(QtGui.QPixmap(self.resourcespath + 'timeline_marker.png'), window.setoffsetAction = window.advancedMenu.addAction(QtGui.QPixmap(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.QPixmap(self.resourcespath + 'shield_edit.png'), window.setTrustedDomainsAction = window.advancedMenu.addAction(QtGui.QPixmap(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.QPixmap(self.resourcespath + 'page_white_key.png'), getMessage("createcontrolledroom-menu-label")) QtGui.QPixmap(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.QPixmap(self.resourcespath + 'key_go.png'), window.identifyascontroller = window.advancedMenu.addAction(QtGui.QPixmap(resourcespath + 'key_go.png'),
getMessage("identifyascontroller-menu-label")) getMessage("identifyascontroller-menu-label"))
window.identifyascontroller.triggered.connect(self.identifyAsController) window.identifyascontroller.triggered.connect(self.identifyAsController)
@ -1446,16 +1423,16 @@ class MainWindow(QtWidgets.QMainWindow):
window.helpMenu = QtWidgets.QMenu(getMessage("help-menu-label"), self) window.helpMenu = QtWidgets.QMenu(getMessage("help-menu-label"), self)
window.userguideAction = window.helpMenu.addAction(QtGui.QPixmap(self.resourcespath + 'help.png'), window.userguideAction = window.helpMenu.addAction(QtGui.QPixmap(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.QPixmap(self.resourcespath + 'application_get.png'), window.updateAction = window.helpMenu.addAction(QtGui.QPixmap(resourcespath + 'application_get.png'),
getMessage("update-menu-label")) getMessage("update-menu-label"))
window.updateAction.triggered.connect(self.userCheckForUpdates) window.updateAction.triggered.connect(self.userCheckForUpdates)
if not isOSX(): if not isOSX():
window.helpMenu.addSeparator() window.helpMenu.addSeparator()
window.about = window.helpMenu.addAction(QtGui.QPixmap(self.resourcespath + 'syncplay.png'), window.about = window.helpMenu.addAction(QtGui.QPixmap(resourcespath + 'syncplay.png'),
getMessage("about-menu-label")) getMessage("about-menu-label"))
else: else:
window.about = window.helpMenu.addAction("&About") window.about = window.helpMenu.addAction("&About")
@ -1530,16 +1507,16 @@ class MainWindow(QtWidgets.QMainWindow):
def updateReadyIcon(self): def updateReadyIcon(self):
ready = self.readyPushButton.isChecked() ready = self.readyPushButton.isChecked()
if ready: if ready:
self.readyPushButton.setIcon(QtGui.QPixmap(self.resourcespath + 'tick_checkbox.png')) self.readyPushButton.setIcon(QtGui.QPixmap(resourcespath + 'tick_checkbox.png'))
else: else:
self.readyPushButton.setIcon(QtGui.QPixmap(self.resourcespath + 'empty_checkbox.png')) self.readyPushButton.setIcon(QtGui.QPixmap(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.QPixmap(self.resourcespath + 'tick_checkbox.png')) self.autoplayPushButton.setIcon(QtGui.QPixmap(resourcespath + 'tick_checkbox.png'))
else: else:
self.autoplayPushButton.setIcon(QtGui.QPixmap(self.resourcespath + 'empty_checkbox.png')) self.autoplayPushButton.setIcon(QtGui.QPixmap(resourcespath + 'empty_checkbox.png'))
def automaticUpdateCheck(self): def automaticUpdateCheck(self):
currentDateTimeValue = QDateTime.currentDateTime() currentDateTimeValue = QDateTime.currentDateTime()
@ -1733,10 +1710,6 @@ class MainWindow(QtWidgets.QMainWindow):
self._syncplayClient = None self._syncplayClient = None
self.folderSearchEnabled = True self.folderSearchEnabled = True
self.QtGui = QtGui self.QtGui = QtGui
if isWindows():
self.resourcespath = utils.findWorkingDir() + u"\\resources\\"
else:
self.resourcespath = utils.findWorkingDir() + u"/resources/"
if isOSX(): if isOSX():
self.setWindowFlags(self.windowFlags()) self.setWindowFlags(self.windowFlags())
else: else:
@ -1748,7 +1721,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.addMenubar(self) self.addMenubar(self)
self.addMainFrame(self) self.addMainFrame(self)
self.loadSettings() self.loadSettings()
self.setWindowIcon(QtGui.QPixmap(self.resourcespath + u"syncplay.png")) self.setWindowIcon(QtGui.QPixmap(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

@ -137,11 +137,21 @@ def findWorkingDir():
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'): elif frozen in ('macosx_app'):
path = os.path.dirname(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(os.path.dirname(__file__)))))
else: else:
path = "" path = ""
return path return path
def getResourcesPath():
if isWindows():
return findWorkingDir() + u"\\resources\\"
else:
return findWorkingDir() + u"/resources/"
resourcespath = getResourcesPath()
posixresourcespath = findWorkingDir().replace(u"\\","/") + u"/resources/"
def limitedPowerset(s, minLength): def limitedPowerset(s, minLength):
return itertools.chain.from_iterable(itertools.combinations(s, r) for r in xrange(len(s), minLength, -1)) return itertools.chain.from_iterable(itertools.combinations(s, r) for r in xrange(len(s), minLength, -1))