[Update] Message Format: [message]と[translation]は一意かつそれぞれ一つだけの使用に。それに伴いエラー表示や初期値の挿入など。
This commit is contained in:
@@ -8,7 +8,7 @@ from tkinter import font
|
|||||||
from languages import selectable_languages
|
from languages import selectable_languages
|
||||||
from models.translation.translation_languages import translatorEngine
|
from models.translation.translation_languages import translatorEngine
|
||||||
from models.transcription.transcription_utils import getInputDevices, getDefaultInputDevice
|
from models.transcription.transcription_utils import getInputDevices, getDefaultInputDevice
|
||||||
from utils import generatePercentageStringsList
|
from utils import generatePercentageStringsList, isUniqueStrings
|
||||||
|
|
||||||
json_serializable_vars = {}
|
json_serializable_vars = {}
|
||||||
def json_serializable(var_name):
|
def json_serializable(var_name):
|
||||||
@@ -447,7 +447,7 @@ class Config:
|
|||||||
@MESSAGE_FORMAT.setter
|
@MESSAGE_FORMAT.setter
|
||||||
def MESSAGE_FORMAT(self, value):
|
def MESSAGE_FORMAT(self, value):
|
||||||
if type(value) is str:
|
if type(value) is str:
|
||||||
if "[message]" not in value or "[translation]" not in value:
|
if isUniqueStrings(["[message]", "[translation]"], value) is False:
|
||||||
value = "[message]([translation])"
|
value = "[message]([translation])"
|
||||||
self._MESSAGE_FORMAT = value
|
self._MESSAGE_FORMAT = value
|
||||||
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
|
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from threading import Thread
|
|||||||
from config import config
|
from config import config
|
||||||
from model import model
|
from model import model
|
||||||
from view import view
|
from view import view
|
||||||
from utils import get_key_by_value
|
from utils import get_key_by_value, isUniqueStrings
|
||||||
from languages import selectable_languages
|
from languages import selectable_languages
|
||||||
|
|
||||||
# Common
|
# Common
|
||||||
@@ -627,8 +627,14 @@ def callbackSetEnableAutoExportMessageLogs(value):
|
|||||||
def callbackSetMessageFormat(value):
|
def callbackSetMessageFormat(value):
|
||||||
print("callbackSetMessageFormat", value)
|
print("callbackSetMessageFormat", value)
|
||||||
if len(value) > 0:
|
if len(value) > 0:
|
||||||
|
if isUniqueStrings(["[message]", "[translation]"], value) is True:
|
||||||
config.MESSAGE_FORMAT = value
|
config.MESSAGE_FORMAT = value
|
||||||
|
view.clearErrorMessage()
|
||||||
view.setMessageFormatEntryWidgets(config.MESSAGE_FORMAT)
|
view.setMessageFormatEntryWidgets(config.MESSAGE_FORMAT)
|
||||||
|
else:
|
||||||
|
view.showErrorMessage_MessageFormat()
|
||||||
|
view.setMessageFormatEntryWidgets(config.MESSAGE_FORMAT)
|
||||||
|
|
||||||
|
|
||||||
def callbackSetEnableSendMessageToVrc(value):
|
def callbackSetEnableSendMessageToVrc(value):
|
||||||
print("callbackSetEnableSendMessageToVrc", value)
|
print("callbackSetEnableSendMessageToVrc", value)
|
||||||
|
|||||||
@@ -182,6 +182,7 @@ config_window:
|
|||||||
label: Message Format
|
label: Message Format
|
||||||
desc: "You can change the decoration of the message you want to send.\n[message] will be replaced with the message, and [translation] will be replaced with the translated message.\nIt will be used in Notification XSOverlay too."
|
desc: "You can change the decoration of the message you want to send.\n[message] will be replaced with the message, and [translation] will be replaced with the translated message.\nIt will be used in Notification XSOverlay too."
|
||||||
example_text: This is an example sentence. Fonts, line breaks, etc. may differ from the actual display.
|
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_message_to_vrc:
|
send_message_to_vrc:
|
||||||
label: Send Message To VRChat
|
label: Send Message To VRChat
|
||||||
|
|||||||
@@ -181,6 +181,7 @@ config_window:
|
|||||||
label: 送信するメッセージのフォーマット
|
label: 送信するメッセージのフォーマット
|
||||||
desc: "VRChatで相手に実際に見えるフォーマットを変更できます。\n[message]がメッセージに置換され、[translation]が翻訳されたメッセージに置換されます。\n※XSOverlayでの通知受け取り機能でも使われます。"
|
desc: "VRChatで相手に実際に見えるフォーマットを変更できます。\n[message]がメッセージに置換され、[translation]が翻訳されたメッセージに置換されます。\n※XSOverlayでの通知受け取り機能でも使われます。"
|
||||||
example_text: これは例文です。フォントや改行箇所など、実際の表示とは異なる場合があります。
|
example_text: これは例文です。フォントや改行箇所など、実際の表示とは異なる場合があります。
|
||||||
|
error_message: "[message]と[translation]という文字は使えません。"
|
||||||
|
|
||||||
send_message_to_vrc:
|
send_message_to_vrc:
|
||||||
label: VRChatにメッセージを送信する
|
label: VRChatにメッセージを送信する
|
||||||
|
|||||||
16
utils.py
16
utils.py
@@ -1,3 +1,4 @@
|
|||||||
|
from typing import Union
|
||||||
from os import path as os_path
|
from os import path as os_path
|
||||||
from PIL.Image import open as Image_open
|
from PIL.Image import open as Image_open
|
||||||
|
|
||||||
@@ -30,3 +31,18 @@ def generatePercentageStringsList(start=40, end=200, step=10):
|
|||||||
|
|
||||||
def intToPercentageStringsFormatter(value:int):
|
def intToPercentageStringsFormatter(value:int):
|
||||||
return f"{value}%"
|
return f"{value}%"
|
||||||
|
|
||||||
|
def isUniqueStrings(unique_strings:Union[str, list], input_string:str, require=False):
|
||||||
|
import re
|
||||||
|
if isinstance(unique_strings, str):
|
||||||
|
unique_strings = [unique_strings]
|
||||||
|
patterns = [re.escape(s) for s in unique_strings]
|
||||||
|
|
||||||
|
counts = [len(re.findall(pattern, input_string)) for pattern in patterns]
|
||||||
|
|
||||||
|
if require is True:
|
||||||
|
# If require is True, unique_strings must appear once
|
||||||
|
return all(count == 1 for count in counts) and counts.count(1) == 2
|
||||||
|
else:
|
||||||
|
# If require is False, check if unique strings are used exactly once
|
||||||
|
return all(count == 1 for count in counts)
|
||||||
15
view.py
15
view.py
@@ -355,6 +355,7 @@ class View():
|
|||||||
VAR_ENTRY_2_MESSAGE_FORMAT=StringVar(value=""),
|
VAR_ENTRY_2_MESSAGE_FORMAT=StringVar(value=""),
|
||||||
VAR_TEXT_REQUIRED_0_MESSAGE_FORMAT=StringVar(value="[message]"),
|
VAR_TEXT_REQUIRED_0_MESSAGE_FORMAT=StringVar(value="[message]"),
|
||||||
VAR_TEXT_REQUIRED_1_MESSAGE_FORMAT=StringVar(value="[translation]"),
|
VAR_TEXT_REQUIRED_1_MESSAGE_FORMAT=StringVar(value="[translation]"),
|
||||||
|
CALLBACK_FOCUS_OUT_MESSAGE_FORMAT=self.callbackBindFocusOut_MessageFormat,
|
||||||
|
|
||||||
|
|
||||||
VAR_LABEL_ENABLE_SEND_MESSAGE_TO_VRC=StringVar(value=i18n.t("config_window.send_message_to_vrc.label")),
|
VAR_LABEL_ENABLE_SEND_MESSAGE_TO_VRC=StringVar(value=i18n.t("config_window.send_message_to_vrc.label")),
|
||||||
@@ -1121,6 +1122,9 @@ class View():
|
|||||||
case "SpeakerMaxPhrases":
|
case "SpeakerMaxPhrases":
|
||||||
self.setGuiVariable_SpeakerMaxPhrases(config.INPUT_SPEAKER_MAX_PHRASES)
|
self.setGuiVariable_SpeakerMaxPhrases(config.INPUT_SPEAKER_MAX_PHRASES)
|
||||||
|
|
||||||
|
case "MessageFormat":
|
||||||
|
self.setMessageFormatEntryWidgets(config.MESSAGE_FORMAT)
|
||||||
|
|
||||||
case _:
|
case _:
|
||||||
raise ValueError(f"No matching case for target_name: {target_name}")
|
raise ValueError(f"No matching case for target_name: {target_name}")
|
||||||
|
|
||||||
@@ -1270,7 +1274,9 @@ class View():
|
|||||||
self.clearErrorMessage()
|
self.clearErrorMessage()
|
||||||
|
|
||||||
|
|
||||||
|
def callbackBindFocusOut_MessageFormat(self, _e=None):
|
||||||
|
self.setLatestConfigVariable("MessageFormat")
|
||||||
|
self.clearErrorMessage()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1352,6 +1358,13 @@ class View():
|
|||||||
self._makeInvalidValueErrorMessage(i18n.t("config_window.speaker_dynamic_energy_threshold.no_device_error_message"))
|
self._makeInvalidValueErrorMessage(i18n.t("config_window.speaker_dynamic_energy_threshold.no_device_error_message"))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def showErrorMessage_MessageFormat(self):
|
||||||
|
self._showErrorMessage(
|
||||||
|
vrct_gui.config_window.sb__entry_message_format_2,
|
||||||
|
self._makeInvalidValueErrorMessage(i18n.t("config_window.message_format.error_message"))
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _makeInvalidValueErrorMessage(error_message):
|
def _makeInvalidValueErrorMessage(error_message):
|
||||||
return i18n.t("config_window.common_error_message.invalid_value") + "\n" + error_message
|
return i18n.t("config_window.common_error_message.invalid_value") + "\n" + error_message
|
||||||
|
|||||||
@@ -547,7 +547,7 @@ class _SettingBoxGenerator():
|
|||||||
justify="center",
|
justify="center",
|
||||||
font=CTkFont(family=self.settings.FONT_FAMILY, size=self.settings.uism.SB__ENTRY_FONT_SIZE, weight="normal"),
|
font=CTkFont(family=self.settings.FONT_FAMILY, size=self.settings.uism.SB__ENTRY_FONT_SIZE, weight="normal"),
|
||||||
)
|
)
|
||||||
setattr(self.config_window, base_entry_attr_name + str(i), entry_widget)
|
setattr(self.config_window, base_entry_attr_name + "_" + str(i), entry_widget)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -588,9 +588,9 @@ class _SettingBoxGenerator():
|
|||||||
entries_wrapper.grid_columnconfigure((0,2,4), weight=1)
|
entries_wrapper.grid_columnconfigure((0,2,4), weight=1)
|
||||||
entries_wrapper.grid_columnconfigure((1,3), weight=0, uniform="message_format_fixed_labels")
|
entries_wrapper.grid_columnconfigure((1,3), weight=0, uniform="message_format_fixed_labels")
|
||||||
|
|
||||||
entry_widget_0 = getattr(self.config_window, base_entry_attr_name+"0")
|
entry_widget_0 = getattr(self.config_window, base_entry_attr_name+"_0")
|
||||||
entry_widget_1 = getattr(self.config_window, base_entry_attr_name+"1")
|
entry_widget_1 = getattr(self.config_window, base_entry_attr_name+"_1")
|
||||||
entry_widget_2 = getattr(self.config_window, base_entry_attr_name+"2")
|
entry_widget_2 = getattr(self.config_window, base_entry_attr_name+"_2")
|
||||||
entry_widget_0.grid(row=0, column=0, sticky="ew")
|
entry_widget_0.grid(row=0, column=0, sticky="ew")
|
||||||
entry_widget_1.grid(row=0, column=2, sticky="ew")
|
entry_widget_1.grid(row=0, column=2, sticky="ew")
|
||||||
entry_widget_2.grid(row=0, column=4, sticky="ew")
|
entry_widget_2.grid(row=0, column=4, sticky="ew")
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ def createSettingBox_Others(setting_box_wrapper, config_window, settings, view_v
|
|||||||
textvariable_1=view_variable.VAR_TEXT_REQUIRED_1_MESSAGE_FORMAT,
|
textvariable_1=view_variable.VAR_TEXT_REQUIRED_1_MESSAGE_FORMAT,
|
||||||
entry_bind__Any_KeyRelease=lambda value: entry_message_format_callback(value),
|
entry_bind__Any_KeyRelease=lambda value: entry_message_format_callback(value),
|
||||||
# entry_textvariable=view_variable.VAR_MESSAGE_FORMAT,
|
# entry_textvariable=view_variable.VAR_MESSAGE_FORMAT,
|
||||||
|
entry_bind__FocusOut=view_variable.CALLBACK_FOCUS_OUT_MESSAGE_FORMAT,
|
||||||
)
|
)
|
||||||
config_window.sb__message_format.grid(row=row)
|
config_window.sb__message_format.grid(row=row)
|
||||||
row+=1
|
row+=1
|
||||||
|
|||||||
Reference in New Issue
Block a user