[Update] Main Window: Message box. 送信したメッセージを、キーボード矢印キー上下で呼び出せるように。

This commit is contained in:
Sakamoto Shiina
2024-02-01 15:54:22 +09:00
parent 4ae35e51a9
commit 6fbc2ede3a
4 changed files with 64 additions and 0 deletions

View File

@@ -197,6 +197,24 @@ class Config:
if value in list(translation_lang.keys()):
self._CHOICE_OUTPUT_TRANSLATOR = value
@property
def SENT_MESSAGES_LOG(self):
return self._SENT_MESSAGES_LOG
@SENT_MESSAGES_LOG.setter
def SENT_MESSAGES_LOG(self, value):
if isinstance(value, list):
self._SENT_MESSAGES_LOG = value
@property
def CURRENT_SENT_MESSAGES_LOG_INDEX(self):
return self._CURRENT_SENT_MESSAGES_LOG_INDEX
@CURRENT_SENT_MESSAGES_LOG_INDEX.setter
def CURRENT_SENT_MESSAGES_LOG_INDEX(self, value):
if isinstance(value, int):
self._CURRENT_SENT_MESSAGES_LOG_INDEX = value
@property
def IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION(self):
return self._IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION
@@ -770,6 +788,8 @@ class Config:
self._SOURCE_COUNTRY = "Japan"
self._TARGET_LANGUAGE = "English"
self._TARGET_COUNTRY = "United States"
self._SENT_MESSAGES_LOG = []
self._CURRENT_SENT_MESSAGES_LOG_INDEX = 0
self._IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False
# Save Json Data

View File

@@ -200,6 +200,8 @@ def stopThreadingTranscriptionReceiveMessageOnOpenConfigWindow():
# func message box
def sendChatMessage(message):
if len(message) > 0:
config.SENT_MESSAGES_LOG.append(view.getTextFromMessageBox())
config.CURRENT_SENT_MESSAGES_LOG_INDEX = len(config.SENT_MESSAGES_LOG)
translation = ""
if config.ENABLE_TRANSLATION is False:
pass
@@ -249,6 +251,25 @@ def messageBoxFocusOut(e):
if config.ENABLE_SEND_MESSAGE_TO_VRC is True:
model.oscStopSendTyping()
def updateMessageBox(index_offset):
if len(config.SENT_MESSAGES_LOG) == 0:
return
try:
new_index = config.CURRENT_SENT_MESSAGES_LOG_INDEX + index_offset
target_message_text = config.SENT_MESSAGES_LOG[new_index]
view.replaceMessageBox(target_message_text)
config.CURRENT_SENT_MESSAGES_LOG_INDEX = new_index
except IndexError:
pass
def messageBoxUpKeyPress():
if config.CURRENT_SENT_MESSAGES_LOG_INDEX > 0:
updateMessageBox(-1)
def messageBoxDownKeyPress():
if config.CURRENT_SENT_MESSAGES_LOG_INDEX < len(config.SENT_MESSAGES_LOG) - 1:
updateMessageBox(1)
def updateTranslationEngineAndEngineList():
engine = config.CHOICE_INPUT_TRANSLATOR
engines = model.findTranslationEngines(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE)
@@ -949,6 +970,8 @@ def createMainWindow(splash):
"message_box_bind_Any_KeyPress": messageBoxPressKeyAny,
"message_box_bind_FocusIn": messageBoxFocusIn,
"message_box_bind_FocusOut": messageBoxFocusOut,
"message_box_bind_Up_KeyPress": messageBoxUpKeyPress,
"message_box_bind_Down_KeyPress": messageBoxDownKeyPress,
},
config_window_registers={

13
view.py
View File

@@ -184,6 +184,8 @@ class View():
VAR_UPDATE_AVAILABLE=StringVar(value=i18n.t("main_window.update_available")),
CALLBACK_MESSAGE_BOX_BIND_KEYSYM__UP=None,
CALLBACK_MESSAGE_BOX_BIND_KEYSYM__DOWN=None,
# Main Window Cover
VAR_LABEL_MAIN_WINDOW_COVER_MESSAGE=StringVar(value=""),
@@ -562,6 +564,10 @@ class View():
self.view_variable.CALLBACK_CLICKED_SEND_MESSAGE_BUTTON = pressedSendMessageButtonFunction
self.view_variable.CALLBACK_MESSAGE_BOX_BIND_KEYSYM__UP=main_window_registers.get("message_box_bind_Up_KeyPress")
self.view_variable.CALLBACK_MESSAGE_BOX_BIND_KEYSYM__DOWN=main_window_registers.get("message_box_bind_Down_KeyPress")
entry_message_box.bind("<FocusIn>", main_window_registers.get("message_box_bind_FocusIn"))
entry_message_box.bind("<FocusOut>", main_window_registers.get("message_box_bind_FocusOut"))
@@ -1637,6 +1643,13 @@ class View():
def clearMessageBox(self):
self._clearTextBox(vrct_gui.entry_message_box)
@staticmethod
def insertMessageBox(text):
vrct_gui.entry_message_box.insert("end", text)
def replaceMessageBox(self, text):
self.clearMessageBox()
self.insertMessageBox(text)

View File

@@ -31,6 +31,14 @@ def createEntryMessageBox(settings, main_window, view_variable):
"Delete", "Select", "Up", "Down", "Next", "End", "Print",
"Prior","Insert","Home", "Left", "Clear", "Right", "Linefeed"
]
if e.keysym == "Up":
callFunctionIfCallable(view_variable.CALLBACK_MESSAGE_BOX_BIND_KEYSYM__UP)
return "break"
if e.keysym == "Down":
callFunctionIfCallable(view_variable.CALLBACK_MESSAGE_BOX_BIND_KEYSYM__DOWN)
return "break"
if e.keysym != "??":
if len(e.char) != 0 and e.keysym in BREAK_KEYSYM_LIST:
main_window.entry_message_box.insert("end", e.char)