From 8bb5b27e9f918d369c39e77c39e2cb9142037c6a Mon Sep 17 00:00:00 2001 From: misyaguziya Date: Fri, 9 Aug 2024 14:59:31 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8D=EF=B8=8F[Update]=20Main/Controller?= =?UTF-8?q?=20:=20=E3=83=87=E3=83=BC=E3=82=BF=E9=80=81=E4=BF=A1=E3=81=AE?= =?UTF-8?q?=E5=BD=A2=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/model.py | 10 +- src-python/webui_controller.py | 451 +++++++++++++++++++-------------- src-python/webui_mainloop.py | 59 ++++- 3 files changed, 312 insertions(+), 208 deletions(-) diff --git a/src-python/model.py b/src-python/model.py index d2556f04..2272eb39 100644 --- a/src-python/model.py +++ b/src-python/model.py @@ -315,7 +315,7 @@ class Model: return update_flag @staticmethod - def updateSoftware(restart:bool=True, func=None): + def updateSoftware(restart:bool=True, download=None, update=None): def updateSoftwareTask(): filename = 'VRCT.zip' program_name = 'VRCT.exe' @@ -336,8 +336,8 @@ class Model: for chunk in res.iter_content(chunk_size=1024*5): file.write(chunk) total_chunk += len(chunk) - if isinstance(func, Callable): - func(progress=total_chunk/file_size, progress_type="downloading") + if isinstance(download, Callable): + download(total_chunk/file_size) print(f"downloaded {total_chunk}/{file_size}") with ZipFile(os_path.join(tmp_path, filename)) as zf: @@ -346,8 +346,8 @@ class Model: for file_info in zf.infolist(): extracted_files += 1 zf.extract(file_info, os_path.join(current_directory, tmp_directory_name)) - if isinstance(func, Callable): - func(progress=extracted_files/total_files, progress_type="extracting") + if isinstance(update, Callable): + update(extracted_files/total_files) print(f"extracted {extracted_files}/{total_files}") copyfile(os_path.join(current_directory, folder_name, "batch", batch_name), os_path.join(current_directory, batch_name)) diff --git a/src-python/webui_controller.py b/src-python/webui_controller.py index 63256a39..a611543e 100644 --- a/src-python/webui_controller.py +++ b/src-python/webui_controller.py @@ -10,47 +10,59 @@ from utils import getKeyByValue, isUniqueStrings, strPctToInt import argparse # Common -def callbackUpdateSoftware(func=None): - print(json.dumps({"log": "callbackUpdateSoftware"}), flush=True) - setMainWindowGeometry() - model.updateSoftware(restart=True, func=func) +class DownloadProgressBar: + def __init__(self, action): + self.action = action -def callbackRestartSoftware(): + def set(self, progress) -> None: + print(json.dumps({"log": "Software Download Progress", "data":progress}), flush=True) + self.action("download", { + "status":200, + "result":{ + "progress":progress + } + }) + +class UpdateProgressBar: + def __init__(self, action): + self.action = action + + def set(self, progress) -> None: + print(json.dumps({"log": "Software Update Progress", "data":progress}), flush=True) + self.action("update", { + "status":200, + "result":{ + "progress":progress + } + }) + +def callbackUpdateSoftware(data, action, *args, **kwargs) -> dict: + print(json.dumps({"log": "callbackUpdateSoftware"}), flush=True) + download = DownloadProgressBar(action) + update = UpdateProgressBar(action) + model.updateSoftware(restart=True, download=download.set, update=update.set) + return {"status":200} + +def callbackRestartSoftware(*args, **kwargs) -> dict: print(json.dumps({"log": "callbackRestartSoftware"}), flush=True) - setMainWindowGeometry() model.reStartSoftware() + return {"status":200} def callbackFilepathLogs(): print(json.dumps({"log": "callbackFilepathLogs"}), flush=True) Popen(['explorer', config.PATH_LOGS.replace('/', '\\')], shell=True) - return "Success", 200 + return {"status":200} def callbackFilepathConfigFile(): print(json.dumps({"log": "callbackFilepathConfigFile"}), flush=True) Popen(['explorer', config.PATH_LOCAL.replace('/', '\\')], shell=True) - return "Success", 200 + return {"status":200} -def callbackQuitVrct(): - print(json.dumps({"log": "callbackQuitVrct"}), flush=True) - setMainWindowGeometry() - -def callbackEnableEasterEgg(): - print(json.dumps({"log": "callbackEnableEasterEgg"}), flush=True) - config.IS_EASTER_EGG_ENABLED = True - config.OVERLAY_UI_TYPE = "sakura" - # view.printToTextbox_enableEasterEgg() - -def setMainWindowGeometry(): - # PRE_SCALING_INT = strPctToInt(view.getPreUiScaling()) - # NEW_SCALING_INT = strPctToInt(config.UI_SCALING) - # MULTIPLY_FLOAT = (NEW_SCALING_INT / PRE_SCALING_INT) - # main_window_geometry = view.getMainWindowGeometry(return_int=True) - # main_window_geometry["width"] = str(int(main_window_geometry["width"] * MULTIPLY_FLOAT)) - # main_window_geometry["height"] = str(int(main_window_geometry["height"] * MULTIPLY_FLOAT)) - # main_window_geometry["x_pos"] = str(main_window_geometry["x_pos"]) - # main_window_geometry["y_pos"] = str(main_window_geometry["y_pos"]) - # config.MAIN_WINDOW_GEOMETRY = main_window_geometry - pass +# def callbackEnableEasterEgg(): +# print(json.dumps({"log": "callbackEnableEasterEgg"}), flush=True) +# config.IS_EASTER_EGG_ENABLED = True +# config.OVERLAY_UI_TYPE = "sakura" +# return {"status":200, "result":config.IS_EASTER_EGG_ENABLED} def messageFormatter(format_type:str, translation, message): if format_type == "RECEIVED": @@ -74,7 +86,6 @@ def changeToCTranslate2Process(): config.CHOICE_INPUT_TRANSLATOR = "CTranslate2" config.CHOICE_OUTPUT_TRANSLATOR = "CTranslate2" updateTranslationEngineAndEngineList() - # view.printToTextbox_TranslationEngineLimitError() # func transcription send message class MicMessage: @@ -83,12 +94,22 @@ class MicMessage: def send(self, message: Union[str, bool]) -> None: if isinstance(message, bool) and message is False: - self.action({"status":"error", "message":"No mic device detected."}) + self.action("error_device", { + "status":404, + "result": { + "message":"No mic device detected." + } + }) elif isinstance(message, str) and len(message) > 0: addSentMessageLog(message) translation = "" if model.checkKeywords(message): - self.action("mic", {"status":"error", "message":f"Detected by word filter:{message}"}) + self.action("word_filter", { + "status":200, + "result": { + "message":f"Detected by word filter:{message}" + } + }) return elif model.detectRepeatSendMessage(message): return @@ -98,6 +119,12 @@ class MicMessage: translation, success = model.getInputTranslate(message) if success is False: changeToCTranslate2Process() + self.action("error_translation_engine", { + "status":404, + "result": { + "message":"translation engine limit error" + } + }) if config.ENABLE_TRANSCRIPTION_SEND is True: if config.ENABLE_SEND_MESSAGE_TO_VRC is True: @@ -110,7 +137,13 @@ class MicMessage: osc_message = messageFormatter("SEND", translation, message) model.oscSendMessage(osc_message) - self.action("mic", {"status":"success", "message":message, "translation":translation}) + self.action("mic", { + "status":200, + "result": { + "message":message, + "translation":translation + } + }) if config.ENABLE_LOGGER is True: if len(translation) > 0: translation = f" ({translation})" @@ -128,7 +161,12 @@ def startTranscriptionSendMessage(action:Callable[[dict], None]) -> None: def stopTranscriptionSendMessage(action:Callable[[dict], None]) -> None: model.stopMicTranscript() - action("mic", {"status":"success", "message":"Stopped sending messages"}) + action("mic", { + "status":200, + "result":{ + "message":"Stopped sending messages" + } + }) def startThreadingTranscriptionSendMessage(action:Callable[[dict], None]) -> None: th_startTranscriptionSendMessage = Thread(target=startTranscriptionSendMessage, args=(action,)) @@ -164,7 +202,12 @@ class SpeakerMessage: def receive(self, message): if isinstance(message, bool) and message is False: - self.action("speaker", {"status":"error", "message":"No mic device detected."}) + self.action("error_device",{ + "status":404, + "result": { + "message":"No mic device detected." + }, + }) elif isinstance(message, str) and len(message) > 0: translation = "" if model.detectRepeatReceiveMessage(message): @@ -175,6 +218,12 @@ class SpeakerMessage: translation, success = model.getOutputTranslate(message) if success is False: changeToCTranslate2Process() + self.action("error_translation_engine", { + "status":404, + "result": { + "message":"translation engine limit error" + } + }) if config.ENABLE_TRANSCRIPTION_RECEIVE is True: if config.ENABLE_NOTICE_XSOVERLAY is True: @@ -197,7 +246,13 @@ class SpeakerMessage: # ------------Speaker2Chatbox------------ # update textbox message log (Received) - self.action("speaker",{"status":"success", "message":message, "translation":translation}) + self.action("speaker",{ + "status":200, + "result": { + "message":message, + "translation":translation + } + }) if config.ENABLE_LOGGER is True: if len(translation) > 0: translation = f" ({translation})" @@ -209,7 +264,12 @@ def startTranscriptionReceiveMessage(action:Callable[[dict], None]) -> None: def stopTranscriptionReceiveMessage(action:Callable[[dict], None]) -> None: model.stopSpeakerTranscript() - action({"status":"success", "message":"Stopped receiving messages"}) + action("speaker", { + "status":200, + "result": { + "message":"Stopped receiving messages" + } + }) def startThreadingTranscriptionReceiveMessage(action:Callable[[dict], None]) -> None: th_startTranscriptionReceiveMessage = Thread(target=startTranscriptionReceiveMessage, args=(action,)) @@ -239,51 +299,62 @@ def stopThreadingTranscriptionReceiveMessageOnOpenConfigWindow(): th_stopTranscriptionReceiveMessage.start() # func message box -def sendChatMessage(message): - if len(message) > 0: - addSentMessageLog(message) - translation = "" - if config.ENABLE_TRANSLATION is False: - pass - else: - translation, success = model.getInputTranslate(message) - if success is False: - changeToCTranslate2Process() +class ChatMessage: + def __init__(self, action:Callable[[dict], None]) -> None: + self.action = action - # send OSC message - if config.ENABLE_SEND_MESSAGE_TO_VRC is True: - if config.ENABLE_SEND_ONLY_TRANSLATED_MESSAGES is True: - if config.ENABLE_TRANSLATION is False: - osc_message = messageFormatter("SEND", "", message) - else: - osc_message = messageFormatter("SEND", "", translation) + def send(self, message): + if len(message) > 0: + addSentMessageLog(message) + translation = "" + if config.ENABLE_TRANSLATION is False: + pass else: - osc_message = messageFormatter("SEND", translation, message) - model.oscSendMessage(osc_message) + translation, success = model.getInputTranslate(message) + if success is False: + changeToCTranslate2Process() + self.action("error_translation_engine", { + "status":404, + "result":{ + "message":"translation engine limit error" + } + }) - # if config.ENABLE_OVERLAY_SMALL_LOG is True: - # overlay_image = model.createOverlayImageShort(message, translation) - # model.updateOverlay(overlay_image) - # overlay_image = model.createOverlayImageLong("send", message, translation) - # model.updateOverlay(overlay_image) + # send OSC message + if config.ENABLE_SEND_MESSAGE_TO_VRC is True: + if config.ENABLE_SEND_ONLY_TRANSLATED_MESSAGES is True: + if config.ENABLE_TRANSLATION is False: + osc_message = messageFormatter("SEND", "", message) + else: + osc_message = messageFormatter("SEND", "", translation) + else: + osc_message = messageFormatter("SEND", translation, message) + model.oscSendMessage(osc_message) - # update textbox message log (Sent) - # view.printToTextbox_SentMessage(message, translation) - if config.ENABLE_LOGGER is True: - if len(translation) > 0: - translation = f" ({translation})" - model.logger.info(f"[SENT] {message}{translation}") + # if config.ENABLE_OVERLAY_SMALL_LOG is True: + # overlay_image = model.createOverlayImageShort(message, translation) + # model.updateOverlay(overlay_image) + # overlay_image = model.createOverlayImageLong("send", message, translation) + # model.updateOverlay(overlay_image) - # delete message in entry message box - if config.ENABLE_AUTO_CLEAR_MESSAGE_BOX is True: - # view.clearMessageBox() - pass + # update textbox message log (Sent) + if config.ENABLE_LOGGER is True: + if len(translation) > 0: + translation = f" ({translation})" + model.logger.info(f"[SENT] {message}{translation}") -def messageBoxPressKeyEnter(): - # model.oscStopSendTyping() - # message = view.getTextFromMessageBox() - # sendChatMessage(message) - pass + return {"status":200, + "result":{ + "message":message, + "translation":translation, + "clear":config.ENABLE_AUTO_CLEAR_MESSAGE_BOX + }, + } + +def callbackMessageBoxPressKeyEnter(data, action, *args, **kwargs) -> dict: + chat = ChatMessage(action) + response = chat.send(data) + return response def messageBoxPressKeyAny(e): if config.ENABLE_SEND_MESSAGE_TO_VRC is True: @@ -304,24 +375,24 @@ def addSentMessageLog(sent_message): config.SENT_MESSAGES_LOG.append(sent_message) config.CURRENT_SENT_MESSAGES_LOG_INDEX = len(config.SENT_MESSAGES_LOG) -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 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 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 messageBoxDownKeyPress(): +# if config.CURRENT_SENT_MESSAGES_LOG_INDEX < len(config.SENT_MESSAGES_LOG) - 1: +# updateMessageBox(1) def updateTranslationEngineAndEngineList(): engine = config.CHOICE_INPUT_TRANSLATOR @@ -365,8 +436,8 @@ def setYourLanguageAndCountry(select:dict, *args, **kwargs) -> dict: config.SOURCE_LANGUAGE = select["language"] config.SOURCE_COUNTRY = select["country"] updateTranslationEngineAndEngineList() - return {"status":"success", - "data":{ + return {"status":200, + "result":{ "your":{ "language":config.SOURCE_LANGUAGE, "country":config.SOURCE_COUNTRY @@ -382,8 +453,8 @@ def setTargetLanguageAndCountry(select:dict, *args, **kwargs) -> dict: config.TARGET_LANGUAGE = select["language"] config.TARGET_COUNTRY = select["country"] updateTranslationEngineAndEngineList() - return {"status":"success", - "data":{ + return {"status":200, + "result":{ "target":{ "language":config.TARGET_LANGUAGE, "country":config.TARGET_COUNTRY @@ -397,8 +468,8 @@ def swapYourLanguageAndTargetLanguage(*args, **kwargs) -> dict: target_language = config.SELECTED_TAB_TARGET_LANGUAGES[config.SELECTED_TAB_NO] setYourLanguageAndCountry(target_language) setTargetLanguageAndCountry(your_language) - return {"status":"success", - "data":{ + return {"status":200, + "result":{ "your":{"language":config.SOURCE_LANGUAGE, "country":config.SOURCE_COUNTRY, }, @@ -431,13 +502,13 @@ def callbackSelectedLanguagePresetTab(selected_tab_no:str, *args, **kwargs) -> d config.TARGET_LANGUAGE = select["language"] config.TARGET_COUNTRY = select["country"] updateTranslationEngineAndEngineList() - return {"status":"success", "data":config.SELECTED_TAB_NO} + return {"status":200, "result":config.SELECTED_TAB_NO} def callbackSelectedTranslationEngine(selected_translation_engine:str, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSelectedTranslationEngine", "data":selected_translation_engine}), flush=True) setYourTranslateEngine(selected_translation_engine) setTargetTranslateEngine(selected_translation_engine) - return {"status":"success", "data":selected_translation_engine} + return {"status":200, "result":selected_translation_engine} # command func def callbackEnableTranslation(*args, **kwargs) -> dict: @@ -445,24 +516,24 @@ def callbackEnableTranslation(*args, **kwargs) -> dict: config.ENABLE_TRANSLATION = True if model.isLoadedCTranslate2Model() is False: model.changeTranslatorCTranslate2Model() - return {"status":"success", "data":config.ENABLE_TRANSLATION} + return {"status":200, "result":config.ENABLE_TRANSLATION} def callbackDisableTranslation(*args, **kwargs) -> dict: print(json.dumps({"log": "callbackDisableTranslation"}), flush=True) config.ENABLE_TRANSLATION = False - return {"status":"success", "data":config.ENABLE_TRANSLATION} + return {"status":200, "result":config.ENABLE_TRANSLATION} def callbackEnableTranscriptionSend(data, action, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackEnableTranscriptionSend"}), flush=True) config.ENABLE_TRANSCRIPTION_SEND = True startThreadingTranscriptionSendMessage(action) - return {"status":"success", "data":config.ENABLE_TRANSCRIPTION_SEND} + return {"status":200, "result":config.ENABLE_TRANSCRIPTION_SEND} def callbackDisableTranscriptionSend(data, action, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackDisableTranscriptionSend"}), flush=True) config.ENABLE_TRANSCRIPTION_SEND = False stopThreadingTranscriptionSendMessage(action) - return {"status":"success", "data":config.ENABLE_TRANSCRIPTION_SEND} + return {"status":200, "result":config.ENABLE_TRANSCRIPTION_SEND} def callbackEnableTranscriptionReceive(data, action, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackEnableTranscriptionReceive"}), flush=True) @@ -472,33 +543,33 @@ def callbackEnableTranscriptionReceive(data, action, *args, **kwargs) -> dict: if config.ENABLE_OVERLAY_SMALL_LOG is True: if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True: model.startOverlay() - return {"status":"success", "data":config.ENABLE_TRANSCRIPTION_RECEIVE} + return {"status":200, "result":config.ENABLE_TRANSCRIPTION_RECEIVE} def callbackDisableTranscriptionReceive(data, action, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackDisableTranscriptionReceive"}), flush=True) config.ENABLE_TRANSCRIPTION_RECEIVE = False stopThreadingTranscriptionReceiveMessage(action) - return {"status":"success", "data":config.ENABLE_TRANSCRIPTION_RECEIVE} + return {"status":200, "result":config.ENABLE_TRANSCRIPTION_RECEIVE} def callbackEnableForeground(*args, **kwargs) -> dict: print(json.dumps({"log": "callbackEnableForeground"}), flush=True) config.ENABLE_FOREGROUND = True - return {"status":"success", "data":config.ENABLE_FOREGROUND} + return {"status":200, "result":config.ENABLE_FOREGROUND} def callbackDisableForeground(*args, **kwargs) -> dict: print(json.dumps({"log": "callbackDisableForeground"}), flush=True) config.ENABLE_FOREGROUND = False - return {"status":"success", "data":config.ENABLE_FOREGROUND} + return {"status":200, "result":config.ENABLE_FOREGROUND} def callbackEnableMainWindowSidebarCompactMode(*args, **kwargs) -> dict: print(json.dumps({"log": "callbackEnableMainWindowSidebarCompactMode"}), flush=True) config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = True - return {"status":"success", "data":config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE} + return {"status":200, "result":config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE} def callbackDisableMainWindowSidebarCompactMode(*args, **kwargs) -> dict: print(json.dumps({"log": "callbackDisableMainWindowSidebarCompactMode"}), flush=True) config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = False - return {"status":"success", "data":config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE} + return {"status":200, "result":config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE} # Config Window def callbackOpenConfigWindow(*args, **kwargs) -> dict: @@ -507,7 +578,7 @@ def callbackOpenConfigWindow(*args, **kwargs) -> dict: stopThreadingTranscriptionSendMessageOnOpenConfigWindow() if config.ENABLE_TRANSCRIPTION_RECEIVE is True: stopThreadingTranscriptionReceiveMessageOnOpenConfigWindow() - return {"status":"success"} + return {"status":200} def callbackCloseConfigWindow(data, action, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackCloseConfigWindow"}), flush=True) @@ -520,7 +591,7 @@ def callbackCloseConfigWindow(data, action, *args, **kwargs) -> dict: sleep(2) if config.ENABLE_TRANSCRIPTION_RECEIVE is True: startThreadingTranscriptionReceiveMessageOnCloseConfigWindow(action) - return {"status":"success"} + return {"status":200} # Compact Mode Switch def callbackEnableConfigWindowCompactMode(*args, **kwargs) -> dict: @@ -528,56 +599,56 @@ def callbackEnableConfigWindowCompactMode(*args, **kwargs) -> dict: config.IS_CONFIG_WINDOW_COMPACT_MODE = True model.stopCheckMicEnergy() model.stopCheckSpeakerEnergy() - return {"status":"success", "data":config.IS_CONFIG_WINDOW_COMPACT_MODE} + return {"status":200, "result":config.IS_CONFIG_WINDOW_COMPACT_MODE} def callbackDisableConfigWindowCompactMode(*args, **kwargs) -> dict: print(json.dumps({"log": "callbackDisableConfigWindowCompactMode"}), flush=True) config.IS_CONFIG_WINDOW_COMPACT_MODE = False model.stopCheckMicEnergy() model.stopCheckSpeakerEnergy() - return {"status":"success", "data":config.IS_CONFIG_WINDOW_COMPACT_MODE} + return {"status":200, "result":config.IS_CONFIG_WINDOW_COMPACT_MODE} # Appearance Tab def callbackSetTransparency(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetTransparency", "data":data}), flush=True) config.TRANSPARENCY = int(data) - return {"status":"success", "data":config.TRANSPARENCY} + return {"status":200, "result":config.TRANSPARENCY} def callbackSetAppearance(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetAppearance", "data":data}), flush=True) config.APPEARANCE_THEME = data - return {"status":"success", "data":config.APPEARANCE_THEME} + return {"status":200, "result":config.APPEARANCE_THEME} def callbackSetUiScaling(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetUiScaling", "data":data}), flush=True) config.UI_SCALING = data - return {"status":"success", "data":config.UI_SCALING} + return {"status":200, "result":config.UI_SCALING} def callbackSetTextboxUiScaling(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetTextboxUiScaling", "data":data}), flush=True) config.TEXTBOX_UI_SCALING = int(data) - return {"status":"success", "data":config.TEXTBOX_UI_SCALING} + return {"status":200, "result":config.TEXTBOX_UI_SCALING} def callbackSetMessageBoxRatio(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetMessageBoxRatio", "data":data}), flush=True) config.MESSAGE_BOX_RATIO = int(data) - return {"status":"success", "data":config.MESSAGE_BOX_RATIO} + return {"status":200, "result":config.MESSAGE_BOX_RATIO} def callbackSetFontFamily(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetFontFamily", "data":data}), flush=True) config.FONT_FAMILY = data - return {"status":"success", "data":config.FONT_FAMILY} + return {"status":200, "result":config.FONT_FAMILY} def callbackSetUiLanguage(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetUiLanguage", "data":data}), flush=True) data = getKeyByValue(config.SELECTABLE_UI_LANGUAGES_DICT, data) config.UI_LANGUAGE = data - return {"status":"success", "data":config.UI_LANGUAGE} + return {"status":200, "result":config.UI_LANGUAGE} def callbackSetEnableRestoreMainWindowGeometry(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetEnableRestoreMainWindowGeometry", "data":data}), flush=True) config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY = data - return {"status":"success", "data":config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY} + return {"status":200, "result":config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY} # Translation Tab def callbackSetUseTranslationFeature(data, *args, **kwargs) -> dict: @@ -595,8 +666,8 @@ def callbackSetUseTranslationFeature(data, *args, **kwargs) -> dict: config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = True else: config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False - return {"status":"success", - "data":{ + return {"status":200, + "result":{ "feature":config.USE_TRANSLATION_FEATURE, "reset":config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION, }, @@ -614,8 +685,8 @@ def callbackSetCtranslate2WeightType(data, *args, **kwargs) -> dict: th_callback.start() else: config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = True - return {"status":"success", - "data":{ + return {"status":200, + "result":{ "feature":config.CTRANSLATE2_WEIGHT_TYPE, "reset":config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION, }, @@ -623,19 +694,19 @@ def callbackSetCtranslate2WeightType(data, *args, **kwargs) -> dict: def callbackSetDeeplAuthKey(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetDeeplAuthKey", "data":data}), flush=True) - status = "error" + status = 404 if len(data) == 36 or len(data) == 39: result = model.authenticationTranslatorDeepLAuthKey(auth_key=data) if result is True: key = data - status = "success" + status = 200 else: key = None auth_keys = config.AUTH_KEYS auth_keys["DeepL_API"] = key config.AUTH_KEYS = auth_keys updateTranslationEngineAndEngineList() - return {"status":status, "data":config.AUTH_KEYS["DeepL_API"]} + return {"status":status, "result":config.AUTH_KEYS["DeepL_API"]} def callbackClearDeeplAuthKey(*args, **kwargs) -> dict: print(json.dumps({"log": "callbackClearDeeplAuthKey"}), flush=True) @@ -643,7 +714,7 @@ def callbackClearDeeplAuthKey(*args, **kwargs) -> dict: auth_keys["DeepL_API"] = None config.AUTH_KEYS = auth_keys updateTranslationEngineAndEngineList() - return {"status":"success", "data":config.AUTH_KEYS["DeepL_API"]} + return {"status":200, "result":config.AUTH_KEYS["DeepL_API"]} # Transcription Tab # Transcription (Mic) @@ -652,8 +723,8 @@ def callbackSetMicHost(data, *args, **kwargs) -> dict: config.CHOICE_MIC_HOST = data config.CHOICE_MIC_DEVICE = model.getInputDefaultDevice() model.stopCheckMicEnergy() - return {"status":"success", - "data":{ + return {"status":200, + "result":{ "host":config.CHOICE_MIC_HOST, "device":config.CHOICE_MIC_DEVICE, }, @@ -663,43 +734,43 @@ def callbackSetMicDevice(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetMicDevice", "data":data}), flush=True) config.CHOICE_MIC_DEVICE = data model.stopCheckMicEnergy() - return {"status":"success", - "data":{ + return {"status":200, + "result":{ "host":config.CHOICE_MIC_HOST, }, } def callbackSetMicEnergyThreshold(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetMicEnergyThreshold", "data":data}), flush=True) - status = "error" + status = 404 data = int(data) if 0 <= data <= config.MAX_MIC_ENERGY_THRESHOLD: config.INPUT_MIC_ENERGY_THRESHOLD = data - status = "success" - return {"status": status, "data": config.INPUT_MIC_ENERGY_THRESHOLD} + status = 200 + return {"status": status, "result": config.INPUT_MIC_ENERGY_THRESHOLD} def callbackSetMicDynamicEnergyThreshold(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetMicDynamicEnergyThreshold", "data":data}), flush=True) config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = data - return {"status":"success", "data":config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD} + return {"status":200, "result":config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD} class ProgressBarEnergy: def __init__(self, action): self.action = action def set(self, energy) -> None: - self.action("energy", {"status":"success", "energy":energy}) + self.action("energy", {"status":200, "result":energy}) def callbackEnableCheckMicThreshold(data, action, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackEnableCheckMicThreshold"}), flush=True) progressbar_mic_energy = ProgressBarEnergy(action) model.startCheckMicEnergy(progressbar_mic_energy.set) - return {"status":"success"} + return {"status":200} def callbackDisableCheckMicThreshold(*args, **kwargs) -> dict: print(json.dumps({"log": "callbackDisableCheckMicThreshold"}), flush=True) model.stopCheckMicEnergy() - return {"status":"success"} + return {"status":200} def callbackSetMicRecordTimeout(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetMicRecordTimeout", "data":data}), flush=True) @@ -710,9 +781,9 @@ def callbackSetMicRecordTimeout(data, *args, **kwargs) -> dict: else: raise ValueError() except Exception: - response = {"status":"error", "message":"Error Mic Record Timeout"} + response = {"status":404, "result":{"message":"Error Mic Record Timeout"}} else: - response = {"status":"success", "data":config.INPUT_MIC_RECORD_TIMEOUT} + response = {"status":200, "result":config.INPUT_MIC_RECORD_TIMEOUT} return response def callbackSetMicPhraseTimeout(data, *args, **kwargs) -> dict: @@ -724,9 +795,9 @@ def callbackSetMicPhraseTimeout(data, *args, **kwargs) -> dict: else: raise ValueError() except Exception: - response = {"status":"error", "message":"Error Mic Phrase Timeout"} + response = {"status":404, "result":{"message":"Error Mic Phrase Timeout"}} else: - response = {"status":"success", "data":config.INPUT_MIC_PHRASE_TIMEOUT} + response = {"status":200, "result":config.INPUT_MIC_PHRASE_TIMEOUT} return response def callbackSetMicMaxPhrases(data, *args, **kwargs) -> dict: @@ -738,9 +809,9 @@ def callbackSetMicMaxPhrases(data, *args, **kwargs) -> dict: else: raise ValueError() except Exception: - response = {"status":"error", "message":"Error Mic Max Phrases"} + response = {"status":404, "result":{"message":"Error Mic Max Phrases"}} else: - response = {"status":"success", "data":config.INPUT_MIC_MAX_PHRASES} + response = {"status":200, "result":config.INPUT_MIC_MAX_PHRASES} return response def callbackSetMicWordFilter(data, *args, **kwargs) -> dict: @@ -761,7 +832,7 @@ def callbackSetMicWordFilter(data, *args, **kwargs) -> dict: model.resetKeywordProcessor() model.addKeywords() - return {"status":"success", "data":config.INPUT_MIC_WORD_FILTER} + return {"status":200, "result":config.INPUT_MIC_WORD_FILTER} def callbackDeleteMicWordFilter(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackDeleteMicWordFilter", "data":data}), flush=True) @@ -773,14 +844,14 @@ def callbackDeleteMicWordFilter(data, *args, **kwargs) -> dict: model.addKeywords() except Exception: print("There was no the target word in config.INPUT_MIC_WORD_FILTER") - return {"status":"success", "data":config.INPUT_MIC_WORD_FILTER} + return {"status":200, "result":config.INPUT_MIC_WORD_FILTER} # Transcription (Speaker) def callbackSetSpeakerDevice(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetSpeakerDevice", "data":data}), flush=True) config.CHOICE_SPEAKER_DEVICE = data model.stopCheckSpeakerEnergy() - return {"status":"success", "data":config.CHOICE_SPEAKER_DEVICE} + return {"status":200, "result":config.CHOICE_SPEAKER_DEVICE} def callbackSetSpeakerEnergyThreshold(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetSpeakerEnergyThreshold", "data":data}), flush=True) @@ -793,26 +864,26 @@ def callbackSetSpeakerEnergyThreshold(data, *args, **kwargs) -> dict: else: raise ValueError() except Exception: - response = {"status":"error", "message":"Error Set Speaker Energy Threshold"} + response = {"status":404, "result":{"message":"Error Set Speaker Energy Threshold"}} else: - response = {"status":"success", "data":config.INPUT_SPEAKER_ENERGY_THRESHOLD} + response = {"status":200, "result":config.INPUT_SPEAKER_ENERGY_THRESHOLD} return response def callbackSetSpeakerDynamicEnergyThreshold(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetSpeakerDynamicEnergyThreshold", "data":data}), flush=True) config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = data - return {"status":"success", "data":config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD} + return {"status":200, "result":config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD} def callbackEnableCheckSpeakerThreshold(data, action, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackEnableCheckSpeakerThreshold"}), flush=True) progressbar_speaker_energy = ProgressBarEnergy(action) model.startCheckSpeakerEnergy(progressbar_speaker_energy.set) - return {"status":"success"} + return {"status":200} def callbackDisableCheckSpeakerThreshold(*args, **kwargs) -> dict: print(json.dumps({"log": "callbackDisableCheckSpeakerThreshold"}), flush=True) model.stopCheckSpeakerEnergy() - return {"status":"success"} + return {"status":200} def callbackSetSpeakerRecordTimeout(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetSpeakerRecordTimeout", "data":data}), flush=True) @@ -823,9 +894,9 @@ def callbackSetSpeakerRecordTimeout(data, *args, **kwargs) -> dict: else: raise ValueError() except Exception: - response = {"status":"error", "message":"Error Speaker Record Timeout"} + response = {"status":404, "result":{"message":"Error Speaker Record Timeout"}} else: - response = {"status":"success", "data":config.INPUT_SPEAKER_RECORD_TIMEOUT} + response = {"status":200, "result":config.INPUT_SPEAKER_RECORD_TIMEOUT} return response def callbackSetSpeakerPhraseTimeout(data, *args, **kwargs) -> dict: @@ -837,9 +908,9 @@ def callbackSetSpeakerPhraseTimeout(data, *args, **kwargs) -> dict: else: raise ValueError() except Exception: - response = {"status":"error", "message":"Error Speaker Phrase Timeout"} + response = {"status":404, "result":{"message":"Error Speaker Phrase Timeout"}} else: - response = {"status":"success", "data":config.INPUT_SPEAKER_PHRASE_TIMEOUT} + response = {"status":200, "result":config.INPUT_SPEAKER_PHRASE_TIMEOUT} return response def callbackSetSpeakerMaxPhrases(data, *args, **kwargs) -> dict: @@ -851,9 +922,9 @@ def callbackSetSpeakerMaxPhrases(data, *args, **kwargs) -> dict: else: raise ValueError() except Exception: - response = {"status":"error", "message":"Error Speaker Max Phrases"} + response = {"status":404, "result":{"message":"Error Speaker Max Phrases"}} else: - response = {"status":"success", "data":config.INPUT_SPEAKER_MAX_PHRASES} + response = {"status":200, "result":config.INPUT_SPEAKER_MAX_PHRASES} return response # Transcription (Internal AI Model) @@ -870,8 +941,8 @@ def callbackSetUserWhisperFeature(data, *args, **kwargs) -> dict: else: config.IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER = False config.SELECTED_TRANSCRIPTION_ENGINE = "Google" - return {"status":"success", - "data":{ + return {"status":200, + "result":{ "feature":config.USE_WHISPER_FEATURE, "transcription_engine":config.SELECTED_TRANSCRIPTION_ENGINE, "reset":config.IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER, @@ -887,8 +958,8 @@ def callbackSetWhisperWeightType(data, *args, **kwargs) -> dict: else: config.IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER = True config.SELECTED_TRANSCRIPTION_ENGINE = "Google" - return {"status":"success", - "data":{ + return {"status":200, + "result":{ "weight_type":config.WHISPER_WEIGHT_TYPE, "transcription_engine":config.SELECTED_TRANSCRIPTION_ENGINE, "reset":config.IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER, @@ -902,7 +973,7 @@ def callbackSetOverlaySettingsOpacity(data, *args, **kwargs) -> dict: pre_settings["opacity"] = data config.OVERLAY_SETTINGS = pre_settings model.updateOverlayImageOpacity() - return {"status":"success", "data":config.OVERLAY_SETTINGS["opacity"]} + return {"status":200, "result":config.OVERLAY_SETTINGS["opacity"]} def callbackSetOverlaySettingsUiScaling(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetOverlaySettingsUiScaling", "data":data}), flush=True) @@ -910,7 +981,7 @@ def callbackSetOverlaySettingsUiScaling(data, *args, **kwargs) -> dict: pre_settings["ui_scaling"] = data config.OVERLAY_SETTINGS = pre_settings model.updateOverlayImageUiScaling() - return {"status":"success", "data":config.OVERLAY_SETTINGS["ui_scaling"]} + return {"status":200, "result":config.OVERLAY_SETTINGS["ui_scaling"]} def callbackEnableOverlaySmallLog(*args, **kwargs) -> dict: print(json.dumps({"log": "callbackEnableOverlaySmallLog"}), flush=True) @@ -919,7 +990,7 @@ def callbackEnableOverlaySmallLog(*args, **kwargs) -> dict: if config.ENABLE_OVERLAY_SMALL_LOG is True and config.ENABLE_TRANSCRIPTION_RECEIVE is True: if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True: model.startOverlay() - return {"status":"success", "data":config.ENABLE_OVERLAY_SMALL_LOG} + return {"status":200, "result":config.ENABLE_OVERLAY_SMALL_LOG} def callbackDisableOverlaySmallLog(*args, **kwargs) -> dict: print(json.dumps({"log": "callbackDisableOverlaySmallLog"}), flush=True) @@ -927,7 +998,7 @@ def callbackDisableOverlaySmallLog(*args, **kwargs) -> dict: if config.ENABLE_OVERLAY_SMALL_LOG is False: model.clearOverlayImage() model.shutdownOverlay() - return {"status":"success", "data":config.ENABLE_OVERLAY_SMALL_LOG} + return {"status":200, "result":config.ENABLE_OVERLAY_SMALL_LOG} def callbackSetOverlaySmallLogSettingsXPos(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetOverlaySmallLogSettingsXPos", "data":data}), flush=True) @@ -935,7 +1006,7 @@ def callbackSetOverlaySmallLogSettingsXPos(data, *args, **kwargs) -> dict: pre_settings["x_pos"] = data config.OVERLAY_SMALL_LOG_SETTINGS = pre_settings model.updateOverlayPosition() - return {"status":"success", "data":config.OVERLAY_SMALL_LOG_SETTINGS["x_pos"]} + return {"status":200, "result":config.OVERLAY_SMALL_LOG_SETTINGS["x_pos"]} def callbackSetOverlaySmallLogSettingsYPos(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetOverlaySmallLogSettingsYPos", "data":data}), flush=True) @@ -943,7 +1014,7 @@ def callbackSetOverlaySmallLogSettingsYPos(data, *args, **kwargs) -> dict: pre_settings["y_pos"] = data config.OVERLAY_SMALL_LOG_SETTINGS = pre_settings model.updateOverlayPosition() - return {"status":"success", "data":config.OVERLAY_SMALL_LOG_SETTINGS["y_pos"]} + return {"status":200, "result":config.OVERLAY_SMALL_LOG_SETTINGS["y_pos"]} def callbackSetOverlaySmallLogSettingsZPos(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetOverlaySmallLogSettingsZPos", "data":data}), flush=True) @@ -951,7 +1022,7 @@ def callbackSetOverlaySmallLogSettingsZPos(data, *args, **kwargs) -> dict: pre_settings["z_pos"] = data config.OVERLAY_SMALL_LOG_SETTINGS = pre_settings model.updateOverlayPosition() - return {"status":"success", "data":config.OVERLAY_SMALL_LOG_SETTINGS["z_pos"]} + return {"status":200, "result":config.OVERLAY_SMALL_LOG_SETTINGS["z_pos"]} def callbackSetOverlaySmallLogSettingsXRotation(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetOverlaySmallLogSettingsXRotation", "data":data}), flush=True) @@ -959,7 +1030,7 @@ def callbackSetOverlaySmallLogSettingsXRotation(data, *args, **kwargs) -> dict: pre_settings["x_rotation"] = data config.OVERLAY_SMALL_LOG_SETTINGS = pre_settings model.updateOverlayPosition() - return {"status":"success", "data":config.OVERLAY_SMALL_LOG_SETTINGS["x_rotation"]} + return {"status":200, "result":config.OVERLAY_SMALL_LOG_SETTINGS["x_rotation"]} def callbackSetOverlaySmallLogSettingsYRotation(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetOverlaySmallLogSettingsYRotation", "data":data}), flush=True) @@ -967,7 +1038,7 @@ def callbackSetOverlaySmallLogSettingsYRotation(data, *args, **kwargs) -> dict: pre_settings["y_rotation"] = data config.OVERLAY_SMALL_LOG_SETTINGS = pre_settings model.updateOverlayPosition() - return {"status":"success", "data":config.OVERLAY_SMALL_LOG_SETTINGS["y_rotation"]} + return {"status":200, "result":config.OVERLAY_SMALL_LOG_SETTINGS["y_rotation"]} def callbackSetOverlaySmallLogSettingsZRotation(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetOverlaySmallLogSettingsZRotation", "data":data}), flush=True) @@ -975,33 +1046,33 @@ def callbackSetOverlaySmallLogSettingsZRotation(data, *args, **kwargs) -> dict: pre_settings["z_rotation"] = data config.OVERLAY_SMALL_LOG_SETTINGS = pre_settings model.updateOverlayPosition() - return {"status":"success", "data":config.OVERLAY_SMALL_LOG_SETTINGS["z_rotation"]} + return {"status":200, "result":config.OVERLAY_SMALL_LOG_SETTINGS["z_rotation"]} # Others Tab def callbackSetEnableAutoClearMessageBox(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetEnableAutoClearMessageBox", "data":data}), flush=True) config.ENABLE_AUTO_CLEAR_MESSAGE_BOX = data - return {"status":"success", "data":config.ENABLE_AUTO_CLEAR_MESSAGE_BOX} + return {"status":200, "result":config.ENABLE_AUTO_CLEAR_MESSAGE_BOX} def callbackSetEnableSendOnlyTranslatedMessages(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetEnableSendOnlyTranslatedMessages", "data":data}), flush=True) config.ENABLE_SEND_ONLY_TRANSLATED_MESSAGES = data - return {"status":"success", "data":config.ENABLE_SEND_ONLY_TRANSLATED_MESSAGES} + return {"status":200, "result":config.ENABLE_SEND_ONLY_TRANSLATED_MESSAGES} def callbackSetSendMessageButtonType(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetSendMessageButtonType", "data":data}), flush=True) config.SEND_MESSAGE_BUTTON_TYPE = data - return {"status":"success", "data":config.SEND_MESSAGE_BUTTON_TYPE} + return {"status":200, "result":config.SEND_MESSAGE_BUTTON_TYPE} def callbackEnableNoticeXsoverlay(*args, **kwargs) -> dict: print(json.dumps({"log": "callbackEnableNoticeXsoverlay"}), flush=True) config.ENABLE_NOTICE_XSOVERLAY = True - return {"status":"success", "data":config.ENABLE_NOTICE_XSOVERLAY} + return {"status":200, "result":config.ENABLE_NOTICE_XSOVERLAY} def callbackDisableNoticeXsoverlay(*args, **kwargs) -> dict: print(json.dumps({"log": "callbackDisableNoticeXsoverlay"}), flush=True) config.ENABLE_NOTICE_XSOVERLAY = False - return {"status":"success", "data":config.ENABLE_NOTICE_XSOVERLAY} + return {"status":200, "result":config.ENABLE_NOTICE_XSOVERLAY} def callbackEnableAutoExportMessageLogs(*args, **kwargs) -> dict: print(json.dumps({"log": "callbackEnableAutoExportMessageLogs"}), flush=True) @@ -1028,63 +1099,63 @@ def callbackDisableVrcMicMuteSync(*args, **kwargs) -> dict: def callbackEnableSendMessageToVrc(*args, **kwargs) -> dict: print(json.dumps({"log": "callbackEnableSendMessageToVrc"}), flush=True) config.ENABLE_SEND_MESSAGE_TO_VRC = True - return {"status":"success", "data":config.ENABLE_SEND_MESSAGE_TO_VRC} + return {"status":200, "result":config.ENABLE_SEND_MESSAGE_TO_VRC} def callbackDisableSendMessageToVrc(*args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetEnableSendMessageToVrc"}), flush=True) config.ENABLE_SEND_MESSAGE_TO_VRC = False - return {"status":"success", "data":config.ENABLE_SEND_MESSAGE_TO_VRC} + return {"status":200, "result":config.ENABLE_SEND_MESSAGE_TO_VRC} # Others (Message Formats(Send) def callbackSetSendMessageFormat(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetSendMessageFormat", "data": str(data)}), flush=True) if isUniqueStrings(["[message]"], data) is True: config.SEND_MESSAGE_FORMAT = data - return {"status":"success", "data":config.SEND_MESSAGE_FORMAT} + return {"status":200, "result":config.SEND_MESSAGE_FORMAT} def callbackSetSendMessageFormatWithT(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetReceivedMessageFormat", "data": str(data)}), flush=True) if len(data) > 0: if isUniqueStrings(["[message]", "[translation]"], data) is True: config.SEND_MESSAGE_FORMAT_WITH_T = data - return {"status":"success", "data":config.SEND_MESSAGE_FORMAT_WITH_T} + return {"status":200, "result":config.SEND_MESSAGE_FORMAT_WITH_T} # Others (Message Formats(Received) def callbackSetReceivedMessageFormat(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetReceivedMessageFormat", "data": str(data)}), flush=True) if isUniqueStrings(["[message]"], data) is True: config.RECEIVED_MESSAGE_FORMAT = data - return {"status":"success", "data":config.RECEIVED_MESSAGE_FORMAT} + return {"status":200, "result":config.RECEIVED_MESSAGE_FORMAT} def callbackSetReceivedMessageFormatWithT(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetReceivedMessageFormatWithT", "data": str(data)}), flush=True) if len(data) > 0: if isUniqueStrings(["[message]", "[translation]"], data) is True: config.RECEIVED_MESSAGE_FORMAT_WITH_T = data - return {"status":"success", "data":config.RECEIVED_MESSAGE_FORMAT_WITH_T} + return {"status":200, "result":config.RECEIVED_MESSAGE_FORMAT_WITH_T} # ---------------------Speaker2Chatbox--------------------- def callbackEnableSendReceivedMessageToVrc(*args, **kwargs) -> dict: print(json.dumps({"log": "callbackEnableSendReceivedMessageToVrc"}), flush=True) config.ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC = True - return {"status":"success", "data":config.ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC} + return {"status":200, "result":config.ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC} def callbackDisableSendReceivedMessageToVrc(*args, **kwargs) -> dict: print(json.dumps({"log": "callbackDisableSendReceivedMessageToVrc"}), flush=True) config.ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC = False - return {"status":"success", "data":config.ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC} + return {"status":200, "result":config.ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC} # ---------------------Speaker2Chatbox--------------------- # Advanced Settings Tab def callbackSetOscIpAddress(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetOscIpAddress", "data": str(data)}), flush=True) config.OSC_IP_ADDRESS = str(data) - return {"status":"success", "data":config.OSC_IP_ADDRESS} + return {"status":200, "result":config.OSC_IP_ADDRESS} def callbackSetOscPort(data, *args, **kwargs) -> dict: print(json.dumps({"log": "callbackSetOscPort", "data": int(data)}), flush=True) config.OSC_PORT = int(data) - return {"status":"success", "data":config.OSC_PORT} + return {"status":200, "result":config.OSC_PORT} def getListLanguageAndCountry(): return model.getListLanguageAndCountry() diff --git a/src-python/webui_mainloop.py b/src-python/webui_mainloop.py index e3000c72..b719607f 100644 --- a/src-python/webui_mainloop.py +++ b/src-python/webui_mainloop.py @@ -97,10 +97,11 @@ controller_mapping = { "/controller/list_mic_host": controller.getListInputHost, "/controller/list_mic_device": controller.getListInputDevice, "/controller/list_speaker_device": controller.getListOutputDevice, - # "/controller/callback_update_software": controller.callbackUpdateSoftware, - # "/controller/callback_restart_software": controller.callbackRestartSoftware, + "/controller/callback_update_software": controller.callbackUpdateSoftware, + "/controller/callback_restart_software": controller.callbackRestartSoftware, "/controller/callback_filepath_logs": controller.callbackFilepathLogs, "/controller/callback_filepath_config_file": controller.callbackFilepathConfigFile, + # "/controller/callback_enable_easter_egg": controller.callbackEnableEasterEgg, "/controller/callback_open_config_window": controller.callbackOpenConfigWindow, "/controller/callback_close_config_window": controller.callbackCloseConfigWindow, "/controller/callback_enable_main_window_sidebar_compact_mode": controller.callbackEnableMainWindowSidebarCompactMode, @@ -111,6 +112,7 @@ controller_mapping = { "/controller/callback_disable_transcription_send": controller.callbackDisableTranscriptionSend, "/controller/callback_enable_transcription_receive": controller.callbackEnableTranscriptionReceive, "/controller/callback_disable_transcription_receive": controller.callbackDisableTranscriptionReceive, + "/controller/callback_messagebox_press_key_enter": controller.callbackMessageBoxPressKeyEnter, "/controller/callback_enable_foreground": controller.callbackEnableForeground, "/controller/callback_disable_foreground": controller.callbackDisableForeground, "/controller/set_your_language_and_country": controller.setYourLanguageAndCountry, @@ -185,12 +187,40 @@ controller_mapping = { } action_mapping = { - "/controller/callback_close_config_window": {"mic":"/action/transcription_send_message", "speaker":"/action/transcription_receive_message"}, - "/controller/callback_enable_transcription_send": {"mic":"/action/transcription_send_message"}, - "/controller/callback_disable_transcription_send": {"mic":"/action/transcription_send_stopped"}, - "/controller/callback_enable_transcription_receive": {"speaker":"/action/transcription_receive_message"}, - "/controller/callback_disable_transcription_receive": {"speaker":"/action/transcription_receive_stopped"}, - "/controller/callback_enable_check_mic_threshold": {"mic":"/action/check_mic_threshold_energy"}, + "/controller/callback_update_software": { + "download":"/action/download_software", + "update":"/action/update_software" + }, + "/controller/callback_close_config_window": { + "mic":"/action/transcription_send_mic_message", + "speaker":"/action/transcription_receive_speaker_message", + "error_device":"/action/error_device", + "error_translation_engine":"/action/error_translation_engine", + "word_filter":"/action/word_filter", + }, + "/controller/callback_enable_transcription_send": { + "mic":"/action/transcription_send_mic_message", + "error_device":"/action/error_device", + "error_translation_engine":"/action/error_translation_engine", + "word_filter":"/action/word_filter", + }, + "/controller/callback_disable_transcription_send": { + "mic":"/action/transcription_send_mic_message_stopped" + }, + "/controller/callback_enable_transcription_receive": { + "speaker":"/action/transcription_receive_speaker_message", + "error_device":"/action/error_device", + "error_translation_engine":"/action/error_translation_engine", + }, + "/controller/callback_disable_transcription_receive": { + "speaker":"/action/transcription_receive_speaker_message_stopped" + }, + "/controller/callback_enable_check_mic_threshold": { + "mic":"/action/check_mic_threshold_energy" + }, + "/controller/callback_messagebox_press_key_enter": { + "error_translation_engine":"/action/error_translation_engine" + }, } def handleConfigRequest(endpoint): @@ -214,18 +244,21 @@ def handleControllerRequest(endpoint, data=None): response = handler(data, Action(action_endpoint).transmit) else: response = handler(data) - status = 200 - return response, status + status = response.get("status", None) + result = response.get("result", None) + return result, status class Action: def __init__(self, endpoints:dict) -> None: self.endpoints = endpoints def transmit(self, key:str, data:dict) -> None: + status = data.get("status", None) + result = data.get("result", None) response = { "endpoint": self.endpoints[key], - "status": 200, - "data": data, + "status": status, + "result": result, } response = json.dumps(response) print(response, flush=True) @@ -291,7 +324,7 @@ if __name__ == "__main__": try: controller.init() - print(json.dumps({"init_key_from_py": "Initialization from Python."}), flush=True) + print(json.dumps({"log": "Initialization from Python."}), flush=True) while True: main() except Exception: