🚧[WIP/TEST] Main: webuiのためのmain実装途中#2

This commit is contained in:
misyaguziya
2024-07-17 01:10:02 +09:00
parent da5a71c93b
commit d80260c113
2 changed files with 108 additions and 107 deletions

View File

@@ -17,12 +17,14 @@ def callbackRestartSoftware():
model.reStartSoftware() model.reStartSoftware()
def callbackFilepathLogs(): def callbackFilepathLogs():
print("callbackFilepathLogs", config.PATH_LOGS.replace('/', '\\')) print("[LOG]", "callbackFilepathLogs", config.PATH_LOGS.replace('/', '\\'))
Popen(['explorer', config.PATH_LOGS.replace('/', '\\')], shell=True) Popen(['explorer', config.PATH_LOGS.replace('/', '\\')], shell=True)
return "Success", 200
def callbackFilepathConfigFile(): def callbackFilepathConfigFile():
print("callbackFilepathConfigFile", config.PATH_LOCAL.replace('/', '\\')) print("[LOG]","callbackFilepathConfigFile", config.PATH_LOCAL.replace('/', '\\'))
Popen(['explorer', config.PATH_LOCAL.replace('/', '\\')], shell=True) Popen(['explorer', config.PATH_LOCAL.replace('/', '\\')], shell=True)
return "Success", 200
def callbackQuitVrct(): def callbackQuitVrct():
setMainWindowGeometry() setMainWindowGeometry()
@@ -310,8 +312,6 @@ def updateTranslationEngineAndEngineList():
engine = engines[0] engine = engines[0]
config.CHOICE_INPUT_TRANSLATOR = engine config.CHOICE_INPUT_TRANSLATOR = engine
config.CHOICE_OUTPUT_TRANSLATOR = engine config.CHOICE_OUTPUT_TRANSLATOR = engine
view.updateSelectableTranslationEngineList(engines)
view.setGuiVariable_SelectedTranslationEngine(engine)
def initSetTranslateEngine(): def initSetTranslateEngine():
engine = config.SELECTED_TAB_YOUR_TRANSLATOR_ENGINES[config.SELECTED_TAB_NO] engine = config.SELECTED_TAB_YOUR_TRANSLATOR_ENGINES[config.SELECTED_TAB_NO]
@@ -346,7 +346,7 @@ def setYourLanguageAndCountry(select):
config.SOURCE_LANGUAGE = select["language"] config.SOURCE_LANGUAGE = select["language"]
config.SOURCE_COUNTRY = select["country"] config.SOURCE_COUNTRY = select["country"]
updateTranslationEngineAndEngineList() updateTranslationEngineAndEngineList()
view.printToTextbox_selectedYourLanguages(select) return True
def setTargetLanguageAndCountry(select): def setTargetLanguageAndCountry(select):
languages = config.SELECTED_TAB_TARGET_LANGUAGES languages = config.SELECTED_TAB_TARGET_LANGUAGES
@@ -355,20 +355,17 @@ def setTargetLanguageAndCountry(select):
config.TARGET_LANGUAGE = select["language"] config.TARGET_LANGUAGE = select["language"]
config.TARGET_COUNTRY = select["country"] config.TARGET_COUNTRY = select["country"]
updateTranslationEngineAndEngineList() updateTranslationEngineAndEngineList()
view.printToTextbox_selectedTargetLanguages(select) return True
def swapYourLanguageAndTargetLanguage(): def swapYourLanguageAndTargetLanguage():
your_language = config.SELECTED_TAB_YOUR_LANGUAGES[config.SELECTED_TAB_NO] your_language = config.SELECTED_TAB_YOUR_LANGUAGES[config.SELECTED_TAB_NO]
target_language = config.SELECTED_TAB_TARGET_LANGUAGES[config.SELECTED_TAB_NO] target_language = config.SELECTED_TAB_TARGET_LANGUAGES[config.SELECTED_TAB_NO]
setYourLanguageAndCountry(target_language) setYourLanguageAndCountry(target_language)
setTargetLanguageAndCountry(your_language) setTargetLanguageAndCountry(your_language)
# Update Selected Languages for UI return True
view.updateGuiVariableByPresetTabNo(config.SELECTED_TAB_NO)
def callbackSelectedLanguagePresetTab(selected_tab_no): def callbackSelectedLanguagePresetTab(selected_tab_no):
config.SELECTED_TAB_NO = selected_tab_no config.SELECTED_TAB_NO = selected_tab_no
view.updateGuiVariableByPresetTabNo(config.SELECTED_TAB_NO)
engines = config.SELECTED_TAB_YOUR_TRANSLATOR_ENGINES engines = config.SELECTED_TAB_YOUR_TRANSLATOR_ENGINES
engine = engines[config.SELECTED_TAB_NO] engine = engines[config.SELECTED_TAB_NO]
@@ -387,83 +384,76 @@ def callbackSelectedLanguagePresetTab(selected_tab_no):
select = languages[config.SELECTED_TAB_NO] select = languages[config.SELECTED_TAB_NO]
config.TARGET_LANGUAGE = select["language"] config.TARGET_LANGUAGE = select["language"]
config.TARGET_COUNTRY = select["country"] config.TARGET_COUNTRY = select["country"]
view.printToTextbox_changedLanguagePresetTab(config.SELECTED_TAB_NO)
updateTranslationEngineAndEngineList() updateTranslationEngineAndEngineList()
return True
def callbackSelectedTranslationEngine(selected_translation_engine): def callbackSelectedTranslationEngine(selected_translation_engine):
print("callbackSelectedTranslationEngine", selected_translation_engine)
setYourTranslateEngine(selected_translation_engine) setYourTranslateEngine(selected_translation_engine)
setTargetTranslateEngine(selected_translation_engine) setTargetTranslateEngine(selected_translation_engine)
view.setGuiVariable_SelectedTranslationEngine(config.CHOICE_OUTPUT_TRANSLATOR) return True
# command func # command func
def callbackToggleTranslation(is_turned_on): def callbackEnableTranslation():
config.ENABLE_TRANSLATION = is_turned_on config.ENABLE_TRANSLATION = True
if config.ENABLE_TRANSLATION is True: if model.isLoadedCTranslate2Model() is False:
if model.isLoadedCTranslate2Model() is False: model.changeTranslatorCTranslate2Model()
model.changeTranslatorCTranslate2Model() return True
view.printToTextbox_enableTranslation()
else:
view.printToTextbox_disableTranslation()
def callbackToggleTranscriptionSend(is_turned_on): def callbackDisableTranslation():
view.setMainWindowAllWidgetsStatusToDisabled() config.ENABLE_TRANSLATION = False
config.ENABLE_TRANSCRIPTION_SEND = is_turned_on return True
if config.ENABLE_TRANSCRIPTION_SEND is True:
startThreadingTranscriptionSendMessage()
view.changeTranscriptionDisplayStatus("MIC_ON")
else:
stopThreadingTranscriptionSendMessage()
view.changeTranscriptionDisplayStatus("MIC_OFF")
def callbackToggleTranscriptionReceive(is_turned_on): def callbackEnableTranscriptionSend():
view.setMainWindowAllWidgetsStatusToDisabled() config.ENABLE_TRANSCRIPTION_SEND = True
config.ENABLE_TRANSCRIPTION_RECEIVE = is_turned_on startThreadingTranscriptionSendMessage()
if config.ENABLE_TRANSCRIPTION_RECEIVE is True: return True
startThreadingTranscriptionReceiveMessage()
view.changeTranscriptionDisplayStatus("SPEAKER_ON")
else:
stopThreadingTranscriptionReceiveMessage()
view.changeTranscriptionDisplayStatus("SPEAKER_OFF")
if config.ENABLE_TRANSCRIPTION_RECEIVE is True and config.ENABLE_OVERLAY_SMALL_LOG is True: def callbackDisableTranscriptionSend():
config.ENABLE_TRANSCRIPTION_SEND = False
stopThreadingTranscriptionSendMessage()
return True
def callbackEnableTranscriptionReceive():
config.ENABLE_TRANSCRIPTION_RECEIVE = True
startThreadingTranscriptionReceiveMessage()
if config.ENABLE_OVERLAY_SMALL_LOG is True:
if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True: if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True:
model.startOverlay() model.startOverlay()
elif config.ENABLE_TRANSCRIPTION_RECEIVE is False: return True
pass
def callbackToggleForeground(is_turned_on): def callbackDisableTranscriptionReceive():
config.ENABLE_FOREGROUND = is_turned_on config.ENABLE_TRANSCRIPTION_RECEIVE = False
if config.ENABLE_FOREGROUND is True: stopThreadingTranscriptionReceiveMessage()
view.printToTextbox_enableForeground() return True
view.foregroundOn()
else: def callbackEnableForeground():
view.printToTextbox_disableForeground() config.ENABLE_FOREGROUND = True
view.foregroundOff() return True
def callbackDisableForeground():
config.ENABLE_FOREGROUND = False
return True
def callbackEnableMainWindowSidebarCompactMode(): def callbackEnableMainWindowSidebarCompactMode():
config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = True config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = True
view.enableMainWindowSidebarCompactMode() return True
def callbackDisableMainWindowSidebarCompactMode(): def callbackDisableMainWindowSidebarCompactMode():
config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = False config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = False
view.disableMainWindowSidebarCompactMode() return True
# Config Window # Config Window
def callbackOpenConfigWindow(): def callbackOpenConfigWindow():
view.setMainWindowAllWidgetsStatusToDisabled()
if config.ENABLE_TRANSCRIPTION_SEND is True: if config.ENABLE_TRANSCRIPTION_SEND is True:
stopThreadingTranscriptionSendMessageOnOpenConfigWindow() stopThreadingTranscriptionSendMessageOnOpenConfigWindow()
if config.ENABLE_TRANSCRIPTION_RECEIVE is True: if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
stopThreadingTranscriptionReceiveMessageOnOpenConfigWindow() stopThreadingTranscriptionReceiveMessageOnOpenConfigWindow()
if config.ENABLE_FOREGROUND is True: return True
view.foregroundOff()
def callbackCloseConfigWindow(): def callbackCloseConfigWindow():
model.stopCheckMicEnergy() model.stopCheckMicEnergy()
model.stopCheckSpeakerEnergy() model.stopCheckSpeakerEnergy()
view.initMicThresholdCheckButton()
view.initSpeakerThresholdCheckButton()
if config.ENABLE_TRANSCRIPTION_SEND is True: if config.ENABLE_TRANSCRIPTION_SEND is True:
startThreadingTranscriptionSendMessageOnCloseConfigWindow() startThreadingTranscriptionSendMessageOnCloseConfigWindow()
@@ -471,79 +461,69 @@ def callbackCloseConfigWindow():
sleep(2) sleep(2)
if config.ENABLE_TRANSCRIPTION_RECEIVE is True: if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
startThreadingTranscriptionReceiveMessageOnCloseConfigWindow() startThreadingTranscriptionReceiveMessageOnCloseConfigWindow()
if config.ENABLE_FOREGROUND is True: return True
view.foregroundOn()
view.setMainWindowAllWidgetsStatusToNormal()
# Compact Mode Switch # Compact Mode Switch
def callbackEnableConfigWindowCompactMode(): def callbackEnableConfigWindowCompactMode():
config.IS_CONFIG_WINDOW_COMPACT_MODE = True config.IS_CONFIG_WINDOW_COMPACT_MODE = True
model.stopCheckMicEnergy() model.stopCheckMicEnergy()
view.initMicThresholdCheckButton()
model.stopCheckSpeakerEnergy() model.stopCheckSpeakerEnergy()
view.initSpeakerThresholdCheckButton() return True
view.enableConfigWindowCompactMode()
def callbackDisableConfigWindowCompactMode(): def callbackDisableConfigWindowCompactMode():
config.IS_CONFIG_WINDOW_COMPACT_MODE = False config.IS_CONFIG_WINDOW_COMPACT_MODE = False
model.stopCheckMicEnergy() model.stopCheckMicEnergy()
view.initMicThresholdCheckButton()
model.stopCheckSpeakerEnergy() model.stopCheckSpeakerEnergy()
view.initSpeakerThresholdCheckButton() return True
view.disableConfigWindowCompactMode()
# Appearance Tab # Appearance Tab
def callbackSetTransparency(value): def callbackSetTransparency(value):
print("callbackSetTransparency", int(value)) print("callbackSetTransparency", int(value))
config.TRANSPARENCY = int(value) config.TRANSPARENCY = int(value)
view.setMainWindowTransparency(config.TRANSPARENCY/100) return True
def callbackSetAppearance(value): def callbackSetAppearance(value):
print("callbackSetAppearance", value) print("callbackSetAppearance", value)
config.APPEARANCE_THEME = value config.APPEARANCE_THEME = value
view.showRestartButtonIfRequired() return True
def callbackSetUiScaling(value): def callbackSetUiScaling(value):
print("callbackSetUiScaling", value) print("callbackSetUiScaling", value)
config.UI_SCALING = value config.UI_SCALING = value
new_scaling_float = strPctToInt(value) / 100 return True
print("callbackSetUiScaling_new_scaling_float", new_scaling_float)
view.showRestartButtonIfRequired()
def callbackSetTextboxUiScaling(value): def callbackSetTextboxUiScaling(value):
print("callbackSetTextboxUiScaling", int(value)) print("callbackSetTextboxUiScaling", int(value))
config.TEXTBOX_UI_SCALING = int(value) config.TEXTBOX_UI_SCALING = int(value)
view.setMainWindowTextboxUiSize(config.TEXTBOX_UI_SCALING/100) return True
def callbackSetMessageBoxRatio(value): def callbackSetMessageBoxRatio(value):
print("callbackSetMessageBoxRatio", int(value)) print("callbackSetMessageBoxRatio", int(value))
config.MESSAGE_BOX_RATIO = int(value) config.MESSAGE_BOX_RATIO = int(value)
view.setMainWindowMessageBoxRatio(config.MESSAGE_BOX_RATIO) return True
def callbackSetFontFamily(value): def callbackSetFontFamily(value):
print("callbackSetFontFamily", value) print("callbackSetFontFamily", value)
config.FONT_FAMILY = value config.FONT_FAMILY = value
view.showRestartButtonIfRequired() return True
def callbackSetUiLanguage(value): def callbackSetUiLanguage(value):
print("callbackSetUiLanguage", value) print("callbackSetUiLanguage", value)
value = getKeyByValue(config.SELECTABLE_UI_LANGUAGES_DICT, value) value = getKeyByValue(config.SELECTABLE_UI_LANGUAGES_DICT, value)
print("callbackSetUiLanguage__after_getKeyByValue", value) print("callbackSetUiLanguage__after_getKeyByValue", value)
config.UI_LANGUAGE = value config.UI_LANGUAGE = value
view.showRestartButtonIfRequired(locale=config.UI_LANGUAGE) return True
def callbackSetEnableRestoreMainWindowGeometry(value): def callbackSetEnableRestoreMainWindowGeometry(value):
print("callbackSetEnableRestoreMainWindowGeometry", value) print("callbackSetEnableRestoreMainWindowGeometry", value)
config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY = value config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY = value
return True
# Translation Tab # Translation Tab
def callbackSetUseTranslationFeature(value): def callbackSetUseTranslationFeature(value):
print("callbackSetUseTranslationFeature", value) print("callbackSetUseTranslationFeature", value)
config.USE_TRANSLATION_FEATURE = value config.USE_TRANSLATION_FEATURE = value
if config.USE_TRANSLATION_FEATURE is True: if config.USE_TRANSLATION_FEATURE is True:
view.useTranslationFeatureProcess("Normal")
if model.checkCTranslatorCTranslate2ModelWeight(): if model.checkCTranslatorCTranslate2ModelWeight():
config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False
def callback(): def callback():
@@ -553,31 +533,23 @@ def callbackSetUseTranslationFeature(value):
th_callback.start() th_callback.start()
else: else:
config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = True config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = True
view.useTranslationFeatureProcess("Restart")
else: else:
config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False
view.useTranslationFeatureProcess("Disable") return True
view.showRestartButtonIfRequired()
def callbackSetCtranslate2WeightType(value): def callbackSetCtranslate2WeightType(value):
print("callbackSetCtranslate2WeightType", value) print("callbackSetCtranslate2WeightType", value)
config.CTRANSLATE2_WEIGHT_TYPE = str(value) config.CTRANSLATE2_WEIGHT_TYPE = str(value)
view.updateSelectedCtranslate2WeightType(config.CTRANSLATE2_WEIGHT_TYPE)
view.setWidgetsStatus_changeWeightType_Pending()
if model.checkCTranslatorCTranslate2ModelWeight(): if model.checkCTranslatorCTranslate2ModelWeight():
config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False
def callback(): def callback():
model.changeTranslatorCTranslate2Model() model.changeTranslatorCTranslate2Model()
view.useTranslationFeatureProcess("Normal")
view.setWidgetsStatus_changeWeightType_Done()
th_callback = Thread(target=callback) th_callback = Thread(target=callback)
th_callback.daemon = True th_callback.daemon = True
th_callback.start() th_callback.start()
else: else:
config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = True config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = True
view.useTranslationFeatureProcess("Restart") return True
view.setWidgetsStatus_changeWeightType_Done()
view.showRestartButtonIfRequired()
def callbackSetDeeplAuthKey(value): def callbackSetDeeplAuthKey(value):
print("callbackSetDeeplAuthKey", str(value)) print("callbackSetDeeplAuthKey", str(value))

View File

@@ -1,3 +1,6 @@
import warnings
warnings.simplefilter('ignore', RuntimeWarning)
import sys import sys
import json import json
import time import time
@@ -94,25 +97,33 @@ controller_mapping = {
"/controller/list_mic_host": controller.getListInputHost, "/controller/list_mic_host": controller.getListInputHost,
"/controller/list_mic_device": controller.getListInputDevice, "/controller/list_mic_device": controller.getListInputDevice,
"/controller/list_speaker_device": controller.getListOutputDevice, "/controller/list_speaker_device": controller.getListOutputDevice,
"/controller/callback_update_software": controller.callbackUpdateSoftware, # "/controller/callback_update_software": controller.callbackUpdateSoftware,
"/controller/callback_restart_software": controller.callbackRestartSoftware, # "/controller/callback_restart_software": controller.callbackRestartSoftware,
"/controller/callback_filepath_logs": controller.callbackFilepathLogs, "/controller/callback_filepath_logs": controller.callbackFilepathLogs,
"/controller/callback_filepath_config_file": controller.callbackFilepathConfigFile, "/controller/callback_filepath_config_file": controller.callbackFilepathConfigFile,
"/controller/callback_open_config_window": controller.callbackOpenConfigWindow, "/controller/callback_open_config_window": controller.callbackOpenConfigWindow,
"/controller/callback_close_config_window": controller.callbackCloseConfigWindow, "/controller/callback_close_config_window": controller.callbackCloseConfigWindow,
"/controller/callback_enable_main_window_sidebar_compact_mode": controller.callbackEnableMainWindowSidebarCompactMode, "/controller/callback_enable_main_window_sidebar_compact_mode": controller.callbackEnableMainWindowSidebarCompactMode,
"/controller/callback_disable_main_window_sidebar_compact_mode": controller.callbackDisableMainWindowSidebarCompactMode, "/controller/callback_disable_main_window_sidebar_compact_mode": controller.callbackDisableMainWindowSidebarCompactMode,
"/controller/callback_toggle_translation": controller.callbackToggleTranslation, "/controller/callback_enable_translation": controller.callbackEnableTranslation,
"/controller/callback_toggle_transcription_send": controller.callbackToggleTranscriptionSend, "/controller/callback_disable_translation": controller.callbackDisableTranslation,
"/controller/callback_toggle_transcription_receive": controller.callbackToggleTranscriptionReceive, "/controller/callback_enable_transcription_send": controller.callbackEnableTranscriptionSend,
"/controller/callback_toggle_foreground": controller.callbackToggleForeground, "/controller/callback_disable_transcription_send": controller.callbackDisableTranscriptionSend,
"/controller/callback_your_language": controller.setYourLanguageAndCountry, "/controller/callback_enable_transcription_receive": controller.callbackEnableTranscriptionReceive,
"/controller/callback_target_language": controller.setTargetLanguageAndCountry, "/controller/callback_disable_transcription_receive": controller.callbackDisableTranscriptionReceive,
"/controller/callback_swap_languages": controller.swapYourLanguageAndTargetLanguage, "/controller/callback_enable_foreground": controller.callbackEnableForeground,
"/controller/callback_disable_foreground": controller.callbackDisableForeground,
"/controller/set_your_language_and_country": controller.setYourLanguageAndCountry,
"/controller/set_target_language_and_country": controller.setTargetLanguageAndCountry,
"/controller/swap_your_language_and_target_language": controller.swapYourLanguageAndTargetLanguage,
"/controller/callback_selected_language_preset_tab": controller.callbackSelectedLanguagePresetTab, "/controller/callback_selected_language_preset_tab": controller.callbackSelectedLanguagePresetTab,
"/controller/callback_selected_translation_engine": controller.callbackSelectedTranslationEngine, "/controller/callback_selected_translation_engine": controller.callbackSelectedTranslationEngine,
"/controller/callback_disable_config_window_compact_mode": controller.callbackEnableConfigWindowCompactMode, "/controller/callback_disable_config_window_compact_mode": controller.callbackEnableConfigWindowCompactMode,
"/controller/callback_enable_config_window_compact_mode": controller.callbackDisableConfigWindowCompactMode, "/controller/callback_enable_config_window_compact_mode": controller.callbackDisableConfigWindowCompactMode,
"/controller/callback_set_transparency": controller.callbackSetTransparency, "/controller/callback_set_transparency": controller.callbackSetTransparency,
"/controller/callback_set_appearance": controller.callbackSetAppearance, "/controller/callback_set_appearance": controller.callbackSetAppearance,
"/controller/callback_set_ui_scaling": controller.callbackSetUiScaling, "/controller/callback_set_ui_scaling": controller.callbackSetUiScaling,
@@ -121,8 +132,10 @@ controller_mapping = {
"/controller/callback_set_font_family": controller.callbackSetFontFamily, "/controller/callback_set_font_family": controller.callbackSetFontFamily,
"/controller/callback_set_ui_language": controller.callbackSetUiLanguage, "/controller/callback_set_ui_language": controller.callbackSetUiLanguage,
"/controller/callback_set_enable_restore_main_window_geometry": controller.callbackSetEnableRestoreMainWindowGeometry, "/controller/callback_set_enable_restore_main_window_geometry": controller.callbackSetEnableRestoreMainWindowGeometry,
"/controller/callback_set_use_translation_feature": controller.callbackSetUseTranslationFeature, "/controller/callback_set_use_translation_feature": controller.callbackSetUseTranslationFeature,
"/controller/callback_set_ctranslate2_weight_type": controller.callbackSetCtranslate2WeightType, "/controller/callback_set_ctranslate2_weight_type": controller.callbackSetCtranslate2WeightType,
"/controller/callback_set_deepl_auth_key": controller.callbackSetDeeplAuthKey, "/controller/callback_set_deepl_auth_key": controller.callbackSetDeeplAuthKey,
"/controller/callback_set_mic_host": controller.callbackSetMicHost, "/controller/callback_set_mic_host": controller.callbackSetMicHost,
"/controller/callback_set_mic_device": controller.callbackSetMicDevice, "/controller/callback_set_mic_device": controller.callbackSetMicDevice,
@@ -185,8 +198,12 @@ def handle_controller_request(endpoint, method, data=None):
response = handler() response = handler()
status = 200 status = 200
elif method == "POST": elif method == "POST":
response = handler(data) if data is None:
status = 200 response = "Invalid data"
status = 400
else:
response = handler(data)
status = 200
return response, status return response, status
def main(): def main():
@@ -218,11 +235,23 @@ def main():
print(response, flush=True) print(response, flush=True)
if __name__ == "__main__": if __name__ == "__main__":
try: # try:
print(json.dumps({"init_key_from_py": "Initialization from Python."}), flush=True) # print(json.dumps({"init_key_from_py": "Initialization from Python."}), flush=True)
while True: # while True:
main() # main()
except Exception: # except Exception:
import traceback # import traceback
with open('error.log', 'a') as f: # with open('error.log', 'a') as f:
traceback.print_exc(file=f) # traceback.print_exc(file=f)
method = "GET"
endpoint = "/controller/getListInputHost"
data = None
response_data, status = handle_controller_request(endpoint, method, data)
response = {
"method": method,
"status": status,
"endpoint": endpoint,
"data": response_data,
}
response = json.dumps(response)
print(response, flush=True)