Config Windowの各項目Callback関数をmain.pyコントローラで実行できるように

This commit is contained in:
Sakamoto Shiina
2023-09-01 02:25:00 +09:00
parent ed88a5b886
commit 799a1a27bb
10 changed files with 282 additions and 61 deletions

168
main.py
View File

@@ -213,6 +213,7 @@ def callbackToggleForeground():
# Config Window
# Compact Mode Switch
def callbackEnableConfigWindowCompactMode():
config.IS_CONFIG_WINDOW_COMPACT_MODE = True
view.reloadConfigWindowSettingBoxContainer()
@@ -221,6 +222,133 @@ def callbackDisableConfigWindowCompactMode():
config.IS_CONFIG_WINDOW_COMPACT_MODE = False
view.reloadConfigWindowSettingBoxContainer()
# Appearance Tab
def callbackSetTransparency(value):
print(int(value))
# self.parent.wm_attributes("-alpha", int(value/100))
config.TRANSPARENCY = int(value)
def callbackSetAppearance(value):
print(value)
config.APPEARANCE_THEME = value
def callbackSetUiScaling(value):
print(value)
config.UI_SCALING = value
new_scaling_float = int(value.replace("%", "")) / 100
def callbackSetFontFamily(value):
print(value)
config.FONT_FAMILY = value
def callbackSetUiLanguage(value):
print(value)
config.UI_LANGUAGE = value
# Translation Tab
def callbackSetDeeplAuthkey(value):
print(str(value))
# config.AUTH_KEYS["DeepL(auth)"] = str(value)
# if len(value) > 0:
# if model.authenticationTranslator(choice_translator="DeepL(auth)", auth_key=value) is True:
# print_textbox(self.parent.textbox_message_log, "Auth key update completed", "INFO")
# print_textbox(self.parent.textbox_message_system_log, "Auth key update completed", "INFO")
# else:
# pass
# Transcription Tab (Mic)
def callbackSetMicHost(value):
print(value)
config.CHOICE_MIC_HOST = value
def callbackSetMicDevice(value):
print(value)
config.CHOICE_MIC_DEVICE = value
def callbackSetMicEnergyThreshold(value):
print(int(value))
config.INPUT_MIC_ENERGY_THRESHOLD = int(value)
def callbackSetMicDynamicEnergyThreshold(value):
print(value)
config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = value
def callbackSetMicRecordTimeout(value):
print(int(value))
config.INPUT_MIC_RECORD_TIMEOUT = int(value)
def callbackSetMicPhraseTimeout(value):
print(int(value))
config.INPUT_MIC_PHRASE_TIMEOUT = int(value)
def callbackSetMicMaxPhrases(value):
print(int(value))
config.INPUT_MIC_MAX_PHRASES = int(value)
def callbackSetMicWordFilter(value):
word_filter = str(value)
word_filter = [w.strip() for w in word_filter.split(",") if len(w.strip()) > 0]
word_filter = ",".join(word_filter)
print(word_filter)
if len(word_filter) > 0:
config.INPUT_MIC_WORD_FILTER = word_filter.split(",")
else:
config.INPUT_MIC_WORD_FILTER = []
# model.resetKeywordProcessor()
# model.addKeywords()
# Transcription Tab (Speaker)
def callbackSetSpeakerDevice(value):
print(value)
config.CHOICE_SPEAKER_DEVICE = value
def callbackSetSpeakerEnergyThreshold(value):
print(int(value))
config.INPUT_SPEAKER_ENERGY_THRESHOLD = int(value)
def callbackSetSpeakerDynamicEnergyThreshold(value):
print(value)
config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = value
def callbackSetSpeakerRecordTimeout(value):
print(int(value))
config.INPUT_SPEAKER_RECORD_TIMEOUT = int(value)
def callbackSetSpeakerPhraseTimeout(value):
print(int(value))
config.INPUT_SPEAKER_PHRASE_TIMEOUT = int(value)
def callbackSetSpeakerMaxPhrases(value):
print(int(value))
config.INPUT_SPEAKER_MAX_PHRASES = int(value)
# Others Tab
def callbackSetEnableAutoClearChatbox(value):
print(value)
config.ENABLE_AUTO_CLEAR_CHATBOX = value
def callbackSetEnableNoticeXsoverlay(value):
print(value)
config.ENABLE_NOTICE_XSOVERLAY = value
def callbackSetMessageFormat(value):
print(value)
if len(value) > 0:
config.MESSAGE_FORMAT = value
# Advanced Settings Tab
def callbackSetOscIpAddress(value):
print(value)
config.OSC_IP_ADDRESS = value
def callbackSetOscPort(value):
print(int(value))
config.OSC_PORT = int(value)
# create GUI
view.createGUI()
@@ -233,7 +361,7 @@ if model.authenticationTranslator() is False:
model.addKeywords()
# check OSC started
model.checkOSCStarted()
# model.checkOSCStarted()
# check Software Updated
model.checkSoftwareUpdated()
@@ -263,8 +391,46 @@ view.register(
},
config_window={
# Compact Mode Switch
"callback_disable_config_window_compact_mode": callbackEnableConfigWindowCompactMode,
"callback_enable_config_window_compact_mode": callbackDisableConfigWindowCompactMode,
# Appearance Tab
"callback_set_transparency": callbackSetTransparency,
"callback_set_appearance": callbackSetAppearance,
"callback_set_ui_scaling": callbackSetUiScaling,
"callback_set_font_family": callbackSetFontFamily,
"callback_set_ui_language": callbackSetUiLanguage,
# Translation Tab
"callback_set_deepl_authkey": callbackSetDeeplAuthkey,
# Transcription Tab (Mic)
"callback_set_mic_host": callbackSetMicHost,
"callback_set_mic_device": callbackSetMicDevice,
"callback_set_mic_energy_threshold": callbackSetMicEnergyThreshold,
"callback_set_mic_dynamic_energy_threshold": callbackSetMicDynamicEnergyThreshold,
"callback_set_mic_record_timeout": callbackSetMicRecordTimeout,
"callback_set_mic_phrase_timeout": callbackSetMicPhraseTimeout,
"callback_set_mic_max_phrases": callbackSetMicMaxPhrases,
"callback_set_mic_word_filter": callbackSetMicWordFilter,
# Transcription Tab (Speaker)
"callback_set_speaker_device": callbackSetSpeakerDevice,
"callback_set_speaker_energy_threshold": callbackSetSpeakerEnergyThreshold,
"callback_set_speaker_dynamic_energy_threshold": callbackSetSpeakerDynamicEnergyThreshold,
"callback_set_speaker_record_timeout": callbackSetSpeakerRecordTimeout,
"callback_set_speaker_phrase_timeout": callbackSetSpeakerPhraseTimeout,
"callback_set_speaker_max_phrases": callbackSetSpeakerMaxPhrases,
# Others Tab
"callback_set_enable_auto_clear_chatbox": callbackSetEnableAutoClearChatbox,
"callback_set_enable_notice_xsoverlay": callbackSetEnableNoticeXsoverlay,
"callback_set_message_format": callbackSetMessageFormat,
# Advanced Settings Tab
"callback_set_osc_ip_address": callbackSetOscIpAddress,
"callback_set_osc_port": callbackSetOscPort,
},
)

View File

@@ -9,4 +9,7 @@ def get_key_by_value(dictionary, value):
for key, val in dictionary.items():
if val == value:
return key
return None
return None
def callFunctionIfCallable(function, *args):
if callable(function) is True: function(*args)

39
view.py
View File

@@ -64,10 +64,49 @@ class View():
entry_message_box.bind("<FocusOut>", self._foregroundOnForcefully)
# Config Window
# Compact Mode Switch
vrct_gui.config_window.CALLBACK_ENABLE_CONFIG_WINDOW_COMPACT_MODE = config_window["callback_disable_config_window_compact_mode"]
vrct_gui.config_window.CALLBACK_DISABLE_CONFIG_WINDOW_COMPACT_MODE = config_window["callback_enable_config_window_compact_mode"]
# Appearance Tab
vrct_gui.config_window.CALLBACK_SET_TRANSPARENCY = config_window["callback_set_transparency"]
vrct_gui.config_window.CALLBACK_SET_APPEARANCE = config_window["callback_set_appearance"]
vrct_gui.config_window.CALLBACK_SET_UI_SCALING = config_window["callback_set_ui_scaling"]
vrct_gui.config_window.CALLBACK_SET_FONT_FAMILY = config_window["callback_set_font_family"]
vrct_gui.config_window.CALLBACK_SET_UI_LANGUAGE = config_window["callback_set_ui_language"]
# Translation Tab
vrct_gui.config_window.CALLBACK_SET_DEEPL_AUTHKEY = config_window["callback_set_deepl_authkey"]
# Transcription Tab (Mic)
vrct_gui.config_window.CALLBACK_SET_MIC_HOST = config_window["callback_set_mic_host"]
vrct_gui.config_window.CALLBACK_SET_MIC_DEVICE = config_window["callback_set_mic_device"]
vrct_gui.config_window.CALLBACK_SET_MIC_ENERGY_THRESHOLD = config_window["callback_set_mic_energy_threshold"]
vrct_gui.config_window.CALLBACK_SET_MIC_DYNAMIC_ENERGY_THRESHOLD = config_window["callback_set_mic_dynamic_energy_threshold"]
vrct_gui.config_window.CALLBACK_SET_MIC_RECORD_TIMEOUT = config_window["callback_set_mic_record_timeout"]
vrct_gui.config_window.CALLBACK_SET_MIC_PHRASE_TIMEOUT = config_window["callback_set_mic_phrase_timeout"]
vrct_gui.config_window.CALLBACK_SET_MIC_MAX_PHRASES = config_window["callback_set_mic_max_phrases"]
vrct_gui.config_window.CALLBACK_SET_MIC_WORD_FILTER = config_window["callback_set_mic_word_filter"]
# Transcription Tab (Speaker)
vrct_gui.config_window.CALLBACK_SET_SPEAKER_DEVICE = config_window["callback_set_speaker_device"]
vrct_gui.config_window.CALLBACK_SET_SPEAKER_ENERGY_THRESHOLD = config_window["callback_set_speaker_energy_threshold"]
vrct_gui.config_window.CALLBACK_SET_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = config_window["callback_set_speaker_dynamic_energy_threshold"]
vrct_gui.config_window.CALLBACK_SET_SPEAKER_RECORD_TIMEOUT = config_window["callback_set_speaker_record_timeout"]
vrct_gui.config_window.CALLBACK_SET_SPEAKER_PHRASE_TIMEOUT = config_window["callback_set_speaker_phrase_timeout"]
vrct_gui.config_window.CALLBACK_SET_SPEAKER_MAX_PHRASES = config_window["callback_set_speaker_max_phrases"]
# Others Tab
vrct_gui.config_window.CALLBACK_SET_ENABLE_AUTO_CLEAR_CHATBOX = config_window["callback_set_enable_auto_clear_chatbox"]
vrct_gui.config_window.CALLBACK_SET_ENABLE_NOTICE_XSOVERLAY = config_window["callback_set_enable_notice_xsoverlay"]
vrct_gui.config_window.CALLBACK_SET_MESSAGE_FORMAT = config_window["callback_set_message_format"]
# Advanced Settings Tab
vrct_gui.config_window.CALLBACK_SET_OSC_IP_ADDRESS = config_window["callback_set_osc_ip_address"]
vrct_gui.config_window.CALLBACK_SET_OSC_PORT = config_window["callback_set_osc_port"]

View File

@@ -20,6 +20,44 @@ class ConfigWindow(CTkToplevel):
self.settings = settings
# Appearance Tab
self.CALLBACK_SET_TRANSPARENCY = None
self.CALLBACK_SET_APPEARANCE = None
self.CALLBACK_SET_UI_SCALING = None
self.CALLBACK_SET_FONT_FAMILY = None
self.CALLBACK_SET_UI_LANGUAGE = None
# Translation Tab
self.CALLBACK_SET_DEEPL_AUTHKEY = None
# Transcription Tab (Mic)
self.CALLBACK_SET_MIC_HOST = None
self.CALLBACK_SET_MIC_DEVICE = None
self.CALLBACK_SET_MIC_ENERGY_THRESHOLD = None
self.CALLBACK_SET_MIC_DYNAMIC_ENERGY_THRESHOLD = None
self.CALLBACK_SET_MIC_RECORD_TIMEOUT = None
self.CALLBACK_SET_MIC_PHRASE_TIMEOUT = None
self.CALLBACK_SET_MIC_MAX_PHRASES = None
self.CALLBACK_SET_MIC_WORD_FILTER = None
# Transcription Tab (Speaker)
self.CALLBACK_SET_SPEAKER_DEVICE = None
self.CALLBACK_SET_SPEAKER_ENERGY_THRESHOLD = None
self.CALLBACK_SET_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = None
self.CALLBACK_SET_SPEAKER_RECORD_TIMEOUT = None
self.CALLBACK_SET_SPEAKER_PHRASE_TIMEOUT = None
self.CALLBACK_SET_SPEAKER_MAX_PHRASES = None
# Others Tab
self.CALLBACK_SET_ENABLE_AUTO_CLEAR_CHATBOX = None
self.CALLBACK_SET_ENABLE_NOTICE_XSOVERLAY = None
self.CALLBACK_SET_MESSAGE_FORMAT = None
# Advanced Settings Tab
self.CALLBACK_SET_OSC_IP_ADDRESS = None
self.CALLBACK_SET_OSC_PORT = None
createConfigWindowTitle(config_window=self, settings=settings)

View File

@@ -2,6 +2,7 @@ from time import sleep
from customtkinter import StringVar, IntVar
from utils import callFunctionIfCallable
from .._SettingBoxGenerator import _SettingBoxGenerator
@@ -13,10 +14,10 @@ def createSettingBox_AdvancedSettings(setting_box_wrapper, config_window, settin
def entry_ip_address_callback(value):
config.OSC_IP_ADDRESS = str(value)
callFunctionIfCallable(config_window.CALLBACK_SET_OSC_IP_ADDRESS, value)
def entry_port_callback(value):
config.OSC_PORT = int(value)
callFunctionIfCallable(config_window.CALLBACK_SET_OSC_PORT, value)
row=0
config_window.sb__ip_address = createSettingBoxEntry(

View File

@@ -3,7 +3,7 @@ from time import sleep
from customtkinter import StringVar, IntVar
from tkinter import font as tk_font
from languages import selectable_languages
from utils import get_key_by_value
from utils import get_key_by_value, callFunctionIfCallable
from .._SettingBoxGenerator import _SettingBoxGenerator
@@ -15,28 +15,25 @@ def createSettingBox_Appearance(setting_box_wrapper, config_window, settings):
createSettingBoxDropdownMenu = sbg.createSettingBoxDropdownMenu
createSettingBoxSlider = sbg.createSettingBoxSlider
# 関数名は変えるかもしれない。
# テーマ変更、フォント変更時、 Widget再生成か再起動かは検討中
# テーマ変更、フォント変更時、 Widget再生成か再起動かは検討中\
def slider_transparency_callback(value):
# self.parent.wm_attributes("-alpha", int(value/100))
config.TRANSPARENCY = int(value)
callFunctionIfCallable(config_window.CALLBACK_SET_TRANSPARENCY, value)
def optionmenu_appearance_theme_callback(value):
config.APPEARANCE_THEME = value
callFunctionIfCallable(config_window.CALLBACK_SET_APPEARANCE, value)
def optionmenu_ui_scaling_callback(value):
callFunctionIfCallable(config_window.CALLBACK_SET_UI_SCALING, value)
# self.optionmenu_ui_scaling.set(choice)
# new_scaling_float = int(choice.replace("%", "")) / 100
config.UI_SCALING = value
def optionmenu_font_family_callback(value):
config.FONT_FAMILY = value
callFunctionIfCallable(config_window.CALLBACK_SET_FONT_FAMILY, value)
def optionmenu_ui_language_callback(value):
config.UI_LANGUAGE = get_key_by_value(selectable_languages, value)
value = get_key_by_value(selectable_languages, value)
callFunctionIfCallable(config_window.CALLBACK_SET_UI_LANGUAGE, value)
row=0
config_window.sb__transparency = createSettingBoxSlider(

View File

@@ -2,6 +2,7 @@ from time import sleep
from customtkinter import StringVar, IntVar
from utils import callFunctionIfCallable
from .._SettingBoxGenerator import _SettingBoxGenerator
@@ -15,16 +16,13 @@ def createSettingBox_Others(setting_box_wrapper, config_window, settings):
# 関数名 chatbox から messagebox に変える予定 config.ENABLE_AUTO_CLEAR_CHATBOX も MESSAGEBOXに変えるかな。
def checkbox_auto_clear_chatbox_callback(checkbox_box_widget):
print(checkbox_box_widget.get())
config.ENABLE_AUTO_CLEAR_CHATBOX = checkbox_box_widget.get()
callFunctionIfCallable(config_window.CALLBACK_SET_DEEPL_AUTHKEY, checkbox_box_widget.get())
def checkbox_notice_xsoverlay_callback(checkbox_box_widget):
print(checkbox_box_widget.get())
config.ENABLE_NOTICE_XSOVERLAY = checkbox_box_widget.get()
callFunctionIfCallable(config_window.CALLBACK_SET_ENABLE_NOTICE_XSOVERLAY, checkbox_box_widget.get())
def entry_message_format_callback(value):
if len(value) > 0:
config.MESSAGE_FORMAT = value
callFunctionIfCallable(config_window.CALLBACK_SET_ENABLE_NOTICE_XSOVERLAY, value)
row=0

View File

@@ -2,6 +2,7 @@ from time import sleep
from customtkinter import StringVar, IntVar
from utils import callFunctionIfCallable
from .._SettingBoxGenerator import _SettingBoxGenerator
@@ -39,42 +40,29 @@ def createSettingBox_Mic(setting_box_wrapper, config_window, settings):
passive_button_wrapper_widget.grid()
def optionmenu_mic_host_callback(value):
config.CHOICE_MIC_HOST = value
callFunctionIfCallable(config_window.CALLBACK_SET_MIC_HOST, value)
def optionmenu_input_mic_device_callback(value):
config.CHOICE_MIC_DEVICE = value
callFunctionIfCallable(config_window.CALLBACK_SET_MIC_DEVICE, value)
def slider_input_mic_energy_threshold_callback(value):
config.INPUT_MIC_ENERGY_THRESHOLD = int(value)
callFunctionIfCallable(config_window.CALLBACK_SET_MIC_ENERGY_THRESHOLD, value)
def checkbox_input_mic_dynamic_energy_threshold_callback(checkbox_box_widget):
print(checkbox_box_widget.get())
config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = checkbox_box_widget.get()
callFunctionIfCallable(config_window.CALLBACK_SET_MIC_DYNAMIC_ENERGY_THRESHOLD, checkbox_box_widget.get())
def entry_input_mic_record_timeout_callback(value):
print(int(value))
config.INPUT_MIC_RECORD_TIMEOUT = int(value)
callFunctionIfCallable(config_window.CALLBACK_SET_MIC_RECORD_TIMEOUT, value)
def entry_input_mic_phrase_timeout_callback(value):
print(int(value))
config.INPUT_MIC_PHRASE_TIMEOUT = int(value)
callFunctionIfCallable(config_window.CALLBACK_SET_MIC_PHRASE_TIMEOUT, value)
def entry_input_mic_max_phrases_callback(value):
print(int(value))
config.INPUT_MIC_MAX_PHRASES = int(value)
callFunctionIfCallable(config_window.CALLBACK_SET_MIC_MAX_PHRASES, value)
def entry_input_mic_word_filters_callback(value):
word_filter = str(value)
word_filter = [w.strip() for w in word_filter.split(",") if len(w.strip()) > 0]
word_filter = ",".join(word_filter)
print(word_filter)
if len(word_filter) > 0:
config.INPUT_MIC_WORD_FILTER = word_filter.split(",")
else:
config.INPUT_MIC_WORD_FILTER = []
# model.resetKeywordProcessor()
# model.addKeywords()
callFunctionIfCallable(config_window.CALLBACK_SET_MIC_WORD_FILTER, value)
row=0

View File

@@ -2,6 +2,7 @@ from time import sleep
from customtkinter import StringVar, IntVar
from utils import callFunctionIfCallable
from .._SettingBoxGenerator import _SettingBoxGenerator
@@ -39,27 +40,23 @@ def createSettingBox_Speaker(setting_box_wrapper, config_window, settings):
passive_button_wrapper_widget.grid()
def optionmenu_input_speaker_device_callback(value):
config.CHOICE_SPEAKER_DEVICE = value
callFunctionIfCallable(config_window.CALLBACK_SET_SPEAKER_DEVICE, value)
def slider_input_speaker_energy_threshold_callback(value):
config.INPUT_SPEAKER_ENERGY_THRESHOLD = int(value)
callFunctionIfCallable(config_window.CALLBACK_SET_SPEAKER_ENERGY_THRESHOLD, value)
def checkbox_input_speaker_dynamic_energy_threshold_callback(checkbox_box_widget):
print(checkbox_box_widget.get())
config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = checkbox_box_widget.get()
callFunctionIfCallable(config_window.CALLBACK_SET_SPEAKER_DYNAMIC_ENERGY_THRESHOLD, checkbox_box_widget.get())
def entry_input_speaker_record_timeout_callback(value):
print(int(value))
config.INPUT_SPEAKER_RECORD_TIMEOUT = int(value)
callFunctionIfCallable(config_window.CALLBACK_SET_SPEAKER_RECORD_TIMEOUT, value)
def entry_input_speaker_phrase_timeout_callback(value):
print(int(value))
config.INPUT_SPEAKER_PHRASE_TIMEOUT = int(value)
callFunctionIfCallable(config_window.CALLBACK_SET_SPEAKER_PHRASE_TIMEOUT, value)
def entry_input_speaker_max_phrases_callback(value):
print(int(value))
config.INPUT_SPEAKER_MAX_PHRASES = int(value)
callFunctionIfCallable(config_window.CALLBACK_SET_SPEAKER_MAX_PHRASES, value)

View File

@@ -2,6 +2,7 @@ from time import sleep
from customtkinter import StringVar, IntVar
from utils import callFunctionIfCallable
from .._SettingBoxGenerator import _SettingBoxGenerator
@@ -13,14 +14,7 @@ def createSettingBox_Translation(setting_box_wrapper, config_window, settings):
def deepl_authkey_callback(value):
print(str(value))
# config.AUTH_KEYS["DeepL(auth)"] = str(value)
# if len(value) > 0:
# if model.authenticationTranslator(choice_translator="DeepL(auth)", auth_key=value) is True:
# print_textbox(self.parent.textbox_message_log, "Auth key update completed", "INFO")
# print_textbox(self.parent.textbox_message_system_log, "Auth key update completed", "INFO")
# else:
# pass
callFunctionIfCallable(config_window.CALLBACK_SET_DEEPL_AUTHKEY, value)
row=0