diff --git a/main.py b/main.py index cfd6c49d..1d84ce3e 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,10 @@ from threading import Thread import customtkinter -from customtkinter import StringVar from vrct_gui import vrct_gui from config import config from model import model -from vrct_gui.ui_utils import setDefaultActiveTab + +from view import viewInitializer # func transcription send message def sendMicMessage(message): @@ -111,14 +111,6 @@ def messageBoxPressKeyAny(e): entry_message_box.insert("end", e.char) return "break" -def foregroundOffForcefully(e): - if config.ENABLE_FOREGROUND: - vrct_gui.attributes("-topmost", False) - -def foregroundOnForcefully(e): - if config.ENABLE_FOREGROUND: - vrct_gui.attributes("-topmost", True) - # func select languages def setYourLanguageAndCountry(select): languages = config.SELECTED_TAB_YOUR_LANGUAGES @@ -314,36 +306,28 @@ model.checkOSCStarted() model.checkSoftwareUpdated() # set UI and callback -vrct_gui.CALLBACK_TOGGLE_TRANSLATION = callbackToggleTranslation -vrct_gui.CALLBACK_TOGGLE_TRANSCRIPTION_SEND = callbackToggleTranscriptionSend -vrct_gui.CALLBACK_TOGGLE_TRANSCRIPTION_RECEIVE = callbackToggleTranscriptionReceive -vrct_gui.CALLBACK_TOGGLE_FOREGROUND = callbackToggleForeground +viewInitializer( + sidebar_features={ + "callback_toggle_translation": callbackToggleTranslation, + "callback_toggle_transcription_send": callbackToggleTranscriptionSend, + "callback_toggle_transcription_receive": callbackToggleTranscriptionReceive, + "callback_toggle_foreground": callbackToggleForeground, + }, -entry_message_box = getattr(vrct_gui, "entry_message_box") -entry_message_box.bind("", messageBoxPressKeyEnter) -entry_message_box.bind("", messageBoxPressKeyAny) -entry_message_box.bind("", foregroundOffForcefully) -entry_message_box.bind("", foregroundOnForcefully) + language_presets={ + "callback_your_language": setYourLanguageAndCountry, + "callback_target_language": setTargetLanguageAndCountry, + "values": model.getListLanguageAndCountry(), -sqls__optionmenu_your_language = getattr(vrct_gui, "sqls__optionmenu_your_language") -sqls__optionmenu_your_language.configure(values=model.getListLanguageAndCountry()) -sqls__optionmenu_your_language.configure(command=setYourLanguageAndCountry) -sqls__optionmenu_your_language.configure(variable=StringVar(value=config.SELECTED_TAB_YOUR_LANGUAGES[config.SELECTED_TAB_NO])) + "callback_selected_tab_no_1": callbackSelectedTabNo1, + "callback_selected_tab_no_2": callbackSelectedTabNo2, + "callback_selected_tab_no_3": callbackSelectedTabNo3, + }, -sqls__optionmenu_target_language = getattr(vrct_gui, "sqls__optionmenu_target_language") -sqls__optionmenu_target_language.configure(values=model.getListLanguageAndCountry()) -sqls__optionmenu_target_language.configure(command=setTargetLanguageAndCountry) -sqls__optionmenu_target_language.configure(variable=StringVar(value=config.SELECTED_TAB_TARGET_LANGUAGES[config.SELECTED_TAB_NO])) - -vrct_gui.CALLBACK_SELECTED_TAB_NO_1 = callbackSelectedTabNo1 -vrct_gui.CALLBACK_SELECTED_TAB_NO_2 = callbackSelectedTabNo2 -vrct_gui.CALLBACK_SELECTED_TAB_NO_3 = callbackSelectedTabNo3 - -vrct_gui.current_active_preset_tab = getattr(vrct_gui, f"sqls__presets_button_{config.SELECTED_TAB_NO}") -setDefaultActiveTab( - active_tab_widget=vrct_gui.current_active_preset_tab, - active_bg_color=vrct_gui.settings.main.ctm.SQLS__PRESETS_TAB_BG_ACTIVE_COLOR, - active_text_color=vrct_gui.settings.main.ctm.SQLS__PRESETS_TAB_ACTIVE_TEXT_COLOR + entry_message_box={ + "bind_Return": messageBoxPressKeyEnter, + "bind_Any_KeyPress": messageBoxPressKeyAny, + }, ) if __name__ == "__main__": diff --git a/view.py b/view.py new file mode 100644 index 00000000..e902a09b --- /dev/null +++ b/view.py @@ -0,0 +1,43 @@ +from customtkinter import StringVar +from vrct_gui import vrct_gui + +from config import config + +def viewInitializer(sidebar_features, language_presets, entry_message_box): + + vrct_gui.CALLBACK_TOGGLE_TRANSLATION = sidebar_features["callback_toggle_translation"], + vrct_gui.CALLBACK_TOGGLE_TRANSCRIPTION_SEND = sidebar_features["callback_toggle_transcription_send"], + vrct_gui.CALLBACK_TOGGLE_TRANSCRIPTION_RECEIVE = sidebar_features["callback_toggle_transcription_receive"], + vrct_gui.CALLBACK_TOGGLE_FOREGROUND = sidebar_features["callback_toggle_foreground"], + + + vrct_gui.sqls__optionmenu_your_language.configure(values=language_presets["values"]) + vrct_gui.sqls__optionmenu_your_language.configure(variable=StringVar(value=config.SELECTED_TAB_YOUR_LANGUAGES[config.SELECTED_TAB_NO])) + vrct_gui.sqls__optionmenu_target_language.configure(values=language_presets["values"]) + vrct_gui.sqls__optionmenu_target_language.configure(variable=StringVar(value=config.SELECTED_TAB_TARGET_LANGUAGES[config.SELECTED_TAB_NO])) + + vrct_gui.CALLBACK_SELECTED_TAB_NO_1 = language_presets["callback_selected_tab_no_1"] + vrct_gui.CALLBACK_SELECTED_TAB_NO_2 = language_presets["callback_selected_tab_no_2"] + vrct_gui.CALLBACK_SELECTED_TAB_NO_3 = language_presets["callback_selected_tab_no_3"] + vrct_gui.setDefaultActiveLanguagePresetTab(tab_no=config.SELECTED_TAB_NO) + + + def foregroundOffForcefully(e): + if config.ENABLE_FOREGROUND: + vrct_gui.attributes("-topmost", False) + + def foregroundOnForcefully(e): + if config.ENABLE_FOREGROUND: + vrct_gui.attributes("-topmost", True) + + + entry_message_box = getattr(vrct_gui, "entry_message_box") + entry_message_box.bind("", lambda: entry_message_box["bind_Return"]) + entry_message_box.bind("", lambda: entry_message_box["bind_Any_KeyPress"]) + entry_message_box.bind("", foregroundOffForcefully) + entry_message_box.bind("", foregroundOnForcefully) + + + + + diff --git a/vrct_gui/config_window/ConfigWindow.py b/vrct_gui/config_window/ConfigWindow.py index f0f27f5b..3e95aa62 100644 --- a/vrct_gui/config_window/ConfigWindow.py +++ b/vrct_gui/config_window/ConfigWindow.py @@ -2,8 +2,6 @@ from .widgets import createConfigWindowTitle, createSettingBoxTitle, createSideM from customtkinter import CTkToplevel -from ..ui_utils import setDefaultActiveTab - from config import config class ConfigWindow(CTkToplevel): diff --git a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/createSideMenuAndSettingsBoxContainers.py b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/createSideMenuAndSettingsBoxContainers.py index 08ef24a7..2c47507f 100644 --- a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/createSideMenuAndSettingsBoxContainers.py +++ b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/createSideMenuAndSettingsBoxContainers.py @@ -1,6 +1,6 @@ from customtkinter import CTkFrame, CTkScrollableFrame -from ....ui_utils import setDefaultActiveTab +from ....ui_utils import _setDefaultActiveTab from ._addConfigSideMenuItem import _addConfigSideMenuItem from ._createSettingBoxContainer import _createSettingBoxContainer @@ -138,7 +138,7 @@ def createSideMenuAndSettingsBoxContainers(config_window, settings): # Set default active side menu tab config_window.main_current_active_config_title.configure(text=sm_and_sbc_setting["text"]) config_window.current_active_side_menu_tab = getattr(config_window, sm_and_sbc_setting["side_menu_tab_attr_name"]) - setDefaultActiveTab( + _setDefaultActiveTab( active_tab_widget=config_window.current_active_side_menu_tab, active_bg_color=settings.ctm.SIDE_MENU_LABELS_BG_COLOR, active_text_color=settings.ctm.SIDE_MENU_LABELS_SELECTED_TEXT_COLOR diff --git a/vrct_gui/main_window/widgets/create_sidebar.py b/vrct_gui/main_window/widgets/create_sidebar.py index 0a24336b..86e6b75f 100644 --- a/vrct_gui/main_window/widgets/create_sidebar.py +++ b/vrct_gui/main_window/widgets/create_sidebar.py @@ -1,6 +1,6 @@ from customtkinter import CTkOptionMenu, CTkFont, CTkFrame, CTkLabel, CTkSwitch, CTkImage, StringVar -from ...ui_utils import getImageFileFromUiUtils, openImageKeepAspectRatio, retag, getLatestHeight, bindEnterAndLeaveColor, bindButtonPressColor, bindEnterAndLeaveFunction, bindButtonReleaseFunction, bindButtonPressAndReleaseFunction, setDefaultActiveTab, bindButtonFunctionAndColor, switchActiveTabAndPassiveTab, switchTabsColor +from ...ui_utils import getImageFileFromUiUtils, openImageKeepAspectRatio, retag, getLatestHeight, bindEnterAndLeaveColor, bindButtonPressColor, bindEnterAndLeaveFunction, bindButtonReleaseFunction, bindButtonPressAndReleaseFunction, bindButtonFunctionAndColor, switchActiveTabAndPassiveTab, switchTabsColor from time import sleep @@ -512,14 +512,6 @@ def createSidebar(settings, main_window): column+=1 - # Set default active preset tab - # main_window.current_active_preset_tab = getattr(main_window, "sqls__presets_button_1") - # setDefaultActiveTab( - # active_tab_widget=main_window.current_active_preset_tab, - # active_bg_color=settings.ctm.SQLS__PRESETS_TAB_BG_ACTIVE_COLOR, - # active_text_color=settings.ctm.SQLS__PRESETS_TAB_ACTIVE_TEXT_COLOR - # ) - # Quick Language settings BOX main_window.sqls__box_frame = CTkFrame(main_window.sqls__container, corner_radius=0, fg_color=settings.ctm.SQLS__BG_COLOR, width=0, height=0) diff --git a/vrct_gui/main_window/widgets/create_textbox.py b/vrct_gui/main_window/widgets/create_textbox.py index 1bc4a05b..c2d6f813 100644 --- a/vrct_gui/main_window/widgets/create_textbox.py +++ b/vrct_gui/main_window/widgets/create_textbox.py @@ -1,6 +1,6 @@ from customtkinter import CTkFont, CTkFrame, CTkLabel, CTkTextbox -from ...ui_utils import getLatestWidth, getLongestText, bindEnterAndLeaveColor, bindButtonPressColor, bindButtonReleaseFunction, setDefaultActiveTab, switchActiveTabAndPassiveTab, switchTabsColor +from ...ui_utils import getLatestWidth, getLongestText, bindEnterAndLeaveColor, bindButtonPressColor, bindButtonReleaseFunction, _setDefaultActiveTab, switchActiveTabAndPassiveTab, switchTabsColor def createTextbox(settings, main_window): @@ -167,7 +167,7 @@ def createTextbox(settings, main_window): # Set default active textbox tab main_window.current_active_textbox_tab = getattr(main_window, "textbox_tab_all") - setDefaultActiveTab( + _setDefaultActiveTab( active_tab_widget=main_window.current_active_textbox_tab, active_bg_color=settings.ctm.TEXTBOX_TAB_BG_ACTIVE_COLOR, active_text_color=settings.ctm.TEXTBOX_TAB_TEXT_ACTIVE_COLOR diff --git a/vrct_gui/ui_utils/__init__.py b/vrct_gui/ui_utils/__init__.py index bc2a1337..e501aebe 100644 --- a/vrct_gui/ui_utils/__init__.py +++ b/vrct_gui/ui_utils/__init__.py @@ -1 +1,2 @@ -from .ui_utils import * \ No newline at end of file +from .ui_utils import * +from .ui_utils import _setDefaultActiveTab \ No newline at end of file diff --git a/vrct_gui/ui_utils/ui_utils.py b/vrct_gui/ui_utils/ui_utils.py index eb45ea3d..d714fc3c 100644 --- a/vrct_gui/ui_utils/ui_utils.py +++ b/vrct_gui/ui_utils/ui_utils.py @@ -83,7 +83,7 @@ def unbindEventFromActiveTabWidget(active_tab_widget): active_tab_widget.unbind(event_name) active_tab_widget.children["!ctklabel"].unbind(event_name) -def setDefaultActiveTab(active_tab_widget, active_bg_color, active_text_color): +def _setDefaultActiveTab(active_tab_widget, active_bg_color, active_text_color): active_tab_widget.configure(fg_color=active_bg_color, cursor="") active_tab_widget.children["!ctklabel"].configure(fg_color=active_bg_color, text_color=active_text_color) unbindEventFromActiveTabWidget(active_tab_widget) diff --git a/vrct_gui/vrct_gui.py b/vrct_gui/vrct_gui.py index 29fb5bc2..dad8a8a6 100644 --- a/vrct_gui/vrct_gui.py +++ b/vrct_gui/vrct_gui.py @@ -10,6 +10,7 @@ from ._printToTextbox import _printToTextbox from .main_window import createMainWindowWidgets from .config_window import ConfigWindow +from .ui_utils import _setDefaultActiveTab from config import config @@ -104,5 +105,14 @@ class VRCT_GUI(CTk): tags=tags, ) + def setDefaultActiveLanguagePresetTab(self, tab_no:str): + vrct_gui.current_active_preset_tab = getattr(self, f"sqls__presets_button_{tab_no}") + _setDefaultActiveTab( + active_tab_widget=vrct_gui.current_active_preset_tab, + active_bg_color=vrct_gui.settings.main.ctm.SQLS__PRESETS_TAB_BG_ACTIVE_COLOR, + active_text_color=vrct_gui.settings.main.ctm.SQLS__PRESETS_TAB_ACTIVE_TEXT_COLOR + ) + + vrct_gui = VRCT_GUI() \ No newline at end of file