mirror of
https://github.com/Syncplay/syncplay
synced 2025-03-11 06:07:53 +00:00
Use dictionaries to get constant values for different OS
This commit is contained in:
parent
4ff359a820
commit
ff6bb74b49
@ -1,4 +1,24 @@
|
|||||||
# coding:utf8
|
# coding:utf8
|
||||||
|
# code needed to get customized constants for different OS
|
||||||
|
import sys
|
||||||
|
|
||||||
|
OS_WINDOWS = "win"
|
||||||
|
OS_LINUX = "linux"
|
||||||
|
OS_MACOS = "darwin"
|
||||||
|
OS_BSD = "freebsd"
|
||||||
|
OS_DRAGONFLY = "dragonfly"
|
||||||
|
OS_DEFAULT = "default"
|
||||||
|
|
||||||
|
def getValueForOS(constantDict):
|
||||||
|
if sys.platform.startswith(OS_WINDOWS):
|
||||||
|
return constantDict[OS_WINDOWS] if OS_WINDOWS in constantDict else constantDict[OS_DEFAULT]
|
||||||
|
if sys.platform.startswith(OS_LINUX):
|
||||||
|
return constantDict[OS_LINUX] if OS_LINUX in constantDict else constantDict[OS_DEFAULT]
|
||||||
|
if sys.platform.startswith(OS_MACOS):
|
||||||
|
return constantDict[OS_MACOS] if OS_MACOS in constantDict else constantDict[OS_DEFAULT]
|
||||||
|
if OS_BSD in sys.platform or sys.platform.startswith(OS_DRAGONFLY):
|
||||||
|
return constantDict[OS_BSD] if OS_BSD in constantDict else constantDict[OS_DEFAULT]
|
||||||
|
|
||||||
# You might want to change these
|
# You might want to change these
|
||||||
DEFAULT_PORT = 8999
|
DEFAULT_PORT = 8999
|
||||||
OSD_DURATION = 3.0
|
OSD_DURATION = 3.0
|
||||||
@ -62,9 +82,10 @@ PLAYLIST_MAX_CHARACTERS = 10000
|
|||||||
PLAYLIST_MAX_ITEMS = 250
|
PLAYLIST_MAX_ITEMS = 250
|
||||||
MAXIMUM_TAB_WIDTH = 350
|
MAXIMUM_TAB_WIDTH = 350
|
||||||
TAB_PADDING = 30
|
TAB_PADDING = 30
|
||||||
DEFAULT_WINDOWS_MONOSPACE_FONT = "Consolas"
|
MONOSPACE_FONT = getValueForOS({
|
||||||
DEFAULT_OSX_MONOSPACE_FONT = "Menlo"
|
OS_DEFAULT: "Monospace",
|
||||||
FALLBACK_MONOSPACE_FONT = "Monospace"
|
OS_MACOS: "Menlo",
|
||||||
|
OS_WINDOWS: "Consolas"})
|
||||||
DEFAULT_CHAT_FONT_SIZE = 24
|
DEFAULT_CHAT_FONT_SIZE = 24
|
||||||
DEFAULT_CHAT_INPUT_FONT_COLOR = "#FFFF00"
|
DEFAULT_CHAT_INPUT_FONT_COLOR = "#FFFF00"
|
||||||
DEFAULT_CHAT_OUTPUT_FONT_COLOR = "#FFFF00"
|
DEFAULT_CHAT_OUTPUT_FONT_COLOR = "#FFFF00"
|
||||||
@ -175,8 +196,12 @@ STYLE_SUBCHECKBOX = "QCheckBox, QLabel, QRadioButton {{ margin-left: 6px; paddin
|
|||||||
STYLE_SUBLABEL = "QCheckBox, QLabel {{ margin-left: 6px; padding-left: 16px; background:url('{}') left no-repeat }}" # Graphic path
|
STYLE_SUBLABEL = "QCheckBox, QLabel {{ margin-left: 6px; padding-left: 16px; background:url('{}') left no-repeat }}" # Graphic path
|
||||||
STYLE_ERRORLABEL = "QLabel { color : black; border-style: outset; border-width: 2px; border-radius: 7px; border-color: red; padding: 2px; background: #FFAAAA; }"
|
STYLE_ERRORLABEL = "QLabel { color : black; border-style: outset; border-width: 2px; border-radius: 7px; border-color: red; padding: 2px; background: #FFAAAA; }"
|
||||||
STYLE_SUCCESSLABEL = "QLabel { color : black; border-style: outset; border-width: 2px; border-radius: 7px; border-color: green; padding: 2px; background: #AAFFAA; }"
|
STYLE_SUCCESSLABEL = "QLabel { color : black; border-style: outset; border-width: 2px; border-radius: 7px; border-color: green; padding: 2px; background: #AAFFAA; }"
|
||||||
STYLE_READY_PUSHBUTTON = "QPushButton { text-align: left; padding: 10px 5px 10px 5px;}"
|
STYLE_READY_PUSHBUTTON = getValueForOS({
|
||||||
STYLE_AUTO_PLAY_PUSHBUTTON = "QPushButton { text-align: left; padding: 5px 5px 5px 5px; }"
|
OS_DEFAULT: "QPushButton { text-align: left; padding: 10px 5px 10px 5px;}",
|
||||||
|
OS_MACOS: "QPushButton { text-align: left; padding: 10px 5px 10px 15px; margin: 0px 3px 0px 2px}"})
|
||||||
|
STYLE_AUTO_PLAY_PUSHBUTTON = getValueForOS({
|
||||||
|
OS_DEFAULT: "QPushButton { text-align: left; padding: 5px 5px 5px 5px; }",
|
||||||
|
OS_MACOS: "QPushButton { text-align: left; padding: 10px 5px 10px 15px; margin: 0px 0px 0px -4px}"})
|
||||||
STYLE_NOTIFICATIONBOX = "Username { color: #367AA9; font-weight:bold; }"
|
STYLE_NOTIFICATIONBOX = "Username { color: #367AA9; font-weight:bold; }"
|
||||||
STYLE_CONTACT_INFO = "<span style=\"color: grey\"><strong><small>{}</span><br /><br />" # Contact info message
|
STYLE_CONTACT_INFO = "<span style=\"color: grey\"><strong><small>{}</span><br /><br />" # Contact info message
|
||||||
STYLE_USER_MESSAGE = "<span style=\"{}\"><{}></span> {}"
|
STYLE_USER_MESSAGE = "<span style=\"{}\"><{}></span> {}"
|
||||||
@ -187,10 +212,6 @@ STYLE_NOFILEITEM_COLOR = 'blue'
|
|||||||
STYLE_NOTCONTROLLER_COLOR = 'grey'
|
STYLE_NOTCONTROLLER_COLOR = 'grey'
|
||||||
STYLE_UNTRUSTEDITEM_COLOR = 'purple'
|
STYLE_UNTRUSTEDITEM_COLOR = 'purple'
|
||||||
|
|
||||||
# Style constants for macOS
|
|
||||||
STYLE_READY_PUSHBUTTON_MACOS = "QPushButton { text-align: left; padding: 10px 5px 10px 15px; margin: 0px 3px 0px 2px}"
|
|
||||||
STYLE_AUTO_PLAY_PUSHBUTTON_MACOS = "QPushButton { text-align: left; padding: 10px 5px 10px 15px; margin: 0px 0px 0px -4px}"
|
|
||||||
|
|
||||||
TLS_CERT_ROTATION_MAX_RETRIES = 10
|
TLS_CERT_ROTATION_MAX_RETRIES = 10
|
||||||
|
|
||||||
USERLIST_GUI_USERNAME_OFFSET = 21 # Pixels
|
USERLIST_GUI_USERNAME_OFFSET = 21 # Pixels
|
||||||
@ -221,8 +242,9 @@ MPV_SYNCPLAYINTF_CONSTANTS_TO_SEND = [
|
|||||||
MPV_SYNCPLAYINTF_LANGUAGE_TO_SEND = ["mpv-key-tab-hint", "mpv-key-hint", "alphakey-mode-warning-first-line", "alphakey-mode-warning-second-line"]
|
MPV_SYNCPLAYINTF_LANGUAGE_TO_SEND = ["mpv-key-tab-hint", "mpv-key-hint", "alphakey-mode-warning-first-line", "alphakey-mode-warning-second-line"]
|
||||||
VLC_SLAVE_ARGS = ['--extraintf=luaintf', '--lua-intf=syncplay', '--no-quiet', '--no-input-fast-seek',
|
VLC_SLAVE_ARGS = ['--extraintf=luaintf', '--lua-intf=syncplay', '--no-quiet', '--no-input-fast-seek',
|
||||||
'--play-and-pause', '--start-time=0']
|
'--play-and-pause', '--start-time=0']
|
||||||
VLC_SLAVE_MACOS_ARGS = ['--verbose=2', '--no-file-logging']
|
VLC_SLAVE_EXTRA_ARGS = getValueForOS({
|
||||||
VLC_SLAVE_NONMACOS_ARGS = ['--no-one-instance', '--no-one-instance-when-started-from-file']
|
OS_DEFAULT: ['--no-one-instance', '--no-one-instance-when-started-from-file'],
|
||||||
|
OS_MACOS: ['--verbose=2', '--no-file-logging']})
|
||||||
MPV_SUPERSEDE_IF_DUPLICATE_COMMANDS = ["no-osd set time-pos ", "loadfile "]
|
MPV_SUPERSEDE_IF_DUPLICATE_COMMANDS = ["no-osd set time-pos ", "loadfile "]
|
||||||
MPV_REMOVE_BOTH_IF_DUPLICATE_COMMANDS = ["cycle pause"]
|
MPV_REMOVE_BOTH_IF_DUPLICATE_COMMANDS = ["cycle pause"]
|
||||||
MPLAYER_ANSWER_REGEX = "^ANS_([a-zA-Z_-]+)=(.+)$|^(Exiting)\.\.\. \((.+)\)$"
|
MPLAYER_ANSWER_REGEX = "^ANS_([a-zA-Z_-]+)=(.+)$|^(Exiting)\.\.\. \((.+)\)$"
|
||||||
@ -279,9 +301,3 @@ DEFAULT_TRUSTED_DOMAINS = ["youtube.com", "youtu.be"]
|
|||||||
TRUSTABLE_WEB_PROTOCOLS = ["http://www.", "https://www.", "http://", "https://"]
|
TRUSTABLE_WEB_PROTOCOLS = ["http://www.", "https://www.", "http://", "https://"]
|
||||||
|
|
||||||
PRIVATE_FILE_FIELDS = ["path"]
|
PRIVATE_FILE_FIELDS = ["path"]
|
||||||
|
|
||||||
OS_WINDOWS = "win"
|
|
||||||
OS_LINUX = "linux"
|
|
||||||
OS_MACOS = "darwin"
|
|
||||||
OS_BSD = "freebsd"
|
|
||||||
OS_DRAGONFLY = "dragonfly"
|
|
||||||
|
@ -28,10 +28,7 @@ class VlcPlayer(BasePlayer):
|
|||||||
|
|
||||||
RE_ANSWER = re.compile(constants.VLC_ANSWER_REGEX)
|
RE_ANSWER = re.compile(constants.VLC_ANSWER_REGEX)
|
||||||
SLAVE_ARGS = constants.VLC_SLAVE_ARGS
|
SLAVE_ARGS = constants.VLC_SLAVE_ARGS
|
||||||
if isMacOS():
|
SLAVE_ARGS.extend(constants.VLC_SLAVE_EXTRA_ARGS)
|
||||||
SLAVE_ARGS.extend(constants.VLC_SLAVE_MACOS_ARGS)
|
|
||||||
else:
|
|
||||||
SLAVE_ARGS.extend(constants.VLC_SLAVE_NONMACOS_ARGS)
|
|
||||||
vlcport = random.randrange(constants.VLC_MIN_PORT, constants.VLC_MAX_PORT) if (constants.VLC_MIN_PORT < constants.VLC_MAX_PORT) else constants.VLC_MIN_PORT
|
vlcport = random.randrange(constants.VLC_MIN_PORT, constants.VLC_MAX_PORT) if (constants.VLC_MIN_PORT < constants.VLC_MAX_PORT) else constants.VLC_MIN_PORT
|
||||||
|
|
||||||
def __init__(self, client, playerPath, filePath, args):
|
def __init__(self, client, playerPath, filePath, args):
|
||||||
|
@ -1426,10 +1426,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
window.readyPushButton.setAutoExclusive(False)
|
window.readyPushButton.setAutoExclusive(False)
|
||||||
window.readyPushButton.toggled.connect(self.changeReadyState)
|
window.readyPushButton.toggled.connect(self.changeReadyState)
|
||||||
window.readyPushButton.setFont(readyFont)
|
window.readyPushButton.setFont(readyFont)
|
||||||
if isMacOS():
|
window.readyPushButton.setStyleSheet(constants.STYLE_READY_PUSHBUTTON)
|
||||||
window.readyPushButton.setStyleSheet(constants.STYLE_READY_PUSHBUTTON_MACOS)
|
|
||||||
else:
|
|
||||||
window.readyPushButton.setStyleSheet(constants.STYLE_READY_PUSHBUTTON)
|
|
||||||
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)
|
||||||
if isMacOS(): window.listLayout.setContentsMargins(0, 0, 0, 10)
|
if isMacOS(): window.listLayout.setContentsMargins(0, 0, 0, 10)
|
||||||
@ -1451,12 +1448,11 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
window.autoplayFrame.setMinimumWidth(window.listFrame.sizeHint().width())
|
window.autoplayFrame.setMinimumWidth(window.listFrame.sizeHint().width())
|
||||||
window.autoplayLayout.setSpacing(15)
|
window.autoplayLayout.setSpacing(15)
|
||||||
window.autoplayLayout.setContentsMargins(0, 8, 3, 3)
|
window.autoplayLayout.setContentsMargins(0, 8, 3, 3)
|
||||||
window.autoplayPushButton.setStyleSheet(constants.STYLE_AUTO_PLAY_PUSHBUTTON_MACOS)
|
|
||||||
window.autoplayPushButton.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
|
window.autoplayPushButton.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
|
||||||
else:
|
else:
|
||||||
window.autoplayLayout.setContentsMargins(0, 0, 0, 0)
|
window.autoplayLayout.setContentsMargins(0, 0, 0, 0)
|
||||||
window.autoplayPushButton.setStyleSheet(constants.STYLE_AUTO_PLAY_PUSHBUTTON)
|
|
||||||
window.autoplayPushButton.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
|
window.autoplayPushButton.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
|
||||||
|
window.autoplayPushButton.setStyleSheet(constants.STYLE_AUTO_PLAY_PUSHBUTTON)
|
||||||
window.autoplayPushButton.setToolTip(getMessage("autoplay-tooltip"))
|
window.autoplayPushButton.setToolTip(getMessage("autoplay-tooltip"))
|
||||||
window.autoplayLabel = QtWidgets.QLabel(getMessage("autoplay-minimum-label"))
|
window.autoplayLabel = QtWidgets.QLabel(getMessage("autoplay-minimum-label"))
|
||||||
window.autoplayLabel.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
|
window.autoplayLabel.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
|
||||||
|
@ -181,12 +181,7 @@ posixresourcespath = findWorkingDir().replace("\\", "/") + "/resources/"
|
|||||||
|
|
||||||
|
|
||||||
def getDefaultMonospaceFont():
|
def getDefaultMonospaceFont():
|
||||||
if platform.system() == "Windows":
|
return constants.MONOSPACE_FONT
|
||||||
return constants.DEFAULT_WINDOWS_MONOSPACE_FONT
|
|
||||||
elif platform.system() == "Darwin":
|
|
||||||
return constants.DEFAULT_OSX_MONOSPACE_FONT
|
|
||||||
else:
|
|
||||||
return constants.FALLBACK_MONOSPACE_FONT
|
|
||||||
|
|
||||||
|
|
||||||
def limitedPowerset(s, minLength):
|
def limitedPowerset(s, minLength):
|
||||||
|
Loading…
Reference in New Issue
Block a user