diff --git a/VRCT.py b/VRCT.py index 238cf878..d52398eb 100644 --- a/VRCT.py +++ b/VRCT.py @@ -1,10 +1,7 @@ from time import sleep from os import path as os_path -from json import load as json_load -from json import dump as json_dump from requests import get as requests_get from queue import Queue -import tkinter as tk import customtkinter from customtkinter import CTk, CTkFrame, CTkCheckBox, CTkFont, CTkButton, CTkImage, CTkTabview, CTkTextbox, CTkEntry from PIL.Image import open as Image_open @@ -15,11 +12,12 @@ from utils import print_textbox, thread_fnc, get_localized_text, widget_main_win from osc_tools import send_typing, send_message, send_test_action, receive_osc_parameters from window_config import ToplevelWindowConfig from window_information import ToplevelWindowInformation -from languages import transcription_lang, translators, translation_lang, selectable_languages -from audio_utils import get_input_device_list, get_output_device_list, get_default_input_device, get_default_output_device +from languages import transcription_lang +from audio_utils import get_input_device_list, get_output_device_list from audio_recorder import SelectedMicRecorder, SelectedSpeakerRecorder from audio_transcriber import AudioTranscriber from translation import Translator +from config import config from notification import notification_xsoverlay_for_vrct __version__ = "1.3.2" @@ -32,241 +30,14 @@ class App(CTk): self.translator = Translator() self.keyword_processor = KeywordProcessor() - # init config - self.PATH_CONFIG = "./config.json" - - ## main window - self.ENABLE_TRANSLATION = False - # self.ENABLE_TRANSCRIPTION_SEND = False - # self.ENABLE_TRANSCRIPTION_RECEIVE = False - self.ENABLE_FOREGROUND = False - ## UI - self.TRANSPARENCY = 100 - self.APPEARANCE_THEME = "System" - self.UI_SCALING = "100%" - self.FONT_FAMILY = "Yu Gothic UI" - self.UI_LANGUAGE = "en" - ## Translation - self.CHOICE_TRANSLATOR = translators[0] - self.INPUT_SOURCE_LANG = list(translation_lang[self.CHOICE_TRANSLATOR]["source"].keys())[0] - self.INPUT_TARGET_LANG = list(translation_lang[self.CHOICE_TRANSLATOR]["target"].keys())[1] - self.OUTPUT_SOURCE_LANG = list(translation_lang[self.CHOICE_TRANSLATOR]["source"].keys())[1] - self.OUTPUT_TARGET_LANG = list(translation_lang[self.CHOICE_TRANSLATOR]["target"].keys())[0] - ## Transcription Send - self.CHOICE_MIC_HOST = get_default_input_device()["host"]["name"] - self.CHOICE_MIC_DEVICE = get_default_input_device()["device"]["name"] - self.INPUT_MIC_VOICE_LANGUAGE = list(transcription_lang.keys())[0] - self.INPUT_MIC_ENERGY_THRESHOLD = 300 - self.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = True - self.INPUT_MIC_RECORD_TIMEOUT = 3 - self.INPUT_MIC_PHRASE_TIMEOUT = 3 - self.INPUT_MIC_MAX_PHRASES = 10 - self.INPUT_MIC_WORD_FILTER = [] - ## Transcription Receive - self.CHOICE_SPEAKER_DEVICE = get_default_output_device()["name"] - self.INPUT_SPEAKER_VOICE_LANGUAGE = list(transcription_lang.keys())[1] - self.INPUT_SPEAKER_ENERGY_THRESHOLD = 300 - self.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = True - self.INPUT_SPEAKER_RECORD_TIMEOUT = 3 - self.INPUT_SPEAKER_PHRASE_TIMEOUT = 3 - self.INPUT_SPEAKER_MAX_PHRASES = 10 - - ## Parameter - self.OSC_IP_ADDRESS = "127.0.0.1" - self.OSC_PORT = 9000 - self.AUTH_KEYS = { - "DeepL(web)": None, - "DeepL(auth)": None, - "Bing(web)": None, - "Google(web)": None, - } - self.MESSAGE_FORMAT = "[message]([translation])" - # Others - self.ENABLE_AUTO_CLEAR_CHATBOX = False - self.ENABLE_OSC = False - self.ENABLE_NOTICE_XSOVERLAY =False - self.UPDATE_FLAG = False - - # load config - if os_path.isfile(self.PATH_CONFIG) is not False: - with open(self.PATH_CONFIG, 'r') as fp: - config = json_load(fp) - # main window - # main windowは初期はすべてOFFにする - # if "ENABLE_TRANSLATION" in config.keys(): - # if type(config["ENABLE_TRANSLATION"]) is bool: - # self.ENABLE_TRANSLATION = config["ENABLE_TRANSLATION"] - - # 環境に依ってマイクとスピーカーを同時起動するとエラーが発生するため、起動時は強制的にOFFにする - # if "ENABLE_TRANSCRIPTION_SEND" in config.keys(): - # if type(config["ENABLE_TRANSCRIPTION_SEND"]) is bool: - # self.ENABLE_TRANSCRIPTION_SEND = config["ENABLE_TRANSCRIPTION_SEND"] - # if "ENABLE_TRANSCRIPTION_RECEIVE" in config.keys(): - # if type(config["ENABLE_TRANSCRIPTION_RECEIVE"]) is bool: - # self.ENABLE_TRANSCRIPTION_RECEIVE = config["ENABLE_TRANSCRIPTION_RECEIVE"] - - # if "ENABLE_FOREGROUND" in config.keys(): - # if type(config["ENABLE_FOREGROUND"]) is bool: - # self.ENABLE_FOREGROUND = config["ENABLE_FOREGROUND"] - - # tab ui - if "TRANSPARENCY" in config.keys(): - if type(config["TRANSPARENCY"]) is int: - if 0 <= config["TRANSPARENCY"] <= 100: - self.TRANSPARENCY = config["TRANSPARENCY"] - if "APPEARANCE_THEME" in config.keys(): - if config["APPEARANCE_THEME"] in ["Light", "Dark", "System"]: - self.APPEARANCE_THEME = config["APPEARANCE_THEME"] - if "UI_SCALING" in config.keys(): - if config["UI_SCALING"] in ["80%", "90%", "100%", "110%", "120%"]: - self.UI_SCALING = config["UI_SCALING"] - if "FONT_FAMILY" in config.keys(): - if config["FONT_FAMILY"] in list(tk.font.families()): - self.FONT_FAMILY = config["FONT_FAMILY"] - if "UI_LANGUAGE" in config.keys(): - if config["UI_LANGUAGE"] in list(selectable_languages.keys()): - self.UI_LANGUAGE = config["UI_LANGUAGE"] - - # translation - if "CHOICE_TRANSLATOR" in config.keys(): - if config["CHOICE_TRANSLATOR"] in list(self.translator.translator_status.keys()): - self.CHOICE_TRANSLATOR = config["CHOICE_TRANSLATOR"] - if "INPUT_SOURCE_LANG" in config.keys(): - if config["INPUT_SOURCE_LANG"] in list(translation_lang[self.CHOICE_TRANSLATOR]["source"].keys()): - self.INPUT_SOURCE_LANG = config["INPUT_SOURCE_LANG"] - if "INPUT_TARGET_LANG" in config.keys(): - if config["INPUT_TARGET_LANG"] in list(translation_lang[self.CHOICE_TRANSLATOR]["target"].keys()): - self.INPUT_TARGET_LANG = config["INPUT_TARGET_LANG"] - if "OUTPUT_SOURCE_LANG" in config.keys(): - if config["OUTPUT_SOURCE_LANG"] in list(translation_lang[self.CHOICE_TRANSLATOR]["source"].keys()): - self.OUTPUT_SOURCE_LANG = config["OUTPUT_SOURCE_LANG"] - if "OUTPUT_TARGET_LANG" in config.keys(): - if config["OUTPUT_TARGET_LANG"] in list(translation_lang[self.CHOICE_TRANSLATOR]["target"].keys()): - self.OUTPUT_TARGET_LANG = config["OUTPUT_TARGET_LANG"] - - # Transcription - if "CHOICE_MIC_HOST" in config.keys(): - if config["CHOICE_MIC_HOST"] in [host for host in get_input_device_list().keys()]: - self.CHOICE_MIC_HOST = config["CHOICE_MIC_HOST"] - if "CHOICE_MIC_DEVICE" in config.keys(): - if config["CHOICE_MIC_DEVICE"] in [device["name"] for device in get_input_device_list()[self.CHOICE_MIC_HOST]]: - self.CHOICE_MIC_DEVICE = config["CHOICE_MIC_DEVICE"] - if "INPUT_MIC_VOICE_LANGUAGE" in config.keys(): - if config["INPUT_MIC_VOICE_LANGUAGE"] in list(transcription_lang.keys()): - self.INPUT_MIC_VOICE_LANGUAGE = config["INPUT_MIC_VOICE_LANGUAGE"] - if "INPUT_MIC_ENERGY_THRESHOLD" in config.keys(): - if type(config["INPUT_MIC_ENERGY_THRESHOLD"]) is int: - self.INPUT_MIC_ENERGY_THRESHOLD = config["INPUT_MIC_ENERGY_THRESHOLD"] - if "INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD" in config.keys(): - if type(config["INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD"]) is bool: - self.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = config["INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD"] - if "INPUT_MIC_RECORD_TIMEOUT" in config.keys(): - if type(config["INPUT_MIC_RECORD_TIMEOUT"]) is int: - self.INPUT_MIC_RECORD_TIMEOUT = config["INPUT_MIC_RECORD_TIMEOUT"] - if "INPUT_MIC_PHRASE_TIMEOUT" in config.keys(): - if type(config["INPUT_MIC_PHRASE_TIMEOUT"]) is int: - self.INPUT_MIC_PHRASE_TIMEOUT = config["INPUT_MIC_PHRASE_TIMEOUT"] - if "INPUT_MIC_MAX_PHRASES" in config.keys(): - if type(config["INPUT_MIC_MAX_PHRASES"]) is int: - self.INPUT_MIC_MAX_PHRASES = config["INPUT_MIC_MAX_PHRASES"] - if "INPUT_MIC_WORD_FILTER" in config.keys(): - if type(config["INPUT_MIC_WORD_FILTER"]) is list: - self.INPUT_MIC_WORD_FILTER = config["INPUT_MIC_WORD_FILTER"] - - if "CHOICE_SPEAKER_DEVICE" in config.keys(): - if config["CHOICE_SPEAKER_DEVICE"] in [device["name"] for device in get_output_device_list()]: - speaker_device = [device for device in get_output_device_list() if device["name"] == config["CHOICE_SPEAKER_DEVICE"]][0] - if get_default_output_device()["index"] == speaker_device["index"]: - self.CHOICE_SPEAKER_DEVICE = config["CHOICE_SPEAKER_DEVICE"] - if "INPUT_SPEAKER_VOICE_LANGUAGE" in config.keys(): - if config["INPUT_SPEAKER_VOICE_LANGUAGE"] in list(transcription_lang.keys()): - self.INPUT_SPEAKER_VOICE_LANGUAGE = config["INPUT_SPEAKER_VOICE_LANGUAGE"] - if "INPUT_SPEAKER_ENERGY_THRESHOLD" in config.keys(): - if type(config["INPUT_SPEAKER_ENERGY_THRESHOLD"]) is int: - self.INPUT_SPEAKER_ENERGY_THRESHOLD = config["INPUT_SPEAKER_ENERGY_THRESHOLD"] - if "INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD" in config.keys(): - if type(config["INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD"]) is bool: - self.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = config["INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD"] - if "INPUT_SPEAKER_RECORD_TIMEOUT" in config.keys(): - if type(config["INPUT_SPEAKER_RECORD_TIMEOUT"]) is int: - self.INPUT_SPEAKER_RECORD_TIMEOUT = config["INPUT_SPEAKER_RECORD_TIMEOUT"] - if "INPUT_SPEAKER_PHRASE_TIMEOUT" in config.keys(): - if type(config["INPUT_SPEAKER_PHRASE_TIMEOUT"]) is int: - self.INPUT_SPEAKER_PHRASE_TIMEOUT = config["INPUT_SPEAKER_PHRASE_TIMEOUT"] - if "INPUT_SPEAKER_MAX_PHRASES" in config.keys(): - if type(config["INPUT_SPEAKER_MAX_PHRASES"]) is int: - self.INPUT_MIC_MAX_PHRASES = config["INPUT_SPEAKER_MAX_PHRASES"] - - # Parameter - if "OSC_IP_ADDRESS" in config.keys(): - if type(config["OSC_IP_ADDRESS"]) is str: - self.OSC_IP_ADDRESS = config["OSC_IP_ADDRESS"] - if "OSC_PORT" in config.keys(): - if type(config["OSC_PORT"]) is int: - self.OSC_PORT = config["OSC_PORT"] - if "AUTH_KEYS" in config.keys(): - if type(config["AUTH_KEYS"]) is dict: - if set(config["AUTH_KEYS"].keys()) == set(self.AUTH_KEYS.keys()): - for key, value in config["AUTH_KEYS"].items(): - if type(value) is str: - self.AUTH_KEYS[key] = config["AUTH_KEYS"][key] - if "MESSAGE_FORMAT" in config.keys(): - if type(config["MESSAGE_FORMAT"]) is str: - self.MESSAGE_FORMAT = config["MESSAGE_FORMAT"] - - # Others - if "ENABLE_AUTO_CLEAR_CHATBOX" in config.keys(): - if type(config["ENABLE_AUTO_CLEAR_CHATBOX"]) is bool: - self.ENABLE_AUTO_CLEAR_CHATBOX = config["ENABLE_AUTO_CLEAR_CHATBOX"] - if "ENABLE_NOTICE_XSOVERLAY" in config.keys(): - if type(config["ENABLE_NOTICE_XSOVERLAY"]) is bool: - self.ENABLE_NOTICE_XSOVERLAY = config["ENABLE_NOTICE_XSOVERLAY"] - - with open(self.PATH_CONFIG, 'w') as fp: - config = { - # "ENABLE_TRANSLATION": self.ENABLE_TRANSLATION, - # "ENABLE_TRANSCRIPTION_SEND": self.ENABLE_TRANSCRIPTION_SEND, - # "ENABLE_TRANSCRIPTION_RECEIVE": self.ENABLE_TRANSCRIPTION_RECEIVE, - # "ENABLE_FOREGROUND": self.ENABLE_FOREGROUND, - "TRANSPARENCY": self.TRANSPARENCY, - "APPEARANCE_THEME": self.APPEARANCE_THEME, - "UI_SCALING": self.UI_SCALING, - "UI_LANGUAGE": self.UI_LANGUAGE, - "FONT_FAMILY": self.FONT_FAMILY, - "CHOICE_TRANSLATOR": self.CHOICE_TRANSLATOR, - "INPUT_SOURCE_LANG": self.INPUT_SOURCE_LANG, - "INPUT_TARGET_LANG": self.INPUT_TARGET_LANG, - "OUTPUT_SOURCE_LANG": self.OUTPUT_SOURCE_LANG, - "OUTPUT_TARGET_LANG": self.OUTPUT_TARGET_LANG, - "CHOICE_MIC_HOST": self.CHOICE_MIC_HOST, - "CHOICE_MIC_DEVICE": self.CHOICE_MIC_DEVICE, - "INPUT_MIC_VOICE_LANGUAGE": self.INPUT_MIC_VOICE_LANGUAGE, - "INPUT_MIC_ENERGY_THRESHOLD": self.INPUT_MIC_ENERGY_THRESHOLD, - "INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD": self.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD, - "INPUT_MIC_RECORD_TIMEOUT": self.INPUT_MIC_RECORD_TIMEOUT, - "INPUT_MIC_PHRASE_TIMEOUT": self.INPUT_MIC_PHRASE_TIMEOUT, - "INPUT_MIC_MAX_PHRASES": self.INPUT_MIC_MAX_PHRASES, - "INPUT_MIC_WORD_FILTER": self.INPUT_MIC_WORD_FILTER, - "CHOICE_SPEAKER_DEVICE": self.CHOICE_SPEAKER_DEVICE, - "INPUT_SPEAKER_VOICE_LANGUAGE": self.INPUT_SPEAKER_VOICE_LANGUAGE, - "INPUT_SPEAKER_ENERGY_THRESHOLD": self.INPUT_SPEAKER_ENERGY_THRESHOLD, - "INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD": self.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD, - "INPUT_SPEAKER_RECORD_TIMEOUT": self.INPUT_SPEAKER_RECORD_TIMEOUT, - "INPUT_SPEAKER_PHRASE_TIMEOUT": self.INPUT_SPEAKER_PHRASE_TIMEOUT, - "INPUT_SPEAKER_MAX_PHRASES": self.INPUT_SPEAKER_MAX_PHRASES, - "OSC_IP_ADDRESS": self.OSC_IP_ADDRESS, - "OSC_PORT": self.OSC_PORT, - "AUTH_KEYS": self.AUTH_KEYS, - "MESSAGE_FORMAT": self.MESSAGE_FORMAT, - "ENABLE_AUTO_CLEAR_CHATBOX": self.ENABLE_AUTO_CLEAR_CHATBOX, - "ENABLE_NOTICE_XSOVERLAY": self.ENABLE_NOTICE_XSOVERLAY, - } - json_dump(config, fp, indent=4) - ## set UI theme - customtkinter.set_appearance_mode(self.APPEARANCE_THEME) + customtkinter.set_appearance_mode(config.APPEARANCE_THEME) customtkinter.set_default_color_theme("blue") + ## flags + self.ENABLE_OSC = False + self.UPDATE_FLAG = False + # init main window self.iconbitmap(os_path.join(os_path.dirname(__file__), "img", "app.ico")) self.title("VRCT") @@ -289,7 +60,7 @@ class App(CTk): onvalue=True, offvalue=False, command=self.checkbox_translation_callback, - font=CTkFont(family=self.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.checkbox_translation.grid(row=0, column=0, columnspan=2, padx=10, pady=(5, 5), sticky="we") @@ -300,7 +71,7 @@ class App(CTk): onvalue=True, offvalue=False, command=self.checkbox_transcription_send_callback, - font=CTkFont(family=self.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.checkbox_transcription_send.grid(row=1, column=0, columnspan=2, padx=10, pady=(5, 5), sticky="we") @@ -311,7 +82,7 @@ class App(CTk): onvalue=True, offvalue=False, command=self.checkbox_transcription_receive_callback, - font=CTkFont(family=self.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.checkbox_transcription_receive.grid(row=2, column=0, columnspan=2, padx=10, pady=(5, 5), sticky="we") @@ -322,7 +93,7 @@ class App(CTk): onvalue=True, offvalue=False, command=self.checkbox_foreground_callback, - font=CTkFont(family=self.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.checkbox_foreground.grid(row=3, column=0, columnspan=2, padx=10, pady=(5, 5), sticky="we") @@ -347,7 +118,7 @@ class App(CTk): self.button_config.grid(row=5, column=1, padx=(5, 10), pady=(5, 5), sticky="wse") # load ui language data - language_yaml_data = get_localized_text(f"{self.UI_LANGUAGE}") + language_yaml_data = get_localized_text(f"{config.UI_LANGUAGE}") # add tabview textbox self.add_tabview_logs(language_yaml_data) @@ -355,13 +126,13 @@ class App(CTk): self.entry_message_box = CTkEntry( self, placeholder_text="message", - font=CTkFont(family=self.FONT_FAMILY), + font=CTkFont(family=config.FONT_FAMILY), ) self.entry_message_box.grid(row=1, column=1, columnspan=2, padx=5, pady=(5, 10), sticky="nsew") # set default values ## set translator - if self.translator.authentication(self.CHOICE_TRANSLATOR, self.AUTH_KEYS[self.CHOICE_TRANSLATOR]) is False: + if self.translator.authentication(config.CHOICE_TRANSLATOR, config.AUTH_KEYS[config.CHOICE_TRANSLATOR]) is False: # error update Auth key print_textbox(self.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") print_textbox(self.textbox_message_system_log, "Auth Key or language setting is incorrect", "ERROR") @@ -395,7 +166,7 @@ class App(CTk): # self.checkbox_foreground.deselect() ## set word filter - for f in self.INPUT_MIC_WORD_FILTER: + for f in config.INPUT_MIC_WORD_FILTER: self.keyword_processor.add_keyword(f) ## set bind entry message box @@ -404,10 +175,10 @@ class App(CTk): self.entry_message_box.bind("", self.entry_message_box_leave) ## set transparency for main window - self.wm_attributes("-alpha", self.TRANSPARENCY/100) + self.wm_attributes("-alpha", config.TRANSPARENCY/100) ## set UI scale - new_scaling_float = int(self.UI_SCALING.replace("%", "")) / 100 + new_scaling_float = int(config.UI_SCALING.replace("%", "")) / 100 customtkinter.set_widget_scaling(new_scaling_float) # delete window @@ -456,8 +227,7 @@ class App(CTk): self.information_window.focus() def checkbox_translation_callback(self): - self.ENABLE_TRANSLATION = self.checkbox_translation.get() - if self.ENABLE_TRANSLATION is True: + if self.checkbox_translation.get() is True: print_textbox(self.textbox_message_log, "Start translation", "INFO") print_textbox(self.textbox_message_system_log, "Start translation", "INFO") else: @@ -466,22 +236,22 @@ class App(CTk): def transcription_send_start(self): self.mic_audio_queue = Queue() - mic_device = [device for device in get_input_device_list()[self.CHOICE_MIC_HOST] if device["name"] == self.CHOICE_MIC_DEVICE][0] + mic_device = [device for device in get_input_device_list()[config.CHOICE_MIC_HOST] if device["name"] == config.CHOICE_MIC_DEVICE][0] self.mic_audio_recorder = SelectedMicRecorder( mic_device, - self.INPUT_MIC_ENERGY_THRESHOLD, - self.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD, - self.INPUT_MIC_RECORD_TIMEOUT, + config.INPUT_MIC_ENERGY_THRESHOLD, + config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD, + config.INPUT_MIC_RECORD_TIMEOUT, ) self.mic_audio_recorder.record_into_queue(self.mic_audio_queue) self.mic_transcriber = AudioTranscriber( speaker=False, source=self.mic_audio_recorder.source, - phrase_timeout=self.INPUT_MIC_PHRASE_TIMEOUT, - max_phrases=self.INPUT_MIC_MAX_PHRASES, + phrase_timeout=config.INPUT_MIC_PHRASE_TIMEOUT, + max_phrases=config.INPUT_MIC_MAX_PHRASES, ) def mic_transcript_to_chatbox(): - self.mic_transcriber.transcribe_audio_queue(self.mic_audio_queue, transcription_lang[self.INPUT_MIC_VOICE_LANGUAGE]) + self.mic_transcriber.transcribe_audio_queue(self.mic_audio_queue, transcription_lang[config.INPUT_MIC_VOICE_LANGUAGE]) message = self.mic_transcriber.get_transcript() if len(message) > 0: # word filter @@ -493,23 +263,23 @@ class App(CTk): # translate if self.checkbox_translation.get() is False: voice_message = f"{message}" - elif self.translator.translator_status[self.CHOICE_TRANSLATOR] is False: + elif self.translator.translator_status[config.CHOICE_TRANSLATOR] is False: print_textbox(self.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") print_textbox(self.textbox_message_system_log, "Auth Key or language setting is incorrect", "ERROR") voice_message = f"{message}" else: result = self.translator.translate( - translator_name=self.CHOICE_TRANSLATOR, - source_language=self.INPUT_SOURCE_LANG, - target_language=self.INPUT_TARGET_LANG, + translator_name=config.CHOICE_TRANSLATOR, + source_language=config.INPUT_SOURCE_LANG, + target_language=config.INPUT_TARGET_LANG, message=message ) - voice_message = self.MESSAGE_FORMAT.replace("[message]", message).replace("[translation]", result) + voice_message = config.MESSAGE_FORMAT.replace("[message]", message).replace("[translation]", result) if self.checkbox_transcription_send.get() is True: if self.ENABLE_OSC is True: # send OSC message - send_message(voice_message, self.OSC_IP_ADDRESS, self.OSC_PORT) + send_message(voice_message, config.OSC_IP_ADDRESS, config.OSC_PORT) else: print_textbox(self.textbox_message_log, "OSC is not enabled, please enable OSC and rejoin.", "ERROR") print_textbox(self.textbox_message_system_log, "OSC is not enabled, please enable OSC and rejoin.", "ERROR") @@ -564,48 +334,48 @@ class App(CTk): def transcription_receive_start(self): self.spk_audio_queue = Queue() - spk_device = [device for device in get_output_device_list() if device["name"] == self.CHOICE_SPEAKER_DEVICE][0] + spk_device = [device for device in get_output_device_list() if device["name"] == config.CHOICE_SPEAKER_DEVICE][0] self.spk_audio_recorder = SelectedSpeakerRecorder( spk_device, - self.INPUT_SPEAKER_ENERGY_THRESHOLD, - self.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD, - self.INPUT_SPEAKER_RECORD_TIMEOUT, + config.INPUT_SPEAKER_ENERGY_THRESHOLD, + config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD, + config.INPUT_SPEAKER_RECORD_TIMEOUT, ) self.spk_audio_recorder.record_into_queue(self.spk_audio_queue) self.spk_transcriber = AudioTranscriber( speaker=True, source=self.spk_audio_recorder.source, - phrase_timeout=self.INPUT_SPEAKER_PHRASE_TIMEOUT, - max_phrases=self.INPUT_SPEAKER_MAX_PHRASES, + phrase_timeout=config.INPUT_SPEAKER_PHRASE_TIMEOUT, + max_phrases=config.INPUT_SPEAKER_MAX_PHRASES, ) def spk_transcript_to_textbox(): - self.spk_transcriber.transcribe_audio_queue(self.spk_audio_queue, transcription_lang[self.INPUT_SPEAKER_VOICE_LANGUAGE]) + self.spk_transcriber.transcribe_audio_queue(self.spk_audio_queue, transcription_lang[config.INPUT_SPEAKER_VOICE_LANGUAGE]) message = self.spk_transcriber.get_transcript() if len(message) > 0: # translate if self.checkbox_translation.get() is False: voice_message = f"{message}" - elif self.translator.translator_status[self.CHOICE_TRANSLATOR] is False: + elif self.translator.translator_status[config.CHOICE_TRANSLATOR] is False: print_textbox(self.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") print_textbox(self.textbox_message_system_log, "Auth Key or language setting is incorrect", "ERROR") voice_message = f"{message}" else: result = self.translator.translate( - translator_name=self.CHOICE_TRANSLATOR, - source_language=self.OUTPUT_SOURCE_LANG, - target_language=self.OUTPUT_TARGET_LANG, + translator_name=config.CHOICE_TRANSLATOR, + source_language=config.OUTPUT_SOURCE_LANG, + target_language=config.OUTPUT_TARGET_LANG, message=message ) - voice_message = self.MESSAGE_FORMAT.replace("[message]", message).replace("[translation]", result) + voice_message = config.MESSAGE_FORMAT.replace("[message]", message).replace("[translation]", result) # send OSC message - # send_message(voice_message, self.OSC_IP_ADDRESS, self.OSC_PORT) + # send_message(voice_message, config.OSC_IP_ADDRESS, self.OSC_PORT) if self.checkbox_transcription_receive.get() is True: # update textbox message receive log print_textbox(self.textbox_message_log, f"{voice_message}", "RECEIVE") print_textbox(self.textbox_message_receive_log, f"{voice_message}", "RECEIVE") - if self.ENABLE_NOTICE_XSOVERLAY is True: + if config.ENABLE_NOTICE_XSOVERLAY is True: notification_xsoverlay_for_vrct(content=f"{voice_message}") self.spk_print_transcript = thread_fnc(spk_transcript_to_textbox) @@ -675,8 +445,7 @@ class App(CTk): th_transcription_receive_stop.start() def checkbox_foreground_callback(self): - self.ENABLE_FOREGROUND = self.checkbox_foreground.get() - if self.ENABLE_FOREGROUND: + if self.checkbox_foreground.get(): self.attributes("-topmost", True) print_textbox(self.textbox_message_log, "Start foreground", "INFO") print_textbox(self.textbox_message_system_log, "Start foreground", "INFO") @@ -686,24 +455,22 @@ class App(CTk): print_textbox(self.textbox_message_system_log, "Stop foreground", "INFO") def foreground_start(self): - self.ENABLE_FOREGROUND = self.checkbox_foreground.get() - if self.ENABLE_FOREGROUND: + if self.checkbox_foreground.get(): self.attributes("-topmost", True) print_textbox(self.textbox_message_log, "Start foreground", "INFO") print_textbox(self.textbox_message_system_log, "Start foreground", "INFO") def foreground_stop(self): - if self.ENABLE_FOREGROUND: + if self.checkbox_foreground.get(): self.attributes("-topmost", False) print_textbox(self.textbox_message_log, "Stop foreground", "INFO") print_textbox(self.textbox_message_system_log, "Stop foreground", "INFO") - self.ENABLE_FOREGROUND = False def entry_message_box_press_key_enter(self, event): # send OSC typing - send_typing(False, self.OSC_IP_ADDRESS, self.OSC_PORT) + send_typing(False, config.OSC_IP_ADDRESS, config.OSC_PORT) - if self.ENABLE_FOREGROUND: + if self.checkbox_foreground.get(): self.attributes("-topmost", True) message = self.entry_message_box.get() @@ -711,22 +478,22 @@ class App(CTk): # translate if self.checkbox_translation.get() is False: chat_message = f"{message}" - elif self.translator.translator_status[self.CHOICE_TRANSLATOR] is False: + elif self.translator.translator_status[config.CHOICE_TRANSLATOR] is False: print_textbox(self.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") print_textbox(self.textbox_message_system_log, "Auth Key or language setting is incorrect", "ERROR") chat_message = f"{message}" else: result = self.translator.translate( - translator_name=self.CHOICE_TRANSLATOR, - source_language=self.INPUT_SOURCE_LANG, - target_language=self.INPUT_TARGET_LANG, + translator_name=config.CHOICE_TRANSLATOR, + source_language=config.INPUT_SOURCE_LANG, + target_language=config.INPUT_TARGET_LANG, message=message ) - chat_message = self.MESSAGE_FORMAT.replace("[message]", message).replace("[translation]", result) + chat_message = config.MESSAGE_FORMAT.replace("[message]", message).replace("[translation]", result) # send OSC message if self.ENABLE_OSC is True: - send_message(chat_message, self.OSC_IP_ADDRESS, self.OSC_PORT) + send_message(chat_message, config.OSC_IP_ADDRESS, config.OSC_PORT) else: print_textbox(self.textbox_message_log, "OSC is not enabled, please enable OSC and rejoin.", "ERROR") print_textbox(self.textbox_message_system_log, "OSC is not enabled, please enable OSC and rejoin.", "ERROR") @@ -736,7 +503,7 @@ class App(CTk): print_textbox(self.textbox_message_send_log, f"{chat_message}", "SEND") # delete message in entry message box - if self.ENABLE_AUTO_CLEAR_CHATBOX is True: + if config.ENABLE_AUTO_CLEAR_CHATBOX is True: self.entry_message_box.delete(0, customtkinter.END) BREAK_KEYSYM_LIST = [ @@ -745,8 +512,8 @@ class App(CTk): ] def entry_message_box_press_key_any(self, event): # send OSC typing - send_typing(True, self.OSC_IP_ADDRESS, self.OSC_PORT) - if self.ENABLE_FOREGROUND: + send_typing(True, config.OSC_IP_ADDRESS, config.OSC_PORT) + if self.checkbox_foreground.get(): self.attributes("-topmost", False) if event.keysym != "??": @@ -756,8 +523,8 @@ class App(CTk): def entry_message_box_leave(self, event): # send OSC typing - send_typing(False, self.OSC_IP_ADDRESS, self.OSC_PORT) - if self.ENABLE_FOREGROUND: + send_typing(False, config.OSC_IP_ADDRESS, config.OSC_PORT) + if self.checkbox_foreground.get(): self.attributes("-topmost", True) def delete_window(self): @@ -783,7 +550,7 @@ class App(CTk): self.tabview_logs.add(main_tab_title_receive) self.tabview_logs.add(main_tab_title_system) self.tabview_logs.grid(row=0, column=1, padx=0, pady=0, sticky="nsew") - self.tabview_logs._segmented_button.configure(font=CTkFont(family=self.FONT_FAMILY)) + self.tabview_logs._segmented_button.configure(font=CTkFont(family=config.FONT_FAMILY)) self.tabview_logs._segmented_button.grid(sticky="W") self.tabview_logs.tab(main_tab_title_log).grid_rowconfigure(0, weight=1) self.tabview_logs.tab(main_tab_title_log).grid_columnconfigure(0, weight=1) @@ -798,7 +565,7 @@ class App(CTk): # add textbox message log self.textbox_message_log = CTkTextbox( self.tabview_logs.tab(main_tab_title_log), - font=CTkFont(family=self.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.textbox_message_log.grid(row=0, column=0, padx=0, pady=0, sticky="nsew") self.textbox_message_log.configure(state='disabled') @@ -806,7 +573,7 @@ class App(CTk): # add textbox message send log self.textbox_message_send_log = CTkTextbox( self.tabview_logs.tab(main_tab_title_send), - font=CTkFont(family=self.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.textbox_message_send_log.grid(row=0, column=0, padx=0, pady=0, sticky="nsew") self.textbox_message_send_log.configure(state='disabled') @@ -814,7 +581,7 @@ class App(CTk): # add textbox message receive log self.textbox_message_receive_log = CTkTextbox( self.tabview_logs.tab(main_tab_title_receive), - font=CTkFont(family=self.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.textbox_message_receive_log.grid(row=0, column=0, padx=0, pady=0, sticky="nsew") self.textbox_message_receive_log.configure(state='disabled') @@ -822,7 +589,7 @@ class App(CTk): # add textbox message system log self.textbox_message_system_log = CTkTextbox( self.tabview_logs.tab(main_tab_title_system), - font=CTkFont(family=self.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.textbox_message_system_log.grid(row=0, column=0, padx=0, pady=0, sticky="nsew") self.textbox_message_system_log.configure(state='disabled') diff --git a/config.py b/config.py new file mode 100644 index 00000000..cf5075b2 --- /dev/null +++ b/config.py @@ -0,0 +1,410 @@ +import inspect +from os import path as os_path +from json import load as json_load +from json import dump as json_dump +import tkinter as tk +from tkinter import font +from utils import save_json +from languages import transcription_lang, translators, translation_lang, selectable_languages +from audio_utils import get_input_device_list, get_output_device_list, get_default_input_device, get_default_output_device + +class Config: + _instance = None + + def __new__(cls): + if cls._instance is None: + cls._instance = super(Config, cls).__new__(cls) + cls._instance.init_config() + cls._instance.load_config() + return cls._instance + + @property + def PATH_CONFIG(self): + return self._PATH_CONFIG + + @property + def TRANSPARENCY(self): + return self._TRANSPARENCY + + @TRANSPARENCY.setter + def TRANSPARENCY(self, value): + if type(value) is int and 0 <= value <= 100: + self._TRANSPARENCY = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def APPEARANCE_THEME(self): + return self._APPEARANCE_THEME + + @APPEARANCE_THEME.setter + def APPEARANCE_THEME(self, value): + if value in ["Light", "Dark", "System"]: + self._APPEARANCE_THEME = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def UI_SCALING(self): + return self._UI_SCALING + + @UI_SCALING.setter + def UI_SCALING(self, value): + if value in ["80%", "90%", "100%", "110%", "120%"]: + self._UI_SCALING = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def FONT_FAMILY(self): + return self._FONT_FAMILY + + @FONT_FAMILY.setter + def FONT_FAMILY(self, value): + root = tk.Tk() + root.withdraw() + if value in list(font.families()): + self._FONT_FAMILY = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + root.destroy() + + @property + def UI_LANGUAGE(self): + return self._UI_LANGUAGE + + @UI_LANGUAGE.setter + def UI_LANGUAGE(self, value): + if value in list(selectable_languages.keys()): + self._UI_LANGUAGE = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def CHOICE_TRANSLATOR(self): + return self._CHOICE_TRANSLATOR + + @CHOICE_TRANSLATOR.setter + def CHOICE_TRANSLATOR(self, value): + if value in translators: + self._CHOICE_TRANSLATOR = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def INPUT_SOURCE_LANG(self): + return self._INPUT_SOURCE_LANG + + @INPUT_SOURCE_LANG.setter + def INPUT_SOURCE_LANG(self, value): + if value in list(translation_lang[self.CHOICE_TRANSLATOR]["source"].keys()): + self._INPUT_SOURCE_LANG = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def INPUT_TARGET_LANG(self): + return self._INPUT_TARGET_LANG + + @INPUT_TARGET_LANG.setter + def INPUT_TARGET_LANG(self, value): + if value in list(translation_lang[self.CHOICE_TRANSLATOR]["target"].keys()): + self._INPUT_TARGET_LANG = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def OUTPUT_SOURCE_LANG(self): + return self._OUTPUT_SOURCE_LANG + + @OUTPUT_SOURCE_LANG.setter + def OUTPUT_SOURCE_LANG(self, value): + if value in list(translation_lang[self.CHOICE_TRANSLATOR]["source"].keys()): + self._OUTPUT_SOURCE_LANG = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def OUTPUT_TARGET_LANG(self): + return self._OUTPUT_TARGET_LANG + + @OUTPUT_TARGET_LANG.setter + def OUTPUT_TARGET_LANG(self, value): + if value in list(translation_lang[self.CHOICE_TRANSLATOR]["target"].keys()): + self._OUTPUT_TARGET_LANG = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def CHOICE_MIC_HOST(self): + return self._CHOICE_MIC_HOST + + @CHOICE_MIC_HOST.setter + def CHOICE_MIC_HOST(self, value): + if value in [host for host in get_input_device_list().keys()]: + self._CHOICE_MIC_HOST = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def CHOICE_MIC_DEVICE(self): + return self._CHOICE_MIC_DEVICE + + @CHOICE_MIC_DEVICE.setter + def CHOICE_MIC_DEVICE(self, value): + if value in [device["name"] for device in get_input_device_list()[self.CHOICE_MIC_HOST]]: + self._CHOICE_MIC_DEVICE = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def INPUT_MIC_VOICE_LANGUAGE(self): + return self._INPUT_MIC_VOICE_LANGUAGE + + @INPUT_MIC_VOICE_LANGUAGE.setter + def INPUT_MIC_VOICE_LANGUAGE(self, value): + if value in list(transcription_lang.keys()): + self._INPUT_MIC_VOICE_LANGUAGE = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def INPUT_MIC_ENERGY_THRESHOLD(self): + return self._INPUT_MIC_ENERGY_THRESHOLD + + @INPUT_MIC_ENERGY_THRESHOLD.setter + def INPUT_MIC_ENERGY_THRESHOLD(self, value): + if type(value) is int: + self._INPUT_MIC_ENERGY_THRESHOLD = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD(self): + return self._INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD + + @INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD.setter + def INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD(self, value): + if type(value) is bool: + self._INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def INPUT_MIC_RECORD_TIMEOUT(self): + return self._INPUT_MIC_RECORD_TIMEOUT + + @INPUT_MIC_RECORD_TIMEOUT.setter + def INPUT_MIC_RECORD_TIMEOUT(self, value): + if type(value) is int: + self._INPUT_MIC_RECORD_TIMEOUT = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def INPUT_MIC_PHRASE_TIMEOUT(self): + return self._INPUT_MIC_PHRASE_TIMEOUT + + @INPUT_MIC_PHRASE_TIMEOUT.setter + def INPUT_MIC_PHRASE_TIMEOUT(self, value): + if type(value) is int: + self._INPUT_MIC_PHRASE_TIMEOUT = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def INPUT_MIC_MAX_PHRASES(self): + return self._INPUT_MIC_MAX_PHRASES + + @INPUT_MIC_MAX_PHRASES.setter + def INPUT_MIC_MAX_PHRASES(self, value): + if type(value) is int: + self._INPUT_MIC_MAX_PHRASES = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def INPUT_MIC_WORD_FILTER(self): + return self._INPUT_MIC_WORD_FILTER + + @INPUT_MIC_WORD_FILTER.setter + def INPUT_MIC_WORD_FILTER(self, value): + if type(value) is list: + self._INPUT_MIC_WORD_FILTER = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def CHOICE_SPEAKER_DEVICE(self): + return self._CHOICE_SPEAKER_DEVICE + + @CHOICE_SPEAKER_DEVICE.setter + def CHOICE_SPEAKER_DEVICE(self, value): + if value in [device["name"] for device in get_output_device_list()]: + speaker_device = [device for device in get_output_device_list() if device["name"] == value][0] + if get_default_output_device()["index"] == speaker_device["index"]: + self._CHOICE_SPEAKER_DEVICE = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def INPUT_SPEAKER_VOICE_LANGUAGE(self): + return self._INPUT_SPEAKER_VOICE_LANGUAGE + + @INPUT_SPEAKER_VOICE_LANGUAGE.setter + def INPUT_SPEAKER_VOICE_LANGUAGE(self, value): + if value in list(transcription_lang.keys()): + self._INPUT_SPEAKER_VOICE_LANGUAGE = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def INPUT_SPEAKER_ENERGY_THRESHOLD(self): + return self._INPUT_SPEAKER_ENERGY_THRESHOLD + + @INPUT_SPEAKER_ENERGY_THRESHOLD.setter + def INPUT_SPEAKER_ENERGY_THRESHOLD(self, value): + if type(value) is int: + self._INPUT_SPEAKER_ENERGY_THRESHOLD = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD(self): + return self._INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD + + @INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD.setter + def INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD(self, value): + if type(value) is bool: + self._INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def INPUT_SPEAKER_RECORD_TIMEOUT(self): + return self._INPUT_SPEAKER_RECORD_TIMEOUT + + @INPUT_SPEAKER_RECORD_TIMEOUT.setter + def INPUT_SPEAKER_RECORD_TIMEOUT(self, value): + if type(value) is int: + self._INPUT_SPEAKER_RECORD_TIMEOUT = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def INPUT_SPEAKER_PHRASE_TIMEOUT(self): + return self._INPUT_SPEAKER_PHRASE_TIMEOUT + + @INPUT_SPEAKER_PHRASE_TIMEOUT.setter + def INPUT_SPEAKER_PHRASE_TIMEOUT(self, value): + if type(value) is int: + self._INPUT_SPEAKER_PHRASE_TIMEOUT = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def INPUT_SPEAKER_MAX_PHRASES(self): + return self._INPUT_SPEAKER_MAX_PHRASES + + @INPUT_SPEAKER_MAX_PHRASES.setter + def INPUT_SPEAKER_MAX_PHRASES(self, value): + if type(value) is int: + self._INPUT_SPEAKER_MAX_PHRASES = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def OSC_IP_ADDRESS(self): + return self._OSC_IP_ADDRESS + + @OSC_IP_ADDRESS.setter + def OSC_IP_ADDRESS(self, value): + if type(value) is str: + self._OSC_IP_ADDRESS = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def OSC_PORT(self): + return self._OSC_PORT + + @OSC_PORT.setter + def OSC_PORT(self, value): + if type(value) is int: + self._OSC_PORT = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def AUTH_KEYS(self): + return self._AUTH_KEYS + + @AUTH_KEYS.setter + def AUTH_KEYS(self, value): + if type(value) is dict and set(value.keys()) == set(self.AUTH_KEYS.keys()): + for key, value in value.items(): + if type(value) is str: + self._AUTH_KEYS[key] = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, self.AUTH_KEYS) + + @property + def MESSAGE_FORMAT(self): + return self._MESSAGE_FORMAT + + @MESSAGE_FORMAT.setter + def MESSAGE_FORMAT(self, value): + if type(value) is str: + self._MESSAGE_FORMAT = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def ENABLE_AUTO_CLEAR_CHATBOX(self): + return self._ENABLE_AUTO_CLEAR_CHATBOX + + @ENABLE_AUTO_CLEAR_CHATBOX.setter + def ENABLE_AUTO_CLEAR_CHATBOX(self, value): + if type(value) is bool: + self._ENABLE_AUTO_CLEAR_CHATBOX = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + @property + def ENABLE_NOTICE_XSOVERLAY(self): + return self._ENABLE_NOTICE_XSOVERLAY + + @ENABLE_NOTICE_XSOVERLAY.setter + def ENABLE_NOTICE_XSOVERLAY(self, value): + if type(value) is bool: + self._ENABLE_NOTICE_XSOVERLAY = value + save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + + def init_config(self): + self._PATH_CONFIG = "./config.json" + self._TRANSPARENCY = 100 + self._APPEARANCE_THEME = "System" + self._UI_SCALING = "100%" + self._FONT_FAMILY = "Yu Gothic UI" + self._UI_LANGUAGE = "en" + self._CHOICE_TRANSLATOR = translators[0] + self._INPUT_SOURCE_LANG = list(translation_lang[self.CHOICE_TRANSLATOR]["source"].keys())[0] + self._INPUT_TARGET_LANG = list(translation_lang[self.CHOICE_TRANSLATOR]["target"].keys())[1] + self._OUTPUT_SOURCE_LANG = list(translation_lang[self.CHOICE_TRANSLATOR]["source"].keys())[1] + self._OUTPUT_TARGET_LANG = list(translation_lang[self.CHOICE_TRANSLATOR]["target"].keys())[0] + self._CHOICE_MIC_HOST = get_default_input_device()["host"]["name"] + self._CHOICE_MIC_DEVICE = get_default_input_device()["device"]["name"] + self._INPUT_MIC_VOICE_LANGUAGE = list(transcription_lang.keys())[0] + self._INPUT_MIC_ENERGY_THRESHOLD = 300 + self._INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = True + self._INPUT_MIC_RECORD_TIMEOUT = 3 + self._INPUT_MIC_PHRASE_TIMEOUT = 3 + self._INPUT_MIC_MAX_PHRASES = 10 + self._INPUT_MIC_WORD_FILTER = [] + self._CHOICE_SPEAKER_DEVICE = get_default_output_device()["name"] + self._INPUT_SPEAKER_VOICE_LANGUAGE = list(transcription_lang.keys())[1] + self._INPUT_SPEAKER_ENERGY_THRESHOLD = 300 + self._INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = True + self._INPUT_SPEAKER_RECORD_TIMEOUT = 3 + self._INPUT_SPEAKER_PHRASE_TIMEOUT = 3 + self._INPUT_SPEAKER_MAX_PHRASES = 10 + self._OSC_IP_ADDRESS = "127.0.0.1" + self._OSC_PORT = 9000 + self._AUTH_KEYS = { + "DeepL(web)": None, + "DeepL(auth)": None, + "Bing(web)": None, + "Google(web)": None, + } + self._MESSAGE_FORMAT = "[message]([translation])" + self._ENABLE_AUTO_CLEAR_CHATBOX = False + self._ENABLE_NOTICE_XSOVERLAY = False + + def load_config(self): + if os_path.isfile(self.PATH_CONFIG) is not False: + with open(self.PATH_CONFIG, 'r') as fp: + config = json_load(fp) + + for key in config.keys(): + setattr(self, key, config[key]) + + with open(self.PATH_CONFIG, 'w') as fp: + setter_methods = [ + name for name, obj in vars(type(self)).items() + if isinstance(obj, property) and obj.fset is not None + ] + config = {} + for method in setter_methods: + config[method] = getattr(self, method) + json_dump(config, fp, indent=4) + +config = Config() \ No newline at end of file diff --git a/window_config.py b/window_config.py index 346c4a03..8b28937e 100644 --- a/window_config.py +++ b/window_config.py @@ -8,7 +8,8 @@ from customtkinter import CTkToplevel, CTkTabview, CTkFont, CTkLabel, CTkSlider, from flashtext import KeywordProcessor from threading import Thread -from utils import save_json, print_textbox, thread_fnc, get_localized_text, get_key_by_value, widget_config_window_label_setter +from config import config +from utils import print_textbox, thread_fnc, get_localized_text, get_key_by_value, widget_config_window_label_setter from audio_utils import get_input_device_list, get_output_device_list, get_default_output_device from audio_recorder import SelectedMicEnergyRecorder, SelectedSpeakeEnergyRecorder from languages import translation_lang, transcription_lang, selectable_languages @@ -42,7 +43,7 @@ class ToplevelWindowConfig(CTkToplevel): self.speaker_energy_plot_progressbar = None # load ui language data - language_yaml_data = get_localized_text(f"{self.parent.UI_LANGUAGE}") + language_yaml_data = get_localized_text(f"{config.UI_LANGUAGE}") # add tabview config self.add_tabview_config(language_yaml_data, selectable_languages) # set all config window labels @@ -52,23 +53,20 @@ class ToplevelWindowConfig(CTkToplevel): def slider_transparency_callback(self, value): self.parent.wm_attributes("-alpha", value/100) - self.parent.TRANSPARENCY = value - save_json(self.parent.PATH_CONFIG, "TRANSPARENCY", self.parent.TRANSPARENCY) + config.TRANSPARENCY = value def optionmenu_appearance_theme_callback(self, choice): self.optionmenu_appearance_theme.set(choice) customtkinter.set_appearance_mode(choice) - self.parent.APPEARANCE_THEME = choice - save_json(self.parent.PATH_CONFIG, "APPEARANCE_THEME", self.parent.APPEARANCE_THEME) + config.APPEARANCE_THEME = choice def optionmenu_ui_scaling_callback(self, choice): self.optionmenu_ui_scaling.set(choice) new_scaling_float = int(choice.replace("%", "")) / 100 customtkinter.set_widget_scaling(new_scaling_float) - self.parent.UI_SCALING = choice - save_json(self.parent.PATH_CONFIG, "UI_SCALING", self.parent.UI_SCALING) + config.UI_SCALING = choice def optionmenu_font_family_callback(self, choice): self.optionmenu_font_family.set(choice) @@ -176,18 +174,15 @@ class ToplevelWindowConfig(CTkToplevel): except: pass - self.parent.FONT_FAMILY = choice - save_json(self.parent.PATH_CONFIG, "FONT_FAMILY", self.parent.FONT_FAMILY) + config.FONT_FAMILY = choice def optionmenu_ui_language_callback(self, choice): self.optionmenu_ui_language.set(choice) self.withdraw() - pre_language_yaml_data = get_localized_text(f"{self.parent.UI_LANGUAGE}") - self.parent.UI_LANGUAGE = get_key_by_value(selectable_languages, choice) - language_yaml_data = get_localized_text(f"{self.parent.UI_LANGUAGE}") - save_json(self.parent.PATH_CONFIG, "UI_LANGUAGE", self.parent.UI_LANGUAGE) - + pre_language_yaml_data = get_localized_text(f"{config.UI_LANGUAGE}") + config.UI_LANGUAGE = get_key_by_value(selectable_languages, choice) + language_yaml_data = get_localized_text(f"{config.UI_LANGUAGE}") # delete self.parent.delete_tabview_logs(pre_language_yaml_data) @@ -207,7 +202,7 @@ class ToplevelWindowConfig(CTkToplevel): def optionmenu_translation_translator_callback(self, choice): self.optionmenu_translation_translator.set(choice) - if self.parent.translator.authentication(choice, self.parent.AUTH_KEYS[choice]) is False: + if self.parent.translator.authentication(choice, config.AUTH_KEYS[choice]) is False: print_textbox(self.parent.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") print_textbox(self.parent.textbox_message_system_log, "Auth Key or language setting is incorrect", "ERROR") else: @@ -234,44 +229,30 @@ class ToplevelWindowConfig(CTkToplevel): self.scrollableDropdown_translation_output_target_language.configure( values=list(translation_lang[choice]["target"].keys())) - self.parent.CHOICE_TRANSLATOR = choice - self.parent.INPUT_SOURCE_LANG = list(translation_lang[choice]["source"].keys())[0] - self.parent.INPUT_TARGET_LANG = list(translation_lang[choice]["target"].keys())[1] - self.parent.OUTPUT_SOURCE_LANG = list(translation_lang[choice]["source"].keys())[1] - self.parent.OUTPUT_TARGET_LANG = list(translation_lang[choice]["target"].keys())[0] - save_json(self.parent.PATH_CONFIG, "CHOICE_TRANSLATOR", self.parent.CHOICE_TRANSLATOR) - save_json(self.parent.PATH_CONFIG, "INPUT_SOURCE_LANG", self.parent.INPUT_SOURCE_LANG) - save_json(self.parent.PATH_CONFIG, "INPUT_TARGET_LANG", self.parent.INPUT_TARGET_LANG) - save_json(self.parent.PATH_CONFIG, "OUTPUT_SOURCE_LANG", self.parent.OUTPUT_SOURCE_LANG) - save_json(self.parent.PATH_CONFIG, "OUTPUT_TARGET_LANG", self.parent.OUTPUT_TARGET_LANG) + config.CHOICE_TRANSLATOR = choice + config.INPUT_SOURCE_LANG = list(translation_lang[choice]["source"].keys())[0] + config.INPUT_TARGET_LANG = list(translation_lang[choice]["target"].keys())[1] + config.OUTPUT_SOURCE_LANG = list(translation_lang[choice]["source"].keys())[1] + config.OUTPUT_TARGET_LANG = list(translation_lang[choice]["target"].keys())[0] def optionmenu_translation_input_source_language_callback(self, choice): self.optionmenu_translation_input_source_language.set(choice) - - self.parent.INPUT_SOURCE_LANG = choice - save_json(self.parent.PATH_CONFIG, "INPUT_SOURCE_LANG", self.parent.INPUT_SOURCE_LANG) + config.INPUT_SOURCE_LANG = choice def optionmenu_translation_input_target_language_callback(self, choice): self.optionmenu_translation_input_target_language.set(choice) - - self.parent.INPUT_TARGET_LANG = choice - save_json(self.parent.PATH_CONFIG, "INPUT_TARGET_LANG", self.parent.INPUT_TARGET_LANG) + config.INPUT_TARGET_LANG = choice def optionmenu_translation_output_source_language_callback(self, choice): self.optionmenu_translation_output_source_language.set(choice) - - self.parent.OUTPUT_SOURCE_LANG = choice - save_json(self.parent.PATH_CONFIG, "OUTPUT_SOURCE_LANG", self.parent.OUTPUT_SOURCE_LANG) + config.OUTPUT_SOURCE_LANG = choice def optionmenu_translation_output_target_language_callback(self, choice): self.optionmenu_translation_output_target_language.set(choice) - - self.parent.OUTPUT_TARGET_LANG = choice - save_json(self.parent.PATH_CONFIG, "OUTPUT_TARGET_LANG", self.parent.OUTPUT_TARGET_LANG) + config.OUTPUT_TARGET_LANG = choice def optionmenu_input_mic_host_callback(self, choice): self.optionmenu_input_mic_host.set(choice) - self.optionmenu_input_mic_device.configure( values=[device["name"] for device in get_input_device_list()[choice]], variable=StringVar(value=[device["name"] for device in get_input_device_list()[choice]][0])) @@ -279,24 +260,18 @@ class ToplevelWindowConfig(CTkToplevel): if SCROLLABLE_DROPDOWN: self.scrollableDropdown_input_mic_device.configure(values=[device["name"] for device in get_input_device_list()[choice]]) - self.parent.CHOICE_MIC_HOST = choice - self.parent.CHOICE_MIC_DEVICE = [device["name"] for device in get_input_device_list()[choice]][0] - save_json(self.parent.PATH_CONFIG, "CHOICE_MIC_HOST", self.parent.CHOICE_MIC_HOST) - save_json(self.parent.PATH_CONFIG, "CHOICE_MIC_DEVICE", self.parent.CHOICE_MIC_DEVICE) + config.CHOICE_MIC_HOST = choice + config.CHOICE_MIC_DEVICE = [device["name"] for device in get_input_device_list()[choice]][0] def optionmenu_input_mic_device_callback(self, choice): self.optionmenu_input_mic_device.set(choice) - - self.parent.CHOICE_MIC_DEVICE = choice - save_json(self.parent.PATH_CONFIG, "CHOICE_MIC_DEVICE", self.parent.CHOICE_MIC_DEVICE) + config.CHOICE_MIC_DEVICE = choice self.checkbox_input_mic_threshold_check.deselect() self.checkbox_input_mic_threshold_check_callback() def optionmenu_input_mic_voice_language_callback(self, choice): self.optionmenu_input_mic_voice_language.set(choice) - - self.parent.INPUT_MIC_VOICE_LANGUAGE = choice - save_json(self.parent.PATH_CONFIG, "INPUT_MIC_VOICE_LANGUAGE", self.parent.INPUT_MIC_VOICE_LANGUAGE) + config.INPUT_MIC_VOICE_LANGUAGE = choice def progressBar_input_mic_energy_plot(self): if self.mic_energy_queue.empty() is False: @@ -309,7 +284,7 @@ class ToplevelWindowConfig(CTkToplevel): def mic_threshold_check_start(self): self.mic_energy_queue = Queue() - mic_device = [device for device in get_input_device_list()[self.parent.CHOICE_MIC_HOST] if device["name"] == self.parent.CHOICE_MIC_DEVICE][0] + mic_device = [device for device in get_input_device_list()[config.CHOICE_MIC_HOST] if device["name"] == config.CHOICE_MIC_DEVICE][0] self.mic_energy_recorder = SelectedMicEnergyRecorder(mic_device) self.mic_energy_recorder.record_into_queue(self.mic_energy_queue) self.mic_energy_plot_progressbar = thread_fnc(self.progressBar_input_mic_energy_plot) @@ -341,55 +316,45 @@ class ToplevelWindowConfig(CTkToplevel): th_mic_threshold_check_stop.start() def slider_input_mic_energy_threshold_callback(self, value): - self.parent.INPUT_MIC_ENERGY_THRESHOLD = int(value) - save_json(self.parent.PATH_CONFIG, "INPUT_MIC_ENERGY_THRESHOLD", self.parent.INPUT_MIC_ENERGY_THRESHOLD) + config.INPUT_MIC_ENERGY_THRESHOLD = int(value) def checkbox_input_mic_dynamic_energy_threshold_callback(self): - value = self.checkbox_input_mic_dynamic_energy_threshold.get() - self.parent.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = value - save_json(self.parent.PATH_CONFIG, "INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD", self.parent.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD) + config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = self.checkbox_input_mic_dynamic_energy_threshold.get() def entry_input_mic_record_timeout_callback(self, event): - self.parent.INPUT_MIC_RECORD_TIMEOUT = int(self.entry_input_mic_record_timeout.get()) - save_json(self.parent.PATH_CONFIG, "INPUT_MIC_RECORD_TIMEOUT", self.parent.INPUT_MIC_RECORD_TIMEOUT) + config.INPUT_MIC_RECORD_TIMEOUT = int(self.entry_input_mic_record_timeout.get()) def entry_input_mic_phrase_timeout_callback(self, event): - self.parent.INPUT_MIC_PHRASE_TIMEOUT = int(self.entry_input_mic_phrase_timeout.get()) - save_json(self.parent.PATH_CONFIG, "INPUT_MIC_PHRASE_TIMEOUT", self.parent.INPUT_MIC_PHRASE_TIMEOUT) + config.INPUT_MIC_PHRASE_TIMEOUT = int(self.entry_input_mic_phrase_timeout.get()) def entry_input_mic_max_phrases_callback(self, event): - self.parent.INPUT_MIC_MAX_PHRASES = int(self.entry_input_mic_max_phrases.get()) - save_json(self.parent.PATH_CONFIG, "INPUT_MIC_MAX_PHRASES", self.parent.INPUT_MIC_MAX_PHRASES) + config.INPUT_MIC_MAX_PHRASES = int(self.entry_input_mic_max_phrases.get()) def entry_input_mic_word_filters_callback(self, event): word_filter = self.entry_input_mic_word_filter.get() word_filter = [w.strip() for w in word_filter.split(",") if len(w.strip()) > 0] word_filter = ",".join(word_filter) if len(word_filter) > 0: - self.parent.INPUT_MIC_WORD_FILTER = word_filter.split(",") + config.INPUT_MIC_WORD_FILTER = word_filter.split(",") else: - self.parent.INPUT_MIC_WORD_FILTER = [] + config.INPUT_MIC_WORD_FILTER = [] self.parent.keyword_processor = KeywordProcessor() for f in self.parent.INPUT_MIC_WORD_FILTER: self.parent.keyword_processor.add_keyword(f) - save_json(self.parent.PATH_CONFIG, "INPUT_MIC_WORD_FILTER", self.parent.INPUT_MIC_WORD_FILTER) def optionmenu_input_speaker_device_callback(self, choice): speaker_device = [device for device in get_output_device_list() if device["name"] == choice][0] if get_default_output_device()["index"] == speaker_device["index"]: self.optionmenu_input_speaker_device.set(choice) - self.parent.CHOICE_SPEAKER_DEVICE = choice - save_json(self.parent.PATH_CONFIG, "CHOICE_SPEAKER_DEVICE", self.parent.CHOICE_SPEAKER_DEVICE) + config.CHOICE_SPEAKER_DEVICE = choice else: print_textbox(self.parent.textbox_message_log, "Windows playback device and selected device do not match. Change the Windows playback device.", "ERROR") print_textbox(self.parent.textbox_message_system_log, "Windows playback device and selected device do not match. Change the Windows playback device.", "ERROR") - self.optionmenu_input_speaker_device.configure(variable=StringVar(value=self.parent.CHOICE_SPEAKER_DEVICE)) + self.optionmenu_input_speaker_device.configure(variable=StringVar(value=config.CHOICE_SPEAKER_DEVICE)) def optionmenu_input_speaker_voice_language_callback(self, choice): self.optionmenu_input_speaker_voice_language.set(choice) - - self.parent.INPUT_SPEAKER_VOICE_LANGUAGE = choice - save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_VOICE_LANGUAGE", self.parent.INPUT_SPEAKER_VOICE_LANGUAGE) + config.INPUT_SPEAKER_VOICE_LANGUAGE = choice def progressBar_input_speaker_energy_plot(self): if self.speaker_energy_queue.empty() is False: @@ -406,7 +371,7 @@ class ToplevelWindowConfig(CTkToplevel): self.speaker_energy_queue.put(energy) def speaker_threshold_check_start(self): - speaker_device = [device for device in get_output_device_list() if device["name"] == self.parent.CHOICE_SPEAKER_DEVICE][0] + speaker_device = [device for device in get_output_device_list() if device["name"] == config.CHOICE_SPEAKER_DEVICE][0] if get_default_output_device()["index"] == speaker_device["index"]: self.speaker_energy_queue = Queue() @@ -448,54 +413,43 @@ class ToplevelWindowConfig(CTkToplevel): th_speaker_threshold_check_stop.start() def slider_input_speaker_energy_threshold_callback(self, value): - self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD = int(value) - save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_ENERGY_THRESHOLD", self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD) + config.INPUT_SPEAKER_ENERGY_THRESHOLD = int(value) def checkbox_input_speaker_dynamic_energy_threshold_callback(self): - value = self.checkbox_input_speaker_dynamic_energy_threshold.get() - self.parent.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = value - save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD", self.parent.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD) + config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = self.checkbox_input_speaker_dynamic_energy_threshold.get() def entry_input_speaker_record_timeout_callback(self, event): - self.parent.INPUT_SPEAKER_RECORD_TIMEOUT = int(self.entry_input_speaker_record_timeout.get()) - save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_RECORD_TIMEOUT", self.parent.INPUT_SPEAKER_RECORD_TIMEOUT) + config.INPUT_SPEAKER_RECORD_TIMEOUT = int(self.entry_input_speaker_record_timeout.get()) def entry_input_speaker_phrase_timeout_callback(self, event): - self.parent.INPUT_SPEAKER_PHRASE_TIMEOUT = int(self.entry_input_speaker_phrase_timeout.get()) - save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_PHRASE_TIMEOUT", self.parent.INPUT_SPEAKER_PHRASE_TIMEOUT) + config.INPUT_SPEAKER_PHRASE_TIMEOUT = int(self.entry_input_speaker_phrase_timeout.get()) def entry_input_speaker_max_phrases_callback(self, event): - self.parent.INPUT_SPEAKER_MAX_PHRASES = int(self.entry_input_speaker_max_phrases.get()) - save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_MAX_PHRASES", self.parent.INPUT_SPEAKER_MAX_PHRASES) + config.INPUT_SPEAKER_MAX_PHRASES = int(self.entry_input_speaker_max_phrases.get()) def entry_ip_address_callback(self, event): - self.parent.OSC_IP_ADDRESS = self.entry_ip_address.get() - save_json(self.parent.PATH_CONFIG, "OSC_IP_ADDRESS", self.parent.OSC_IP_ADDRESS) + config.OSC_IP_ADDRESS = self.entry_ip_address.get() def entry_port_callback(self, event): - self.parent.OSC_PORT = self.entry_port.get() - save_json(self.parent.PATH_CONFIG, "OSC_PORT", self.parent.OSC_PORT) + config.OSC_PORT = self.entry_port.get() def entry_authkey_callback(self, event): value = self.entry_authkey.get() if len(value) > 0: if self.parent.translator.authentication("DeepL(auth)", value) is True: - self.parent.AUTH_KEYS["DeepL(auth)"] = value - save_json(self.parent.PATH_CONFIG, "AUTH_KEYS", self.parent.AUTH_KEYS) + auth_keys = config.AUTH_KEYS + auth_keys["DeepL(auth)"] = value + config.AUTH_KEYS = auth_keys 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") else: pass def checkbox_auto_clear_chatbox_callback(self): - value = self.checkbox_auto_clear_chatbox.get() - self.parent.ENABLE_AUTO_CLEAR_CHATBOX = value - save_json(self.parent.PATH_CONFIG, "ENABLE_AUTO_CLEAR_CHATBOX", self.parent.ENABLE_AUTO_CLEAR_CHATBOX) + config.ENABLE_AUTO_CLEAR_CHATBOX = self.checkbox_auto_clear_chatbox.get() def checkbox_notice_xsoverlay_callback(self): - value = self.checkbox_notice_xsoverlay.get() - self.parent.ENABLE_NOTICE_XSOVERLAY = value - save_json(self.parent.PATH_CONFIG, "ENABLE_NOTICE_XSOVERLAY", self.parent.ENABLE_NOTICE_XSOVERLAY) + config.ENABLE_NOTICE_XSOVERLAY = self.checkbox_notice_xsoverlay.get() def delete_window(self): self.checkbox_input_mic_threshold_check.deselect() @@ -522,8 +476,7 @@ class ToplevelWindowConfig(CTkToplevel): def entry_message_format_callback(self, event): value = self.entry_message_format.get() if len(value) > 0: - self.parent.MESSAGE_FORMAT = value - save_json(self.parent.PATH_CONFIG, "MESSAGE_FORMAT", self.parent.MESSAGE_FORMAT) + config.MESSAGE_FORMAT = value def delete_tabview_config(self, pre_language_yaml_data): self.tabview_config.delete(pre_language_yaml_data["config_tab_title_ui"]) @@ -554,7 +507,7 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_transcription).grid_columnconfigure(1, weight=1) self.tabview_config.tab(config_tab_title_parameter).grid_columnconfigure(1, weight=1) self.tabview_config.tab(config_tab_title_others).grid_columnconfigure(1, weight=1) - self.tabview_config._segmented_button.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + self.tabview_config._segmented_button.configure(font=CTkFont(family=config.FONT_FAMILY)) self.tabview_config._segmented_button.grid(sticky="W") # tab UI @@ -566,7 +519,7 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_ui), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_transparency.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.slider_transparency = CTkSlider( @@ -574,7 +527,7 @@ class ToplevelWindowConfig(CTkToplevel): from_=50, to=100, command=self.slider_transparency_callback, - variable=DoubleVar(value=self.parent.TRANSPARENCY), + variable=DoubleVar(value=config.TRANSPARENCY), ) self.slider_transparency.grid(row=row, column=1, columnspan=1, padx=padx, pady=10, sticky="nsew") @@ -584,16 +537,16 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_ui), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_appearance_theme.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.optionmenu_appearance_theme = CTkOptionMenu( self.tabview_config.tab(config_tab_title_ui), values=["Light", "Dark", "System"], command=self.optionmenu_appearance_theme_callback, - variable=StringVar(value=self.parent.APPEARANCE_THEME), - font=CTkFont(family=self.parent.FONT_FAMILY), - dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), + variable=StringVar(value=config.APPEARANCE_THEME), + font=CTkFont(family=config.FONT_FAMILY), + dropdown_font=CTkFont(family=config.FONT_FAMILY), ) self.optionmenu_appearance_theme.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") @@ -605,7 +558,7 @@ class ToplevelWindowConfig(CTkToplevel): justify="left", button_color="transparent", command=self.optionmenu_appearance_theme_callback, - font=CTkFont(family=self.parent.FONT_FAMILY), + font=CTkFont(family=config.FONT_FAMILY), ) self.scrollableDropdown_appearance_theme.bind( "", @@ -618,16 +571,16 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_ui), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_ui_scaling.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.optionmenu_ui_scaling = CTkOptionMenu( self.tabview_config.tab(config_tab_title_ui), values=["80%", "90%", "100%", "110%", "120%"], command=self.optionmenu_ui_scaling_callback, - variable=StringVar(value=self.parent.UI_SCALING), - font=CTkFont(family=self.parent.FONT_FAMILY), - dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), + variable=StringVar(value=config.UI_SCALING), + font=CTkFont(family=config.FONT_FAMILY), + dropdown_font=CTkFont(family=config.FONT_FAMILY), ) self.optionmenu_ui_scaling.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") @@ -639,7 +592,7 @@ class ToplevelWindowConfig(CTkToplevel): justify="left", button_color="transparent", command=self.optionmenu_ui_scaling_callback, - font=CTkFont(family=self.parent.FONT_FAMILY), + font=CTkFont(family=config.FONT_FAMILY), ) self.scrollableDropdown_ui_scaling.bind( "", @@ -652,7 +605,7 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_ui), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_font_family.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") font_families = list(tk_font.families()) @@ -660,9 +613,9 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_ui), values=font_families, command=self.optionmenu_font_family_callback, - variable=StringVar(value=self.parent.FONT_FAMILY), - font=CTkFont(family=self.parent.FONT_FAMILY), - dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), + variable=StringVar(value=config.FONT_FAMILY), + font=CTkFont(family=config.FONT_FAMILY), + dropdown_font=CTkFont(family=config.FONT_FAMILY), ) self.optionmenu_font_family.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") @@ -674,7 +627,7 @@ class ToplevelWindowConfig(CTkToplevel): justify="left", button_color="transparent", command=self.optionmenu_font_family_callback, - font=CTkFont(family=self.parent.FONT_FAMILY), + font=CTkFont(family=config.FONT_FAMILY), ) self.scrollableDropdown_font_family.bind( "", @@ -687,7 +640,7 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_ui), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_ui_language.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") selectable_languages_values = list(selectable_languages.values()) @@ -695,9 +648,9 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_ui), values=selectable_languages_values, command=self.optionmenu_ui_language_callback, - variable=StringVar(value=selectable_languages[self.parent.UI_LANGUAGE]), - font=CTkFont(family=self.parent.FONT_FAMILY), - dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), + variable=StringVar(value=selectable_languages[config.UI_LANGUAGE]), + font=CTkFont(family=config.FONT_FAMILY), + dropdown_font=CTkFont(family=config.FONT_FAMILY), ) self.optionmenu_ui_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") @@ -709,7 +662,7 @@ class ToplevelWindowConfig(CTkToplevel): justify="left", button_color="transparent", command=self.optionmenu_ui_language_callback, - font=CTkFont(family=self.parent.FONT_FAMILY), + font=CTkFont(family=config.FONT_FAMILY), ) self.scrollableDropdown_ui_language.bind( "", @@ -725,16 +678,16 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_translation), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY), + font=CTkFont(family=config.FONT_FAMILY), ) self.label_translation_translator.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.optionmenu_translation_translator = CTkOptionMenu( self.tabview_config.tab(config_tab_title_translation), values=list(self.parent.translator.translator_status.keys()), command=self.optionmenu_translation_translator_callback, - variable=StringVar(value=self.parent.CHOICE_TRANSLATOR), - font=CTkFont(family=self.parent.FONT_FAMILY), - dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), + variable=StringVar(value=config.CHOICE_TRANSLATOR), + font=CTkFont(family=config.FONT_FAMILY), + dropdown_font=CTkFont(family=config.FONT_FAMILY), ) self.optionmenu_translation_translator.grid(row=row, column=1, columnspan=3, padx=padx, pady=pady, sticky="nsew") @@ -746,7 +699,7 @@ class ToplevelWindowConfig(CTkToplevel): justify="left", button_color="transparent", command=self.optionmenu_translation_translator_callback, - font=CTkFont(family=self.parent.FONT_FAMILY), + font=CTkFont(family=config.FONT_FAMILY), ) self.scrollableDropdown_translation_translator.bind( "", @@ -759,7 +712,7 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_translation), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_translation_input_language.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") @@ -767,10 +720,10 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_translation_input_source_language = CTkOptionMenu( self.tabview_config.tab(config_tab_title_translation), command=self.optionmenu_translation_input_source_language_callback, - values=list(translation_lang[self.parent.CHOICE_TRANSLATOR]["source"].keys()), - variable=StringVar(value=self.parent.INPUT_SOURCE_LANG), - font=CTkFont(family=self.parent.FONT_FAMILY), - dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), + values=list(translation_lang[config.CHOICE_TRANSLATOR]["source"].keys()), + variable=StringVar(value=config.INPUT_SOURCE_LANG), + font=CTkFont(family=config.FONT_FAMILY), + dropdown_font=CTkFont(family=config.FONT_FAMILY), ) self.optionmenu_translation_input_source_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") @@ -778,11 +731,11 @@ class ToplevelWindowConfig(CTkToplevel): if SCROLLABLE_DROPDOWN: self.scrollableDropdown_translation_input_source_language = CTkScrollableDropdown( self.optionmenu_translation_input_source_language, - values=list(translation_lang[self.parent.CHOICE_TRANSLATOR]["source"].keys()), + values=list(translation_lang[config.CHOICE_TRANSLATOR]["source"].keys()), justify="left", button_color="transparent", command=self.optionmenu_translation_input_source_language_callback, - font=CTkFont(family=self.parent.FONT_FAMILY), + font=CTkFont(family=config.FONT_FAMILY), ) self.scrollableDropdown_translation_input_source_language.bind( "", @@ -794,7 +747,7 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_translation), text="-->", fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_translation_input_arrow.grid(row=row, column=2, columnspan=1, padx=padx, pady=pady, sticky="nsew") @@ -802,10 +755,10 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_translation_input_target_language = CTkOptionMenu( self.tabview_config.tab(config_tab_title_translation), command=self.optionmenu_translation_input_target_language_callback, - values=list(translation_lang[self.parent.CHOICE_TRANSLATOR]["target"].keys()), - variable=StringVar(value=self.parent.INPUT_TARGET_LANG), - font=CTkFont(family=self.parent.FONT_FAMILY), - dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), + values=list(translation_lang[config.CHOICE_TRANSLATOR]["target"].keys()), + variable=StringVar(value=config.INPUT_TARGET_LANG), + font=CTkFont(family=config.FONT_FAMILY), + dropdown_font=CTkFont(family=config.FONT_FAMILY), ) self.optionmenu_translation_input_target_language.grid(row=row, column=3, columnspan=1, padx=padx, pady=pady, sticky="nsew") @@ -813,11 +766,11 @@ class ToplevelWindowConfig(CTkToplevel): if SCROLLABLE_DROPDOWN: self.scrollableDropdown_translation_input_target_language = CTkScrollableDropdown( self.optionmenu_translation_input_target_language, - values=list(translation_lang[self.parent.CHOICE_TRANSLATOR]["target"].keys()), + values=list(translation_lang[config.CHOICE_TRANSLATOR]["target"].keys()), justify="left", button_color="transparent", command=self.optionmenu_translation_input_target_language_callback, - font=CTkFont(family=self.parent.FONT_FAMILY), + font=CTkFont(family=config.FONT_FAMILY), ) self.scrollableDropdown_translation_input_target_language.bind( "", @@ -830,7 +783,7 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_translation), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_translation_output_language.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") @@ -838,10 +791,10 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_translation_output_source_language = CTkOptionMenu( self.tabview_config.tab(config_tab_title_translation), command=self.optionmenu_translation_output_source_language_callback, - values=list(translation_lang[self.parent.CHOICE_TRANSLATOR]["source"].keys()), - variable=StringVar(value=self.parent.OUTPUT_SOURCE_LANG), - font=CTkFont(family=self.parent.FONT_FAMILY), - dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), + values=list(translation_lang[config.CHOICE_TRANSLATOR]["source"].keys()), + variable=StringVar(value=config.OUTPUT_SOURCE_LANG), + font=CTkFont(family=config.FONT_FAMILY), + dropdown_font=CTkFont(family=config.FONT_FAMILY), ) self.optionmenu_translation_output_source_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") @@ -849,11 +802,11 @@ class ToplevelWindowConfig(CTkToplevel): if SCROLLABLE_DROPDOWN: self.scrollableDropdown_translation_output_source_language = CTkScrollableDropdown( self.optionmenu_translation_output_source_language, - values=list(translation_lang[self.parent.CHOICE_TRANSLATOR]["source"].keys()), + values=list(translation_lang[config.CHOICE_TRANSLATOR]["source"].keys()), justify="left", button_color="transparent", command=self.optionmenu_translation_output_source_language_callback, - font=CTkFont(family=self.parent.FONT_FAMILY), + font=CTkFont(family=config.FONT_FAMILY), ) self.scrollableDropdown_translation_output_source_language.bind( "", @@ -865,7 +818,7 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_translation), text="-->", fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_translation_output_arrow.grid(row=row, column=2, columnspan=1, padx=padx, pady=pady, sticky="nsew") @@ -873,10 +826,10 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_translation_output_target_language = CTkOptionMenu( self.tabview_config.tab(config_tab_title_translation), command=self.optionmenu_translation_output_target_language_callback, - values=list(translation_lang[self.parent.CHOICE_TRANSLATOR]["target"].keys()), - variable=StringVar(value=self.parent.OUTPUT_TARGET_LANG), - font=CTkFont(family=self.parent.FONT_FAMILY), - dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), + values=list(translation_lang[config.CHOICE_TRANSLATOR]["target"].keys()), + variable=StringVar(value=config.OUTPUT_TARGET_LANG), + font=CTkFont(family=config.FONT_FAMILY), + dropdown_font=CTkFont(family=config.FONT_FAMILY), ) self.optionmenu_translation_output_target_language.grid(row=row, column=3, columnspan=1, padx=padx, pady=pady, sticky="nsew") @@ -884,11 +837,11 @@ class ToplevelWindowConfig(CTkToplevel): if SCROLLABLE_DROPDOWN: self.scrollableDropdown_translation_output_target_language = CTkScrollableDropdown( self.optionmenu_translation_output_target_language, - values=list(translation_lang[self.parent.CHOICE_TRANSLATOR]["target"].keys()), + values=list(translation_lang[config.CHOICE_TRANSLATOR]["target"].keys()), justify="left", button_color="transparent", command=self.optionmenu_translation_output_target_language_callback, - font=CTkFont(family=self.parent.FONT_FAMILY), + font=CTkFont(family=config.FONT_FAMILY), ) self.scrollableDropdown_translation_output_target_language.bind( "", @@ -904,16 +857,16 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_transcription), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_input_mic_host.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.optionmenu_input_mic_host = CTkOptionMenu( self.tabview_config.tab(config_tab_title_transcription), values=[host for host in get_input_device_list().keys()], command=self.optionmenu_input_mic_host_callback, - variable=StringVar(value=self.parent.CHOICE_MIC_HOST), - font=CTkFont(family=self.parent.FONT_FAMILY), - dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), + variable=StringVar(value=config.CHOICE_MIC_HOST), + font=CTkFont(family=config.FONT_FAMILY), + dropdown_font=CTkFont(family=config.FONT_FAMILY), ) self.optionmenu_input_mic_host.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") @@ -925,7 +878,7 @@ class ToplevelWindowConfig(CTkToplevel): justify="left", button_color="transparent", command=self.optionmenu_input_mic_host_callback, - font=CTkFont(family=self.parent.FONT_FAMILY), + font=CTkFont(family=config.FONT_FAMILY), ) self.scrollableDropdown_input_mic_host.bind( "", @@ -938,16 +891,16 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_transcription), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_input_mic_device.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.optionmenu_input_mic_device = CTkOptionMenu( self.tabview_config.tab(config_tab_title_transcription), - values=[device["name"] for device in get_input_device_list()[self.parent.CHOICE_MIC_HOST]], + values=[device["name"] for device in get_input_device_list()[config.CHOICE_MIC_HOST]], command=self.optionmenu_input_mic_device_callback, - variable=StringVar(value=self.parent.CHOICE_MIC_DEVICE), - font=CTkFont(family=self.parent.FONT_FAMILY), - dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), + variable=StringVar(value=config.CHOICE_MIC_DEVICE), + font=CTkFont(family=config.FONT_FAMILY), + dropdown_font=CTkFont(family=config.FONT_FAMILY), ) self.optionmenu_input_mic_device.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") @@ -955,11 +908,11 @@ class ToplevelWindowConfig(CTkToplevel): if SCROLLABLE_DROPDOWN: self.scrollableDropdown_input_mic_device = CTkScrollableDropdown( self.optionmenu_input_mic_device, - values=[device["name"] for device in get_input_device_list()[self.parent.CHOICE_MIC_HOST]], + values=[device["name"] for device in get_input_device_list()[config.CHOICE_MIC_HOST]], justify="left", button_color="transparent", command=self.optionmenu_input_mic_device_callback, - font=CTkFont(family=self.parent.FONT_FAMILY), + font=CTkFont(family=config.FONT_FAMILY), ) self.scrollableDropdown_input_mic_device.bind( "", @@ -972,16 +925,16 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_transcription), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_input_mic_voice_language.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.optionmenu_input_mic_voice_language = CTkOptionMenu( self.tabview_config.tab(config_tab_title_transcription), values=list(transcription_lang.keys()), command=self.optionmenu_input_mic_voice_language_callback, - variable=StringVar(value=self.parent.INPUT_MIC_VOICE_LANGUAGE), - font=CTkFont(family=self.parent.FONT_FAMILY), - dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), + variable=StringVar(value=config.INPUT_MIC_VOICE_LANGUAGE), + font=CTkFont(family=config.FONT_FAMILY), + dropdown_font=CTkFont(family=config.FONT_FAMILY), ) self.optionmenu_input_mic_voice_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") @@ -993,7 +946,7 @@ class ToplevelWindowConfig(CTkToplevel): justify="left", button_color="transparent", command=self.optionmenu_input_mic_voice_language_callback, - font=CTkFont(family=self.parent.FONT_FAMILY), + font=CTkFont(family=config.FONT_FAMILY), ) self.scrollableDropdown_input_voice_language.bind( "", @@ -1006,7 +959,7 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_transcription), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_input_mic_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") @@ -1019,7 +972,7 @@ class ToplevelWindowConfig(CTkToplevel): button_corner_radius=3, number_of_steps=self.MAX_MIC_ENERGY_THRESHOLD, command=self.slider_input_mic_energy_threshold_callback, - variable=IntVar(value=self.parent.INPUT_MIC_ENERGY_THRESHOLD), + variable=IntVar(value=config.INPUT_MIC_ENERGY_THRESHOLD), ) self.slider_input_mic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=0, pady=5, sticky="nsew") @@ -1031,7 +984,7 @@ class ToplevelWindowConfig(CTkToplevel): onvalue=True, offvalue=False, command=self.checkbox_input_mic_threshold_check_callback, - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.checkbox_input_mic_threshold_check.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") @@ -1048,7 +1001,7 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_transcription), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_input_mic_dynamic_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.checkbox_input_mic_dynamic_energy_threshold = CTkCheckBox( @@ -1057,10 +1010,10 @@ class ToplevelWindowConfig(CTkToplevel): onvalue=True, offvalue=False, command=self.checkbox_input_mic_dynamic_energy_threshold_callback, - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.checkbox_input_mic_dynamic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - if self.parent.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD is True: + if config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD is True: self.checkbox_input_mic_dynamic_energy_threshold.select() else: self.checkbox_input_mic_dynamic_energy_threshold.deselect() @@ -1071,13 +1024,13 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_transcription), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_input_mic_record_timeout.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.entry_input_mic_record_timeout = CTkEntry( self.tabview_config.tab(config_tab_title_transcription), - textvariable=StringVar(value=self.parent.INPUT_MIC_RECORD_TIMEOUT), - font=CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=config.INPUT_MIC_RECORD_TIMEOUT), + font=CTkFont(family=config.FONT_FAMILY) ) self.entry_input_mic_record_timeout.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_input_mic_record_timeout.bind("", self.entry_input_mic_record_timeout_callback) @@ -1088,13 +1041,13 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_transcription), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_input_mic_phrase_timeout.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.entry_input_mic_phrase_timeout = CTkEntry( self.tabview_config.tab(config_tab_title_transcription), - textvariable=StringVar(value=self.parent.INPUT_MIC_PHRASE_TIMEOUT), - font=CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=config.INPUT_MIC_PHRASE_TIMEOUT), + font=CTkFont(family=config.FONT_FAMILY) ) self.entry_input_mic_phrase_timeout.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_input_mic_phrase_timeout.bind("", self.entry_input_mic_phrase_timeout_callback) @@ -1105,13 +1058,13 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_transcription), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_input_mic_max_phrases.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.entry_input_mic_max_phrases = CTkEntry( self.tabview_config.tab(config_tab_title_transcription), - textvariable=StringVar(value=self.parent.INPUT_MIC_MAX_PHRASES), - font=CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=config.INPUT_MIC_MAX_PHRASES), + font=CTkFont(family=config.FONT_FAMILY) ) self.entry_input_mic_max_phrases.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_input_mic_max_phrases.bind("", self.entry_input_mic_max_phrases_callback) @@ -1122,18 +1075,18 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_transcription), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_input_mic_word_filter.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - if len(self.parent.INPUT_MIC_WORD_FILTER) > 0: - textvariable=StringVar(value=",".join(self.parent.INPUT_MIC_WORD_FILTER)) + if len(config.INPUT_MIC_WORD_FILTER) > 0: + textvariable=StringVar(value=",".join(config.INPUT_MIC_WORD_FILTER)) else: textvariable=None self.entry_input_mic_word_filter = CTkEntry( self.tabview_config.tab(config_tab_title_transcription), textvariable=textvariable, placeholder_text="AAA,BBB,CCC", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.entry_input_mic_word_filter.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_input_mic_word_filter.bind("", self.entry_input_mic_word_filters_callback) @@ -1144,16 +1097,16 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_transcription), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_input_speaker_device.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.optionmenu_input_speaker_device = CTkOptionMenu( self.tabview_config.tab(config_tab_title_transcription), values=[device["name"] for device in get_output_device_list()], command=self.optionmenu_input_speaker_device_callback, - variable=StringVar(value=self.parent.CHOICE_SPEAKER_DEVICE), - font=CTkFont(family=self.parent.FONT_FAMILY), - dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), + variable=StringVar(value=config.CHOICE_SPEAKER_DEVICE), + font=CTkFont(family=config.FONT_FAMILY), + dropdown_font=CTkFont(family=config.FONT_FAMILY), ) self.optionmenu_input_speaker_device.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") @@ -1165,7 +1118,7 @@ class ToplevelWindowConfig(CTkToplevel): justify="left", button_color="transparent", command=self.optionmenu_input_speaker_device_callback, - font=CTkFont(family=self.parent.FONT_FAMILY), + font=CTkFont(family=config.FONT_FAMILY), ) self.scrollableDropdown_input_speaker_device.bind( "", @@ -1178,16 +1131,16 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_transcription), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_input_speaker_voice_language.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.optionmenu_input_speaker_voice_language = CTkOptionMenu( self.tabview_config.tab(config_tab_title_transcription), values=list(transcription_lang.keys()), command=self.optionmenu_input_speaker_voice_language_callback, - variable=StringVar(value=self.parent.INPUT_SPEAKER_VOICE_LANGUAGE), - font=CTkFont(family=self.parent.FONT_FAMILY), - dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), + variable=StringVar(value=config.INPUT_SPEAKER_VOICE_LANGUAGE), + font=CTkFont(family=config.FONT_FAMILY), + dropdown_font=CTkFont(family=config.FONT_FAMILY), ) self.optionmenu_input_speaker_voice_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") @@ -1199,7 +1152,7 @@ class ToplevelWindowConfig(CTkToplevel): justify="left", button_color="transparent", command=self.optionmenu_input_speaker_voice_language_callback, - font=CTkFont(family=self.parent.FONT_FAMILY), + font=CTkFont(family=config.FONT_FAMILY), ) self.scrollableDropdown_input_speaker_voice_language.bind( "", @@ -1212,7 +1165,7 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_transcription), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_input_speaker_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") @@ -1226,7 +1179,7 @@ class ToplevelWindowConfig(CTkToplevel): button_corner_radius=3, number_of_steps=self.MAX_SPEAKER_ENERGY_THRESHOLD, command=self.slider_input_speaker_energy_threshold_callback, - variable=IntVar(value=self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD), + variable=IntVar(value=config.INPUT_SPEAKER_ENERGY_THRESHOLD), ) self.slider_input_speaker_energy_threshold.grid(row=row, column=1, columnspan=1, padx=0, pady=5, sticky="nsew") @@ -1238,7 +1191,7 @@ class ToplevelWindowConfig(CTkToplevel): onvalue=True, offvalue=False, command=self.checkbox_input_speaker_threshold_check_callback, - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.checkbox_input_speaker_threshold_check.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") @@ -1255,7 +1208,7 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_transcription), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_input_speaker_dynamic_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.checkbox_input_speaker_dynamic_energy_threshold = CTkCheckBox( @@ -1264,10 +1217,10 @@ class ToplevelWindowConfig(CTkToplevel): onvalue=True, offvalue=False, command=self.checkbox_input_speaker_dynamic_energy_threshold_callback, - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.checkbox_input_speaker_dynamic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - if self.parent.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD is True: + if config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD is True: self.checkbox_input_speaker_dynamic_energy_threshold.select() else: self.checkbox_input_speaker_dynamic_energy_threshold.deselect() @@ -1278,13 +1231,13 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_transcription), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_input_speaker_record_timeout.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.entry_input_speaker_record_timeout = CTkEntry( self.tabview_config.tab(config_tab_title_transcription), - textvariable=StringVar(value=self.parent.INPUT_SPEAKER_RECORD_TIMEOUT), - font=CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=config.INPUT_SPEAKER_RECORD_TIMEOUT), + font=CTkFont(family=config.FONT_FAMILY) ) self.entry_input_speaker_record_timeout.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_input_speaker_record_timeout.bind("", self.entry_input_speaker_record_timeout_callback) @@ -1295,13 +1248,13 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_transcription), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_input_speaker_phrase_timeout.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.entry_input_speaker_phrase_timeout = CTkEntry( self.tabview_config.tab(config_tab_title_transcription), - textvariable=StringVar(value=self.parent.INPUT_SPEAKER_PHRASE_TIMEOUT), - font=CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=config.INPUT_SPEAKER_PHRASE_TIMEOUT), + font=CTkFont(family=config.FONT_FAMILY) ) self.entry_input_speaker_phrase_timeout.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_input_speaker_phrase_timeout.bind("", self.entry_input_speaker_phrase_timeout_callback) @@ -1312,13 +1265,13 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_transcription), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_input_speaker_max_phrases.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.entry_input_speaker_max_phrases = CTkEntry( self.tabview_config.tab(config_tab_title_transcription), - textvariable=StringVar(value=self.parent.INPUT_SPEAKER_MAX_PHRASES), - font=CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=config.INPUT_SPEAKER_MAX_PHRASES), + font=CTkFont(family=config.FONT_FAMILY) ) self.entry_input_speaker_max_phrases.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_input_speaker_max_phrases.bind("", self.entry_input_speaker_max_phrases_callback) @@ -1332,13 +1285,13 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_parameter), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_ip_address.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.entry_ip_address = CTkEntry( self.tabview_config.tab(config_tab_title_parameter), - textvariable=StringVar(value=self.parent.OSC_IP_ADDRESS), - font=CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=config.OSC_IP_ADDRESS), + font=CTkFont(family=config.FONT_FAMILY) ) self.entry_ip_address.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_ip_address.bind("", self.entry_ip_address_callback) @@ -1349,13 +1302,13 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_parameter), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_port.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.entry_port = CTkEntry( self.tabview_config.tab(config_tab_title_parameter), - textvariable=StringVar(value=self.parent.OSC_PORT), - font=CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=config.OSC_PORT), + font=CTkFont(family=config.FONT_FAMILY) ) self.entry_port.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_port.bind("", self.entry_port_callback) @@ -1366,13 +1319,13 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_parameter), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_authkey.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.entry_authkey = CTkEntry( self.tabview_config.tab(config_tab_title_parameter), - textvariable=StringVar(value=self.parent.AUTH_KEYS["DeepL(auth)"]), - font=CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=config.AUTH_KEYS["DeepL(auth)"]), + font=CTkFont(family=config.FONT_FAMILY) ) self.entry_authkey.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_authkey.bind("", self.entry_authkey_callback) @@ -1383,13 +1336,13 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_parameter), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_message_format.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.entry_message_format = CTkEntry( self.tabview_config.tab(config_tab_title_parameter), - textvariable=StringVar(value=self.parent.MESSAGE_FORMAT), - font=CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=config.MESSAGE_FORMAT), + font=CTkFont(family=config.FONT_FAMILY) ) self.entry_message_format.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_message_format.bind("", self.entry_message_format_callback) @@ -1401,7 +1354,7 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_others), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_checkbox_auto_clear_chatbox.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.checkbox_auto_clear_chatbox = CTkCheckBox( @@ -1410,10 +1363,10 @@ class ToplevelWindowConfig(CTkToplevel): onvalue=True, offvalue=False, command=self.checkbox_auto_clear_chatbox_callback, - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.checkbox_auto_clear_chatbox.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - if self.parent.ENABLE_AUTO_CLEAR_CHATBOX is True: + if config.ENABLE_AUTO_CLEAR_CHATBOX is True: self.checkbox_auto_clear_chatbox.select() else: self.checkbox_auto_clear_chatbox.deselect() @@ -1424,7 +1377,7 @@ class ToplevelWindowConfig(CTkToplevel): self.tabview_config.tab(config_tab_title_others), text=init_lang_text, fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.label_checkbox_notice_xsoverlay.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.checkbox_notice_xsoverlay = CTkCheckBox( @@ -1433,10 +1386,10 @@ class ToplevelWindowConfig(CTkToplevel): onvalue=True, offvalue=False, command=self.checkbox_notice_xsoverlay_callback, - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.checkbox_notice_xsoverlay.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - if self.parent.ENABLE_NOTICE_XSOVERLAY is True: + if config.ENABLE_NOTICE_XSOVERLAY is True: self.checkbox_notice_xsoverlay.select() else: self.checkbox_notice_xsoverlay.deselect() diff --git a/window_information.py b/window_information.py index 8e912c0d..cc8d8792 100644 --- a/window_information.py +++ b/window_information.py @@ -1,5 +1,6 @@ import os from customtkinter import CTkToplevel, CTkTextbox, CTkFont +from config import config class ToplevelWindowInformation(CTkToplevel): def __init__(self, parent, *args, **kwargs): @@ -16,7 +17,7 @@ class ToplevelWindowInformation(CTkToplevel): # create textbox information self.textbox_information = CTkTextbox( self, - font=CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=config.FONT_FAMILY) ) self.textbox_information.grid(row=0, column=0, padx=(10, 10), pady=(10, 10), sticky="nsew") textbox_information_message = """VRCT(v1.3.2)