diff --git a/config.py b/config.py index 9d8d2ae0..e6199231 100644 --- a/config.py +++ b/config.py @@ -400,9 +400,9 @@ class Config: def GITHUB_URL(self): return self._GITHUB_URL - @property - def BREAK_KEYSYM_LIST(self): - return self._BREAK_KEYSYM_LIST + # @property + # def BREAK_KEYSYM_LIST(self): + # return self._BREAK_KEYSYM_LIST @property def MAX_MIC_ENERGY_THRESHOLD(self): @@ -487,10 +487,10 @@ class Config: self._ENABLE_OSC = False self._UPDATE_FLAG = False self._GITHUB_URL = "https://api.github.com/repos/misyaguziya/VRCT/releases/latest" - self._BREAK_KEYSYM_LIST = [ - "Delete", "Select", "Up", "Down", "Next", "End", "Print", - "Prior","Insert","Home", "Left", "Clear", "Right", "Linefeed" - ] + # self._BREAK_KEYSYM_LIST = [ + # "Delete", "Select", "Up", "Down", "Next", "End", "Print", + # "Prior","Insert","Home", "Left", "Clear", "Right", "Linefeed" + # ] self._MAX_MIC_ENERGY_THRESHOLD = 2000 self._MAX_SPEAKER_ENERGY_THRESHOLD = 4000 self._SELECTED_TAB_NO = "1" diff --git a/main.py b/main.py index cfd6c49d..d1a39236 100644 --- a/main.py +++ b/main.py @@ -1,22 +1,19 @@ 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 view # func transcription send message def sendMicMessage(message): if len(message) > 0: translation = "" if model.checkKeywords(message): - logDetectWordFilter(message) + view.printToTextbox_DetectedByWordFilter(detected_message=message) return elif config.ENABLE_TRANSLATION is False: pass elif model.getTranslatorStatus() is False: - logAuthenticationError() + view.printToTextbox_AuthenticationError() else: translation = model.getInputTranslate(message) @@ -29,17 +26,17 @@ def sendMicMessage(message): osc_message = message model.oscSendMessage(osc_message) else: - logOSCError() + view.printToTextbox_OSCError() - logSendMessage(message, translation) + view.printToTextbox_SentMessage(message, translation) def startTranscriptionSendMessage(): model.startMicTranscript(sendMicMessage) - vrct_gui.changeMainWindowWidgetsStatus("normal", "All") + view.setMainWindowAllWidgetsStatusToNormal() def stopTranscriptionSendMessage(): model.stopMicTranscript() - vrct_gui.changeMainWindowWidgetsStatus("normal", "All") + view.setMainWindowAllWidgetsStatusToNormal() # func transcription receive message def receiveSpeakerMessage(message): @@ -48,7 +45,7 @@ def receiveSpeakerMessage(message): if config.ENABLE_TRANSLATION is False: pass elif model.getTranslatorStatus() is False: - logAuthenticationError() + view.printToTextbox_AuthenticationError() else: translation = model.getOutputTranslate(message) @@ -57,15 +54,15 @@ def receiveSpeakerMessage(message): xsoverlay_message = config.MESSAGE_FORMAT.replace("[message]", message) xsoverlay_message = xsoverlay_message.replace("[translation]", translation) model.notificationXSOverlay(xsoverlay_message) - logReceiveMessage(message, translation) + view.printToTextbox_ReceivedMessage(message, translation) def startTranscriptionReceiveMessage(): model.startSpeakerTranscript(receiveSpeakerMessage) - vrct_gui.changeMainWindowWidgetsStatus("normal", "All") + view.setMainWindowAllWidgetsStatusToNormal() def stopTranscriptionReceiveMessage(): model.stopSpeakerTranscript() - vrct_gui.changeMainWindowWidgetsStatus("normal", "All") + view.setMainWindowAllWidgetsStatusToNormal() # func message box def sendChatMessage(message): @@ -74,7 +71,7 @@ def sendChatMessage(message): if config.ENABLE_TRANSLATION is False: pass elif model.getTranslatorStatus() is False: - logAuthenticationError() + view.printToTextbox_AuthenticationError() else: translation = model.getInputTranslate(message) @@ -87,37 +84,22 @@ def sendChatMessage(message): osc_message = message model.oscSendMessage(osc_message) else: - logOSCError() + view.printToTextbox_OSCError() # update textbox message log - logSendMessage(message, translation) + view.printToTextbox_SentMessage(message, translation) # delete message in entry message box if config.ENABLE_AUTO_CLEAR_CHATBOX is True: - entry_message_box = getattr(vrct_gui, "entry_message_box") - entry_message_box.delete(0, customtkinter.END) + view.clearMessageBox() def messageBoxPressKeyEnter(e): model.oscStopSendTyping() - entry_message_box = getattr(vrct_gui, "entry_message_box") - message = entry_message_box.get() + message = view.getTextFromMessageBox() sendChatMessage(message) def messageBoxPressKeyAny(e): model.oscStartSendTyping() - entry_message_box = getattr(vrct_gui, "entry_message_box") - if e.keysym != "??": - if len(e.char) != 0 and e.keysym in config.BREAK_KEYSYM_LIST: - 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): @@ -140,8 +122,7 @@ def setTargetLanguageAndCountry(select): def callbackSelectedTabNo1(): config.SELECTED_TAB_NO = "1" - vrct_gui.YOUR_LANGUAGE = config.SELECTED_TAB_YOUR_LANGUAGES[config.SELECTED_TAB_NO] - vrct_gui.TARGET_LANGUAGE = config.SELECTED_TAB_TARGET_LANGUAGES[config.SELECTED_TAB_NO] + view.updateGuiVariableByPresetTabNo(config.SELECTED_TAB_NO) languages = config.SELECTED_TAB_YOUR_LANGUAGES select = languages[config.SELECTED_TAB_NO] language, country = model.getLanguageAndCountry(select) @@ -156,8 +137,7 @@ def callbackSelectedTabNo1(): def callbackSelectedTabNo2(): config.SELECTED_TAB_NO = "2" - vrct_gui.YOUR_LANGUAGE = config.SELECTED_TAB_YOUR_LANGUAGES[config.SELECTED_TAB_NO] - vrct_gui.TARGET_LANGUAGE = config.SELECTED_TAB_TARGET_LANGUAGES[config.SELECTED_TAB_NO] + view.updateGuiVariableByPresetTabNo(config.SELECTED_TAB_NO) languages = config.SELECTED_TAB_YOUR_LANGUAGES select = languages[config.SELECTED_TAB_NO] language, country = model.getLanguageAndCountry(select) @@ -172,8 +152,7 @@ def callbackSelectedTabNo2(): def callbackSelectedTabNo3(): config.SELECTED_TAB_NO = "3" - vrct_gui.YOUR_LANGUAGE = config.SELECTED_TAB_YOUR_LANGUAGES[config.SELECTED_TAB_NO] - vrct_gui.TARGET_LANGUAGE = config.SELECTED_TAB_TARGET_LANGUAGES[config.SELECTED_TAB_NO] + view.updateGuiVariableByPresetTabNo(config.SELECTED_TAB_NO) languages = config.SELECTED_TAB_YOUR_LANGUAGES select = languages[config.SELECTED_TAB_NO] language, country = model.getLanguageAndCountry(select) @@ -186,123 +165,59 @@ def callbackSelectedTabNo3(): config.TARGET_COUNTRY = country config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE) -# func print textbox -def logTranslationStatusChange(): - textbox_all = getattr(vrct_gui, "textbox_all") - textbox_system = getattr(vrct_gui, "textbox_system") - if config.ENABLE_TRANSLATION is True: - vrct_gui.printToTextbox(textbox_all, "翻訳機能をONにしました", "", "INFO") - vrct_gui.printToTextbox(textbox_system, "翻訳機能をONにしました", "", "INFO") - else: - vrct_gui.printToTextbox(textbox_all, "翻訳機能をOFFにしました", "", "INFO") - vrct_gui.printToTextbox(textbox_system, "翻訳機能をOFFにしました", "", "INFO") - -def logTranscriptionSendStatusChange(): - textbox_all = getattr(vrct_gui, "textbox_all") - textbox_system = getattr(vrct_gui, "textbox_system") - if config.ENABLE_TRANSCRIPTION_SEND is True: - vrct_gui.printToTextbox(textbox_all, "Voice2chatbox機能をONにしました", "", "INFO") - vrct_gui.printToTextbox(textbox_system, "Voice2chatbox機能をONにしました", "", "INFO") - else: - vrct_gui.printToTextbox(textbox_all, "Voice2chatbox機能をOFFにしました", "", "INFO") - vrct_gui.printToTextbox(textbox_system, "Voice2chatbox機能をOFFにしました", "", "INFO") - -def logTranscriptionReceiveStatusChange(): - textbox_all = getattr(vrct_gui, "textbox_all") - textbox_system = getattr(vrct_gui, "textbox_system") - if config.ENABLE_TRANSCRIPTION_RECEIVE is True: - vrct_gui.printToTextbox(textbox_all, "Speaker2chatbox機能をONにしました", "", "INFO") - vrct_gui.printToTextbox(textbox_system, "Speaker2chatbox機能をONにしました", "", "INFO") - else: - vrct_gui.printToTextbox(textbox_all, "Speaker2chatbox機能をOFFにしました", "", "INFO") - vrct_gui.printToTextbox(textbox_system, "Speaker2chatbox機能をOFFにしました", "", "INFO") - -def logSendMessage(message, translate): - textbox_all = getattr(vrct_gui, "textbox_all") - textbox_sent = getattr(vrct_gui, "textbox_sent") - vrct_gui.printToTextbox(textbox_all, message, translate, "SEND") - vrct_gui.printToTextbox(textbox_sent, message, translate, "SEND") - -def logReceiveMessage(message, translate): - textbox_all = getattr(vrct_gui, "textbox_all") - textbox_sent = getattr(vrct_gui, "textbox_received") - vrct_gui.printToTextbox(textbox_all, message, translate, "RECEIVE") - vrct_gui.printToTextbox(textbox_sent, message, translate, "RECEIVE") - -def logDetectWordFilter(message): - textbox_all = getattr(vrct_gui, "textbox_all") - textbox_system = getattr(vrct_gui, "textbox_system") - vrct_gui.printToTextbox(textbox_all, f"Detect WordFilter :{message}", "", "INFO") - vrct_gui.printToTextbox(textbox_system, f"Detect WordFilter :{message}", "", "INFO") - -def logAuthenticationError(): - textbox_all = getattr(vrct_gui, "textbox_all") - textbox_system = getattr(vrct_gui, "textbox_system") - vrct_gui.printToTextbox(textbox_all, "Auth Key or language setting is incorrect", "", "INFO") - vrct_gui.printToTextbox(textbox_system, "Auth Key or language setting is incorrect", "", "INFO") - -def logOSCError(): - textbox_all = getattr(vrct_gui, "textbox_all") - textbox_system = getattr(vrct_gui, "textbox_system") - vrct_gui.printToTextbox(textbox_all, "OSC is not enabled, please enable OSC and rejoin", "", "INFO") - vrct_gui.printToTextbox(textbox_system, "OSC is not enabled, please enable OSC and rejoin", "", "INFO") - -def logForegroundStatusChange(): - textbox_all = getattr(vrct_gui, "textbox_all") - textbox_system = getattr(vrct_gui, "textbox_system") - if config.ENABLE_FOREGROUND is True: - vrct_gui.printToTextbox(textbox_all, "Start foreground", "", "INFO") - vrct_gui.printToTextbox(textbox_system, "Start foreground", "", "INFO") - else: - vrct_gui.printToTextbox(textbox_all, "Stop foreground", "", "INFO") - vrct_gui.printToTextbox(textbox_system, "Stop foreground", "", "INFO") # command func def callbackToggleTranslation(): - config.ENABLE_TRANSLATION = getattr(vrct_gui, "translation_switch_box").get() - logTranslationStatusChange() + config.ENABLE_TRANSLATION = view.getTranslationButtonStatus() + if config.ENABLE_TRANSLATION is True: + view.printToTextbox_enableTranslation() + else: + view.printToTextbox_disableTranslation() def callbackToggleTranscriptionSend(): - vrct_gui.changeMainWindowWidgetsStatus("disabled", "All") - config.ENABLE_TRANSCRIPTION_SEND = getattr(vrct_gui, "transcription_send_switch_box").get() + view.setMainWindowAllWidgetsStatusToDisabled() + config.ENABLE_TRANSCRIPTION_SEND = view.getTranscriptionSendButtonStatus() if config.ENABLE_TRANSCRIPTION_SEND is True: + view.printToTextbox_enableTranscriptionSend() th_startTranscriptionSendMessage = Thread(target=startTranscriptionSendMessage) th_startTranscriptionSendMessage.daemon = True th_startTranscriptionSendMessage.start() else: + view.printToTextbox_disableTranscriptionSend() th_stopTranscriptionSendMessage = Thread(target=stopTranscriptionSendMessage) th_stopTranscriptionSendMessage.daemon = True th_stopTranscriptionSendMessage.start() - logTranscriptionSendStatusChange() def callbackToggleTranscriptionReceive(): - vrct_gui.changeMainWindowWidgetsStatus("disabled", "All") - config.ENABLE_TRANSCRIPTION_RECEIVE = getattr(vrct_gui, "transcription_receive_switch_box").get() + view.setMainWindowAllWidgetsStatusToDisabled() + config.ENABLE_TRANSCRIPTION_RECEIVE = view.getTranscriptionReceiveButtonStatus() if config.ENABLE_TRANSCRIPTION_RECEIVE is True: + view.printToTextbox_enableTranscriptionReceive() th_startTranscriptionReceiveMessage = Thread(target=startTranscriptionReceiveMessage) th_startTranscriptionReceiveMessage.daemon = True th_startTranscriptionReceiveMessage.start() else: + view.printToTextbox_disableTranscriptionReceive() th_stopTranscriptionReceiveMessage = Thread(target=stopTranscriptionReceiveMessage) th_stopTranscriptionReceiveMessage.daemon = True th_stopTranscriptionReceiveMessage.start() - logTranscriptionReceiveStatusChange() def callbackToggleForeground(): - config.ENABLE_FOREGROUND = getattr(vrct_gui, "foreground_switch_box").get() + config.ENABLE_FOREGROUND = view.getForegroundButtonStatus() if config.ENABLE_FOREGROUND is True: - vrct_gui.attributes("-topmost", True) + view.printToTextbox_enableForeground() + view.foregroundOn() else: - vrct_gui.attributes("-topmost", False) - logForegroundStatusChange() + view.printToTextbox_disableForeground() + view.foregroundOff() # create GUI -vrct_gui.createGUI() +view.createGUI() # init config if model.authenticationTranslator() is False: # error update Auth key - logAuthenticationError() + view.printToTextbox_AuthenticationError() # set word filter model.addKeywords() @@ -314,37 +229,35 @@ 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 +view.initializer( + 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 + # 辞書型で関数を渡しても上手く行かず、仕方なくタプルで渡してる。 + # 本当はコメントアウト(以下とview.py内33,34行目)しているようにできたらいいけど、 + # _tkinter.TclError: unknown option "-bind_Any_KeyPress"みたいにエラーがでる。 + entry_message_box=None, + # entry_message_box={ + # "bind_Return": messageBoxPressKeyEnter, + # "bind_Any_KeyPress": messageBoxPressKeyAny, + # }, + entry_message_box_bind_Return=messageBoxPressKeyEnter, + entry_message_box_bind_Any_KeyPress=messageBoxPressKeyAny, ) if __name__ == "__main__": - vrct_gui.startMainLoop() \ No newline at end of file + view.startMainLoop() \ No newline at end of file diff --git a/view.py b/view.py new file mode 100644 index 00000000..0f7c2590 --- /dev/null +++ b/view.py @@ -0,0 +1,151 @@ +from customtkinter import StringVar, END as CTK_END +from vrct_gui import vrct_gui + +from config import config + +class View(): + def __init__(self): + pass + + + def initializer(self, sidebar_features, language_presets, entry_message_box, entry_message_box_bind_Return, entry_message_box_bind_Any_KeyPress): + + 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(command=language_presets["callback_your_language"]) + 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(command=language_presets["callback_target_language"]) + 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) + + + entry_message_box = getattr(vrct_gui, "entry_message_box") + # entry_message_box.bind("", lambda e: entry_message_box["bind_Return"](e)) + # entry_message_box.bind("", lambda e: entry_message_box["bind_Any_KeyPress"](e)) + entry_message_box.bind("", entry_message_box_bind_Return) + entry_message_box.bind("", entry_message_box_bind_Any_KeyPress) + + entry_message_box.bind("", self._foregroundOffForcefully) + entry_message_box.bind("", self._foregroundOnForcefully) + + + + def setMainWindowAllWidgetsStatusToNormal(self): + vrct_gui.changeMainWindowWidgetsStatus("normal", "All") + + def setMainWindowAllWidgetsStatusToDisabled(self): + vrct_gui.changeMainWindowWidgetsStatus("disabled", "All") + + + + def _foregroundOnForcefully(self, _e): + if config.ENABLE_FOREGROUND: + self.foregroundOn() + + def _foregroundOffForcefully(self, _e): + if config.ENABLE_FOREGROUND: + self.foregroundOff() + + + def foregroundOn(self): + vrct_gui.attributes("-topmost", True) + + def foregroundOff(self): + vrct_gui.attributes("-topmost", False) + + + def updateGuiVariableByPresetTabNo(self, tab_no:str): + vrct_gui.YOUR_LANGUAGE = config.SELECTED_TAB_YOUR_LANGUAGES[tab_no] + vrct_gui.TARGET_LANGUAGE = config.SELECTED_TAB_TARGET_LANGUAGES[tab_no] + + + + def getTranslationButtonStatus(self): + return vrct_gui.translation_switch_box.get() + def getTranscriptionSendButtonStatus(self): + return vrct_gui.transcription_send_switch_box.get() + def getTranscriptionReceiveButtonStatus(self): + return vrct_gui.transcription_receive_switch_box.get() + def getForegroundButtonStatus(self): + return vrct_gui.foreground_switch_box.get() + + + def printToTextbox_enableTranslation(self): + self._printToTextbox_Info("翻訳機能をONにしました") + def printToTextbox_disableTranslation(self): + self._printToTextbox_Info("翻訳機能をOFFにしました") + + def printToTextbox_enableTranscriptionSend(self): + self._printToTextbox_Info("Voice2chatbox機能をONにしました") + def printToTextbox_disableTranscriptionSend(self): + self._printToTextbox_Info("Voice2chatbox機能をOFFにしました") + + def printToTextbox_enableTranscriptionReceive(self): + self._printToTextbox_Info("Speaker2chatbox機能をONにしました") + def printToTextbox_disableTranscriptionReceive(self): + self._printToTextbox_Info("Speaker2chatbox機能をOFFにしました") + + def printToTextbox_enableForeground(self): + self._printToTextbox_Info("Start foreground") + def printToTextbox_disableForeground(self): + self._printToTextbox_Info("Stop foreground") + + + def printToTextbox_AuthenticationError(self): + self._printToTextbox_Info("Auth Key or language setting is incorrect") + + def printToTextbox_OSCError(self): + self._printToTextbox_Info("OSC is not enabled, please enable OSC and rejoin") + + def printToTextbox_DetectedByWordFilter(self, detected_message): + self._printToTextbox_Info(f"Detect WordFilter :{detected_message}") + + + def _printToTextbox_Info(self, info_message): + vrct_gui.printToTextbox(vrct_gui.textbox_all, info_message, "", "INFO") + vrct_gui.printToTextbox(vrct_gui.textbox_system, info_message, "", "INFO") + + + + def printToTextbox_SentMessage(self, original_message, translated_message): + self._printToTextbox_Sent(original_message, translated_message) + + def _printToTextbox_Sent(self, original_message, translated_message): + vrct_gui.printToTextbox(vrct_gui.textbox_all, original_message, translated_message, "SEND") + vrct_gui.printToTextbox(vrct_gui.textbox_sent, original_message, translated_message, "SEND") + + + def printToTextbox_ReceivedMessage(self, original_message, translated_message): + self._printToTextbox_Received(original_message, translated_message) + + def _printToTextbox_Received(self, original_message, translated_message): + vrct_gui.printToTextbox(vrct_gui.textbox_all, original_message, translated_message, "RECEIVE") + vrct_gui.printToTextbox(vrct_gui.textbox_received, original_message, translated_message, "RECEIVE") + + + def getTextFromMessageBox(self): + return vrct_gui.entry_message_box.get() + + def clearMessageBox(self): + vrct_gui.entry_message_box.delete(0, CTK_END) + + + + + def createGUI(self): + vrct_gui.createGUI() + + def startMainLoop(self): + vrct_gui.startMainLoop() + +view = View() \ No newline at end of file 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_entry_message_box.py b/vrct_gui/main_window/widgets/create_entry_message_box.py index 61dfe593..7bdfb491 100644 --- a/vrct_gui/main_window/widgets/create_entry_message_box.py +++ b/vrct_gui/main_window/widgets/create_entry_message_box.py @@ -19,3 +19,17 @@ def createEntryMessageBox(settings, main_window): ) main_window.entry_message_box.grid(row=0, column=0, padx=settings.uism.TEXTBOX_ENTRY_PADX, pady=settings.uism.TEXTBOX_ENTRY_PADY, sticky="nsew") main_window.entry_message_box._entry.grid(padx=settings.uism.TEXTBOX_ENTRY_IPADX, pady=settings.uism.TEXTBOX_ENTRY_IPADY) + + + def messageBoxAnyKeyPress(e): + BREAK_KEYSYM_LIST = [ + "Delete", "Select", "Up", "Down", "Next", "End", "Print", + "Prior","Insert","Home", "Left", "Clear", "Right", "Linefeed" + ] + if e.keysym != "??": + if len(e.char) != 0 and e.keysym in BREAK_KEYSYM_LIST: + main_window.entry_message_box.insert("end", e.char) + return "break" + + main_window.entry_message_box.bind("", messageBoxAnyKeyPress) + 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