Merge branch 'speaker2chatbox' into develop

This commit is contained in:
misyaguziya
2023-11-25 22:53:05 +09:00
9 changed files with 246 additions and 10 deletions

View File

@@ -505,6 +505,35 @@ class Config:
# self._STARTUP_OSC_ENABLED_CHECK = value
# saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
# Speaker2Chatbox------------------
@property
@json_serializable('RECEIVED_MESSAGE_FORMAT')
def RECEIVED_MESSAGE_FORMAT(self):
return self._RECEIVED_MESSAGE_FORMAT
@RECEIVED_MESSAGE_FORMAT.setter
def RECEIVED_MESSAGE_FORMAT(self, value):
if isinstance(value, str):
if isUniqueStrings(["[message]", "[translation]"], value) is False:
value = "[message]([translation])"
self._RECEIVED_MESSAGE_FORMAT = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
@json_serializable('ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC')
def ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC(self):
return self._ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC
@ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC.setter
def ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC(self, value):
if isinstance(value, bool):
self._ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
# Speaker2Chatbox------------------
@property
@json_serializable('ENABLE_LOGGER')
def ENABLE_LOGGER(self):
@@ -595,9 +624,11 @@ class Config:
"Google": None,
}
self._MESSAGE_FORMAT = "[message]([translation])"
self._RECEIVED_MESSAGE_FORMAT = "[message]([translation])" # speaker2Chatbox
self._ENABLE_AUTO_CLEAR_MESSAGE_BOX = True
self._ENABLE_NOTICE_XSOVERLAY = False
self._ENABLE_SEND_MESSAGE_TO_VRC = True
self._ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC = False # speaker2Chatbox
# self._STARTUP_OSC_ENABLED_CHECK = True # [deprecated]
self._ENABLE_LOGGER = False
self._IS_CONFIG_WINDOW_COMPACT_MODE = False

View File

@@ -112,6 +112,17 @@ def receiveSpeakerMessage(message):
xsoverlay_message = message
model.notificationXSOverlay(xsoverlay_message)
# ------------Speaker2Chatbox------------
# send OSC message
if config.ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC is True:
if len(translation) > 0:
osc_message = config.RECEIVED_MESSAGE_FORMAT.replace("[message]", message)
osc_message = osc_message.replace("[translation]", translation)
else:
osc_message = message
model.oscSendMessage(osc_message)
# ------------Speaker2Chatbox------------
# update textbox message log (Received)
view.printToTextbox_ReceivedMessage(message, translation)
if config.ENABLE_LOGGER is True:
@@ -672,6 +683,24 @@ def callbackSetEnableSendMessageToVrc(value):
# print("callbackSetStartupOscEnabledCheck", value)
# config.STARTUP_OSC_ENABLED_CHECK = value
# ---------------------Speaker2Chatbox---------------------
def callbackSetReceivedMessageFormat(value):
print("callbackSetReceivedMessageFormat", value)
if len(value) > 0:
if isUniqueStrings(["[message]", "[translation]"], value) is True:
config.RECEIVED_MESSAGE_FORMAT = value
view.clearErrorMessage()
view.setReceivedMessageFormatEntryWidgets(config.RECEIVED_MESSAGE_FORMAT)
else:
view.showErrorMessage_ReceivedMessageFormat()
view.setReceivedMessageFormatEntryWidgets(config.RECEIVED_MESSAGE_FORMAT)
def callbackSetEnableSendReceivedMessageToVrc(value):
print("callbackSetEnableSendReceivedMessageToVrc", value)
config.ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC = value
# ---------------------Speaker2Chatbox---------------------
# Advanced Settings Tab
def callbackSetOscIpAddress(value):
if value == "":
@@ -808,6 +837,10 @@ def createMainWindow():
"callback_set_message_format": callbackSetMessageFormat,
"callback_set_enable_send_message_to_vrc": callbackSetEnableSendMessageToVrc,
# "callback_set_startup_osc_enabled_check": callbackSetStartupOscEnabledCheck, # [deprecated]
# Speaker2Chatbox----------------
"callback_set_received_message_format": callbackSetReceivedMessageFormat,
"callback_set_enable_send_received_message_to_vrc": callbackSetEnableSendReceivedMessageToVrc,
# Speaker2Chatbox----------------
# Advanced Settings Tab
"callback_set_osc_ip_address": callbackSetOscIpAddress,

View File

@@ -82,6 +82,7 @@ config_window:
transcription_mic: Mic
transcription_speaker: Speaker
others: Others
others_speaker2chatbox: Speaker2Chatbox
advanced_settings: Advanced Settings
@@ -189,6 +190,16 @@ config_window:
label: Send Message To VRChat
desc: There is a way to use it without sending messages to VRChat, but it is not supported. Enable this feature when you intend to send a message to VRChat.
# Speaker2Chatbox
received_message_format:
label: Message Format (Speaker2Chatbox)
example_text: This is an example sentence. Fonts, line breaks, etc. may differ from the actual display.
error_message: "The characters '[message]' and '[translation]' cannot be used."
send_received_message_to_vrc:
label: Send Received Message To VRChat
# Speaker2Chatbox
osc_ip_address:
label: OSC IP Address

98
view.py
View File

@@ -373,6 +373,32 @@ class View():
# -------------------Speaker2Chatbox-----------
VAR_SECOND_TITLE_OTHERS_SPEAKER2CHATBOX=StringVar(value=i18n.t("config_window.side_menu_labels.others_speaker2chatbox")),
VAR_LABEL_RECEIVED_MESSAGE_FORMAT=StringVar(value=i18n.t("config_window.received_message_format.label")),
VAR_DESC_RECEIVED_MESSAGE_FORMAT=StringVar(value=i18n.t("config_window.received_message_format.desc")),
CALLBACK_SET_RECEIVED_MESSAGE_FORMAT=None,
CALLBACK_SWAP_RECEIVED_MESSAGE_FORMAT_REQUIRED_TEXT=self._swapReceivedMessageFormatRequiredText,
VAR_RECEIVED_MESSAGE_FORMAT=StringVar(value=config.RECEIVED_MESSAGE_FORMAT),
VAR_LABEL_EXAMPLE_TEXT_RECEIVED_MESSAGE_FORMAT=StringVar(value=""),
VAR_ENTRY_0_RECEIVED_MESSAGE_FORMAT=StringVar(value=""),
VAR_ENTRY_1_RECEIVED_MESSAGE_FORMAT=StringVar(value=""),
VAR_ENTRY_2_RECEIVED_MESSAGE_FORMAT=StringVar(value=""),
VAR_TEXT_REQUIRED_0_RECEIVED_MESSAGE_FORMAT=StringVar(value="[message]"),
VAR_TEXT_REQUIRED_1_RECEIVED_MESSAGE_FORMAT=StringVar(value="[translation]"),
CALLBACK_FOCUS_OUT_RECEIVED_MESSAGE_FORMAT=self.callbackBindFocusOut_ReceivedMessageFormat,
VAR_LABEL_ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC=StringVar(value=i18n.t("config_window.send_received_message_to_vrc.label")),
VAR_DESC_ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC=StringVar(value=i18n.t("config_window.send_received_message_to_vrc.desc")),
CALLBACK_SET_ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC=None,
VAR_ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC=BooleanVar(value=config.ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC),
# -------------------Speaker2Chatbox-----------
# Advanced Settings Tab
VAR_LABEL_OSC_IP_ADDRESS=StringVar(value=i18n.t("config_window.osc_ip_address.label")),
VAR_DESC_OSC_IP_ADDRESS=None,
@@ -501,6 +527,13 @@ class View():
self.view_variable.CALLBACK_SET_ENABLE_SEND_MESSAGE_TO_VRC = config_window_registers.get("callback_set_enable_send_message_to_vrc", None)
# self.view_variable.CALLBACK_SET_STARTUP_OSC_ENABLED_CHECK = config_window_registers.get("callback_set_startup_osc_enabled_check", None) #[deprecated]
self.view_variable.CALLBACK_SET_RECEIVED_MESSAGE_FORMAT = config_window_registers.get("callback_set_received_message_format", None)
self.view_variable.CALLBACK_SET_ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC = config_window_registers.get("callback_set_enable_send_received_message_to_vrc", None)
# Advanced Settings Tab
self.view_variable.CALLBACK_SET_OSC_IP_ADDRESS = config_window_registers.get("callback_set_osc_ip_address", None)
self.view_variable.CALLBACK_SET_OSC_PORT = config_window_registers.get("callback_set_osc_port", None)
@@ -540,6 +573,7 @@ class View():
self.setMessageFormatEntryWidgets(config.MESSAGE_FORMAT)
self.setReceivedMessageFormatEntryWidgets(config.RECEIVED_MESSAGE_FORMAT)
# Insert sample conversation for testing.
# self._insertSampleConversationToTextbox()
@@ -590,6 +624,57 @@ class View():
self.view_variable.VAR_LABEL_EXAMPLE_TEXT_MESSAGE_FORMAT.set(example_message)
# Speaker2Chatbox----------------------------
def setReceivedMessageFormatEntryWidgets(self, message_format:str):
result = self.extractMessageFormat(message_format)
if result.is_message_first is True:
self.view_variable.VAR_TEXT_REQUIRED_0_RECEIVED_MESSAGE_FORMAT.set("[message]")
self.view_variable.VAR_TEXT_REQUIRED_1_RECEIVED_MESSAGE_FORMAT.set("[translation]")
else:
self.view_variable.VAR_TEXT_REQUIRED_0_RECEIVED_MESSAGE_FORMAT.set("[translation]")
self.view_variable.VAR_TEXT_REQUIRED_1_RECEIVED_MESSAGE_FORMAT.set("[message]")
self.view_variable.VAR_ENTRY_0_RECEIVED_MESSAGE_FORMAT.set(result.before)
self.view_variable.VAR_ENTRY_1_RECEIVED_MESSAGE_FORMAT.set(result.between)
self.view_variable.VAR_ENTRY_2_RECEIVED_MESSAGE_FORMAT.set(result.after)
self.updateReceivedMessageFormat_ExampleTextWidget()
def _swapReceivedMessageFormatRequiredText(self):
text_0 = self.view_variable.VAR_TEXT_REQUIRED_0_RECEIVED_MESSAGE_FORMAT.get()
text_1 = self.view_variable.VAR_TEXT_REQUIRED_1_RECEIVED_MESSAGE_FORMAT.get()
self.view_variable.VAR_TEXT_REQUIRED_0_RECEIVED_MESSAGE_FORMAT.set(text_1)
self.view_variable.VAR_TEXT_REQUIRED_1_RECEIVED_MESSAGE_FORMAT.set(text_0)
self.updateReceivedMessageFormat_ExampleTextWidget()
new_message_format = self.getLatestReceivedMessageFormatFromWidget()
callFunctionIfCallable(self.view_variable.CALLBACK_SET_RECEIVED_MESSAGE_FORMAT, new_message_format)
def getLatestReceivedMessageFormatFromWidget(self):
text_0 = self.view_variable.VAR_TEXT_REQUIRED_0_RECEIVED_MESSAGE_FORMAT.get()
text_1 = self.view_variable.VAR_TEXT_REQUIRED_1_RECEIVED_MESSAGE_FORMAT.get()
entry_0 = self.view_variable.VAR_ENTRY_0_RECEIVED_MESSAGE_FORMAT.get()
entry_1 = self.view_variable.VAR_ENTRY_1_RECEIVED_MESSAGE_FORMAT.get()
entry_2 = self.view_variable.VAR_ENTRY_2_RECEIVED_MESSAGE_FORMAT.get()
return entry_0+text_0+entry_1+text_1+entry_2
def updateReceivedMessageFormat_ExampleTextWidget(self):
message = i18n.t("config_window.message_format.example_text", locale=config.UI_LANGUAGE)
translation_locale = "ja" if config.UI_LANGUAGE == "en" else "en"
translation = i18n.t("config_window.message_format.example_text", locale=translation_locale)
example_message = config.RECEIVED_MESSAGE_FORMAT.replace("[message]", message)
example_message = example_message.replace("[translation]", translation)
self.view_variable.VAR_LABEL_EXAMPLE_TEXT_RECEIVED_MESSAGE_FORMAT.set(example_message)
# Speaker2Chatbox----------------------------
# GUI process
def createGUI(self):
vrct_gui._createGUI(settings=self.settings, view_variable=self.view_variable)
@@ -1128,6 +1213,8 @@ class View():
case "MessageFormat":
self.setMessageFormatEntryWidgets(config.MESSAGE_FORMAT)
case "ReceivedMessageFormat":
self.setReceivedMessageFormatEntryWidgets(config.RECEIVED_MESSAGE_FORMAT)
case _:
raise ValueError(f"No matching case for target_name: {target_name}")
@@ -1282,6 +1369,10 @@ class View():
self.setLatestConfigVariable("MessageFormat")
self.clearErrorMessage()
def callbackBindFocusOut_ReceivedMessageFormat(self, _e=None):
self.setLatestConfigVariable("ReceivedMessageFormat")
self.clearErrorMessage()
@@ -1369,6 +1460,13 @@ class View():
self._makeInvalidValueErrorMessage(i18n.t("config_window.message_format.error_message"))
)
def showErrorMessage_ReceivedMessageFormat(self):
self._showErrorMessage(
vrct_gui.config_window.sb__entry_received_message_format_2,
self._makeInvalidValueErrorMessage(i18n.t("config_window.message_format.error_message"))
)
@staticmethod
def _makeInvalidValueErrorMessage(error_message):
return i18n.t("config_window.common_error_message.invalid_value") + "\n" + error_message

View File

@@ -8,7 +8,7 @@ from ._createSettingBoxContainer import _createSettingBoxContainer
from .setting_box_containers.setting_box_appearance import createSettingBox_Appearance
from .setting_box_containers.setting_box_transcription import createSettingBox_Mic, createSettingBox_Speaker
from .setting_box_containers.setting_box_others import createSettingBox_Others
from .setting_box_containers.setting_box_others import createSettingBox_Others, createSettingBox_Others_Additional
from .setting_box_containers.setting_box_advanced_settings import createSettingBox_AdvancedSettings
from .setting_box_containers.setting_box_translation import createSettingBox_Translation
@@ -106,6 +106,7 @@ def createSideMenuAndSettingsBoxContainers(config_window, settings, view_variabl
"setting_box_container_attr_name": "setting_box_container_others",
"setting_boxes": [
{ "var_section_title": None, "setting_box": createSettingBox_Others },
{ "var_section_title": view_variable.VAR_SECOND_TITLE_OTHERS_SPEAKER2CHATBOX, "setting_box": createSettingBox_Others_Additional },
]
},
},

View File

@@ -109,8 +109,9 @@ class _SettingBoxGenerator():
def createSettingBox_Labels(
self,
for_var_label_text, for_var_desc_text,
for_var_label_text,
labels_attr_name,
for_var_desc_text=None,
):
setting_box_frame= self._createSettingBoxFrame(labels_attr_name, for_var_label_text, for_var_desc_text, expand_label_frame=True)
@@ -216,10 +217,11 @@ class _SettingBoxGenerator():
def createSettingBoxCheckbox(self,
for_var_label_text, for_var_desc_text,
for_var_label_text,
checkbox_attr_name,
command,
variable,
for_var_desc_text=None,
):
(setting_box_frame, setting_box_item_frame) = self._createSettingBoxFrame(checkbox_attr_name, for_var_label_text, for_var_desc_text)
@@ -543,6 +545,8 @@ class _SettingBoxGenerator():
entry_textvariable_2,
textvariable_0,
textvariable_1,
example_label_textvariable,
swap_button_command,
entry_bind__Any_KeyRelease,
entry_bind__FocusOut=None,
):
@@ -577,7 +581,7 @@ class _SettingBoxGenerator():
example_frame_widget.grid_columnconfigure((0,2), weight=1)
example_label_widget = CTkLabel(
example_frame_widget,
textvariable=self.view_variable.VAR_LABEL_EXAMPLE_TEXT_MESSAGE_FORMAT,
textvariable=example_label_textvariable,
anchor="center",
justify="center",
wraplength=self.settings.uism.SB__MESSAGE_FORMAT__EXAMPLE_WRAP_LENGTH,
@@ -713,10 +717,6 @@ class _SettingBoxGenerator():
)
swap_button_label_1.grid(row=1, column=3)
def adjustedCommand():
callFunctionIfCallable(self.view_variable.CALLBACK_SWAP_MESSAGE_FORMAT_REQUIRED_TEXT)
bindButtonFunctionAndColor(
target_widgets=[
swap_button,
@@ -728,7 +728,7 @@ class _SettingBoxGenerator():
enter_color=self.settings.ctm.SB__MESSAGE_FORMAT__SWAP_BUTTON_HOVERED_COLOR,
leave_color=self.settings.ctm.SB__MESSAGE_FORMAT__SWAP_BUTTON_COLOR,
clicked_color=self.settings.ctm.SB__MESSAGE_FORMAT__SWAP_BUTTON_CLICKED_COLOR,
buttonReleasedFunction=lambda _e: adjustedCommand(),
buttonReleasedFunction=swap_button_command,
)

View File

@@ -1 +1,2 @@
from .createSettingBox_Others import createSettingBox_Others
from .createSettingBox_Others import createSettingBox_Others
from .createSettingBox_Others_Additional import createSettingBox_Others_Additional

View File

@@ -33,6 +33,9 @@ def createSettingBox_Others(setting_box_wrapper, config_window, settings, view_v
def entry_message_format_callback(value):
callFunctionIfCallable(view_variable.CALLBACK_SET_MESSAGE_FORMAT, value)
def entry_swap_message_format_callback(_e):
callFunctionIfCallable(view_variable.CALLBACK_SWAP_MESSAGE_FORMAT_REQUIRED_TEXT)
row=0
config_window.sb__auto_clear_message_box = createSettingBoxCheckbox(
@@ -85,7 +88,9 @@ def createSettingBox_Others(setting_box_wrapper, config_window, settings, view_v
entry_textvariable_2=view_variable.VAR_ENTRY_2_MESSAGE_FORMAT,
textvariable_0=view_variable.VAR_TEXT_REQUIRED_0_MESSAGE_FORMAT,
textvariable_1=view_variable.VAR_TEXT_REQUIRED_1_MESSAGE_FORMAT,
example_label_textvariable=view_variable.VAR_LABEL_EXAMPLE_TEXT_MESSAGE_FORMAT,
entry_bind__Any_KeyRelease=lambda value: entry_message_format_callback(value),
swap_button_command=entry_swap_message_format_callback,
# entry_textvariable=view_variable.VAR_MESSAGE_FORMAT,
entry_bind__FocusOut=view_variable.CALLBACK_FOCUS_OUT_MESSAGE_FORMAT,
)

View File

@@ -0,0 +1,56 @@
from utils import callFunctionIfCallable
from .._SettingBoxGenerator import _SettingBoxGenerator
def createSettingBox_Others_Additional(setting_box_wrapper, config_window, settings, view_variable):
sbg = _SettingBoxGenerator(setting_box_wrapper, config_window, settings, view_variable)
createSettingBoxCheckbox = sbg.createSettingBoxCheckbox
createSettingBox_Labels = sbg.createSettingBox_Labels
createSettingBoxMessageFormatEntries = sbg.createSettingBoxMessageFormatEntries
def checkbox_enable_send_received_message_to_vrc_callback(checkbox_box_widget):
callFunctionIfCallable(view_variable.CALLBACK_SET_ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC, checkbox_box_widget.get())
def entry_received_message_format_callback(value):
callFunctionIfCallable(view_variable.CALLBACK_SET_RECEIVED_MESSAGE_FORMAT, value)
def entry_swap_received_message_format_callback(_e):
callFunctionIfCallable(view_variable.CALLBACK_SWAP_RECEIVED_MESSAGE_FORMAT_REQUIRED_TEXT)
row=0
config_window.sb__received_message_format_labels = createSettingBox_Labels(
for_var_label_text=view_variable.VAR_LABEL_RECEIVED_MESSAGE_FORMAT,
# for_var_desc_text=view_variable.VAR_DESC_RECEIVED_MESSAGE_FORMAT,
labels_attr_name="sb__labels_message_format",
)
config_window.sb__received_message_format_labels.grid(row=row, pady=0)
row+=1
config_window.sb__received_message_format = createSettingBoxMessageFormatEntries(
base_entry_attr_name="sb__entry_received_message_format",
# entry_width=settings.uism.RESPONSIVE_UI_SIZE_INT_150,
entry_textvariable_0=view_variable.VAR_ENTRY_0_RECEIVED_MESSAGE_FORMAT,
entry_textvariable_1=view_variable.VAR_ENTRY_1_RECEIVED_MESSAGE_FORMAT,
entry_textvariable_2=view_variable.VAR_ENTRY_2_RECEIVED_MESSAGE_FORMAT,
textvariable_0=view_variable.VAR_TEXT_REQUIRED_0_RECEIVED_MESSAGE_FORMAT,
textvariable_1=view_variable.VAR_TEXT_REQUIRED_1_RECEIVED_MESSAGE_FORMAT,
example_label_textvariable=view_variable.VAR_LABEL_EXAMPLE_TEXT_RECEIVED_MESSAGE_FORMAT,
entry_bind__Any_KeyRelease=lambda value: entry_received_message_format_callback(value),
swap_button_command=entry_swap_received_message_format_callback,
# entry_textvariable=view_variable.VAR_RECEIVED_MESSAGE_FORMAT,
entry_bind__FocusOut=view_variable.CALLBACK_FOCUS_OUT_RECEIVED_MESSAGE_FORMAT,
)
config_window.sb__received_message_format.grid(row=row)
row+=1
config_window.sb__enable_send_received_message_to_vrc = createSettingBoxCheckbox(
for_var_label_text=view_variable.VAR_LABEL_ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC,
# for_var_desc_text=view_variable.VAR_DESC_ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC,
checkbox_attr_name="sb__checkbox_enable_send_received_message_to_vrc",
command=lambda: checkbox_enable_send_received_message_to_vrc_callback(config_window.sb__checkbox_enable_send_received_message_to_vrc),
variable=view_variable.VAR_ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC,
)
config_window.sb__enable_send_received_message_to_vrc.grid(row=row, pady=0)
row+=1