From 53cb8d90886a814b69224871d306401acc4c19a0 Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Thu, 5 Oct 2023 10:51:15 +0900 Subject: [PATCH] =?UTF-8?q?[Update]=20Config=20Window:=20=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E6=A9=9F=E8=83=BD(=E3=83=A1=E3=83=83?= =?UTF-8?q?=E3=82=BB=E3=83=BC=E3=82=B8=E5=86=85=E5=AE=B9=E3=81=AF=E4=BB=AE?= =?UTF-8?q?=E7=BD=AE=E3=81=8D):=20=E3=83=90=E3=83=AA=E3=83=87=E3=83=BC?= =?UTF-8?q?=E3=82=B7=E3=83=A7=E3=83=B3=E3=81=AB=E3=82=88=E3=82=8A=E7=84=A1?= =?UTF-8?q?=E5=8A=B9=E3=81=AA=E5=80=A4=E3=82=92=E5=85=A5=E5=8A=9B=E3=81=97?= =?UTF-8?q?=E3=81=9F=E5=A0=B4=E5=90=88=E3=81=AB=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8=E3=82=92=E8=A1=A8?= =?UTF-8?q?=E7=A4=BA=E3=80=82=E3=82=A8=E3=83=A9=E3=83=BC=E3=83=A1=E3=83=83?= =?UTF-8?q?=E3=82=BB=E3=83=BC=E3=82=B8=E3=81=AF=E6=96=B0=E3=81=97=E3=81=8F?= =?UTF-8?q?Window=E3=82=92=E4=BD=9C=E3=81=A3=E3=81=A6=E8=A2=AB=E3=81=9B?= =?UTF-8?q?=E3=82=8B=E5=BD=A2=E3=81=AB=E3=81=97=E3=81=A6=E3=81=84=E3=81=BE?= =?UTF-8?q?=E3=81=99=E3=80=82=E4=BB=96=E3=81=AE=E9=83=A8=E5=88=86=E3=82=92?= =?UTF-8?q?=E3=82=AF=E3=83=AA=E3=83=83=E3=82=AF=E3=81=97=E3=81=9F=E3=82=8A?= =?UTF-8?q?=E3=80=81=E3=83=9B=E3=82=A4=E3=83=BC=E3=83=AB=E3=81=AB=E3=82=88?= =?UTF-8?q?=E3=82=8B=E3=82=B9=E3=82=AF=E3=83=AD=E3=83=BC=E3=83=AB=E3=81=AA?= =?UTF-8?q?=E3=81=A9=E3=81=A7=E7=94=BB=E9=9D=A2=E5=A4=96=E3=81=B8=E3=81=84?= =?UTF-8?q?=E3=81=A3=E3=81=9F=E6=99=82=E3=81=AB=E6=B6=88=E3=81=97=E3=81=9F?= =?UTF-8?q?=E3=82=8A=E3=81=AA=E3=81=A9=E3=81=AE=E5=87=A6=E7=90=86=E3=82=82?= =?UTF-8?q?=E5=AE=9F=E8=A3=85=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Entry Widget系フォーカスアウト機能:そのWidget外をクリックした時にちゃんとフォーカスアウトし、その際にconfigに保存されている有効な値をセット。 (今のところTranscription項目内のEntry Widgetがある項目のみ) [bugfix] Main Window: Modal Windowのevent unbindに、ちゃんとIDを指定してunbindするように。(vrct_gui.py line 90) --- main.py | 118 ++++++++------- view.py | 95 +++++++++++-- vrct_gui/_CreateErrorWindow.py | 134 ++++++++++++++++++ vrct_gui/config_window/ConfigWindow.py | 5 +- .../_SettingBoxGenerator.py | 12 +- .../createSettingBox_Mic.py | 4 + .../createSettingBox_Speaker.py | 4 + vrct_gui/vrct_gui.py | 26 +++- 8 files changed, 326 insertions(+), 72 deletions(-) create mode 100644 vrct_gui/_CreateErrorWindow.py 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 a49da319..88661660 100644 --- a/view.py +++ b/view.py @@ -130,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")), @@ -200,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")), @@ -210,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")), @@ -240,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")), @@ -250,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 @@ -718,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() @@ -738,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/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/vrct_gui.py b/vrct_gui/vrct_gui.py index 54705bb9..bd167560 100644 --- a/vrct_gui/vrct_gui.py +++ b/vrct_gui/vrct_gui.py @@ -5,6 +5,7 @@ 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 @@ -19,6 +20,7 @@ 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): @@ -50,6 +52,12 @@ class VRCT_GUI(CTk): 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): @@ -61,12 +69,12 @@ 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("", self.adjustToMainWindowGeometry) + self.BIND_CONFIGURE_ADJUSTED_GEOMETRY_FUNC_ID = self.bind("", self.adjustToMainWindowGeometry) self.config_window.deiconify() self.config_window.focus_set() @@ -74,11 +82,12 @@ class VRCT_GUI(CTk): 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.unbind("", self.BIND_CONFIGURE_ADJUSTED_GEOMETRY_FUNC_ID) self.adjusted_event=None @@ -195,4 +204,15 @@ class VRCT_GUI(CTk): 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