Merge branch 'model_callback' into UI_2.0

This commit is contained in:
misyaguziya
2023-09-04 05:09:13 +09:00
2 changed files with 19 additions and 10 deletions

17
main.py
View File

@@ -143,6 +143,15 @@ def callbackSelectedLanguagePresetTab(selected_tab_no):
config.TARGET_COUNTRY = country config.TARGET_COUNTRY = country
config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE) config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE)
def callbackSetAuthKeys(keys):
config.AUTH_KEYS = keys
def callbackChangeStatusOSC(value):
config.ENABLE_OSC = value
def callbackChangeStatusSoftwareUpdated(value):
config.UPDATE_FLAG = value
# command func # command func
def callbackToggleTranslation(is_turned_on): def callbackToggleTranslation(is_turned_on):
config.ENABLE_TRANSLATION = is_turned_on config.ENABLE_TRANSLATION = is_turned_on
@@ -230,7 +239,7 @@ def callbackSetDeeplAuthkey(value):
print("callbackSetDeeplAuthkey", str(value)) print("callbackSetDeeplAuthkey", str(value))
# config.AUTH_KEYS["DeepL(auth)"] = str(value) # config.AUTH_KEYS["DeepL(auth)"] = str(value)
# if len(value) > 0: # if len(value) > 0:
# if model.authenticationTranslator(choice_translator="DeepL(auth)", auth_key=value) is True: # if model.authenticationTranslator(callbackSetAuthKeys, choice_translator="DeepL(auth)", auth_key=value) is True:
# print_textbox(self.parent.textbox_message_log, "Auth key update completed", "INFO") # print_textbox(self.parent.textbox_message_log, "Auth key update completed", "INFO")
# print_textbox(self.parent.textbox_message_system_log, "Auth key update completed", "INFO") # print_textbox(self.parent.textbox_message_system_log, "Auth key update completed", "INFO")
# else: # else:
@@ -352,7 +361,7 @@ def callbackSetOscPort(value):
view.createGUI() view.createGUI()
# init config # init config
if model.authenticationTranslator() is False: if model.authenticationTranslator(callbackSetAuthKeys) is False:
# error update Auth key # error update Auth key
view.printToTextbox_AuthenticationError() view.printToTextbox_AuthenticationError()
@@ -360,10 +369,10 @@ if model.authenticationTranslator() is False:
model.addKeywords() model.addKeywords()
# check OSC started # check OSC started
model.checkOSCStarted() model.checkOSCStarted(callbackChangeStatusOSC)
# check Software Updated # check Software Updated
model.checkSoftwareUpdated() model.checkSoftwareUpdated(callbackChangeStatusSoftwareUpdated)
# init logger # init logger
if config.ENABLE_LOGGER is True: if config.ENABLE_LOGGER is True:

View File

@@ -68,7 +68,7 @@ class Model:
del self.translator del self.translator
self.keyword_processor = KeywordProcessor() self.keyword_processor = KeywordProcessor()
def authenticationTranslator(self, choice_translator=None, auth_key=None): def authenticationTranslator(self, fnc, choice_translator=None, auth_key=None):
if choice_translator == None: if choice_translator == None:
choice_translator = config.CHOICE_TRANSLATOR choice_translator = config.CHOICE_TRANSLATOR
if auth_key == None: if auth_key == None:
@@ -78,7 +78,7 @@ class Model:
if result: if result:
auth_keys = config.AUTH_KEYS auth_keys = config.AUTH_KEYS
auth_keys[choice_translator] = auth_key auth_keys[choice_translator] = auth_key
config.AUTH_KEYS = auth_keys fnc(auth_key)
return result return result
def startLogger(self): def startLogger(self):
@@ -165,10 +165,10 @@ class Model:
sendMessage(message, config.OSC_IP_ADDRESS, config.OSC_PORT) sendMessage(message, config.OSC_IP_ADDRESS, config.OSC_PORT)
@staticmethod @staticmethod
def checkOSCStarted(): def checkOSCStarted(fnc):
def checkOscReceive(address, osc_arguments): def checkOscReceive(address, osc_arguments):
if config.ENABLE_OSC is False: if config.ENABLE_OSC is False:
config.ENABLE_OSC = True fnc(True)
# start receive osc # start receive osc
th_receive_osc_parameters = Thread(target=receiveOscParameters, args=(checkOscReceive,)) th_receive_osc_parameters = Thread(target=receiveOscParameters, args=(checkOscReceive,))
@@ -179,12 +179,12 @@ class Model:
sendTestAction() sendTestAction()
@staticmethod @staticmethod
def checkSoftwareUpdated(): def checkSoftwareUpdated(fnc):
# check update # check update
response = requests_get(config.GITHUB_URL) response = requests_get(config.GITHUB_URL)
tag_name = response.json()["tag_name"] tag_name = response.json()["tag_name"]
if tag_name != config.VERSION: if tag_name != config.VERSION:
config.UPDATE_FLAG = True fnc(True)
@staticmethod @staticmethod
def getListInputHost(): def getListInputHost():