diff --git a/controller.py b/controller.py index d6c6bdb4..bb7fae7b 100644 --- a/controller.py +++ b/controller.py @@ -212,7 +212,7 @@ def initSetLanguageAndCountry(): config.TARGET_LANGUAGE = language config.TARGET_COUNTRY = country config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE) - model.authenticationTranslator(callbackSetAuthKeys) + model.authenticationTranslator() def setYourLanguageAndCountry(select): languages = config.SELECTED_TAB_YOUR_LANGUAGES @@ -222,7 +222,7 @@ def setYourLanguageAndCountry(select): config.SOURCE_LANGUAGE = language config.SOURCE_COUNTRY = country config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE) - model.authenticationTranslator(callbackSetAuthKeys) + model.authenticationTranslator() view.printToTextbox_selectedYourLanguages(select) def setTargetLanguageAndCountry(select): @@ -233,7 +233,7 @@ def setTargetLanguageAndCountry(select): config.TARGET_LANGUAGE = language config.TARGET_COUNTRY = country config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE) - model.authenticationTranslator(callbackSetAuthKeys) + model.authenticationTranslator() view.printToTextbox_selectedTargetLanguages(select) def callbackSelectedLanguagePresetTab(selected_tab_no): @@ -250,12 +250,9 @@ def callbackSelectedLanguagePresetTab(selected_tab_no): config.TARGET_LANGUAGE = language config.TARGET_COUNTRY = country config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE) - model.authenticationTranslator(callbackSetAuthKeys) + model.authenticationTranslator() view.printToTextbox_changedLanguagePresetTab(config.SELECTED_TAB_NO) -def callbackSetAuthKeys(keys): - config.AUTH_KEYS = keys - # command func def callbackToggleTranslation(is_turned_on): config.ENABLE_TRANSLATION = is_turned_on @@ -377,17 +374,22 @@ def callbackSetUiLanguage(value): # Translation Tab def callbackSetDeeplAuthkey(value): print("callbackSetDeeplAuthkey", str(value)) - if len(value) > 0 and model.authenticationTranslator(callbackSetAuthKeys, choice_translator="DeepL(auth)", auth_key=value) is True: + if len(value) > 0: + result = model.authenticationTranslator(choice_translator="DeepL_API", auth_key=value) + if result is True: + auth_keys = config.AUTH_KEYS + auth_keys["DeepL_API"] = value + config.AUTH_KEYS = auth_keys + view.printToTextbox_AuthenticationSuccess() config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE) - model.authenticationTranslator(callbackSetAuthKeys) - view.printToTextbox_AuthenticationSuccess() elif len(value) == 0: auth_keys = config.AUTH_KEYS - auth_keys["DeepL(auth)"] = None + auth_keys["DeepL_API"] = None config.AUTH_KEYS = auth_keys - model.authenticationTranslator(callbackSetAuthKeys) + config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE) else: view.printToTextbox_AuthenticationError() + print(config.AUTH_KEYS, config.CHOICE_TRANSLATOR) # Transcription Tab (Mic) def callbackSetMicHost(value): @@ -634,11 +636,11 @@ def createMainWindow(): # init config initSetLanguageAndCountry() - if model.authenticationTranslator(callbackSetAuthKeys) is False: + if model.authenticationTranslator() is False: # error update Auth key view.printToTextbox_AuthenticationError() config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE) - model.authenticationTranslator(callbackSetAuthKeys) + model.authenticationTranslator() # set word filter model.addKeywords() diff --git a/model.py b/model.py index 68b48e81..91507df1 100644 --- a/model.py +++ b/model.py @@ -81,20 +81,13 @@ class Model: del self.keyword_processor self.keyword_processor = KeywordProcessor() - def authenticationTranslator(self, fnc, choice_translator=None, auth_key=None): + def authenticationTranslator(self, choice_translator=None, auth_key=None): if choice_translator == None: choice_translator = config.CHOICE_TRANSLATOR if auth_key == None: auth_key = config.AUTH_KEYS[choice_translator] result = self.translator.authentication(choice_translator, auth_key) - if result: - auth_keys = config.AUTH_KEYS - auth_keys[choice_translator] = auth_key - try: - fnc(auth_keys) - except: - pass return result def startLogger(self): @@ -139,6 +132,8 @@ class Model: engine_name = compatible_engines[0] if engine_name == "DeepL" and config.AUTH_KEYS["DeepL_API"] != None: + engine_name = "DeepL_API" + elif engine_name == "DeepL_API" and config.AUTH_KEYS["DeepL_API"] == None: engine_name = "DeepL" return engine_name @@ -146,9 +141,6 @@ class Model: def getTranslatorStatus(self): return self.translator.translator_status[config.CHOICE_TRANSLATOR] - def getListTranslatorName(self): - return list(self.translator.translator_status.keys()) - def getInputTranslate(self, message): try: if config.CHOICE_TRANSLATOR == "DeepL_API":