Skip to content
Permalink
Browse files

Use dictionaries to get constant values for different OS

  • Loading branch information...
albertosottile committed May 10, 2019
1 parent 4ff359a commit ff6bb74b498be1666baa93cafbcb3e1af08c0634
Showing with 37 additions and 33 deletions.
  1. +33 −17 syncplay/constants.py
  2. +1 −4 syncplay/players/vlc.py
  3. +2 −6 syncplay/ui/gui.py
  4. +1 −6 syncplay/utils.py
@@ -1,4 +1,24 @@
# 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
DEFAULT_PORT = 8999
OSD_DURATION = 3.0
@@ -62,9 +82,10 @@
PLAYLIST_MAX_ITEMS = 250
MAXIMUM_TAB_WIDTH = 350
TAB_PADDING = 30
DEFAULT_WINDOWS_MONOSPACE_FONT = "Consolas"
DEFAULT_OSX_MONOSPACE_FONT = "Menlo"
FALLBACK_MONOSPACE_FONT = "Monospace"
MONOSPACE_FONT = getValueForOS({
OS_DEFAULT: "Monospace",
OS_MACOS: "Menlo",
OS_WINDOWS: "Consolas"})
DEFAULT_CHAT_FONT_SIZE = 24
DEFAULT_CHAT_INPUT_FONT_COLOR = "#FFFF00"
DEFAULT_CHAT_OUTPUT_FONT_COLOR = "#FFFF00"
@@ -175,8 +196,12 @@
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_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_AUTO_PLAY_PUSHBUTTON = "QPushButton { text-align: left; padding: 5px 5px 5px 5px; }"
STYLE_READY_PUSHBUTTON = getValueForOS({
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_CONTACT_INFO = "<span style=\"color: grey\"><strong><small>{}</span><br /><br />" # Contact info message
STYLE_USER_MESSAGE = "<span style=\"{}\">&lt;{}&gt;</span> {}"
@@ -187,10 +212,6 @@
STYLE_NOTCONTROLLER_COLOR = 'grey'
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

USERLIST_GUI_USERNAME_OFFSET = 21 # Pixels
@@ -221,8 +242,9 @@
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',
'--play-and-pause', '--start-time=0']
VLC_SLAVE_MACOS_ARGS = ['--verbose=2', '--no-file-logging']
VLC_SLAVE_NONMACOS_ARGS = ['--no-one-instance', '--no-one-instance-when-started-from-file']
VLC_SLAVE_EXTRA_ARGS = getValueForOS({
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_REMOVE_BOTH_IF_DUPLICATE_COMMANDS = ["cycle pause"]
MPLAYER_ANSWER_REGEX = "^ANS_([a-zA-Z_-]+)=(.+)$|^(Exiting)\.\.\. \((.+)\)$"
@@ -279,9 +301,3 @@
TRUSTABLE_WEB_PROTOCOLS = ["http://www.", "https://www.", "http://", "https://"]

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)
SLAVE_ARGS = constants.VLC_SLAVE_ARGS
if isMacOS():
SLAVE_ARGS.extend(constants.VLC_SLAVE_MACOS_ARGS)
else:
SLAVE_ARGS.extend(constants.VLC_SLAVE_NONMACOS_ARGS)
SLAVE_ARGS.extend(constants.VLC_SLAVE_EXTRA_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

def __init__(self, client, playerPath, filePath, args):
@@ -1426,10 +1426,7 @@ def addBottomLayout(self, window):
window.readyPushButton.setAutoExclusive(False)
window.readyPushButton.toggled.connect(self.changeReadyState)
window.readyPushButton.setFont(readyFont)
if isMacOS():
window.readyPushButton.setStyleSheet(constants.STYLE_READY_PUSHBUTTON_MACOS)
else:
window.readyPushButton.setStyleSheet(constants.STYLE_READY_PUSHBUTTON)
window.readyPushButton.setStyleSheet(constants.STYLE_READY_PUSHBUTTON)
window.readyPushButton.setToolTip(getMessage("ready-tooltip"))
window.listLayout.addWidget(window.readyPushButton, Qt.AlignRight)
if isMacOS(): window.listLayout.setContentsMargins(0, 0, 0, 10)
@@ -1451,12 +1448,11 @@ def addBottomLayout(self, window):
window.autoplayFrame.setMinimumWidth(window.listFrame.sizeHint().width())
window.autoplayLayout.setSpacing(15)
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)
else:
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.setStyleSheet(constants.STYLE_AUTO_PLAY_PUSHBUTTON)
window.autoplayPushButton.setToolTip(getMessage("autoplay-tooltip"))
window.autoplayLabel = QtWidgets.QLabel(getMessage("autoplay-minimum-label"))
window.autoplayLabel.setSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
@@ -181,12 +181,7 @@ def getResourcesPath():


def getDefaultMonospaceFont():
if platform.system() == "Windows":
return constants.DEFAULT_WINDOWS_MONOSPACE_FONT
elif platform.system() == "Darwin":
return constants.DEFAULT_OSX_MONOSPACE_FONT
else:
return constants.FALLBACK_MONOSPACE_FONT
return constants.MONOSPACE_FONT


def limitedPowerset(s, minLength):

0 comments on commit ff6bb74

Please sign in to comment.
You can’t perform that action at this time.