diff --git a/main.py b/main.py index 8ac04026..c09a0755 100644 --- a/main.py +++ b/main.py @@ -242,24 +242,29 @@ def callbackCloseConfigWindow(): if config.ENABLE_TRANSCRIPTION_RECEIVE is True: startThreadingTranscriptionReceiveMessage() model.stopCheckMicEnergy() + view.replaceMicThresholdCheckButton_Passive() + # view.initProgressBar_MicEnergy() # ProgressBarに0をセットしたい + model.stopCheckSpeakerEnergy() + view.replaceSpeakerThresholdCheckButton_Passive() + # view.initProgressBar_SpeakerEnergy() # ProgressBarに0をセットしたい # Compact Mode Switch def callbackEnableConfigWindowCompactMode(): config.IS_CONFIG_WINDOW_COMPACT_MODE = True model.stopCheckMicEnergy() - view.replaceConfigWindowMicThresholdCheckButtonToPassive() + view.replaceMicThresholdCheckButton_Passive() model.stopCheckSpeakerEnergy() - view.replaceConfigWindowSpeakerThresholdCheckButtonToPassive() + view.replaceSpeakerThresholdCheckButton_Passive() view.reloadConfigWindowSettingBoxContainer() def callbackDisableConfigWindowCompactMode(): config.IS_CONFIG_WINDOW_COMPACT_MODE = False model.stopCheckMicEnergy() - view.replaceConfigWindowMicThresholdCheckButtonToPassive() + view.replaceMicThresholdCheckButton_Passive() model.stopCheckSpeakerEnergy() - view.replaceConfigWindowSpeakerThresholdCheckButtonToPassive() + view.replaceSpeakerThresholdCheckButton_Passive() view.reloadConfigWindowSettingBoxContainer() @@ -308,14 +313,14 @@ def callbackSetMicHost(value): view.updateList_MicDevice(model.getListInputDevice()) model.stopCheckMicEnergy() - view.replaceConfigWindowMicThresholdCheckButtonToPassive() + view.replaceMicThresholdCheckButton_Passive() def callbackSetMicDevice(value): print("callbackSetMicDevice", value) config.CHOICE_MIC_DEVICE = value model.stopCheckMicEnergy() - view.replaceConfigWindowMicThresholdCheckButtonToPassive() + view.replaceMicThresholdCheckButton_Passive() def callbackSetMicEnergyThreshold(value): print("callbackSetMicEnergyThreshold", value) @@ -344,19 +349,15 @@ def setProgressBarMicEnergy(energy): def callbackCheckMicThreshold(is_turned_on): print("callbackCheckMicThreshold", is_turned_on) if is_turned_on is True: - # view.setConfigWindowCompactModeSwitchStatusToDisabled() - - view.setConfigWindowThresholdCheckWidgetsStatusToDisabled() + view.setWidgetsStatus_ThresholdCheckButton_Disabled() model.startCheckMicEnergy(setProgressBarMicEnergy) - view.replaceConfigWindowMicThresholdCheckButtonToActive() - view.setConfigWindowThresholdCheckWidgetsStatusToNormal() + view.replaceMicThresholdCheckButton_Active() + view.setWidgetsStatus_ThresholdCheckButton_Normal() else: - view.setConfigWindowThresholdCheckWidgetsStatusToDisabled() + view.setWidgetsStatus_ThresholdCheckButton_Disabled() model.stopCheckMicEnergy() - view.replaceConfigWindowMicThresholdCheckButtonToPassive() - view.setConfigWindowThresholdCheckWidgetsStatusToNormal() - - # view.setConfigWindowCompactModeSwitchStatusToNormal() + view.replaceMicThresholdCheckButton_Passive() + view.setWidgetsStatus_ThresholdCheckButton_Normal() def callbackSetMicRecordTimeout(value): print("callbackSetMicRecordTimeout", value) @@ -407,7 +408,7 @@ def callbackSetSpeakerDevice(value): config.CHOICE_SPEAKER_DEVICE = value model.stopCheckSpeakerEnergy() - view.replaceConfigWindowSpeakerThresholdCheckButtonToPassive() + view.replaceSpeakerThresholdCheckButton_Passive() def callbackSetSpeakerEnergyThreshold(value): print("callbackSetSpeakerEnergyThreshold", value) @@ -436,20 +437,16 @@ def setProgressBarSpeakerEnergy(energy): def callbackCheckSpeakerThreshold(is_turned_on): print("callbackCheckSpeakerThreshold", is_turned_on) if is_turned_on is True: - # view.setConfigWindowCompactModeSwitchStatusToDisabled() - - view.setConfigWindowThresholdCheckWidgetsStatusToDisabled() + view.setWidgetsStatus_ThresholdCheckButton_Disabled() model.startCheckSpeakerEnergy(setProgressBarSpeakerEnergy) - view.replaceConfigWindowSpeakerThresholdCheckButtonToActive() - view.setConfigWindowThresholdCheckWidgetsStatusToNormal() + view.replaceSpeakerThresholdCheckButton_Active() + view.setWidgetsStatus_ThresholdCheckButton_Normal() else: - view.setConfigWindowThresholdCheckWidgetsStatusToDisabled() + view.setWidgetsStatus_ThresholdCheckButton_Disabled() model.stopCheckSpeakerEnergy() - view.replaceConfigWindowSpeakerThresholdCheckButtonToPassive() - view.setConfigWindowThresholdCheckWidgetsStatusToNormal() - - # view.setConfigWindowCompactModeSwitchStatusToNormal() + view.replaceSpeakerThresholdCheckButton_Passive() + view.setWidgetsStatus_ThresholdCheckButton_Normal() def callbackSetSpeakerRecordTimeout(value): print("callbackSetSpeakerRecordTimeout", value) @@ -540,6 +537,11 @@ if config.ENABLE_LOGGER is True: # set UI and callback view.register( + window_action_registers={ + "callback_open_config_window": callbackOpenConfigWindow, + "callback_close_config_window": callbackCloseConfigWindow, + }, + sidebar_features_registers={ "callback_toggle_translation": callbackToggleTranslation, "callback_toggle_transcription_send": callbackToggleTranscriptionSend, diff --git a/view.py b/view.py index d1b8d688..00c1bf96 100644 --- a/view.py +++ b/view.py @@ -43,6 +43,11 @@ class View(): ) self.view_variable = SimpleNamespace( + # Open Config Window + CALLBACK_OPEN_CONFIG_WINDOW=None, + CALLBACK_CLOSE_CONFIG_WINDOW=None, + + # Main Window # Sidebar # Sidebar Compact Mode @@ -255,12 +260,21 @@ class View(): def register( self, + window_action_registers=None, sidebar_features_registers=None, language_presets_registers=None, entry_message_box_registers=None, config_window_registers=None ): + + # Open Config Window + if window_action_registers is not None: + self.view_variable.CALLBACK_OPEN_CONFIG_WINDOW=window_action_registers.get("callback_open_config_window", None) + self.view_variable.CALLBACK_CLOSE_CONFIG_WINDOW=window_action_registers.get("callback_close_config_window", None) + + + self.view_variable.CALLBACK_TOGGLE_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = self._toggleMainWindowSidebarCompactMode if sidebar_features_registers is not None: @@ -350,6 +364,7 @@ class View(): self.view_variable.CALLBACK_SET_OSC_IP_ADDRESS = config_window_registers.get("callback_set_osc_ip_address", None) self.view_variable.CALLBACK_SET_OSC_PORT = config_window_registers.get("callback_set_osc_port", None) + # Insert sample conversation for testing. # self._insertSampleConversationToTextbox() @@ -446,16 +461,15 @@ class View(): - def printToTextbox_SentMessage(self, original_message, translated_message, actual_sent_message=None): - self._printToTextbox_Sent(original_message, translated_message, actual_sent_message) + def printToTextbox_SentMessage(self, original_message, translated_message): + self._printToTextbox_Sent(original_message, translated_message) @staticmethod - def _printToTextbox_Sent(original_message, translated_message, actual_sent_message=None): + def _printToTextbox_Sent(original_message, translated_message): vrct_gui.printToTextbox( target_type="SENT", original_message=original_message, translated_message=translated_message, - actual_sent_message=actual_sent_message, ) @@ -495,15 +509,15 @@ class View(): # Config Window @staticmethod - def setConfigWindowCompactModeSwitchStatusToDisabled(): + def setWidgetsStatus_ConfigWindowCompactModeSwitch_Disabled(): vrct_gui.config_window.setting_box_compact_mode_switch_box.configure(state="disabled") @staticmethod - def setConfigWindowCompactModeSwitchStatusToNormal(): + def setWidgetsStatus_ConfigWindowCompactModeSwitch_Normal(): vrct_gui.config_window.setting_box_compact_mode_switch_box.configure(state="normal") @staticmethod - def setConfigWindowThresholdCheckWidgetsStatusToDisabled(): + def setWidgetsStatus_ThresholdCheckButton_Disabled(): vrct_gui.changeConfigWindowWidgetsStatus( status="disabled", target_names=[ @@ -513,7 +527,7 @@ class View(): ) @staticmethod - def setConfigWindowThresholdCheckWidgetsStatusToNormal(): + def setWidgetsStatus_ThresholdCheckButton_Normal(): vrct_gui.changeConfigWindowWidgetsStatus( status="normal", target_names=[ @@ -523,24 +537,24 @@ class View(): ) @staticmethod - def replaceConfigWindowMicThresholdCheckButtonToActive(): + def replaceMicThresholdCheckButton_Active(): vrct_gui.config_window.sb__progressbar_x_slider__passive_button_mic_energy_threshold.grid_remove() vrct_gui.config_window.sb__progressbar_x_slider__active_button_mic_energy_threshold.grid() @staticmethod - def replaceConfigWindowMicThresholdCheckButtonToPassive(): + def replaceMicThresholdCheckButton_Passive(): vrct_gui.config_window.sb__progressbar_x_slider__active_button_mic_energy_threshold.grid_remove() vrct_gui.config_window.sb__progressbar_x_slider__passive_button_mic_energy_threshold.grid() @staticmethod - def replaceConfigWindowSpeakerThresholdCheckButtonToActive(): + def replaceSpeakerThresholdCheckButton_Active(): vrct_gui.config_window.sb__progressbar_x_slider__passive_button_speaker_energy_threshold.grid_remove() vrct_gui.config_window.sb__progressbar_x_slider__active_button_speaker_energy_threshold.grid() @staticmethod - def replaceConfigWindowSpeakerThresholdCheckButtonToPassive(): + def replaceSpeakerThresholdCheckButton_Passive(): vrct_gui.config_window.sb__progressbar_x_slider__active_button_speaker_energy_threshold.grid_remove() vrct_gui.config_window.sb__progressbar_x_slider__passive_button_speaker_energy_threshold.grid() @@ -566,16 +580,28 @@ class View(): def updateSelected_MicDevice(self, default_selected_mic_device_name:str): self.view_variable.VAR_MIC_DEVICE.set(default_selected_mic_device_name) - def updateSetProgressBar_MicEnergy(self, new_mic_energy): + + @staticmethod + def updateSetProgressBar_MicEnergy(new_mic_energy): vrct_gui.config_window.sb__progressbar_x_slider__progressbar_mic_energy_threshold.set(new_mic_energy/config.MAX_MIC_ENERGY_THRESHOLD) + @staticmethod + def initProgressBar_MicEnergy(): + vrct_gui.config_window.sb__progressbar_x_slider__progressbar_mic_energy_threshold.set(0) + + def updateList_SpeakerDevice(self, new_speaker_device_list): self.view_variable.LIST_SPEAKER_DEVICE = new_speaker_device_list vrct_gui.config_window.sb__optionmenu_speaker_device.configure(values=new_speaker_device_list) - def updateSetProgressBar_SpeakerEnergy(self, new_speaker_energy): + @staticmethod + def updateSetProgressBar_SpeakerEnergy(new_speaker_energy): vrct_gui.config_window.sb__progressbar_x_slider__progressbar_speaker_energy_threshold.set(new_speaker_energy/config.MAX_SPEAKER_ENERGY_THRESHOLD) + @staticmethod + def initProgressBar_SpeakerEnergy(): + vrct_gui.config_window.sb__progressbar_x_slider__progressbar_speaker_energy_threshold.set(0) + def setGuiVariable_MicEnergyThreshold(self, slider_value:int, entry_value:Union[None, str]=None): @@ -628,7 +654,7 @@ class View(): - # These conversation is generated by ChatGPT + # These conversations are generated by ChatGPT def _insertSampleConversationToTextbox(self): self.printToTextbox_enableTranscriptionSend() @@ -738,10 +764,7 @@ class View(): ] for data in conversation_data: if data.get("me", None) is not None: - # actual_sent_message = config.MESSAGE_FORMAT.replace("[message]", data.get("me", None)) - # actual_sent_message = actual_sent_message.replace("[translation]", data.get("me_t", None)) self.printToTextbox_SentMessage(data.get("me", None), data.get("me_t", None)) - # self.printToTextbox_SentMessage(data.get("me", None), data.get("me_t", None), actual_sent_message) if data.get("target", None) is not None: self.printToTextbox_ReceivedMessage(data.get("target", None), data.get("target_t", None)) diff --git a/vrct_gui/_printToTextbox.py b/vrct_gui/_printToTextbox.py index 8854071f..cb732f81 100644 --- a/vrct_gui/_printToTextbox.py +++ b/vrct_gui/_printToTextbox.py @@ -1,7 +1,7 @@ from datetime import datetime from customtkinter import CTkFont -def _printToTextbox(vrct_gui, settings, target_type, original_message=None, translated_message=None, actual_sent_message=None, tags=None, disable_print_to_textbox_all:bool=False): +def _printToTextbox(vrct_gui, settings, target_type, original_message=None, translated_message=None, tags=None, disable_print_to_textbox_all:bool=False): now_raw_data = datetime.now() # now = now_raw_data.strftime("%H:%M:%S") now_hm = now_raw_data.strftime("%H:%M") @@ -72,8 +72,6 @@ def _printToTextbox(vrct_gui, settings, target_type, original_message=None, tran target_textbox.insert("end", original_message, ("SENT_SUB_TEXT", "SENT_SECONDARY_TEXT_FONT", "JUSTIFY_RIGHT")) target_textbox.insert("end", "\n") target_textbox.insert("end", translated_message, ("SENT_TEXT", "SENT_MAIN_TEXT_FONT", "JUSTIFY_RIGHT")) - # _actual_sent_message = "" if actual_sent_message is None else actual_sent_message - # target_textbox.insert("end", _actual_sent_message, ("SENT_TEXT", "SENT_MAIN_TEXT_FONT", "JUSTIFY_RIGHT")) else: target_textbox.insert("end", original_message, ("SENT_TEXT", "SENT_MAIN_TEXT_FONT", "JUSTIFY_RIGHT")) @@ -95,26 +93,4 @@ def _printToTextbox(vrct_gui, settings, target_type, original_message=None, tran printEachTextbox(target_textbox) # To automatically print the same log to the textbox_all widget as well. - if disable_print_to_textbox_all is not True: printEachTextbox(vrct_gui.textbox_all) - - - - # target_textbox.tag_config("ERROR", foreground="#FF0000") - - # target_textbox.tag_config("SYSTEM", justify="center") - # target_textbox.tag_config("SYSTEM_TAG", foreground="#1BFF00") - - # target_textbox.tag_config("SENT", justify="left") - # target_textbox.tag_config("SENT_COLOR", foreground="#0378e2") - - # target_textbox.tag_config("RECEIVED", justify="left") - # target_textbox.tag_config("RECEIVED_COLOR", foreground="#ffa500") - - - # target_textbox.configure(state="normal") - # target_textbox.insert("end", f"[{tags}] ", ("START", "LABEL", tags, f"{tags}_COLOR")) - # target_textbox.insert("end", f"{now_hm} ", ("TIMESTAMP", tags)) - # target_textbox.insert("end", f"{original_message}\n", ("SECONDARY_TEXT_FONT", "MAIN_TEXT_COLOR", tags)) - # target_textbox.insert("end", f"{translated_message}\n", ("MAIN_TEXT_FONT", "MAIN_TEXT_COLOR", tags)) - # target_textbox.configure(state="disabled") - # target_textbox.see("end") \ No newline at end of file + if disable_print_to_textbox_all is not True: printEachTextbox(vrct_gui.textbox_all) \ No newline at end of file diff --git a/vrct_gui/main_window/widgets/_create_sidebar/createSidebarLanguagesSettings.py b/vrct_gui/main_window/widgets/_create_sidebar/createSidebarLanguagesSettings.py index 08dd9c70..5ed03a2c 100644 --- a/vrct_gui/main_window/widgets/_create_sidebar/createSidebarLanguagesSettings.py +++ b/vrct_gui/main_window/widgets/_create_sidebar/createSidebarLanguagesSettings.py @@ -74,7 +74,7 @@ def createSidebarLanguagesSettings(settings, main_window, view_variable): - sls__selected_language_box = CTkFrame(sls__box_wrapper, corner_radius=0, fg_color=settings.ctm.SLS__DROPDOWN_MENU_BG_COLOR) + sls__selected_language_box = CTkFrame(sls__box_wrapper, corner_radius=0, fg_color=settings.ctm.SLS__DROPDOWN_MENU_BG_COLOR, cursor="hand2") sls__selected_language_box.grid(row=1, column=0) @@ -111,8 +111,8 @@ def createSidebarLanguagesSettings(settings, main_window, view_variable): - bindEnterAndLeaveColor([sls__selected_language_label_frame, sls__selected_language_box, sls__selected_language_label], settings.ctm.SLS__DROPDOWN_MENU_HOVERED_BG_COLOR, settings.ctm.SLS__DROPDOWN_MENU_BG_COLOR) - bindButtonPressColor([sls__selected_language_label_frame, sls__selected_language_box, sls__selected_language_label], settings.ctm.SLS__DROPDOWN_MENU_CLICKED_BG_COLOR, settings.ctm.SLS__DROPDOWN_MENU_HOVERED_BG_COLOR) + bindEnterAndLeaveColor([sls__selected_language_label_frame, sls__selected_language_box, sls__selected_language_label, sls__selected_language_arrow_img], settings.ctm.SLS__DROPDOWN_MENU_HOVERED_BG_COLOR, settings.ctm.SLS__DROPDOWN_MENU_BG_COLOR) + bindButtonPressColor([sls__selected_language_label_frame, sls__selected_language_box, sls__selected_language_label, sls__selected_language_arrow_img], settings.ctm.SLS__DROPDOWN_MENU_CLICKED_BG_COLOR, settings.ctm.SLS__DROPDOWN_MENU_HOVERED_BG_COLOR) diff --git a/vrct_gui/vrct_gui.py b/vrct_gui/vrct_gui.py index ea23f65b..383bf4cd 100644 --- a/vrct_gui/vrct_gui.py +++ b/vrct_gui/vrct_gui.py @@ -1,5 +1,3 @@ -from types import SimpleNamespace - from customtkinter import CTk, CTkImage # from window_help_and_info import ToplevelWindowInformation @@ -14,8 +12,9 @@ from .main_window import createMainWindowWidgets from .config_window import ConfigWindow from .ui_utils import _setDefaultActiveTab -from .main_window.widgets import createSidebar, createMinimizeSidebarButton +from .main_window.widgets import createMinimizeSidebarButton +from utils import callFunctionIfCallable class VRCT_GUI(CTk): def __init__(self): @@ -54,12 +53,14 @@ class VRCT_GUI(CTk): def openConfigWindow(self, e): + callFunctionIfCallable(self._view_variable.CALLBACK_OPEN_CONFIG_WINDOW) self.config_window.deiconify() self.config_window.focus_set() self.config_window.focus() self.config_window.grab_set() def closeConfigWindow(self): + callFunctionIfCallable(self._view_variable.CALLBACK_CLOSE_CONFIG_WINDOW) self.config_window.withdraw() self.config_window.grab_release() @@ -67,6 +68,9 @@ class VRCT_GUI(CTk): def openSelectableLanguagesWindow(self, selectable_language_window_type): + # print("___________________________________open____________________________________________________") + # print("your", self._view_variable.IS_OPENED_SELECTABLE_YOUR_LANGUAGE_WINDOW) + # print("target", self._view_variable.IS_OPENED_SELECTABLE_TARGET_LANGUAGE_WINDOW) if selectable_language_window_type == "your_language": if self._view_variable.IS_OPENED_SELECTABLE_YOUR_LANGUAGE_WINDOW is False: self.sls__arrow_img_your_language.configure(image=CTkImage((self.settings.main.image_file.ARROW_LEFT),size=(20,20))) @@ -96,8 +100,16 @@ class VRCT_GUI(CTk): self.sls__arrow_img_your_language.configure(image=CTkImage((self.settings.main.image_file.ARROW_LEFT).rotate(180),size=(20,20))) self.sls__arrow_img_target_language.configure(image=CTkImage((self.settings.main.image_file.ARROW_LEFT).rotate(180),size=(20,20))) self.selectable_languages_window.withdraw() - self._view_variable.IS_OPENED_SELECTABLE_TARGET_LANGUAGE_WINDOW = False - self._view_variable.IS_OPENED_SELECTABLE_YOUR_LANGUAGE_WINDOW = False + + + # print("______________________________________close_________________________________________________") + # print("your", self._view_variable.IS_OPENED_SELECTABLE_YOUR_LANGUAGE_WINDOW) + # print("target", self._view_variable.IS_OPENED_SELECTABLE_TARGET_LANGUAGE_WINDOW) + if self._view_variable.IS_OPENED_SELECTABLE_TARGET_LANGUAGE_WINDOW is not False or self._view_variable.IS_OPENED_SELECTABLE_YOUR_LANGUAGE_WINDOW is not False: + def callback(): + self._view_variable.IS_OPENED_SELECTABLE_TARGET_LANGUAGE_WINDOW = False + self._view_variable.IS_OPENED_SELECTABLE_YOUR_LANGUAGE_WINDOW = False + self.after(500,callback) @@ -125,14 +137,13 @@ class VRCT_GUI(CTk): target_names=target_names, ) - def printToTextbox(self, target_type, original_message=None, translated_message=None, actual_sent_message=None): + def printToTextbox(self, target_type, original_message=None, translated_message=None): _printToTextbox( vrct_gui=self, settings=self.settings.main, target_type=target_type, original_message=original_message, translated_message=translated_message, - actual_sent_message=actual_sent_message, tags=target_type, )