📝[Refactor] ruffを使用しコード検証修正を行った

This commit is contained in:
misyaguziya
2023-11-08 17:35:50 +09:00
parent 02acc4a191
commit 4351122cb4
17 changed files with 107 additions and 90 deletions

View File

@@ -70,7 +70,7 @@ class Config:
@ENABLE_TRANSLATION.setter @ENABLE_TRANSLATION.setter
def ENABLE_TRANSLATION(self, value): def ENABLE_TRANSLATION(self, value):
if type(value) is bool: if isinstance(value, bool):
self._ENABLE_TRANSLATION = value self._ENABLE_TRANSLATION = value
@property @property
@@ -79,7 +79,7 @@ class Config:
@ENABLE_TRANSCRIPTION_SEND.setter @ENABLE_TRANSCRIPTION_SEND.setter
def ENABLE_TRANSCRIPTION_SEND(self, value): def ENABLE_TRANSCRIPTION_SEND(self, value):
if type(value) is bool: if isinstance(value, bool):
self._ENABLE_TRANSCRIPTION_SEND = value self._ENABLE_TRANSCRIPTION_SEND = value
@property @property
@@ -88,7 +88,7 @@ class Config:
@ENABLE_TRANSCRIPTION_RECEIVE.setter @ENABLE_TRANSCRIPTION_RECEIVE.setter
def ENABLE_TRANSCRIPTION_RECEIVE(self, value): def ENABLE_TRANSCRIPTION_RECEIVE(self, value):
if type(value) is bool: if isinstance(value, bool):
self._ENABLE_TRANSCRIPTION_RECEIVE = value self._ENABLE_TRANSCRIPTION_RECEIVE = value
@property @property
@@ -97,7 +97,7 @@ class Config:
@ENABLE_FOREGROUND.setter @ENABLE_FOREGROUND.setter
def ENABLE_FOREGROUND(self, value): def ENABLE_FOREGROUND(self, value):
if type(value) is bool: if isinstance(value, bool):
self._ENABLE_FOREGROUND = value self._ENABLE_FOREGROUND = value
@property @property
@@ -106,7 +106,7 @@ class Config:
@SOURCE_COUNTRY.setter @SOURCE_COUNTRY.setter
def SOURCE_COUNTRY(self, value): def SOURCE_COUNTRY(self, value):
if type(value) is str: if isinstance(value, str):
self._SOURCE_COUNTRY = value self._SOURCE_COUNTRY = value
@property @property
@@ -115,7 +115,7 @@ class Config:
@SOURCE_LANGUAGE.setter @SOURCE_LANGUAGE.setter
def SOURCE_LANGUAGE(self, value): def SOURCE_LANGUAGE(self, value):
if type(value) is str: if isinstance(value, str):
self._SOURCE_LANGUAGE = value self._SOURCE_LANGUAGE = value
@property @property
@@ -124,7 +124,7 @@ class Config:
@TARGET_COUNTRY.setter @TARGET_COUNTRY.setter
def TARGET_COUNTRY(self, value): def TARGET_COUNTRY(self, value):
if type(value) is str: if isinstance(value, str):
self._TARGET_COUNTRY = value self._TARGET_COUNTRY = value
@property @property
@@ -133,7 +133,7 @@ class Config:
@TARGET_LANGUAGE.setter @TARGET_LANGUAGE.setter
def TARGET_LANGUAGE(self, value): def TARGET_LANGUAGE(self, value):
if type(value) is str: if isinstance(value, str):
self._TARGET_LANGUAGE = value self._TARGET_LANGUAGE = value
@property @property
@@ -154,7 +154,7 @@ class Config:
@SELECTED_TAB_NO.setter @SELECTED_TAB_NO.setter
def SELECTED_TAB_NO(self, value): def SELECTED_TAB_NO(self, value):
if type(value) is str: if isinstance(value, str):
self._SELECTED_TAB_NO = value self._SELECTED_TAB_NO = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -165,7 +165,7 @@ class Config:
@SELECTED_TAB_YOUR_LANGUAGES.setter @SELECTED_TAB_YOUR_LANGUAGES.setter
def SELECTED_TAB_YOUR_LANGUAGES(self, value): def SELECTED_TAB_YOUR_LANGUAGES(self, value):
if type(value) is dict: if isinstance(value, dict):
self._SELECTED_TAB_YOUR_LANGUAGES = value self._SELECTED_TAB_YOUR_LANGUAGES = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -176,7 +176,7 @@ class Config:
@SELECTED_TAB_TARGET_LANGUAGES.setter @SELECTED_TAB_TARGET_LANGUAGES.setter
def SELECTED_TAB_TARGET_LANGUAGES(self, value): def SELECTED_TAB_TARGET_LANGUAGES(self, value):
if type(value) is dict: if isinstance(value, dict):
self._SELECTED_TAB_TARGET_LANGUAGES = value self._SELECTED_TAB_TARGET_LANGUAGES = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -187,7 +187,7 @@ class Config:
@IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE.setter @IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE.setter
def IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE(self, value): def IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE(self, value):
if type(value) is bool: if isinstance(value, bool):
self._IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = value self._IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -199,7 +199,7 @@ class Config:
@TRANSPARENCY.setter @TRANSPARENCY.setter
def TRANSPARENCY(self, value): def TRANSPARENCY(self, value):
if type(value) is int and 0 <= value <= 100: if isinstance(value, int) and 0 <= value <= 100:
self._TRANSPARENCY = value self._TRANSPARENCY = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -232,7 +232,7 @@ class Config:
@TEXTBOX_UI_SCALING.setter @TEXTBOX_UI_SCALING.setter
def TEXTBOX_UI_SCALING(self, value): def TEXTBOX_UI_SCALING(self, value):
if type(value) is int and 50 <= value <= 200: if isinstance(value, int) and 50 <= value <= 200:
self._TEXTBOX_UI_SCALING = value self._TEXTBOX_UI_SCALING = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -290,7 +290,7 @@ class Config:
@INPUT_MIC_ENERGY_THRESHOLD.setter @INPUT_MIC_ENERGY_THRESHOLD.setter
def INPUT_MIC_ENERGY_THRESHOLD(self, value): def INPUT_MIC_ENERGY_THRESHOLD(self, value):
if type(value) is int: if isinstance(value, int):
self._INPUT_MIC_ENERGY_THRESHOLD = value self._INPUT_MIC_ENERGY_THRESHOLD = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -301,7 +301,7 @@ class Config:
@INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD.setter @INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD.setter
def INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD(self, value): def INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD(self, value):
if type(value) is bool: if isinstance(value, bool):
self._INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = value self._INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -312,7 +312,7 @@ class Config:
@INPUT_MIC_RECORD_TIMEOUT.setter @INPUT_MIC_RECORD_TIMEOUT.setter
def INPUT_MIC_RECORD_TIMEOUT(self, value): def INPUT_MIC_RECORD_TIMEOUT(self, value):
if type(value) is int: if isinstance(value, int):
self._INPUT_MIC_RECORD_TIMEOUT = value self._INPUT_MIC_RECORD_TIMEOUT = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -323,7 +323,7 @@ class Config:
@INPUT_MIC_PHRASE_TIMEOUT.setter @INPUT_MIC_PHRASE_TIMEOUT.setter
def INPUT_MIC_PHRASE_TIMEOUT(self, value): def INPUT_MIC_PHRASE_TIMEOUT(self, value):
if type(value) is int: if isinstance(value, int):
self._INPUT_MIC_PHRASE_TIMEOUT = value self._INPUT_MIC_PHRASE_TIMEOUT = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -334,7 +334,7 @@ class Config:
@INPUT_MIC_MAX_PHRASES.setter @INPUT_MIC_MAX_PHRASES.setter
def INPUT_MIC_MAX_PHRASES(self, value): def INPUT_MIC_MAX_PHRASES(self, value):
if type(value) is int: if isinstance(value, int):
self._INPUT_MIC_MAX_PHRASES = value self._INPUT_MIC_MAX_PHRASES = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -345,7 +345,7 @@ class Config:
@INPUT_MIC_WORD_FILTER.setter @INPUT_MIC_WORD_FILTER.setter
def INPUT_MIC_WORD_FILTER(self, value): def INPUT_MIC_WORD_FILTER(self, value):
if type(value) is list: if isinstance(value, list):
self._INPUT_MIC_WORD_FILTER = sorted(set(value), key=value.index) self._INPUT_MIC_WORD_FILTER = sorted(set(value), key=value.index)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -356,7 +356,7 @@ class Config:
@INPUT_SPEAKER_ENERGY_THRESHOLD.setter @INPUT_SPEAKER_ENERGY_THRESHOLD.setter
def INPUT_SPEAKER_ENERGY_THRESHOLD(self, value): def INPUT_SPEAKER_ENERGY_THRESHOLD(self, value):
if type(value) is int: if isinstance(value, int):
self._INPUT_SPEAKER_ENERGY_THRESHOLD = value self._INPUT_SPEAKER_ENERGY_THRESHOLD = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -367,7 +367,7 @@ class Config:
@INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD.setter @INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD.setter
def INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD(self, value): def INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD(self, value):
if type(value) is bool: if isinstance(value, bool):
self._INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = value self._INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -378,7 +378,7 @@ class Config:
@INPUT_SPEAKER_RECORD_TIMEOUT.setter @INPUT_SPEAKER_RECORD_TIMEOUT.setter
def INPUT_SPEAKER_RECORD_TIMEOUT(self, value): def INPUT_SPEAKER_RECORD_TIMEOUT(self, value):
if type(value) is int: if isinstance(value, int):
self._INPUT_SPEAKER_RECORD_TIMEOUT = value self._INPUT_SPEAKER_RECORD_TIMEOUT = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -389,7 +389,7 @@ class Config:
@INPUT_SPEAKER_PHRASE_TIMEOUT.setter @INPUT_SPEAKER_PHRASE_TIMEOUT.setter
def INPUT_SPEAKER_PHRASE_TIMEOUT(self, value): def INPUT_SPEAKER_PHRASE_TIMEOUT(self, value):
if type(value) is int: if isinstance(value, int):
self._INPUT_SPEAKER_PHRASE_TIMEOUT = value self._INPUT_SPEAKER_PHRASE_TIMEOUT = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -400,7 +400,7 @@ class Config:
@INPUT_SPEAKER_MAX_PHRASES.setter @INPUT_SPEAKER_MAX_PHRASES.setter
def INPUT_SPEAKER_MAX_PHRASES(self, value): def INPUT_SPEAKER_MAX_PHRASES(self, value):
if type(value) is int: if isinstance(value, int):
self._INPUT_SPEAKER_MAX_PHRASES = value self._INPUT_SPEAKER_MAX_PHRASES = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -411,7 +411,7 @@ class Config:
@OSC_IP_ADDRESS.setter @OSC_IP_ADDRESS.setter
def OSC_IP_ADDRESS(self, value): def OSC_IP_ADDRESS(self, value):
if type(value) is str: if isinstance(value, str):
self._OSC_IP_ADDRESS = value self._OSC_IP_ADDRESS = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -422,7 +422,7 @@ class Config:
@OSC_PORT.setter @OSC_PORT.setter
def OSC_PORT(self, value): def OSC_PORT(self, value):
if type(value) is int: if isinstance(value, int):
self._OSC_PORT = value self._OSC_PORT = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -433,9 +433,9 @@ class Config:
@AUTH_KEYS.setter @AUTH_KEYS.setter
def AUTH_KEYS(self, value): def AUTH_KEYS(self, value):
if type(value) is dict and set(value.keys()) == set(self.AUTH_KEYS.keys()): if isinstance(value, dict) and set(value.keys()) == set(self.AUTH_KEYS.keys()):
for key, value in value.items(): for key, value in value.items():
if type(value) is str: if isinstance(value, str):
self._AUTH_KEYS[key] = value self._AUTH_KEYS[key] = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, self.AUTH_KEYS) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, self.AUTH_KEYS)
@@ -446,7 +446,7 @@ class Config:
@MESSAGE_FORMAT.setter @MESSAGE_FORMAT.setter
def MESSAGE_FORMAT(self, value): def MESSAGE_FORMAT(self, value):
if type(value) is str: if isinstance(value, str):
if isUniqueStrings(["[message]", "[translation]"], value) is False: if isUniqueStrings(["[message]", "[translation]"], value) is False:
value = "[message]([translation])" value = "[message]([translation])"
self._MESSAGE_FORMAT = value self._MESSAGE_FORMAT = value
@@ -459,7 +459,7 @@ class Config:
@ENABLE_AUTO_CLEAR_MESSAGE_BOX.setter @ENABLE_AUTO_CLEAR_MESSAGE_BOX.setter
def ENABLE_AUTO_CLEAR_MESSAGE_BOX(self, value): def ENABLE_AUTO_CLEAR_MESSAGE_BOX(self, value):
if type(value) is bool: if isinstance(value, bool):
self._ENABLE_AUTO_CLEAR_MESSAGE_BOX = value self._ENABLE_AUTO_CLEAR_MESSAGE_BOX = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -470,7 +470,7 @@ class Config:
@ENABLE_NOTICE_XSOVERLAY.setter @ENABLE_NOTICE_XSOVERLAY.setter
def ENABLE_NOTICE_XSOVERLAY(self, value): def ENABLE_NOTICE_XSOVERLAY(self, value):
if type(value) is bool: if isinstance(value, bool):
self._ENABLE_NOTICE_XSOVERLAY = value self._ENABLE_NOTICE_XSOVERLAY = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -481,7 +481,7 @@ class Config:
@ENABLE_SEND_MESSAGE_TO_VRC.setter @ENABLE_SEND_MESSAGE_TO_VRC.setter
def ENABLE_SEND_MESSAGE_TO_VRC(self, value): def ENABLE_SEND_MESSAGE_TO_VRC(self, value):
if type(value) is bool: if isinstance(value, bool):
self._ENABLE_SEND_MESSAGE_TO_VRC = value self._ENABLE_SEND_MESSAGE_TO_VRC = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -493,7 +493,7 @@ class Config:
# @STARTUP_OSC_ENABLED_CHECK.setter # @STARTUP_OSC_ENABLED_CHECK.setter
# def STARTUP_OSC_ENABLED_CHECK(self, value): # def STARTUP_OSC_ENABLED_CHECK(self, value):
# if type(value) is bool: # if isinstance(value, bool):
# self._STARTUP_OSC_ENABLED_CHECK = value # self._STARTUP_OSC_ENABLED_CHECK = value
# saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) # saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -504,7 +504,7 @@ class Config:
@ENABLE_LOGGER.setter @ENABLE_LOGGER.setter
def ENABLE_LOGGER(self, value): def ENABLE_LOGGER(self, value):
if type(value) is bool: if isinstance(value, bool):
self._ENABLE_LOGGER = value self._ENABLE_LOGGER = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@@ -515,7 +515,7 @@ class Config:
@IS_CONFIG_WINDOW_COMPACT_MODE.setter @IS_CONFIG_WINDOW_COMPACT_MODE.setter
def IS_CONFIG_WINDOW_COMPACT_MODE(self, value): def IS_CONFIG_WINDOW_COMPACT_MODE(self, value):
if type(value) is bool: if isinstance(value, bool):
self._IS_CONFIG_WINDOW_COMPACT_MODE = value self._IS_CONFIG_WINDOW_COMPACT_MODE = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)

View File

@@ -30,7 +30,7 @@ def sendMicMessage(message):
pass pass
else: else:
translation = model.getInputTranslate(message) translation = model.getInputTranslate(message)
if translation == False: if translation is False:
config.ENABLE_TRANSLATION = False config.ENABLE_TRANSLATION = False
translation = "" translation = ""
view.translationEngineLimitErrorProcess() view.translationEngineLimitErrorProcess()
@@ -94,7 +94,7 @@ def receiveSpeakerMessage(message):
pass pass
else: else:
translation = model.getOutputTranslate(message) translation = model.getOutputTranslate(message)
if translation == False: if translation is False:
config.ENABLE_TRANSLATION = False config.ENABLE_TRANSLATION = False
translation = "" translation = ""
view.translationEngineLimitErrorProcess() view.translationEngineLimitErrorProcess()
@@ -160,7 +160,7 @@ def sendChatMessage(message):
pass pass
else: else:
translation = model.getInputTranslate(message) translation = model.getInputTranslate(message)
if translation == False: if translation is False:
config.ENABLE_TRANSLATION = False config.ENABLE_TRANSLATION = False
translation = "" translation = ""
view.translationEngineLimitErrorProcess() view.translationEngineLimitErrorProcess()
@@ -426,7 +426,8 @@ def callbackSetMicDevice(value):
def callbackSetMicEnergyThreshold(value): def callbackSetMicEnergyThreshold(value):
print("callbackSetMicEnergyThreshold", value) print("callbackSetMicEnergyThreshold", value)
if value == "": return if value == "":
return
try: try:
value = int(value) value = int(value)
if 0 <= value and value <= config.MAX_MIC_ENERGY_THRESHOLD: if 0 <= value and value <= config.MAX_MIC_ENERGY_THRESHOLD:
@@ -435,7 +436,7 @@ def callbackSetMicEnergyThreshold(value):
view.setGuiVariable_MicEnergyThreshold(config.INPUT_MIC_ENERGY_THRESHOLD) view.setGuiVariable_MicEnergyThreshold(config.INPUT_MIC_ENERGY_THRESHOLD)
else: else:
raise ValueError() raise ValueError()
except: except Exception:
view.showErrorMessage_MicEnergyThreshold() view.showErrorMessage_MicEnergyThreshold()
def callbackSetMicDynamicEnergyThreshold(value): def callbackSetMicDynamicEnergyThreshold(value):
@@ -462,7 +463,8 @@ def callbackCheckMicThreshold(is_turned_on):
def callbackSetMicRecordTimeout(value): def callbackSetMicRecordTimeout(value):
print("callbackSetMicRecordTimeout", value) print("callbackSetMicRecordTimeout", value)
if value == "": return if value == "":
return
try: try:
value = int(value) value = int(value)
if 0 <= value and value <= config.INPUT_MIC_PHRASE_TIMEOUT: if 0 <= value and value <= config.INPUT_MIC_PHRASE_TIMEOUT:
@@ -471,12 +473,13 @@ def callbackSetMicRecordTimeout(value):
view.setGuiVariable_MicRecordTimeout(config.INPUT_MIC_RECORD_TIMEOUT) view.setGuiVariable_MicRecordTimeout(config.INPUT_MIC_RECORD_TIMEOUT)
else: else:
raise ValueError() raise ValueError()
except: except Exception:
view.showErrorMessage_MicRecordTimeout() view.showErrorMessage_MicRecordTimeout()
def callbackSetMicPhraseTimeout(value): def callbackSetMicPhraseTimeout(value):
print("callbackSetMicPhraseTimeout", value) print("callbackSetMicPhraseTimeout", value)
if value == "": return if value == "":
return
try: try:
value = int(value) value = int(value)
if 0 <= value and value >= config.INPUT_MIC_RECORD_TIMEOUT: if 0 <= value and value >= config.INPUT_MIC_RECORD_TIMEOUT:
@@ -485,12 +488,13 @@ def callbackSetMicPhraseTimeout(value):
view.setGuiVariable_MicPhraseTimeout(config.INPUT_MIC_PHRASE_TIMEOUT) view.setGuiVariable_MicPhraseTimeout(config.INPUT_MIC_PHRASE_TIMEOUT)
else: else:
raise ValueError() raise ValueError()
except: except Exception:
view.showErrorMessage_MicPhraseTimeout() view.showErrorMessage_MicPhraseTimeout()
def callbackSetMicMaxPhrases(value): def callbackSetMicMaxPhrases(value):
print("callbackSetMicMaxPhrases", value) print("callbackSetMicMaxPhrases", value)
if value == "": return if value == "":
return
try: try:
value = int(value) value = int(value)
if 0 <= value: if 0 <= value:
@@ -499,7 +503,7 @@ def callbackSetMicMaxPhrases(value):
view.setGuiVariable_MicMaxPhrases(config.INPUT_MIC_MAX_PHRASES) view.setGuiVariable_MicMaxPhrases(config.INPUT_MIC_MAX_PHRASES)
else: else:
raise ValueError() raise ValueError()
except: except Exception:
view.showErrorMessage_MicMaxPhrases() view.showErrorMessage_MicMaxPhrases()
def callbackSetMicWordFilter(values): def callbackSetMicWordFilter(values):
@@ -532,13 +536,14 @@ def callbackDeleteMicWordFilter(value):
new_input_mic_word_filter_list.remove(str(value)) new_input_mic_word_filter_list.remove(str(value))
config.INPUT_MIC_WORD_FILTER = new_input_mic_word_filter_list config.INPUT_MIC_WORD_FILTER = new_input_mic_word_filter_list
view.setLatestConfigVariable("MicMicWordFilter") view.setLatestConfigVariable("MicMicWordFilter")
except: except Exception:
print("There was no the target word in config.INPUT_MIC_WORD_FILTER") print("There was no the target word in config.INPUT_MIC_WORD_FILTER")
def callbackSetSpeakerEnergyThreshold(value): def callbackSetSpeakerEnergyThreshold(value):
print("callbackSetSpeakerEnergyThreshold", value) print("callbackSetSpeakerEnergyThreshold", value)
if value == "": return if value == "":
return
try: try:
value = int(value) value = int(value)
if 0 <= value and value <= config.MAX_SPEAKER_ENERGY_THRESHOLD: if 0 <= value and value <= config.MAX_SPEAKER_ENERGY_THRESHOLD:
@@ -547,7 +552,7 @@ def callbackSetSpeakerEnergyThreshold(value):
view.setGuiVariable_SpeakerEnergyThreshold(config.INPUT_SPEAKER_ENERGY_THRESHOLD) view.setGuiVariable_SpeakerEnergyThreshold(config.INPUT_SPEAKER_ENERGY_THRESHOLD)
else: else:
raise ValueError() raise ValueError()
except: except Exception:
view.showErrorMessage_SpeakerEnergyThreshold() view.showErrorMessage_SpeakerEnergyThreshold()
def callbackSetSpeakerDynamicEnergyThreshold(value): def callbackSetSpeakerDynamicEnergyThreshold(value):
@@ -580,7 +585,8 @@ def callbackCheckSpeakerThreshold(is_turned_on):
def callbackSetSpeakerRecordTimeout(value): def callbackSetSpeakerRecordTimeout(value):
print("callbackSetSpeakerRecordTimeout", value) print("callbackSetSpeakerRecordTimeout", value)
if value == "": return if value == "":
return
try: try:
value = int(value) value = int(value)
if 0 <= value and value <= config.INPUT_SPEAKER_PHRASE_TIMEOUT: if 0 <= value and value <= config.INPUT_SPEAKER_PHRASE_TIMEOUT:
@@ -589,12 +595,13 @@ def callbackSetSpeakerRecordTimeout(value):
view.setGuiVariable_SpeakerRecordTimeout(config.INPUT_SPEAKER_RECORD_TIMEOUT) view.setGuiVariable_SpeakerRecordTimeout(config.INPUT_SPEAKER_RECORD_TIMEOUT)
else: else:
raise ValueError() raise ValueError()
except: except Exception:
view.showErrorMessage_SpeakerRecordTimeout() view.showErrorMessage_SpeakerRecordTimeout()
def callbackSetSpeakerPhraseTimeout(value): def callbackSetSpeakerPhraseTimeout(value):
print("callbackSetSpeakerPhraseTimeout", value) print("callbackSetSpeakerPhraseTimeout", value)
if value == "": return if value == "":
return
try: try:
value = int(value) value = int(value)
if 0 <= value and value >= config.INPUT_SPEAKER_RECORD_TIMEOUT: if 0 <= value and value >= config.INPUT_SPEAKER_RECORD_TIMEOUT:
@@ -603,12 +610,13 @@ def callbackSetSpeakerPhraseTimeout(value):
view.setGuiVariable_SpeakerPhraseTimeout(config.INPUT_SPEAKER_PHRASE_TIMEOUT) view.setGuiVariable_SpeakerPhraseTimeout(config.INPUT_SPEAKER_PHRASE_TIMEOUT)
else: else:
raise ValueError() raise ValueError()
except: except Exception:
view.showErrorMessage_SpeakerPhraseTimeout() view.showErrorMessage_SpeakerPhraseTimeout()
def callbackSetSpeakerMaxPhrases(value): def callbackSetSpeakerMaxPhrases(value):
print("callbackSetSpeakerMaxPhrases", value) print("callbackSetSpeakerMaxPhrases", value)
if value == "": return if value == "":
return
try: try:
value = int(value) value = int(value)
if 0 <= value: if 0 <= value:
@@ -617,7 +625,7 @@ def callbackSetSpeakerMaxPhrases(value):
view.setGuiVariable_SpeakerMaxPhrases(config.INPUT_SPEAKER_MAX_PHRASES) view.setGuiVariable_SpeakerMaxPhrases(config.INPUT_SPEAKER_MAX_PHRASES)
else: else:
raise ValueError() raise ValueError()
except: except Exception:
view.showErrorMessage_SpeakerMaxPhrases() view.showErrorMessage_SpeakerMaxPhrases()
@@ -662,12 +670,14 @@ def callbackSetEnableSendMessageToVrc(value):
# Advanced Settings Tab # Advanced Settings Tab
def callbackSetOscIpAddress(value): def callbackSetOscIpAddress(value):
if value == "": return if value == "":
return
print("callbackSetOscIpAddress", str(value)) print("callbackSetOscIpAddress", str(value))
config.OSC_IP_ADDRESS = str(value) config.OSC_IP_ADDRESS = str(value)
def callbackSetOscPort(value): def callbackSetOscPort(value):
if value == "": return if value == "":
return
print("callbackSetOscPort", int(value)) print("callbackSetOscPort", int(value))
config.OSC_PORT = int(value) config.OSC_PORT = int(value)

View File

@@ -12,7 +12,7 @@ if __name__ == "__main__":
splash.destroySplash() splash.destroySplash()
controller.showMainWindow() controller.showMainWindow()
except Exception as e: 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)

View File

@@ -82,9 +82,9 @@ class Model:
self.keyword_processor = KeywordProcessor() self.keyword_processor = KeywordProcessor()
def authenticationTranslator(self, choice_translator=None, auth_key=None): def authenticationTranslator(self, choice_translator=None, auth_key=None):
if choice_translator == None: if choice_translator is None:
choice_translator = config.CHOICE_TRANSLATOR choice_translator = config.CHOICE_TRANSLATOR
if auth_key == None: if auth_key is None:
auth_key = config.AUTH_KEYS[choice_translator] auth_key = config.AUTH_KEYS[choice_translator]
result = self.translator.authentication(choice_translator, auth_key) result = self.translator.authentication(choice_translator, auth_key)
@@ -130,10 +130,10 @@ class Model:
compatible_engines.append(engine) compatible_engines.append(engine)
engine_name = compatible_engines[0] engine_name = compatible_engines[0]
if engine_name == "DeepL" and config.AUTH_KEYS["DeepL_API"] != None: if engine_name == "DeepL" and config.AUTH_KEYS["DeepL_API"] is not None:
if self.authenticationTranslator(engine_name, config.AUTH_KEYS["DeepL_API"]) is True: if self.authenticationTranslator(engine_name, config.AUTH_KEYS["DeepL_API"]) is True:
engine_name = "DeepL_API" engine_name = "DeepL_API"
elif engine_name == "DeepL_API" and config.AUTH_KEYS["DeepL_API"] == None: elif engine_name == "DeepL_API" and config.AUTH_KEYS["DeepL_API"] is None:
engine_name = "DeepL" engine_name = "DeepL"
return engine_name return engine_name
@@ -288,7 +288,7 @@ class Model:
rmtree(os_path.join(current_directory, tmp_directory_name)) rmtree(os_path.join(current_directory, tmp_directory_name))
command = [os_path.join(program_directory, "batch", batch_name), program_name, temporary_name, str(restart)] command = [os_path.join(program_directory, "batch", batch_name), program_name, temporary_name, str(restart)]
Popen(command) Popen(command)
except: except Exception:
webbrowser.open(config.BOOTH_URL, new=2, autoraise=True) webbrowser.open(config.BOOTH_URL, new=2, autoraise=True)
@staticmethod @staticmethod
@@ -319,7 +319,7 @@ class Model:
if config.CHOICE_MIC_HOST == "NoHost" or config.CHOICE_MIC_DEVICE == "NoDevice": if config.CHOICE_MIC_HOST == "NoHost" or config.CHOICE_MIC_DEVICE == "NoDevice":
try: try:
error_fnc() error_fnc()
except: except Exception:
pass pass
return return
@@ -348,7 +348,7 @@ class Model:
message = mic_transcriber.getTranscript() message = mic_transcriber.getTranscript()
try: try:
fnc(message) fnc(message)
except: except Exception:
pass pass
self.mic_print_transcript = threadFnc(sendMicTranscript) self.mic_print_transcript = threadFnc(sendMicTranscript)
@@ -367,7 +367,7 @@ class Model:
if config.CHOICE_MIC_HOST == "NoHost" or config.CHOICE_MIC_DEVICE == "NoDevice": if config.CHOICE_MIC_HOST == "NoHost" or config.CHOICE_MIC_DEVICE == "NoDevice":
try: try:
error_fnc() error_fnc()
except: except Exception:
pass pass
return return
@@ -376,7 +376,7 @@ class Model:
energy = mic_energy_queue.get() energy = mic_energy_queue.get()
try: try:
fnc(energy) fnc(energy)
except: except Exception:
pass pass
sleep(0.01) sleep(0.01)
@@ -401,7 +401,7 @@ class Model:
if speaker_device["name"] == "NoDevice": if speaker_device["name"] == "NoDevice":
try: try:
error_fnc() error_fnc()
except: except Exception:
pass pass
return return
@@ -429,7 +429,7 @@ class Model:
message = speaker_transcriber.getTranscript() message = speaker_transcriber.getTranscript()
try: try:
fnc(message) fnc(message)
except: except Exception:
pass pass
self.speaker_print_transcript = threadFnc(sendSpeakerTranscript) self.speaker_print_transcript = threadFnc(sendSpeakerTranscript)
@@ -449,7 +449,7 @@ class Model:
if speaker_device["name"] == "NoDevice": if speaker_device["name"] == "NoDevice":
try: try:
error_fnc() error_fnc()
except: except Exception:
pass pass
return return
@@ -458,7 +458,7 @@ class Model:
energy = speaker_energy_queue.get() energy = speaker_energy_queue.get()
try: try:
fnc(energy) fnc(energy)
except: except Exception:
pass pass
sleep(0.01) sleep(0.01)

View File

@@ -1,5 +1,4 @@
from time import sleep from time import sleep
from typing import List
from pythonosc import osc_message_builder from pythonosc import osc_message_builder
from pythonosc import udp_client from pythonosc import udp_client
from pythonosc import dispatcher from pythonosc import dispatcher
@@ -15,7 +14,7 @@ def sendTyping(flag=False, ip_address="127.0.0.1", port=9000):
# send OSC message # send OSC message
def sendMessage(message=None, ip_address="127.0.0.1", port=9000): def sendMessage(message=None, ip_address="127.0.0.1", port=9000):
if message != None: if message is not None:
msg = osc_message_builder.OscMessageBuilder(address="/chatbox/input") msg = osc_message_builder.OscMessageBuilder(address="/chatbox/input")
msg.add_arg(f"{message}") msg.add_arg(f"{message}")
msg.add_arg(True) msg.add_arg(True)

View File

@@ -38,7 +38,7 @@ class AudioTranscriber:
# os.close(fd) # os.close(fd)
audio_data = self.audio_sources["process_data_func"]() audio_data = self.audio_sources["process_data_func"]()
text = self.audio_recognizer.recognize_google(audio_data, language=transcription_lang[language][country]) text = self.audio_recognizer.recognize_google(audio_data, language=transcription_lang[language][country])
except Exception as e: except Exception:
pass pass
finally: finally:
pass pass

View File

@@ -1,7 +1,7 @@
from deepl import Translator as deepl_Translator from deepl import Translator as deepl_Translator
from deepl_translate import translate as deepl_web_Translator from deepl_translate import translate as deepl_web_Translator
from translators import translate_text as other_web_Translator from translators import translate_text as other_web_Translator
from .translation_languages import translatorEngine, translation_lang from .translation_languages import translation_lang
# Translator # Translator
class Translator(): class Translator():
@@ -16,7 +16,7 @@ class Translator():
try: try:
self.deepl_client = deepl_Translator(authkey) self.deepl_client = deepl_Translator(authkey)
self.deepl_client.translate_text(" ", target_lang="EN-US") self.deepl_client.translate_text(" ", target_lang="EN-US")
except: except Exception:
result = False result = False
return result return result
@@ -52,7 +52,7 @@ class Translator():
from_language=source_language, from_language=source_language,
to_language=target_language, to_language=target_language,
) )
except Exception as e: 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)

View File

@@ -33,7 +33,7 @@ def XSOverlay(
with open(icon, "rb") as f: with open(icon, "rb") as f:
icon_data_bytes = f.read() icon_data_bytes = f.read()
icon_data = base64.b64encode(icon_data_bytes).decode("utf-8") icon_data = base64.b64encode(icon_data_bytes).decode("utf-8")
except: except Exception:
icon_data = "default" icon_data = "default"
else: else:
icon_data = icon icon_data = icon

View File

@@ -13,7 +13,8 @@ def get_key_by_value(dictionary, value):
return None return None
def callFunctionIfCallable(function, *args): def callFunctionIfCallable(function, *args):
if callable(function) is True: function(*args) if callable(function) is True:
function(*args)
def isEven(number): def isEven(number):
return number % 2 == 0 return number % 2 == 0

View File

@@ -233,7 +233,8 @@ class _CreateConfirmationModal(CTkToplevel):
self.grab_release() self.grab_release()
def focusOutFunction(self, e): def focusOutFunction(self, e):
if str(e.widget) != ".!_createconfirmationmodal": return if str(e.widget) != ".!_createconfirmationmodal":
return
callFunctionIfCallable(self._view_variable.CALLBACK_HIDE_CONFIRMATION_MODAL) callFunctionIfCallable(self._view_variable.CALLBACK_HIDE_CONFIRMATION_MODAL)
def _grab_set(self): def _grab_set(self):

View File

@@ -262,7 +262,8 @@ class _CreateDropdownMenuWindow(CTkToplevel):
def show(self, dropdown_menu_widget_id): def show(self, dropdown_menu_widget_id):
if self.hide is False: return if self.hide is False:
return
self.wm_attributes("-alpha", 0) self.wm_attributes("-alpha", 0)

View File

@@ -80,7 +80,8 @@ class _CreateErrorWindow(CTkToplevel):
def show(self, target_widget): def show(self, target_widget):
if self.hide is False: return if self.hide is False:
return
self.attach_widget = target_widget self.attach_widget = target_widget

View File

@@ -178,5 +178,6 @@ class _CreateSelectableLanguagesWindow(CTkToplevel):
def focusOutFunction(self, e): def focusOutFunction(self, e):
if str(e.widget) != ".!_createselectablelanguageswindow": return if str(e.widget) != ".!_createselectablelanguageswindow":
return
self.vrct_gui._closeSelectableLanguagesWindow() self.vrct_gui._closeSelectableLanguagesWindow()

View File

@@ -2,7 +2,7 @@ from functools import partial
from types import SimpleNamespace from types import SimpleNamespace
from typing import Union from typing import Union
from customtkinter import CTkOptionMenu, CTkFont, CTkFrame, CTkLabel, CTkRadioButton, CTkEntry, CTkSlider, CTkSwitch, CTkCheckBox, CTkProgressBar, CTkImage from customtkinter import CTkFont, CTkFrame, CTkLabel, CTkEntry, CTkSlider, CTkSwitch, CTkCheckBox, CTkProgressBar, CTkImage
from CTkToolTip import * from CTkToolTip import *
from vrct_gui.ui_utils import createButtonWithImage, getLatestWidth, createOptionMenuBox, getLatestHeight, bindButtonFunctionAndColor from vrct_gui.ui_utils import createButtonWithImage, getLatestWidth, createOptionMenuBox, getLatestHeight, bindButtonFunctionAndColor
@@ -1068,7 +1068,8 @@ class _SettingBoxGenerator():
items[i] = item_data items[i] = item_data
is_replaced = True is_replaced = True
break break
if is_replaced is False: items.append(item_data) if is_replaced is False:
items.append(item_data)
return mic_word_filter_item_wrapper return mic_word_filter_item_wrapper

View File

@@ -2,7 +2,7 @@ from functools import partial
from customtkinter import CTkFont, CTkFrame, CTkLabel, CTkSwitch, CTkImage from customtkinter import CTkFont, CTkFrame, CTkLabel, CTkSwitch, CTkImage
from ....ui_utils import openImageKeepAspectRatio, retag, getLatestHeight, bindEnterAndLeaveFunction, bindButtonReleaseFunction, bindButtonPressAndReleaseFunction from ....ui_utils import openImageKeepAspectRatio, retag, bindEnterAndLeaveFunction, bindButtonReleaseFunction, bindButtonPressAndReleaseFunction
from utils import callFunctionIfCallable from utils import callFunctionIfCallable

View File

@@ -162,10 +162,12 @@ def createOptionMenuBox(parent_widget, optionmenu_bg_color, optionmenu_hovered_b
option_menu_box = CTkFrame(parent_widget, corner_radius=6, fg_color=optionmenu_bg_color, cursor="hand2") option_menu_box = CTkFrame(parent_widget, corner_radius=6, fg_color=optionmenu_bg_color, cursor="hand2")
option_menu_box.grid_rowconfigure(0, weight=1) option_menu_box.grid_rowconfigure(0, weight=1)
if optionmenu_min_height is not None: option_menu_box.grid_rowconfigure(0, minsize=optionmenu_min_height) if optionmenu_min_height is not None:
option_menu_box.grid_rowconfigure(0, minsize=optionmenu_min_height)
option_menu_box.grid_columnconfigure(0, weight=1) option_menu_box.grid_columnconfigure(0, weight=1)
if optionmenu_min_width is not None: option_menu_box.grid_columnconfigure(0, minsize=optionmenu_min_width) if optionmenu_min_width is not None:
option_menu_box.grid_columnconfigure(0, minsize=optionmenu_min_width)
optionmenu_label_wrapper = CTkFrame(option_menu_box, corner_radius=0, fg_color=optionmenu_bg_color) optionmenu_label_wrapper = CTkFrame(option_menu_box, corner_radius=0, fg_color=optionmenu_bg_color)
optionmenu_label_wrapper.grid(row=0, column=0, padx=(optionmenu_ipadx[0],0), pady=optionmenu_ipady, sticky="ew") optionmenu_label_wrapper.grid(row=0, column=0, padx=(optionmenu_ipadx[0],0), pady=optionmenu_ipady, sticky="ew")

View File

@@ -269,7 +269,7 @@ class VRCT_GUI(CTk):
def _clearErrorMessage(self): def _clearErrorMessage(self):
try: try:
self.error_message_window._withdraw() self.error_message_window._withdraw()
except: except Exception:
pass pass