diff --git a/resources/syncplayintf.lua b/resources/syncplayintf.lua index fb2301a..f5ad996 100644 --- a/resources/syncplayintf.lua +++ b/resources/syncplayintf.lua @@ -296,12 +296,16 @@ end) local utils = require 'mp.utils' local options = require 'mp.options' opts = { + -- All drawing is scaled by this value, including the text borders and the -- cursor. Change it if you have a high-DPI display. scale = 1, -- Set the font used for the REPL and the console. This probably doesn't -- have to be a monospaced font. ['chatInputFontFamily'] = 'monospace', + -- Enable/Disable + ['chatInputEnabled'] = true, + ['chatOutputEnabled'] = true, -- Set the font size used for the REPL and the console. This will be -- multiplied by "scale." ['chatInputFontSize'] = 20, @@ -870,8 +874,6 @@ mp.register_script_message('type', function(text) show_and_type(text) end) -mp.add_forced_key_binding('enter', handle_enter) -mp.add_forced_key_binding('kp_enter', handle_enter) mp.command('print-text ""') function set_syncplayintf_options(input) @@ -893,10 +895,13 @@ function set_syncplayintf_options(input) chat_format = get_output_style() local vertical_output_area = CANVAS_HEIGHT-(opts['chatTopMargin']+opts['chatBottomMargin']+(opts['chatOutputFontSize']+opts['scrollingFirstRowOffset'])) max_scrolling_rows = math.floor(vertical_output_area/opts['chatOutputFontSize']) + if opts['chatInputEnabled'] == true then + mp.add_forced_key_binding('enter', handle_enter) + mp.add_forced_key_binding('kp_enter', handle_enter) if opts['chatDirectInput'] == true then - add_repl_alpharow_bindings(alpharowbindings) - mp.add_forced_key_binding('tab', handle_tab) - key_hints_enabled = true - else + add_repl_alpharow_bindings(alpharowbindings) + mp.add_forced_key_binding('tab', handle_tab) + key_hints_enabled = true + end end end \ No newline at end of file diff --git a/syncplay/constants.py b/syncplay/constants.py index b36de1a..b492cf8 100644 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -185,7 +185,7 @@ MPV_ARGS = ['--force-window', '--idle', '--hr-seek=always', '--keep-open'] MPV_SLAVE_ARGS = ['--msg-level=all=error,cplayer=info,term-msg=info', '--input-terminal=no', '--input-file=/dev/stdin'] MPV_SLAVE_ARGS_NEW = ['--term-playing-msg=\nANS_filename=${filename}\nANS_length=${=length:${=duration:0}}\nANS_path=${path}\n', '--terminal=yes'] MPV_NEW_VERSION = False -MPV_SYNCPLAYINTF_OPTIONS_TO_SEND = ["chatInputFontFamily", "chatInputFontSize", "chatInputFontWeight","chatInputFontUnderline", +MPV_SYNCPLAYINTF_OPTIONS_TO_SEND = ["chatInputEnabled","chatInputFontFamily", "chatInputFontSize", "chatInputFontWeight","chatInputFontUnderline", "chatInputFontColor", "chatInputPosition","chatOutputFontFamily","chatOutputFontSize", "chatOutputFontWeight","chatOutputFontUnderline","chatOutputMode","chatMaxLines", "chatTopMargin","chatLeftMargin","chatBottomMargin","chatDirectInput", diff --git a/syncplay/messages_de.py b/syncplay/messages_de.py index 0c740d3..2f19dd8 100644 --- a/syncplay/messages_de.py +++ b/syncplay/messages_de.py @@ -237,6 +237,7 @@ de = { "chat-title": u"Chat message input", # TODO: Translate "chatinputenabled-label": u"Enable chat input via mpv (using enter key)", # TODO: Translate + "chatdirectinput-label" : u"Enable instant chat input (bypass having to press enter key to chat)", # TODO: Translate "chatinputfont-label": u"Chat input font", # TODO: Translate "chatfont-label": u"Set font", # TODO: Translate "chatcolour-label": u"Set colour", # TODO: Translate @@ -378,6 +379,7 @@ de = { "trusteddomains-arguments-tooltip" : u"Domains that it is okay for Syncplay to automatically switch to when shared playlists is enabled.", # TODO: Translate into German "chatinputenabled-tooltip": u"Enable chat input in mpv (press enter to chat, enter to send, escape to cancel)", # TODO: Translate + "chatdirectinput-tooltip" : u"Skip having to press 'enter' to go into chat input mode in mpv.", # TODO: Translate "font-label-tooltip": u"Font used for when entering chat messages in mpv. Client-side only, so doesn't affect what other see.", # TODO: Translate "set-input-font-tooltip": u"Font family used for when entering chat messages in mpv. Client-side only, so doesn't affect what other see.", # TODO: Translate "set-input-colour-tooltip": u"Font colour used for when entering chat messages in mpv. Client-side only, so doesn't affect what other see.", # TODO: Translate diff --git a/syncplay/messages_en.py b/syncplay/messages_en.py index f0ae04e..d852a25 100644 --- a/syncplay/messages_en.py +++ b/syncplay/messages_en.py @@ -242,6 +242,7 @@ en = { "chat-title" : u"Chat message input", "chatinputenabled-label" : u"Enable chat input via mpv", + "chatdirectinput-label" : u"Enable instant chat input (bypass having to press enter key to chat)", "chatinputfont-label" : u"Chat input font", "chatfont-label" : u"Set font", "chatcolour-label" : u"Set colour", @@ -381,6 +382,7 @@ en = { "trusteddomains-arguments-tooltip" : u"Domains that it is okay for Syncplay to automatically switch to when shared playlists is enabled.", "chatinputenabled-tooltip" : u"Enable chat input in mpv (press enter to chat, enter to send, escape to cancel)", + "chatdirectinput-tooltip" : u"Skip having to press 'enter' to go into chat input mode in mpv.", "font-label-tooltip" : u"Font used for when entering chat messages in mpv. Client-side only, so doesn't affect what other see.", "set-input-font-tooltip" : u"Font family used for when entering chat messages in mpv. Client-side only, so doesn't affect what other see.", "set-input-colour-tooltip" : u"Font colour used for when entering chat messages in mpv. Client-side only, so doesn't affect what other see.", diff --git a/syncplay/messages_ru.py b/syncplay/messages_ru.py index 666f3d4..3670df8 100644 --- a/syncplay/messages_ru.py +++ b/syncplay/messages_ru.py @@ -246,6 +246,7 @@ ru = { "chat-title": u"Chat message input", # TODO: Translate "chatinputenabled-label": u"Enable chat input via mpv (using enter key)", # TODO: Translate + "chatdirectinput-label" : u"Enable instant chat input (bypass having to press enter key to chat)", # TODO: Translate "chatinputfont-label": u"Chat input font", # TODO: Translate "chatfont-label": u"Set font", # TODO: Translate "chatcolour-label": u"Set colour", # TODO: Translate @@ -384,6 +385,7 @@ ru = { "trusteddomains-arguments-tooltip" : u"Сайты, которые разрешены для автоматического воспроизведения из общего списка воспроизведения.", "chatinputenabled-tooltip": u"Enable chat input in mpv (press enter to chat, enter to send, escape to cancel)",# TODO: Translate + "chatdirectinput-tooltip" : u"Skip having to press 'enter' to go into chat input mode in mpv.", # TODO: Translate "font-label-tooltip": u"Font used for when entering chat messages in mpv. Client-side only, so doesn't affect what other see.",# TODO: Translate "set-input-font-tooltip": u"Font family used for when entering chat messages in mpv. Client-side only, so doesn't affect what other see.",# TODO: Translate "set-input-colour-tooltip": u"Font colour used for when entering chat messages in mpv. Client-side only, so doesn't affect what other see.",# TODO: Translate diff --git a/syncplay/players/mplayer.py b/syncplay/players/mplayer.py index 3b414e2..dc6d233 100644 --- a/syncplay/players/mplayer.py +++ b/syncplay/players/mplayer.py @@ -92,20 +92,13 @@ class MplayerPlayer(BasePlayer): def displayMessage(self, message, duration=(constants.OSD_DURATION * 1000), OSDType=constants.OSD_NOTIFICATION, mood=constants.MESSAGE_NEUTRAL): messageString = self._sanitizeText(message.replace("\\n", "")).replace("", "\\n") - self._listener.sendLine( - u'script-message-to syncplayintf {}-osd-{} "{}"'.format(OSDType,mood, messageString)) - - return - - # TODO: Support legacy displayMessage for versiosn that don't support syncplayintf.lua - message = self._sanitizeText(message.replace("\\n","")).replace("","\\n") - #self._listener.sendLine(u'{} "{!s}" {} {}'.format(self.OSD_QUERY, message, duration, constants.MPLAYER_OSD_LEVEL).encode('utf-8')) + self._listener.sendLine(u'{} "{!s}" {} {}'.format(self.OSD_QUERY, messageString, duration, constants.MPLAYER_OSD_LEVEL).encode('utf-8')) def displayChatMessage(self, username, message): - username = self._sanitizeText(username) - message = self._sanitizeText(message) messageString = u"<{}> {}".format(username, message) - self._listener.sendLine(u'script-message-to syncplayintf chat "{}"'.format(messageString)) + messageString = self._sanitizeText(messageString.replace("\\n", "")).replace("", "\\n") + duration = int(constants.OSD_DURATION * 1000) + self._listener.sendLine(u'{} "{!s}" {} {}'.format(self.OSD_QUERY, messageString, duration, constants.MPLAYER_OSD_LEVEL).encode('utf-8')) def setSpeed(self, value): self._setProperty('speed', "{:.2f}".format(value)) diff --git a/syncplay/players/mpv.py b/syncplay/players/mpv.py index cece587..e7c0851 100644 --- a/syncplay/players/mpv.py +++ b/syncplay/players/mpv.py @@ -113,6 +113,23 @@ class NewMpvPlayer(OldMpvPlayer): alertOSDSupported = True chatOSDSupported = True + def displayMessage(self, message, duration=(constants.OSD_DURATION * 1000), OSDType=constants.OSD_NOTIFICATION, + mood=constants.MESSAGE_NEUTRAL): + if not self._client._config["chatOutputEnabled"]: + super(self.__class__, self).displayMessage(message=message,duration=duration,OSDType=OSDType,mood=mood) + return + messageString = self._sanitizeText(message.replace("\\n", "")).replace("", "\\n") + self._listener.sendLine(u'script-message-to syncplayintf {}-osd-{} "{}"'.format(OSDType, mood, messageString)) + + def displayChatMessage(self, username, message): + if not self._client._config["chatOutputEnabled"]: + super(self.__class__, self).displayChatMessage(username,message) + return + username = self._sanitizeText(username) + message = self._sanitizeText(message) + messageString = u"<{}> {}".format(username, message) + self._listener.sendLine(u'script-message-to syncplayintf chat "{}"'.format(messageString)) + def setPaused(self, value): if self._paused == value: self._client.ui.showDebugMessage("Not sending setPaused to mpv as state is already {}".format(value)) @@ -256,7 +273,7 @@ class NewMpvPlayer(OldMpvPlayer): self._listener.setReadyToSend(True) def _setOSDPosition(self): - if self._client._config['chatInputEnabled']: + if self._client._config['chatInputEnabled'] and self._client._config['chatOutputEnabled']: if self._client._config['chatInputPosition'] == constants.INPUT_POSITION_BOTTOM: self._setProperty("osd-align-y", "center") else: diff --git a/syncplay/ui/GuiConfiguration.py b/syncplay/ui/GuiConfiguration.py index 5cc0d4e..9898525 100644 --- a/syncplay/ui/GuiConfiguration.py +++ b/syncplay/ui/GuiConfiguration.py @@ -883,6 +883,12 @@ class ConfigDialog(QtWidgets.QDialog): self.chatInputEnabledCheckbox.setObjectName("chatInputEnabled") self.chatInputLayout.addWidget(self.chatInputEnabledCheckbox, 1, 0, 1,1, Qt.AlignLeft) + self.chatDirectInputCheckbox = QCheckBox(getMessage("chatdirectinput-label")) + self.chatDirectInputCheckbox.setObjectName("chatDirectInput") + self.chatDirectInputCheckbox.setStyleSheet( + constants.STYLE_SUBCHECKBOX.format(self.posixresourcespath + u"chevrons_right.png")) + self.chatInputLayout.addWidget(self.chatDirectInputCheckbox, 2, 0, 1,1, Qt.AlignLeft) + self.inputFontLayout = QtWidgets.QHBoxLayout() self.inputFontLayout.setContentsMargins(0, 0, 0, 0) self.inputFontFrame = QtWidgets.QFrame() @@ -904,7 +910,7 @@ class ConfigDialog(QtWidgets.QDialog): self.inputFontLayout.addWidget(self.chatFontLabel, Qt.AlignLeft) self.inputFontLayout.addWidget(self.chatInputFontButton, Qt.AlignLeft) self.inputFontLayout.addWidget(self.chatInputColourButton, Qt.AlignLeft) - self.chatInputLayout.addWidget(self.inputFontFrame, 2, 0, 1, 3, Qt.AlignLeft) + self.chatInputLayout.addWidget(self.inputFontFrame, 3, 0, 1, 3, Qt.AlignLeft) self.chatInputPositionFrame = QtWidgets.QFrame() self.chatInputPositionLayout = QtWidgets.QHBoxLayout() @@ -935,7 +941,7 @@ class ConfigDialog(QtWidgets.QDialog): self.subitems['chatInputEnabled'] = [self.chatInputPositionLabel.objectName(), self.chatInputTopOption.objectName(), self.chatInputMiddleOption.objectName(), self.chatInputBottomOption.objectName(), self.chatInputFontButton.objectName(), self.chatFontLabel.objectName(), - self.chatInputColourButton.objectName()] + self.chatInputColourButton.objectName(), self.chatDirectInputCheckbox.objectName()] # Output self.chatOutputGroup = QtWidgets.QGroupBox(u"Chat message output") self.chatOutputLayout = QtWidgets.QGridLayout()