[Update] Config Window:

エラーメッセージ表示機能(メッセージ内容は仮置き): バリデーションにより無効な値を入力した場合にエラーメッセージを表示。エラーメッセージは新しくWindowを作って被せる形にしています。他の部分をクリックしたり、ホイールによるスクロールなどで画面外へいった時に消したりなどの処理も実装。

Entry Widget系フォーカスアウト機能:そのWidget外をクリックした時にちゃんとフォーカスアウトし、その際にconfigに保存されている有効な値をセット。
(今のところTranscription項目内のEntry Widgetがある項目のみ)

[bugfix] Main Window: Modal Windowのevent unbindに、ちゃんとIDを指定してunbindするように。(vrct_gui.py line 90)
This commit is contained in:
Sakamoto Shiina
2023-10-05 10:51:15 +09:00
parent 584eb7e33a
commit 53cb8d9088
8 changed files with 326 additions and 72 deletions

118
main.py
View File

@@ -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

95
view.py
View File

@@ -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):

View File

@@ -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("<Configure>", self._adjustToTargetWidgetGeometry, "+")
self.BIND_UNMAP_FUNC_ID = self.attach_widget.bind("<Unmap>", 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("<Configure>", self.BIND_CONFIGURE_FUNC_ID)
self.attach_widget.unbind("<Unmap>", 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()

View File

@@ -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)
createSideMenuAndSettingsBoxContainers(config_window=self, settings=self.settings, view_variable=self._view_variable)
self.bind_all("<Button-1>", lambda event: event.widget.focus_set(), "+")

View File

@@ -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("<Any-KeyRelease>", adjusted_command__for_entry_bind__Any_KeyRelease)
if entry_bind__FocusOut is not None:
entry_widget.bind("<FocusOut>", 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("<FocusOut>", entry_bind__FocusOut, "+")
return setting_box_frame

View File

@@ -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

View File

@@ -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

View File

@@ -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("<Configure>", self.adjustToMainWindowGeometry)
self.BIND_CONFIGURE_ADJUSTED_GEOMETRY_FUNC_ID = self.bind("<Configure>", 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("<Configure>")
self.unbind("<Configure>", 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()