diff --git a/locales/en.yml b/locales/en.yml index 2c6ed497..abfe232f 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -16,6 +16,9 @@ main_window: update_available: New version is here! + modal_message: + opened_config_window: The functionality is temporarily disabled until the settings window is closed. + selectable_language_window: title_your_language: Select Your Language title_target_language: Select Target Language diff --git a/locales/ja.yml b/locales/ja.yml index 040bb36c..4b5f373a 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -16,6 +16,10 @@ main_window: update_available: 新しいバージョンが出ました! + modal_message: + opened_config_window: 設定画面が閉じられるまで、一時的に機能を停止しています。 + + selectable_language_window: title_your_language: あなたの言語 title_target_language: 相手の言語 diff --git a/main.py b/main.py index 311827b0..94d943cd 100644 --- a/main.py +++ b/main.py @@ -388,19 +388,15 @@ def callbackSetMicDevice(value): def callbackSetMicEnergyThreshold(value): print("callbackSetMicEnergyThreshold", value) try: - if 0 > int(value) or int(value) > config.MAX_MIC_ENERGY_THRESHOLD: raise ValueError() + value = int(value) + if 0 <= value and value <= config.MAX_MIC_ENERGY_THRESHOLD: + view.clearErrorMessage() + config.INPUT_MIC_ENERGY_THRESHOLD = value + view.setGuiVariable_MicEnergyThreshold(config.INPUT_MIC_ENERGY_THRESHOLD) + else: + raise ValueError() except: - view.setGuiVariable_MicEnergyThreshold( - slider_value=config.INPUT_MIC_ENERGY_THRESHOLD, - entry_value=None, - ) - return - config.INPUT_MIC_ENERGY_THRESHOLD = int(value) - view.setGuiVariable_MicEnergyThreshold( - slider_value=config.INPUT_MIC_ENERGY_THRESHOLD, - entry_value=str(config.INPUT_MIC_ENERGY_THRESHOLD), - ) - + view.showErrorMessage_MicEnergyThreshold() def callbackSetMicDynamicEnergyThreshold(value): print("callbackSetMicDynamicEnergyThreshold", value) @@ -425,32 +421,41 @@ def callbackCheckMicThreshold(is_turned_on): def callbackSetMicRecordTimeout(value): print("callbackSetMicRecordTimeout", value) try: - if int(value) < 0 or int(value) > config.INPUT_MIC_PHRASE_TIMEOUT: raise ValueError() + value = int(value) + if 0 <= value and value <= config.INPUT_MIC_PHRASE_TIMEOUT: + view.clearErrorMessage() + config.INPUT_MIC_RECORD_TIMEOUT = value + view.setGuiVariable_MicRecordTimeout(str(config.INPUT_MIC_RECORD_TIMEOUT)) + else: + raise ValueError() except: - view.setGuiVariable_MicRecordTimeout(delete=True) - return - config.INPUT_MIC_RECORD_TIMEOUT = int(value) - view.setGuiVariable_MicRecordTimeout(str(config.INPUT_MIC_RECORD_TIMEOUT)) + view.showErrorMessage_MicRecordTimeout() def callbackSetMicPhraseTimeout(value): print("callbackSetMicPhraseTimeout", value) try: - if int(value) < 0 or int(value) < config.INPUT_MIC_RECORD_TIMEOUT: raise ValueError() + value = int(value) + if 0 <= value and value >= config.INPUT_MIC_RECORD_TIMEOUT: + view.clearErrorMessage() + config.INPUT_MIC_PHRASE_TIMEOUT = value + view.setGuiVariable_MicPhraseTimeout(str(config.INPUT_MIC_PHRASE_TIMEOUT)) + else: + raise ValueError() except: - view.setGuiVariable_MicPhraseTimeout(delete=True) - return - config.INPUT_MIC_PHRASE_TIMEOUT = int(value) - view.setGuiVariable_MicPhraseTimeout(str(config.INPUT_MIC_PHRASE_TIMEOUT)) + view.showErrorMessage_MicPhraseTimeout() def callbackSetMicMaxPhrases(value): print("callbackSetMicMaxPhrases", value) try: - if int(value) < 0: raise ValueError() + value = int(value) + if 0 <= value: + view.clearErrorMessage() + config.INPUT_MIC_MAX_PHRASES = value + view.setGuiVariable_MicMaxPhrases(str(config.INPUT_MIC_MAX_PHRASES)) + else: + raise ValueError() except: - view.setGuiVariable_MicMaxPhrases(delete=True) - return - config.INPUT_MIC_MAX_PHRASES = int(value) - view.setGuiVariable_MicMaxPhrases(str(config.INPUT_MIC_MAX_PHRASES)) + view.showErrorMessage_MicMaxPhrases() def callbackSetMicWordFilter(value): print("callbackSetMicWordFilter", value) @@ -476,19 +481,15 @@ def callbackSetSpeakerDevice(value): def callbackSetSpeakerEnergyThreshold(value): print("callbackSetSpeakerEnergyThreshold", value) try: - if 0 > int(value) or int(value) > config.MAX_SPEAKER_ENERGY_THRESHOLD: raise ValueError() + value = int(value) + if 0 <= value and value <= config.MAX_SPEAKER_ENERGY_THRESHOLD: + view.clearErrorMessage() + config.INPUT_SPEAKER_ENERGY_THRESHOLD = value + view.setGuiVariable_SpeakerEnergyThreshold(config.INPUT_SPEAKER_ENERGY_THRESHOLD) + else: + raise ValueError() except: - view.setGuiVariable_SpeakerEnergyThreshold( - slider_value=config.INPUT_SPEAKER_ENERGY_THRESHOLD, - entry_value=None, - ) - return - config.INPUT_SPEAKER_ENERGY_THRESHOLD = int(value) - view.setGuiVariable_SpeakerEnergyThreshold( - slider_value=config.INPUT_SPEAKER_ENERGY_THRESHOLD, - entry_value=str(config.INPUT_SPEAKER_ENERGY_THRESHOLD), - ) - + view.showErrorMessage_SpeakerEnergyThreshold() def callbackSetSpeakerDynamicEnergyThreshold(value): print("callbackSetSpeakerDynamicEnergyThreshold", value) @@ -514,32 +515,41 @@ def callbackCheckSpeakerThreshold(is_turned_on): def callbackSetSpeakerRecordTimeout(value): print("callbackSetSpeakerRecordTimeout", value) try: - if int(value) < 0 or int(value) > config.INPUT_SPEAKER_PHRASE_TIMEOUT: raise ValueError() + value = int(value) + if 0 <= value and value <= config.INPUT_SPEAKER_PHRASE_TIMEOUT: + view.clearErrorMessage() + config.INPUT_SPEAKER_RECORD_TIMEOUT = value + view.setGuiVariable_SpeakerRecordTimeout(str(config.INPUT_SPEAKER_RECORD_TIMEOUT)) + else: + raise ValueError() except: - view.setGuiVariable_SpeakerRecordTimeout(delete=True) - return - config.INPUT_SPEAKER_RECORD_TIMEOUT = int(value) - view.setGuiVariable_SpeakerRecordTimeout(str(config.INPUT_SPEAKER_RECORD_TIMEOUT)) + view.showErrorMessage_SpeakerRecordTimeout() def callbackSetSpeakerPhraseTimeout(value): print("callbackSetSpeakerPhraseTimeout", value) try: - if int(value) < 0 or int(value) < config.INPUT_SPEAKER_RECORD_TIMEOUT: raise ValueError() + value = int(value) + if 0 <= value and value >= config.INPUT_SPEAKER_RECORD_TIMEOUT: + view.clearErrorMessage() + config.INPUT_SPEAKER_PHRASE_TIMEOUT = value + view.setGuiVariable_SpeakerPhraseTimeout(str(config.INPUT_SPEAKER_PHRASE_TIMEOUT)) + else: + raise ValueError() except: - view.setGuiVariable_SpeakerPhraseTimeout(delete=True) - return - config.INPUT_SPEAKER_PHRASE_TIMEOUT = int(value) - view.setGuiVariable_SpeakerPhraseTimeout(str(config.INPUT_SPEAKER_PHRASE_TIMEOUT)) + view.showErrorMessage_SpeakerPhraseTimeout() def callbackSetSpeakerMaxPhrases(value): print("callbackSetSpeakerMaxPhrases", value) try: - if int(value) < 0: raise ValueError() + value = int(value) + if 0 <= value: + view.clearErrorMessage() + config.INPUT_SPEAKER_MAX_PHRASES = value + view.setGuiVariable_SpeakerMaxPhrases(str(config.INPUT_SPEAKER_MAX_PHRASES)) + else: + raise ValueError() except: - view.setGuiVariable_SpeakerMaxPhrases(delete=True) - return - config.INPUT_SPEAKER_MAX_PHRASES = int(value) - view.setGuiVariable_SpeakerMaxPhrases(str(config.INPUT_SPEAKER_MAX_PHRASES)) + view.showErrorMessage_SpeakerMaxPhrases() # Others Tab diff --git a/view.py b/view.py index e1f924ad..88661660 100644 --- a/view.py +++ b/view.py @@ -53,6 +53,12 @@ class View(): **common_args ) + self.settings.modal_window = SimpleNamespace( + ctm=all_ctm.modal_window, + uism=all_uism.modal_window, + **common_args + ) + self.view_variable = SimpleNamespace( # Open Config Window CALLBACK_OPEN_CONFIG_WINDOW=None, @@ -112,6 +118,9 @@ class View(): VAR_UPDATE_AVAILABLE=StringVar(value=i18n.t("main_window.update_available")), + # Modal Window For Main Window + VAR_LABEL_MODAL_MESSAGE_FOR__MAIN_WINDOW=StringVar(value=i18n.t("main_window.modal_message.opened_config_window")), + # Selectable Language Window VAR_TITLE_LABEL_SELECTABLE_LANGUAGE=StringVar(value=""), VAR_GO_BACK_LABEL_SELECTABLE_LANGUAGE=StringVar(value=i18n.t("selectable_language_window.go_back_button")), @@ -121,6 +130,8 @@ class View(): # Config Window ACTIVE_SETTING_BOX_TAB_ATTR_NAME="side_menu_tab_appearance", CALLBACK_SELECTED_SETTING_BOX_TAB=None, + VAR_ERROR_MESSAGE=StringVar(value=""), + # Side Menu Labels VAR_SIDE_MENU_LABEL_APPEARANCE=StringVar(value=i18n.t("config_window.side_menu_labels.appearance")), @@ -191,6 +202,7 @@ class View(): CALLBACK_CHECK_MIC_THRESHOLD=None, VAR_MIC_ENERGY_THRESHOLD__SLIDER=IntVar(value=config.INPUT_MIC_ENERGY_THRESHOLD), VAR_MIC_ENERGY_THRESHOLD__ENTRY=StringVar(value=config.INPUT_MIC_ENERGY_THRESHOLD), + CALLBACK_FOCUS_OUT_MIC_ENERGY_THRESHOLD=self.setLatestConfigVariable_MicEnergyThreshold, VAR_LABEL_MIC_DYNAMIC_ENERGY_THRESHOLD=StringVar(value=i18n.t("config_window.mic_dynamic_energy_threshold.label")), VAR_DESC_MIC_DYNAMIC_ENERGY_THRESHOLD=StringVar(value=i18n.t("config_window.mic_dynamic_energy_threshold.desc")), @@ -201,16 +213,19 @@ class View(): VAR_DESC_MIC_RECORD_TIMEOUT=None, CALLBACK_SET_MIC_RECORD_TIMEOUT=None, VAR_MIC_RECORD_TIMEOUT=StringVar(value=config.INPUT_MIC_RECORD_TIMEOUT), + CALLBACK_FOCUS_OUT_MIC_RECORD_TIMEOUT=self.setLatestConfigVariable_MicRecordTimeout, VAR_LABEL_MIC_PHRASE_TIMEOUT=StringVar(value=i18n.t("config_window.mic_phrase_timeout.label")), VAR_DESC_MIC_PHRASE_TIMEOUT=None, CALLBACK_SET_MIC_PHRASE_TIMEOUT=None, VAR_MIC_PHRASE_TIMEOUT=StringVar(value=config.INPUT_MIC_PHRASE_TIMEOUT), + CALLBACK_FOCUS_OUT_MIC_PHRASE_TIMEOUT=self.setLatestConfigVariable_MicPhraseTimeout, VAR_LABEL_MIC_MAX_PHRASES=StringVar(value=i18n.t("config_window.mic_max_phrase.label")), VAR_DESC_MIC_MAX_PHRASES=StringVar(value=i18n.t("config_window.mic_max_phrase.desc")), CALLBACK_SET_MIC_MAX_PHRASES=None, VAR_MIC_MAX_PHRASES=StringVar(value=config.INPUT_MIC_MAX_PHRASES), + CALLBACK_FOCUS_OUT_MIC_MAX_PHRASES=self.setLatestConfigVariable_MicMaxPhrases, VAR_LABEL_MIC_WORD_FILTER=StringVar(value=i18n.t("config_window.mic_word_filter.label")), VAR_DESC_MIC_WORD_FILTER=StringVar(value=i18n.t("config_window.mic_word_filter.desc")), @@ -231,6 +246,7 @@ class View(): CALLBACK_CHECK_SPEAKER_THRESHOLD=None, VAR_SPEAKER_ENERGY_THRESHOLD__SLIDER=IntVar(value=config.INPUT_SPEAKER_ENERGY_THRESHOLD), VAR_SPEAKER_ENERGY_THRESHOLD__ENTRY=StringVar(value=config.INPUT_SPEAKER_ENERGY_THRESHOLD), + CALLBACK_FOCUS_OUT_SPEAKER_ENERGY_THRESHOLD=self.setLatestConfigVariable_SpeakerEnergyThreshold, VAR_LABEL_SPEAKER_DYNAMIC_ENERGY_THRESHOLD=StringVar(value=i18n.t("config_window.speaker_dynamic_energy_threshold.label")), VAR_DESC_SPEAKER_DYNAMIC_ENERGY_THRESHOLD=StringVar(value=i18n.t("config_window.speaker_dynamic_energy_threshold.desc")), @@ -241,16 +257,19 @@ class View(): VAR_DESC_SPEAKER_RECORD_TIMEOUT=None, CALLBACK_SET_SPEAKER_RECORD_TIMEOUT=None, VAR_SPEAKER_RECORD_TIMEOUT=StringVar(value=config.INPUT_SPEAKER_RECORD_TIMEOUT), + CALLBACK_FOCUS_OUT_SPEAKER_RECORD_TIMEOUT=self.setLatestConfigVariable_SpeakerRecordTimeout, VAR_LABEL_SPEAKER_PHRASE_TIMEOUT=StringVar(value=i18n.t("config_window.speaker_phrase_timeout.label")), VAR_DESC_SPEAKER_PHRASE_TIMEOUT=None, CALLBACK_SET_SPEAKER_PHRASE_TIMEOUT=None, VAR_SPEAKER_PHRASE_TIMEOUT=StringVar(value=config.INPUT_SPEAKER_PHRASE_TIMEOUT), + CALLBACK_FOCUS_OUT_SPEAKER_PHRASE_TIMEOUT=self.setLatestConfigVariable_SpeakerPhraseTimeout, VAR_LABEL_SPEAKER_MAX_PHRASES=StringVar(value=i18n.t("config_window.speaker_max_phrase.label")), VAR_DESC_SPEAKER_MAX_PHRASES=StringVar(value=i18n.t("config_window.speaker_max_phrase.desc")), CALLBACK_SET_SPEAKER_MAX_PHRASES=None, VAR_SPEAKER_MAX_PHRASES=StringVar(value=config.INPUT_SPEAKER_MAX_PHRASES), + CALLBACK_FOCUS_OUT_SPEAKER_MAX_PHRASES=self.setLatestConfigVariable_SpeakerMaxPhrases, # Others Tab @@ -709,19 +728,22 @@ class View(): - def setGuiVariable_MicEnergyThreshold(self, slider_value:int, entry_value:Union[None, str]=None): - self.view_variable.VAR_MIC_ENERGY_THRESHOLD__SLIDER.set(slider_value) - if entry_value is None: - self._clearEntryBox(vrct_gui.config_window.sb__progressbar_x_slider__entry_mic_energy_threshold) - else: - self.view_variable.VAR_MIC_ENERGY_THRESHOLD__ENTRY.set(entry_value) + def setGuiVariable_MicEnergyThreshold(self, value:int): + self.view_variable.VAR_MIC_ENERGY_THRESHOLD__SLIDER.set(value) + self.view_variable.VAR_MIC_ENERGY_THRESHOLD__ENTRY.set(str(value)) - def setGuiVariable_SpeakerEnergyThreshold(self, slider_value:int, entry_value:Union[None, str]=None): - self.view_variable.VAR_SPEAKER_ENERGY_THRESHOLD__SLIDER.set(slider_value) - if entry_value is None: - self._clearEntryBox(vrct_gui.config_window.sb__progressbar_x_slider__entry_speaker_energy_threshold) - else: - self.view_variable.VAR_SPEAKER_ENERGY_THRESHOLD__ENTRY.set(entry_value) + def setLatestConfigVariable_MicEnergyThreshold(self, _e=None): + self.setGuiVariable_MicEnergyThreshold(config.INPUT_MIC_ENERGY_THRESHOLD) + self.clearErrorMessage() + + + def setGuiVariable_SpeakerEnergyThreshold(self, value:int): + self.view_variable.VAR_SPEAKER_ENERGY_THRESHOLD__SLIDER.set(value) + self.view_variable.VAR_SPEAKER_ENERGY_THRESHOLD__ENTRY.set(str(value)) + + def setLatestConfigVariable_SpeakerEnergyThreshold(self, _e=None): + self.setGuiVariable_SpeakerEnergyThreshold(config.INPUT_SPEAKER_ENERGY_THRESHOLD) + self.clearErrorMessage() @@ -729,35 +751,93 @@ class View(): if delete is True: self._clearEntryBox(vrct_gui.config_window.sb__entry_mic_record_timeout) self.view_variable.VAR_MIC_RECORD_TIMEOUT.set(value) + def setLatestConfigVariable_MicRecordTimeout(self, _e=None): + self.setGuiVariable_MicRecordTimeout(config.INPUT_MIC_RECORD_TIMEOUT) + self.clearErrorMessage() + + def setGuiVariable_MicPhraseTimeout(self, value:str="", delete=False): if delete is True: self._clearEntryBox(vrct_gui.config_window.sb__entry_mic_phrase_timeout) self.view_variable.VAR_MIC_PHRASE_TIMEOUT.set(value) + def setLatestConfigVariable_MicPhraseTimeout(self, _e=None): + self.setGuiVariable_MicPhraseTimeout(config.INPUT_MIC_PHRASE_TIMEOUT) + self.clearErrorMessage() + + def setGuiVariable_MicMaxPhrases(self, value:str="", delete=False): if delete is True: self._clearEntryBox(vrct_gui.config_window.sb__entry_mic_max_phrases) self.view_variable.VAR_MIC_MAX_PHRASES.set(value) + def setLatestConfigVariable_MicMaxPhrases(self, _e=None): + self.setGuiVariable_MicMaxPhrases(config.INPUT_MIC_MAX_PHRASES) + self.clearErrorMessage() + def setGuiVariable_SpeakerRecordTimeout(self, value:str="", delete=False): if delete is True: self._clearEntryBox(vrct_gui.config_window.sb__entry_speaker_record_timeout) self.view_variable.VAR_SPEAKER_RECORD_TIMEOUT.set(value) + def setLatestConfigVariable_SpeakerRecordTimeout(self, _e=None): + self.setGuiVariable_SpeakerRecordTimeout(config.INPUT_SPEAKER_RECORD_TIMEOUT) + self.clearErrorMessage() + + def setGuiVariable_SpeakerPhraseTimeout(self, value:str="", delete=False): if delete is True: self._clearEntryBox(vrct_gui.config_window.sb__entry_speaker_phrase_timeout) self.view_variable.VAR_SPEAKER_PHRASE_TIMEOUT.set(value) + def setLatestConfigVariable_SpeakerPhraseTimeout(self, _e=None): + self.setGuiVariable_SpeakerPhraseTimeout(config.INPUT_SPEAKER_PHRASE_TIMEOUT) + self.clearErrorMessage() + + def setGuiVariable_SpeakerMaxPhrases(self, value:str="", delete=False): if delete is True: self._clearEntryBox(vrct_gui.config_window.sb__entry_speaker_max_phrases) self.view_variable.VAR_SPEAKER_MAX_PHRASES.set(value) + def setLatestConfigVariable_SpeakerMaxPhrases(self, _e=None): + self.setGuiVariable_SpeakerMaxPhrases(config.INPUT_SPEAKER_MAX_PHRASES) + self.clearErrorMessage() + @staticmethod def _clearEntryBox(entry_widget): entry_widget.delete(0, CTK_END) + def showErrorMessage_MicEnergyThreshold(self): + self._showErrorMessage(vrct_gui.config_window.sb__progressbar_x_slider__entry_mic_energy_threshold, "Mic Energy Threshold Error Message") + def showErrorMessage_MicRecordTimeout(self): + self._showErrorMessage(vrct_gui.config_window.sb__entry_mic_record_timeout, "Mic Record Timeout Error Message") + + def showErrorMessage_MicPhraseTimeout(self): + self._showErrorMessage(vrct_gui.config_window.sb__entry_mic_phrase_timeout, "Mic Phrase Timeout Error Message") + + def showErrorMessage_MicMaxPhrases(self): + self._showErrorMessage(vrct_gui.config_window.sb__entry_mic_max_phrases, "Mic Max Phrases Error Message") + + + def showErrorMessage_SpeakerEnergyThreshold(self): + self._showErrorMessage(vrct_gui.config_window.sb__progressbar_x_slider__entry_speaker_energy_threshold, "Speaker Energy Threshold Error Message") + + def showErrorMessage_SpeakerRecordTimeout(self): + self._showErrorMessage(vrct_gui.config_window.sb__entry_speaker_record_timeout, "Speaker Record Timeout Error Message") + + def showErrorMessage_SpeakerPhraseTimeout(self): + self._showErrorMessage(vrct_gui.config_window.sb__entry_speaker_phrase_timeout, "Speaker Phrase Timeout Error Message") + + def showErrorMessage_SpeakerMaxPhrases(self): + self._showErrorMessage(vrct_gui.config_window.sb__entry_speaker_max_phrases, "Speaker Max Phrases Error Message") + + def _showErrorMessage(self, target_widget, message): + self.view_variable.VAR_ERROR_MESSAGE.set(message) + vrct_gui.showErrorMessage(target_widget=target_widget) + + def clearErrorMessage(self): + vrct_gui._clearErrorMessage() # These conversations are generated by ChatGPT def _insertSampleConversationToTextbox(self): diff --git a/vrct_gui/_CreateErrorWindow.py b/vrct_gui/_CreateErrorWindow.py new file mode 100644 index 00000000..24a33c27 --- /dev/null +++ b/vrct_gui/_CreateErrorWindow.py @@ -0,0 +1,134 @@ +from customtkinter import CTkToplevel, CTkFrame, CTkLabel, CTkFont +from time import sleep + +class _CreateErrorWindow(CTkToplevel): + def __init__(self, settings, view_variable, wrapper_widget): + super().__init__() + self.withdraw() + self.hide = True + + self.title("") + self.overrideredirect(True) + + self.wm_attributes("-alpha", 0) + self.wm_attributes("-toolwindow", True) + + self.settings = settings + self.attach_widget = None + self._view_variable = view_variable + self.wrapper_widget = wrapper_widget + + + + self.attach_widget_width = None + self.attach_widget_height = None + self.attach_widget_x_pos = None + self.attach_widget_y_pos = None + self.x_pos = None + self.y_pos = None + + + + self.rowconfigure(0,weight=1) + self.columnconfigure(0,weight=1) + + # The color code [#bb4448] is a mixture of [#a9555c] and [#cc3333] (for a redder shade). + self.modal_container = CTkFrame(self, corner_radius=0, fg_color="#bb4448", width=0, height=0) + self.modal_container.grid(row=0, column=0, sticky="nsew") + + + self.modal_container_label_wrapper = CTkLabel( + self.modal_container, + # text=message, + textvariable=self._view_variable.VAR_ERROR_MESSAGE, + height=0, + corner_radius=0, + font=CTkFont(family=self.settings.FONT_FAMILY, size=12, weight="normal"), + anchor="w", + text_color="white", + ) + self.modal_container_label_wrapper.grid(row=0, column=0, padx=10, pady=6, sticky="nsew") + + + + def show(self, target_widget): + if self.hide is False: return + + self.attach_widget = target_widget + + self.deiconify() + self._adjustToTargetWidgetGeometry() + self.BIND_CONFIGURE_FUNC_ID = self.attach_widget.winfo_toplevel().bind("", self._adjustToTargetWidgetGeometry, "+") + self.BIND_UNMAP_FUNC_ID = self.attach_widget.bind("", self._withdraw, "+") + + self.hide = False + + + for i in range(0,101,20): + if not self.winfo_exists(): + break + self.attributes("-alpha", i/100) + self.update() + sleep(1/100) + + sleep(0.1) + + for i in range(0,91,10): + if not self.winfo_exists(): + break + self.attributes("-alpha", i/100) + self.update() + sleep(1/80) + + + def _withdraw(self, e=None): + self.withdraw() + self.attach_widget.winfo_toplevel().unbind("", self.BIND_CONFIGURE_FUNC_ID) + self.attach_widget.unbind("", self.BIND_UNMAP_FUNC_ID) + self.hide = True + + + + def _adjustToTargetWidgetGeometry(self, e=None): + if not self.attach_widget.winfo_exists(): + return + self.attach_widget.update_idletasks() + + + + self.update() + if self.attach_widget_x_pos == self.attach_widget.winfo_rootx() and self.attach_widget_y_pos == self.attach_widget.winfo_rooty(): + self.lift() + return + + self.wrapper_widget_y_pos = self.wrapper_widget.winfo_rooty() + self.wrapper_widget_bottom_y_pos = self.wrapper_widget_y_pos + self.wrapper_widget.winfo_height() + + self.attach_widget_width = self.attach_widget.winfo_width() + self.attach_widget_height = self.attach_widget.winfo_height() + self.attach_widget_x_pos = self.attach_widget.winfo_rootx() + self.attach_widget_y_pos = self.attach_widget.winfo_rooty() + + + self.y_pos = int(self.attach_widget_y_pos + self.attach_widget_height + 4) + + if self.wrapper_widget_y_pos > self.y_pos or self.y_pos > self.wrapper_widget_bottom_y_pos: + self.hideTemporarily() + else: + if self.winfo_exists(): + self.deiconify() + + + if self.winfo_width() >= self.attach_widget_width: + self.x_pos = int(self.attach_widget_x_pos - (self.winfo_width() - self.attach_widget_width)) + else: + self.x_pos = self.attach_widget_x_pos + + self.geometry("+{}+{}".format(self.x_pos, self.y_pos)) + + self.lift() + + def hideTemporarily(self): + self.withdraw() + + diff --git a/vrct_gui/_CreateModalWindow.py b/vrct_gui/_CreateModalWindow.py new file mode 100644 index 00000000..b54bad76 --- /dev/null +++ b/vrct_gui/_CreateModalWindow.py @@ -0,0 +1,49 @@ +from customtkinter import CTkToplevel, CTkFrame, CTkLabel, CTkFont + +class _CreateModalWindow(CTkToplevel): + def __init__(self, attach_window, settings, view_variable): + super().__init__() + self.withdraw() + + + self.title("") + self.overrideredirect(True) + + self.wm_attributes("-alpha", 0.5) + self.wm_attributes("-toolwindow", True) + + self.attach_window = attach_window + + + self.configure(fg_color="black") + self.protocol("WM_DELETE_WINDOW", lambda e: self.withdraw()) + + self.settings = settings + self._view_variable = view_variable + + + self.attach_window.update_idletasks() + self.x_pos = self.attach_window.winfo_rootx() + self.y_pos = self.attach_window.winfo_rooty() + self.width_new = self.attach_window.winfo_width() + self.height_new = self.attach_window.winfo_height() + + + self.geometry('{}x{}+{}+{}'.format(self.width_new, self.height_new, self.x_pos, self.y_pos)) + + self.rowconfigure(0,weight=1) + self.columnconfigure(0,weight=1) + self.modal_container = CTkFrame(self, corner_radius=0, fg_color="black", width=0, height=0) + self.modal_container.grid(row=0, column=0, sticky="nsew") + + + self.modal_container_label_wrapper = CTkLabel( + self.modal_container, + textvariable=self._view_variable.VAR_LABEL_MODAL_MESSAGE_FOR__MAIN_WINDOW, + height=0, + corner_radius=0, + font=CTkFont(family=self.settings.FONT_FAMILY, size=self.settings.uism.TEXT_FONT_SIZE, weight="normal"), + anchor="w", + text_color=self.settings.ctm.TEXT_COLOR, + ) + self.modal_container_label_wrapper.place(relx=0.5, rely=0.5, anchor="center") \ No newline at end of file diff --git a/vrct_gui/config_window/ConfigWindow.py b/vrct_gui/config_window/ConfigWindow.py index 26d94b46..4e469de2 100644 --- a/vrct_gui/config_window/ConfigWindow.py +++ b/vrct_gui/config_window/ConfigWindow.py @@ -31,4 +31,7 @@ class ConfigWindow(CTkToplevel): createSettingBoxTopBar(config_window=self, settings=self.settings, view_variable=self._view_variable) - createSideMenuAndSettingsBoxContainers(config_window=self, settings=self.settings, view_variable=self._view_variable) \ No newline at end of file + createSideMenuAndSettingsBoxContainers(config_window=self, settings=self.settings, view_variable=self._view_variable) + + + self.bind_all("", lambda event: event.widget.focus_set(), "+") \ No newline at end of file diff --git a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/_SettingBoxGenerator.py b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/_SettingBoxGenerator.py index 766e0ccd..051e09eb 100644 --- a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/_SettingBoxGenerator.py +++ b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/_SettingBoxGenerator.py @@ -185,12 +185,13 @@ class _SettingBoxGenerator(): def createSettingBoxProgressbarXSlider( self, for_var_label_text, for_var_desc_text, command, - entry_attr_name, + entry_attr_name, entry_bind__FocusOut, slider_attr_name, slider_range, progressbar_attr_name, passive_button_attr_name, passive_button_command, active_button_attr_name, active_button_command, button_image_file, + entry_variable, slider_variable, @@ -220,10 +221,14 @@ class _SettingBoxGenerator(): ) entry_widget.bind("", adjusted_command__for_entry_bind__Any_KeyRelease) + if entry_bind__FocusOut is not None: + entry_widget.bind("", entry_bind__FocusOut, "+") + entry_widget.grid(row=1, column=SETTING_BOX_COLUMN, padx=0, pady=0, sticky="e") setattr(self.config_window, entry_attr_name, entry_widget) + # at least 2px is needed otherwise the slider button is gonna broken. SLIDER_BORDER_WIDTH = max(2,self.settings.uism.SB__PROGRESSBAR_X_SLIDER__SLIDER_BUTTON_LENGTH) SLIDER_BUTTON_LENGTH = int(SLIDER_BORDER_WIDTH/2) @@ -286,7 +291,7 @@ class _SettingBoxGenerator(): - def createSettingBoxEntry(self, for_var_label_text, for_var_desc_text, entry_attr_name, entry_width, entry_bind__Any_KeyRelease, entry_textvariable): + def createSettingBoxEntry(self, for_var_label_text, for_var_desc_text, entry_attr_name, entry_width, entry_bind__Any_KeyRelease, entry_textvariable, entry_bind__FocusOut=None): (setting_box_frame, setting_box_item_frame) = self._createSettingBoxFrame(for_var_label_text, for_var_desc_text) def adjusted_command__for_entry_bind__Any_KeyRelease(e): @@ -305,6 +310,9 @@ class _SettingBoxGenerator(): entry_widget.grid(row=1, column=SETTING_BOX_COLUMN, sticky="e") + if entry_bind__FocusOut is not None: + entry_widget.bind("", entry_bind__FocusOut, "+") + return setting_box_frame diff --git a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_transcription/createSettingBox_Mic.py b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_transcription/createSettingBox_Mic.py index 66160591..a02bc583 100644 --- a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_transcription/createSettingBox_Mic.py +++ b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_transcription/createSettingBox_Mic.py @@ -72,6 +72,7 @@ def createSettingBox_Mic(setting_box_wrapper, config_window, settings, view_vari entry_attr_name="sb__progressbar_x_slider__entry_mic_energy_threshold", entry_variable=view_variable.VAR_MIC_ENERGY_THRESHOLD__ENTRY, + entry_bind__FocusOut=view_variable.CALLBACK_FOCUS_OUT_MIC_ENERGY_THRESHOLD, slider_attr_name="progressbar_x_slider__slider_mic_energy_threshold", @@ -109,6 +110,7 @@ def createSettingBox_Mic(setting_box_wrapper, config_window, settings, view_vari entry_width=settings.uism.SB__ENTRY_WIDTH_100, entry_bind__Any_KeyRelease=lambda value: entry_input_mic_record_timeout_callback(value), entry_textvariable=view_variable.VAR_MIC_RECORD_TIMEOUT, + entry_bind__FocusOut=view_variable.CALLBACK_FOCUS_OUT_MIC_RECORD_TIMEOUT, ) config_window.sb__mic_record_timeout.grid(row=row) row+=1 @@ -120,6 +122,7 @@ def createSettingBox_Mic(setting_box_wrapper, config_window, settings, view_vari entry_width=settings.uism.SB__ENTRY_WIDTH_100, entry_bind__Any_KeyRelease=lambda value: entry_input_mic_phrase_timeout_callback(value), entry_textvariable=view_variable.VAR_MIC_PHRASE_TIMEOUT, + entry_bind__FocusOut=view_variable.CALLBACK_FOCUS_OUT_MIC_PHRASE_TIMEOUT, ) config_window.sb__mic_phrase_timeout.grid(row=row) row+=1 @@ -131,6 +134,7 @@ def createSettingBox_Mic(setting_box_wrapper, config_window, settings, view_vari entry_width=settings.uism.SB__ENTRY_WIDTH_100, entry_bind__Any_KeyRelease=lambda value: entry_input_mic_max_phrases_callback(value), entry_textvariable=view_variable.VAR_MIC_MAX_PHRASES, + entry_bind__FocusOut=view_variable.CALLBACK_FOCUS_OUT_MIC_MAX_PHRASES, ) config_window.sb__mic_max_phrases.grid(row=row) row+=1 diff --git a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_transcription/createSettingBox_Speaker.py b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_transcription/createSettingBox_Speaker.py index 0a04eca7..5ebae1b5 100644 --- a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_transcription/createSettingBox_Speaker.py +++ b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_transcription/createSettingBox_Speaker.py @@ -55,6 +55,7 @@ def createSettingBox_Speaker(setting_box_wrapper, config_window, settings, view_ entry_variable=view_variable.VAR_SPEAKER_ENERGY_THRESHOLD__ENTRY, entry_attr_name="sb__progressbar_x_slider__entry_speaker_energy_threshold", + entry_bind__FocusOut=view_variable.CALLBACK_FOCUS_OUT_SPEAKER_ENERGY_THRESHOLD, slider_attr_name="progressbar_x_slider__slider_speaker_energy_threshold", @@ -92,6 +93,7 @@ def createSettingBox_Speaker(setting_box_wrapper, config_window, settings, view_ entry_width=settings.uism.SB__ENTRY_WIDTH_100, entry_bind__Any_KeyRelease=lambda value: entry_input_speaker_record_timeout_callback(value), entry_textvariable=view_variable.VAR_SPEAKER_RECORD_TIMEOUT, + entry_bind__FocusOut=view_variable.CALLBACK_FOCUS_OUT_SPEAKER_RECORD_TIMEOUT, ) config_window.sb__speaker_record_timeout.grid(row=row) row+=1 @@ -103,6 +105,7 @@ def createSettingBox_Speaker(setting_box_wrapper, config_window, settings, view_ entry_width=settings.uism.SB__ENTRY_WIDTH_100, entry_bind__Any_KeyRelease=lambda value: entry_input_speaker_phrase_timeout_callback(value), entry_textvariable=view_variable.VAR_SPEAKER_PHRASE_TIMEOUT, + entry_bind__FocusOut=view_variable.CALLBACK_FOCUS_OUT_SPEAKER_PHRASE_TIMEOUT, ) config_window.sb__speaker_phrase_timeout.grid(row=row) row+=1 @@ -114,6 +117,7 @@ def createSettingBox_Speaker(setting_box_wrapper, config_window, settings, view_ entry_width=settings.uism.SB__ENTRY_WIDTH_100, entry_bind__Any_KeyRelease=lambda value: entry_input_speaker_max_phrases_callback(value), entry_textvariable=view_variable.VAR_SPEAKER_MAX_PHRASES, + entry_bind__FocusOut=view_variable.CALLBACK_FOCUS_OUT_SPEAKER_MAX_PHRASES, ) config_window.sb__speaker_max_phrases.grid(row=row) row+=1 diff --git a/vrct_gui/ui_managers/ColorThemeManager.py b/vrct_gui/ui_managers/ColorThemeManager.py index 2b5833ef..c712b2d4 100644 --- a/vrct_gui/ui_managers/ColorThemeManager.py +++ b/vrct_gui/ui_managers/ColorThemeManager.py @@ -5,6 +5,7 @@ class ColorThemeManager(): self.main = SimpleNamespace() self.config_window = SimpleNamespace() self.selectable_language_window = SimpleNamespace() + self.modal_window = SimpleNamespace() # old one. But leave it here for now. # self.PRIMARY_100_COLOR = "#c4eac1" @@ -207,6 +208,9 @@ class ColorThemeManager(): self.selectable_language_window.LANGUAGE_BUTTON_BG_CLICKED_COLOR = self.DARK_888_COLOR + # Modal Window (Main Window) + self.modal_window.TEXT_COLOR = self.LIGHT_100_COLOR + # Common self.config_window.BASIC_TEXT_COLOR = self.main.BASIC_TEXT_COLOR diff --git a/vrct_gui/ui_managers/UiScalingManager.py b/vrct_gui/ui_managers/UiScalingManager.py index ebac9bec..902951b5 100644 --- a/vrct_gui/ui_managers/UiScalingManager.py +++ b/vrct_gui/ui_managers/UiScalingManager.py @@ -6,6 +6,7 @@ class UiScalingManager(): self.SCALING_FLOAT = max(scaling_float, 0.4) self.main = SimpleNamespace() self.config_window = SimpleNamespace() + self.modal_window = SimpleNamespace() self._calculatedUiSizes() @@ -96,7 +97,7 @@ class UiScalingManager(): self.main.MINIMIZE_SIDEBAR_BUTTON_ICON_SIZE_Y = self._calculateUiSize(26) - + self.modal_window.TEXT_FONT_SIZE = self._calculateUiSize(20) # Top bar common self.config_window.TOP_BAR__HEIGHT = self._calculateUiSize(40) diff --git a/vrct_gui/vrct_gui.py b/vrct_gui/vrct_gui.py index 4913c64b..bd167560 100644 --- a/vrct_gui/vrct_gui.py +++ b/vrct_gui/vrct_gui.py @@ -4,6 +4,8 @@ from customtkinter import CTk, CTkImage from ._CreateSelectableLanguagesWindow import _CreateSelectableLanguagesWindow +from ._CreateModalWindow import _CreateModalWindow +from ._CreateErrorWindow import _CreateErrorWindow from ._changeMainWindowWidgetsStatus import _changeMainWindowWidgetsStatus from ._changeConfigWindowWidgetsStatus import _changeConfigWindowWidgetsStatus from ._printToTextbox import _printToTextbox @@ -17,6 +19,9 @@ from utils import callFunctionIfCallable class VRCT_GUI(CTk): def __init__(self): super().__init__() + self.adjusted_event=None + self.BIND_CONFIGURE_ADJUSTED_GEOMETRY_FUNC_ID=None + def createGUI(self, settings, view_variable): self.settings = settings @@ -41,6 +46,20 @@ class VRCT_GUI(CTk): view_variable=self._view_variable ) + self.modal_window = _CreateModalWindow( + attach_window=self, + settings=self.settings.modal_window, + view_variable=self._view_variable + ) + + self.error_message_window = _CreateErrorWindow( + settings=self.settings.modal_window, + view_variable=self._view_variable, + wrapper_widget=self.config_window.main_bg_container, + ) + + + def startMainLoop(self): self.mainloop() @@ -50,18 +69,26 @@ class VRCT_GUI(CTk): self.destroy() - def openConfigWindow(self, e): + def openConfigWindow(self, _e): callFunctionIfCallable(self._view_variable.CALLBACK_OPEN_CONFIG_WINDOW) + + self.adjustToMainWindowGeometry() + self.modal_window.deiconify() + self.BIND_CONFIGURE_ADJUSTED_GEOMETRY_FUNC_ID = self.bind("", self.adjustToMainWindowGeometry) + 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() + self.modal_window.withdraw() + self.unbind("", self.BIND_CONFIGURE_ADJUSTED_GEOMETRY_FUNC_ID) + self.adjusted_event=None @@ -160,4 +187,32 @@ class VRCT_GUI(CTk): self.minimize_sidebar_button_container__for_closing.grid() + def adjustToMainWindowGeometry(self, e=None): + self.update_idletasks() + x_pos = self.winfo_rootx() + y_pos = self.winfo_rooty() + width_new = self.winfo_width() + height_new = self.winfo_height() + self.modal_window.geometry("{}x{}+{}+{}".format(width_new, height_new, x_pos, y_pos)) + + self.modal_window.lift() + if self.adjusted_event == str(e): + self.after(150, lambda: self.config_window.lift()) + elif self.adjusted_event is None: + self.after(150, lambda: self.config_window.lift()) + + if e is not None: + self.adjusted_event=str(e) + + + def showErrorMessage(self, target_widget): + self.error_message_window.show(target_widget=target_widget) + + def _clearErrorMessage(self): + try: + self.error_message_window._withdraw() + except: + pass + + vrct_gui = VRCT_GUI() \ No newline at end of file