Merge branch 'develop'
This commit is contained in:
633
VRCT.py
633
VRCT.py
@@ -1,85 +1,91 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import deepl
|
import deepl
|
||||||
|
import deepl_translate
|
||||||
|
import translators as ts
|
||||||
from pythonosc import osc_message_builder
|
from pythonosc import osc_message_builder
|
||||||
from pythonosc import udp_client
|
from pythonosc import udp_client
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
import customtkinter
|
import customtkinter
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
# global
|
def save_json(path, key, value):
|
||||||
PATH_CONFIG = "./config.json"
|
with open(path, "r") as fp:
|
||||||
OSC_IP_ADDRESS = "127.0.0.1"
|
json_data = json.load(fp)
|
||||||
OSC_PORT = 9000
|
json_data[key] = value
|
||||||
TARGET_LANG = "EN-US"
|
with open(path, "w") as fp:
|
||||||
ENABLE_TRANSLATION = True
|
json.dump(json_data, fp, indent=4)
|
||||||
CHOICE_TRANSLATOR = "DeepL"
|
|
||||||
ENABLE_FOREGROUND = False
|
|
||||||
AUTH_KEY = None
|
|
||||||
TRANSLATOR = None
|
|
||||||
MESSAGE_FORMAT = "[message]([translation])"
|
|
||||||
FONT_FAMILY = "Yu Gothic UI"
|
|
||||||
TRANSPARENCY = 100
|
|
||||||
APPEARANCE_THEME = "System"
|
|
||||||
UI_SCALING = "100%"
|
|
||||||
|
|
||||||
# load config
|
# Translator
|
||||||
if os.path.isfile(PATH_CONFIG) is not False:
|
class Translator():
|
||||||
with open(PATH_CONFIG, 'r') as fp:
|
def __init__(self):
|
||||||
config = json.load(fp)
|
self.translator_status = {
|
||||||
if "OSC_IP_ADDRESS" in config.keys():
|
"DeepL(web)": False,
|
||||||
OSC_IP_ADDRESS = config["OSC_IP_ADDRESS"]
|
"DeepL(auth)": False,
|
||||||
if "OSC_PORT" in config.keys():
|
"Google(web)": False,
|
||||||
OSC_PORT = config["OSC_PORT"]
|
"Bing(web)": False,
|
||||||
if "TARGET_LANG" in config.keys():
|
}
|
||||||
TARGET_LANG = config["TARGET_LANG"]
|
self.languages = {}
|
||||||
if "ENABLE_TRANSLATION" in config.keys():
|
self.languages["DeepL(web)"] = [
|
||||||
ENABLE_TRANSLATION = config["ENABLE_TRANSLATION"]
|
"JA","EN","BG","ZH","CS","DA","NL","ET","FI","FR","DE","EL","HU","IT",
|
||||||
if "CHOICE_TRANSLATOR" in config.keys():
|
"LV","LT","PL","PT","RO","RU","SK","SL","ES","SV",
|
||||||
CHOICE_TRANSLATOR = config["CHOICE_TRANSLATOR"]
|
]
|
||||||
if "ENABLE_FOREGROUND" in config.keys():
|
self.languages["DeepL(auth)"] = [
|
||||||
ENABLE_FOREGROUND = config["ENABLE_FOREGROUND"]
|
"JA","EN-US","EN-GB","BG","CS","DA","DE","EL","ES","ET","FI","FR","HU",
|
||||||
if "AUTH_KEY" in config.keys():
|
"ID","IT","KO","LT","LV","NB","NL","PL","PT","PT-BR","PT-PT","RO","RU",
|
||||||
AUTH_KEY = config["AUTH_KEY"]
|
"SK","SL","SV","TR","UK","ZH",
|
||||||
if "MESSAGE_FORMAT" in config.keys():
|
]
|
||||||
MESSAGE_FORMAT = config["MESSAGE_FORMAT"]
|
self.languages["Google(web)"] = [
|
||||||
if "FONT_FAMILY" in config.keys():
|
"ja","en","zh","ar","ru","fr","de","es","pt","it","ko","el","nl","hi",
|
||||||
FONT_FAMILY = config["FONT_FAMILY"]
|
"tr","ms","th","vi","id","he","pl","mn","cs","hu","et","bg","da","fi",
|
||||||
if "TRANSPARENCY" in config.keys():
|
"ro","sv","sl","fa","bs","sr","tl","ht","ca","hr","lv","lt","ur","uk",
|
||||||
TRANSPARENCY = config["TRANSPARENCY"]
|
"cy","sw","sm","sk","af","no","bn","mg","mt","gu","ta","te","pa","am",
|
||||||
if "APPEARANCE_THEME" in config.keys():
|
"az","be","ceb","eo","eu","ga"
|
||||||
APPEARANCE_THEME = config["APPEARANCE_THEME"]
|
]
|
||||||
if "UI_SCALING" in config.keys():
|
self.languages["Bing(web)"] = [
|
||||||
UI_SCALING = config["UI_SCALING"]
|
"ja","en","zh","ar","ru","fr","de","es","pt","it","ko","el","nl","hi",
|
||||||
|
"tr","ms","th","vi","id","he","pl","cs","hu","et","bg","da","fi","ro",
|
||||||
|
"sv","sl","fa","bs","sr","fj","tl","ht","ca","hr","lv","lt","ur","uk",
|
||||||
|
"cy","ty","to","sw","sm","sk","af","no","bn","mg","mt","otq","tlh","gu",
|
||||||
|
"ta","te","pa","ga"
|
||||||
|
]
|
||||||
|
self.deepl_client = None
|
||||||
|
|
||||||
with open(PATH_CONFIG, 'w') as fp:
|
def authentication(self, translator_name, authkey=None):
|
||||||
config = {
|
result = False
|
||||||
"OSC_IP_ADDRESS": OSC_IP_ADDRESS,
|
try:
|
||||||
"OSC_PORT": OSC_PORT,
|
if translator_name == "DeepL(web)":
|
||||||
"TARGET_LANG": TARGET_LANG,
|
self.translator_status["DeepL(web)"] = True
|
||||||
"ENABLE_TRANSLATION": ENABLE_TRANSLATION,
|
result = True
|
||||||
"CHOICE_TRANSLATOR": CHOICE_TRANSLATOR,
|
elif translator_name == "DeepL(auth)":
|
||||||
"ENABLE_FOREGROUND": ENABLE_FOREGROUND,
|
self.deepl_client = deepl.Translator(authkey)
|
||||||
"AUTH_KEY": AUTH_KEY,
|
self.deepl_client.translate_text(" ", target_lang="EN-US")
|
||||||
"MESSAGE_FORMAT": MESSAGE_FORMAT,
|
self.translator_status["DeepL(auth)"] = True
|
||||||
"FONT_FAMILY": FONT_FAMILY,
|
result = True
|
||||||
"TRANSPARENCY": TRANSPARENCY,
|
elif translator_name == "Google(web)":
|
||||||
"APPEARANCE_THEME": APPEARANCE_THEME,
|
self.translator_status["Google(web)"] = True
|
||||||
"UI_SCALING": UI_SCALING,
|
result = True
|
||||||
}
|
elif translator_name == "Bing(web)":
|
||||||
json.dump(config, fp, indent=4)
|
self.translator_status["Bing(web)"] = True
|
||||||
|
result = True
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return result
|
||||||
|
|
||||||
# deepl connect
|
def translate(self, translator_name, source_language, target_language, message):
|
||||||
if AUTH_KEY is not None:
|
result = False
|
||||||
TRANSLATOR = deepl.Translator(AUTH_KEY)
|
try:
|
||||||
try:
|
if translator_name == "DeepL(web)":
|
||||||
TRANSLATOR.translate_text(" ", target_lang="EN-US")
|
result = deepl_translate.translate(source_language=source_language, target_language=target_language, text=message)
|
||||||
except:
|
elif translator_name == "DeepL(auth)":
|
||||||
TRANSLATOR = None
|
result = self.deepl_client.translate_text(message, source_lang=source_language, target_lang=target_language).text
|
||||||
|
elif translator_name == "Google(web)":
|
||||||
# GUI
|
result = ts.translate_text(query_text=message, translator="google", from_language=source_language, to_language=target_language)
|
||||||
customtkinter.set_appearance_mode(APPEARANCE_THEME)
|
elif translator_name == "Bing(web)":
|
||||||
customtkinter.set_default_color_theme("blue")
|
result = ts.translate_text(query_text=message, translator="bing", from_language=source_language, to_language=target_language)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return result
|
||||||
|
|
||||||
class ToplevelWindowInformation(customtkinter.CTkToplevel):
|
class ToplevelWindowInformation(customtkinter.CTkToplevel):
|
||||||
def __init__(self, parent, *args, **kwargs):
|
def __init__(self, parent, *args, **kwargs):
|
||||||
@@ -95,7 +101,7 @@ class ToplevelWindowInformation(customtkinter.CTkToplevel):
|
|||||||
# create textbox information
|
# create textbox information
|
||||||
self.textbox_information = customtkinter.CTkTextbox(
|
self.textbox_information = customtkinter.CTkTextbox(
|
||||||
self,
|
self,
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.textbox_information.grid(row=0, column=0, padx=(10, 10), pady=(10, 10), sticky="nsew")
|
self.textbox_information.grid(row=0, column=0, padx=(10, 10), pady=(10, 10), sticky="nsew")
|
||||||
textbox_information_message = """VRCT(v0.3b)
|
textbox_information_message = """VRCT(v0.3b)
|
||||||
@@ -182,128 +188,143 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel):
|
|||||||
self.tabview_config.grid(row=0, column=0, padx=5, pady=5, sticky="nsew")
|
self.tabview_config.grid(row=0, column=0, padx=5, pady=5, sticky="nsew")
|
||||||
self.tabview_config.add("GUI")
|
self.tabview_config.add("GUI")
|
||||||
self.tabview_config.add("Parameter")
|
self.tabview_config.add("Parameter")
|
||||||
self.tabview_config.tab("GUI").grid_columnconfigure(0, weight=1)
|
self.tabview_config.tab("GUI").grid_columnconfigure(2, weight=1)
|
||||||
self.tabview_config.tab("Parameter").grid_columnconfigure(0, weight=1)
|
self.tabview_config.tab("Parameter").grid_columnconfigure(1, weight=1)
|
||||||
self.tabview_config._segmented_button.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.tabview_config._segmented_button.configure(font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY))
|
||||||
|
|
||||||
# optionmenu translator
|
# optionmenu translator
|
||||||
self.label_translator = customtkinter.CTkLabel(
|
self.label_translator = customtkinter.CTkLabel(
|
||||||
self.tabview_config.tab("GUI"),
|
self.tabview_config.tab("GUI"),
|
||||||
text="Select Translator:",
|
text="Select Translator:",
|
||||||
fg_color="transparent",
|
fg_color="transparent",
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.label_translator.grid(row=0, column=0, columnspan=1, padx=5, pady=5, sticky="nsew")
|
self.label_translator.grid(row=0, column=0, columnspan=1, padx=5, pady=5, sticky="nsw")
|
||||||
self.optionmenu_translator = customtkinter.CTkOptionMenu(
|
self.optionmenu_translator = customtkinter.CTkOptionMenu(
|
||||||
self.tabview_config.tab("GUI"),
|
self.tabview_config.tab("GUI"),
|
||||||
values=["DeepL"],
|
values=list(self.parent.translator.translator_status.keys()),
|
||||||
command=self.optionmenu_translator_callback,
|
command=self.optionmenu_translator_callback,
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY),
|
||||||
|
variable=customtkinter.StringVar(value=self.parent.CHOICE_TRANSLATOR)
|
||||||
)
|
)
|
||||||
self.optionmenu_translator.grid(row=0, column=1, columnspan=2 ,padx=(0, 5), pady=5, sticky="nsew")
|
self.optionmenu_translator.grid(row=0, column=1, columnspan=3 ,padx=5, pady=5, sticky="nsew")
|
||||||
self.optionmenu_translator.set(CHOICE_TRANSLATOR)
|
|
||||||
|
|
||||||
# optionmenu language
|
# optionmenu language
|
||||||
self.label_language = customtkinter.CTkLabel(
|
self.label_language = customtkinter.CTkLabel(
|
||||||
self.tabview_config.tab("GUI"),
|
self.tabview_config.tab("GUI"),
|
||||||
text="Select Language:",
|
text="Select Language:",
|
||||||
fg_color="transparent",
|
fg_color="transparent",
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.label_language.grid(row=1, column=0, columnspan=1, padx=5, pady=5, sticky="nsew")
|
self.label_language.grid(row=1, column=0, columnspan=1, padx=5, pady=5, sticky="nsw")
|
||||||
self.optionmenu_language = customtkinter.CTkOptionMenu(
|
|
||||||
|
## select source language
|
||||||
|
self.optionmenu_source_language = customtkinter.CTkOptionMenu(
|
||||||
self.tabview_config.tab("GUI"),
|
self.tabview_config.tab("GUI"),
|
||||||
command=self.optionmenu_language_callback,
|
command=self.optionmenu_source_language_callback,
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY),
|
||||||
|
values=self.parent.translator.languages[self.parent.CHOICE_TRANSLATOR],
|
||||||
|
variable=customtkinter.StringVar(value=self.parent.SOURCE_LANG),
|
||||||
)
|
)
|
||||||
self.optionmenu_language.grid(row=1, column=1, columnspan=2, padx=(0, 5), pady=5, sticky="nsew")
|
self.optionmenu_source_language.grid(row=1, column=1, columnspan=1, padx=5, pady=5, sticky="nsew")
|
||||||
self.optionmenu_language.configure(
|
|
||||||
values=[
|
## label -->
|
||||||
"JA","BG","CS","DA","DE","EL","EN","EN-US","EN-GB","ES","ET","FI","FR","HU",
|
self.label_arrow = customtkinter.CTkLabel(
|
||||||
"ID","IT","KO","LT","LV","NB","NL","PL","PT","PT-BR","PT-PT","RO","RU","SK",
|
self.tabview_config.tab("GUI"),
|
||||||
"SL","SV","TR","UK","ZH",
|
text="-->",
|
||||||
]
|
fg_color="transparent",
|
||||||
|
font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.optionmenu_language.set(TARGET_LANG)
|
self.label_arrow.grid(row=1, column=2, columnspan=1, padx=5, pady=5, sticky="nsew")
|
||||||
|
|
||||||
|
## select target language
|
||||||
|
self.optionmenu_target_language = customtkinter.CTkOptionMenu(
|
||||||
|
self.tabview_config.tab("GUI"),
|
||||||
|
command=self.optionmenu_target_language_callback,
|
||||||
|
font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY),
|
||||||
|
values=self.parent.translator.languages[self.parent.CHOICE_TRANSLATOR],
|
||||||
|
variable=customtkinter.StringVar(value=self.parent.TARGET_LANG),
|
||||||
|
)
|
||||||
|
self.optionmenu_target_language.grid(row=1, column=3, columnspan=1, padx=5, pady=5, sticky="nsew")
|
||||||
|
|
||||||
# slider transparency
|
# slider transparency
|
||||||
self.label_transparency = customtkinter.CTkLabel(
|
self.label_transparency = customtkinter.CTkLabel(
|
||||||
self.tabview_config.tab("GUI"),
|
self.tabview_config.tab("GUI"),
|
||||||
text="Transparency:",
|
text="Transparency:",
|
||||||
fg_color="transparent",
|
fg_color="transparent",
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.label_transparency.grid(row=2, column=0, columnspan=1, padx=(0, 5), pady=5, sticky="nsew")
|
self.label_transparency.grid(row=2, column=0, columnspan=1, padx=5, pady=5, sticky="nsw")
|
||||||
self.slider_transparency = customtkinter.CTkSlider(
|
self.slider_transparency = customtkinter.CTkSlider(
|
||||||
self.tabview_config.tab("GUI"),
|
self.tabview_config.tab("GUI"),
|
||||||
from_=50,
|
from_=50,
|
||||||
to=100,
|
to=100,
|
||||||
command=self.slider_transparency_callback
|
command=self.slider_transparency_callback,
|
||||||
|
variable=tk.DoubleVar(value=self.parent.TRANSPARENCY),
|
||||||
)
|
)
|
||||||
self.slider_transparency.grid(row=2, column=1, columnspan=2, padx=5, pady=10, sticky="nsew")
|
self.slider_transparency.grid(row=2, column=1, columnspan=3, padx=5, pady=10, sticky="nsew")
|
||||||
self.slider_transparency.set(TRANSPARENCY)
|
|
||||||
|
|
||||||
# optionmenu theme
|
# optionmenu theme
|
||||||
self.label_appearance_theme = customtkinter.CTkLabel(
|
self.label_appearance_theme = customtkinter.CTkLabel(
|
||||||
self.tabview_config.tab("GUI"),
|
self.tabview_config.tab("GUI"),
|
||||||
text="Appearance Theme:",
|
text="Appearance Theme:",
|
||||||
fg_color="transparent",
|
fg_color="transparent",
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.label_appearance_theme.grid(row=3, column=0, columnspan=1, padx=(0, 5), pady=5, sticky="nsew")
|
self.label_appearance_theme.grid(row=3, column=0, columnspan=1, padx=5, pady=5, sticky="nsw")
|
||||||
self.optionmenu_appearance_theme = customtkinter.CTkOptionMenu(
|
self.optionmenu_appearance_theme = customtkinter.CTkOptionMenu(
|
||||||
self.tabview_config.tab("GUI"),
|
self.tabview_config.tab("GUI"),
|
||||||
values=["Light", "Dark", "System"],
|
values=["Light", "Dark", "System"],
|
||||||
command=self.optionmenu_theme_callback
|
command=self.optionmenu_theme_callback,
|
||||||
|
variable=customtkinter.StringVar(value=self.parent.APPEARANCE_THEME)
|
||||||
)
|
)
|
||||||
self.optionmenu_appearance_theme.grid(row=3, column=1, columnspan=2, padx=(0, 5), pady=5, sticky="nsew")
|
self.optionmenu_appearance_theme.grid(row=3, column=1, columnspan=3, padx=5, pady=5, sticky="nsew")
|
||||||
self.optionmenu_appearance_theme.set(APPEARANCE_THEME)
|
|
||||||
|
|
||||||
# optionmenu UI scaling
|
# optionmenu UI scaling
|
||||||
self.label_ui_scaling = customtkinter.CTkLabel(
|
self.label_ui_scaling = customtkinter.CTkLabel(
|
||||||
self.tabview_config.tab("GUI"),
|
self.tabview_config.tab("GUI"),
|
||||||
text="UI Scaling:",
|
text="UI Scaling:",
|
||||||
fg_color="transparent",
|
fg_color="transparent",
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.label_ui_scaling.grid(row=4, column=0, columnspan=1, padx=(0, 5), pady=5, sticky="nsew")
|
self.label_ui_scaling.grid(row=4, column=0, columnspan=1, padx=5, pady=5, sticky="nsw")
|
||||||
self.optionmenu_ui_scaling = customtkinter.CTkOptionMenu(
|
self.optionmenu_ui_scaling = customtkinter.CTkOptionMenu(
|
||||||
self.tabview_config.tab("GUI"),
|
self.tabview_config.tab("GUI"),
|
||||||
values=["80%", "90%", "100%", "110%", "120%"],
|
values=["80%", "90%", "100%", "110%", "120%"],
|
||||||
command=self.optionmenu_ui_scaling_callback
|
command=self.optionmenu_ui_scaling_callback,
|
||||||
|
variable=customtkinter.StringVar(value=self.parent.UI_SCALING)
|
||||||
)
|
)
|
||||||
self.optionmenu_ui_scaling.grid(row=4, column=1, columnspan=2, padx=(0, 5), pady=5, sticky="nsew")
|
self.optionmenu_ui_scaling.grid(row=4, column=1, columnspan=3, padx=5, pady=5, sticky="nsew")
|
||||||
self.optionmenu_ui_scaling.set(UI_SCALING)
|
|
||||||
|
|
||||||
# optionmenu font family
|
# optionmenu font family
|
||||||
self.label_font_family = customtkinter.CTkLabel(
|
self.label_font_family = customtkinter.CTkLabel(
|
||||||
self.tabview_config.tab("GUI"),
|
self.tabview_config.tab("GUI"),
|
||||||
text="Font Family:",
|
text="Font Family:",
|
||||||
fg_color="transparent",
|
fg_color="transparent",
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.label_font_family.grid(row=5, column=0, columnspan=1, padx=(0, 5), pady=5, sticky="nsew")
|
self.label_font_family.grid(row=5, column=0, columnspan=1, padx=5, pady=5, sticky="nsw")
|
||||||
font_families = list(tk.font.families())
|
font_families = list(tk.font.families())
|
||||||
self.optionmenu_font_family = customtkinter.CTkOptionMenu(
|
self.optionmenu_font_family = customtkinter.CTkOptionMenu(
|
||||||
self.tabview_config.tab("GUI"),
|
self.tabview_config.tab("GUI"),
|
||||||
values=font_families,
|
values=font_families,
|
||||||
command=self.optionmenu_font_family_callback
|
command=self.optionmenu_font_family_callback,
|
||||||
|
variable=customtkinter.StringVar(value=self.parent.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.optionmenu_font_family.grid(row=5, column=1, columnspan=2, padx=(0, 5), pady=5, sticky="nsew")
|
self.optionmenu_font_family.grid(row=5, column=1, columnspan=3, padx=5, pady=5, sticky="nsew")
|
||||||
self.optionmenu_font_family.set(FONT_FAMILY)
|
|
||||||
|
|
||||||
# entry ip address
|
# entry ip address
|
||||||
self.label_ip_address = customtkinter.CTkLabel(
|
self.label_ip_address = customtkinter.CTkLabel(
|
||||||
self.tabview_config.tab("Parameter"),
|
self.tabview_config.tab("Parameter"),
|
||||||
text="OSC IP address:",
|
text="OSC IP address:",
|
||||||
fg_color="transparent",
|
fg_color="transparent",
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.label_ip_address.grid(row=0, column=0, columnspan=1, padx=5, pady=5, sticky="nsew")
|
self.label_ip_address.grid(row=0, column=0, columnspan=1, padx=5, pady=5, sticky="nsw")
|
||||||
self.entry_ip_address = customtkinter.CTkEntry(
|
self.entry_ip_address = customtkinter.CTkEntry(
|
||||||
self.tabview_config.tab("Parameter"),
|
self.tabview_config.tab("Parameter"),
|
||||||
placeholder_text=OSC_IP_ADDRESS,
|
textvariable=customtkinter.StringVar(value=self.parent.OSC_IP_ADDRESS),
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.entry_ip_address.grid(row=0, column=1, columnspan=1, padx=1, pady=5, sticky="nsew")
|
self.entry_ip_address.grid(row=0, column=1, columnspan=1, padx=1, pady=5, sticky="nsew")
|
||||||
self.button_ip_address = customtkinter.CTkButton(
|
self.button_ip_address = customtkinter.CTkButton(
|
||||||
@@ -320,13 +341,13 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel):
|
|||||||
self.tabview_config.tab("Parameter"),
|
self.tabview_config.tab("Parameter"),
|
||||||
text="OSC Port:",
|
text="OSC Port:",
|
||||||
fg_color="transparent",
|
fg_color="transparent",
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.label_port.grid(row=1, column=0, columnspan=1, padx=5, pady=5, sticky="nsew")
|
self.label_port.grid(row=1, column=0, columnspan=1, padx=5, pady=5, sticky="nsw")
|
||||||
self.entry_port = customtkinter.CTkEntry(
|
self.entry_port = customtkinter.CTkEntry(
|
||||||
self.tabview_config.tab("Parameter"),
|
self.tabview_config.tab("Parameter"),
|
||||||
placeholder_text=OSC_PORT,
|
textvariable=customtkinter.StringVar(value=self.parent.OSC_PORT),
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.entry_port.grid(row=1, column=1, columnspan=1, padx=1, pady=5, sticky="nsew")
|
self.entry_port.grid(row=1, column=1, columnspan=1, padx=1, pady=5, sticky="nsew")
|
||||||
self.button_port = customtkinter.CTkButton(
|
self.button_port = customtkinter.CTkButton(
|
||||||
@@ -343,13 +364,13 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel):
|
|||||||
self.tabview_config.tab("Parameter"),
|
self.tabview_config.tab("Parameter"),
|
||||||
text="DeepL Auth Key:",
|
text="DeepL Auth Key:",
|
||||||
fg_color="transparent",
|
fg_color="transparent",
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.label_authkey.grid(row=2, column=0, columnspan=1, padx=5, pady=5, sticky="nsew")
|
self.label_authkey.grid(row=2, column=0, columnspan=1, padx=5, pady=5, sticky="nsw")
|
||||||
self.entry_authkey = customtkinter.CTkEntry(
|
self.entry_authkey = customtkinter.CTkEntry(
|
||||||
self.tabview_config.tab("Parameter"),
|
self.tabview_config.tab("Parameter"),
|
||||||
placeholder_text=AUTH_KEY,
|
textvariable=customtkinter.StringVar(value=self.parent.AUTH_KEYS["DeepL(auth)"]),
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.entry_authkey.grid(row=2, column=1, columnspan=1, padx=1, pady=5, sticky="nsew")
|
self.entry_authkey.grid(row=2, column=1, columnspan=1, padx=1, pady=5, sticky="nsew")
|
||||||
self.button_authkey = customtkinter.CTkButton(
|
self.button_authkey = customtkinter.CTkButton(
|
||||||
@@ -366,13 +387,13 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel):
|
|||||||
self.tabview_config.tab("Parameter"),
|
self.tabview_config.tab("Parameter"),
|
||||||
text="Message Format:",
|
text="Message Format:",
|
||||||
fg_color="transparent",
|
fg_color="transparent",
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.label_message_format.grid(row=3, column=0, columnspan=1, padx=5, pady=5, sticky="nsew")
|
self.label_message_format.grid(row=3, column=0, columnspan=1, padx=5, pady=5, sticky="nsw")
|
||||||
self.entry_message_format = customtkinter.CTkEntry(
|
self.entry_message_format = customtkinter.CTkEntry(
|
||||||
self.tabview_config.tab("Parameter"),
|
self.tabview_config.tab("Parameter"),
|
||||||
placeholder_text=MESSAGE_FORMAT,
|
textvariable=customtkinter.StringVar(value=self.parent.MESSAGE_FORMAT),
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.entry_message_format.grid(row=3, column=1, columnspan=1, padx=1, pady=5, sticky="nsew")
|
self.entry_message_format.grid(row=3, column=1, columnspan=1, padx=1, pady=5, sticky="nsew")
|
||||||
self.button_message_format = customtkinter.CTkButton(
|
self.button_message_format = customtkinter.CTkButton(
|
||||||
@@ -387,45 +408,26 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel):
|
|||||||
def update_ip_address(self):
|
def update_ip_address(self):
|
||||||
value = self.entry_ip_address.get()
|
value = self.entry_ip_address.get()
|
||||||
if len(value) > 0:
|
if len(value) > 0:
|
||||||
global OSC_IP_ADDRESS
|
self.parent.OSC_IP_ADDRESS = value
|
||||||
OSC_IP_ADDRESS = value
|
save_json(self.parent.PATH_CONFIG, "OSC_IP_ADDRESS", self.parent.OSC_IP_ADDRESS)
|
||||||
with open(PATH_CONFIG, "r") as fp:
|
|
||||||
config = json.load(fp)
|
|
||||||
config["OSC_IP_ADDRESS"] = OSC_IP_ADDRESS
|
|
||||||
with open(PATH_CONFIG, "w") as fp:
|
|
||||||
json.dump(config, fp, indent=4)
|
|
||||||
|
|
||||||
def update_port(self):
|
def update_port(self):
|
||||||
value = self.entry_port.get()
|
value = self.entry_port.get()
|
||||||
if len(value) > 0:
|
if len(value) > 0:
|
||||||
global OSC_PORT
|
self.parent.OSC_PORT = value
|
||||||
OSC_PORT = value
|
save_json(self.parent.PATH_CONFIG, "OSC_PORT", self.parent.OSC_PORT)
|
||||||
with open(PATH_CONFIG, "r") as fp:
|
|
||||||
config = json.load(fp)
|
|
||||||
config["OSC_PORT"] = OSC_PORT
|
|
||||||
with open(PATH_CONFIG, "w") as fp:
|
|
||||||
json.dump(config, fp, indent=4)
|
|
||||||
|
|
||||||
def update_authkey(self):
|
def update_authkey(self):
|
||||||
value = self.entry_authkey.get()
|
value = self.entry_authkey.get()
|
||||||
if len(value) > 0:
|
if len(value) > 0:
|
||||||
global AUTH_KEY
|
|
||||||
global TRANSLATOR
|
|
||||||
AUTH_KEY = value
|
|
||||||
with open(PATH_CONFIG, "r") as fp:
|
|
||||||
config = json.load(fp)
|
|
||||||
config["AUTH_KEY"] = AUTH_KEY
|
|
||||||
with open(PATH_CONFIG, "w") as fp:
|
|
||||||
json.dump(config, fp, indent=4)
|
|
||||||
|
|
||||||
TRANSLATOR = deepl.Translator(AUTH_KEY)
|
|
||||||
self.parent.textbox_message_log.configure(state='normal')
|
self.parent.textbox_message_log.configure(state='normal')
|
||||||
self.parent.textbox_message_log.delete("0.0", "end")
|
self.parent.textbox_message_log.delete("0.0", "end")
|
||||||
self.parent.textbox_message_log.configure(state='disabled')
|
self.parent.textbox_message_log.configure(state='disabled')
|
||||||
try:
|
|
||||||
TRANSLATOR.translate_text(" ", target_lang="EN-US")
|
if self.parent.translator.authentication(self.parent.CHOICE_TRANSLATOR, self.parent.AUTH_KEYS[self.parent.CHOICE_TRANSLATOR]) is True:
|
||||||
except:
|
self.parent.AUTH_KEYS["DeepL(auth)"] = value
|
||||||
TRANSLATOR = None
|
save_json(self.parent.PATH_CONFIG, "AUTH_KEYS", self.parent.AUTH_KEYS)
|
||||||
|
else:
|
||||||
self.parent.textbox_message_log.configure(state='normal')
|
self.parent.textbox_message_log.configure(state='normal')
|
||||||
self.parent.textbox_message_log.insert("0.0", f"Auth Keyを設定してないか間違っています\n")
|
self.parent.textbox_message_log.insert("0.0", f"Auth Keyを設定してないか間違っています\n")
|
||||||
self.parent.textbox_message_log.configure(state='disabled')
|
self.parent.textbox_message_log.configure(state='disabled')
|
||||||
@@ -433,104 +435,164 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel):
|
|||||||
def update_message_format(self):
|
def update_message_format(self):
|
||||||
value = self.entry_message_format.get()
|
value = self.entry_message_format.get()
|
||||||
if len(value) > 0:
|
if len(value) > 0:
|
||||||
global MESSAGE_FORMAT
|
self.parent.MESSAGE_FORMAT = value
|
||||||
MESSAGE_FORMAT = value
|
save_json(self.parent.PATH_CONFIG, "MESSAGE_FORMAT", self.parent.MESSAGE_FORMAT)
|
||||||
with open(PATH_CONFIG, "r") as fp:
|
|
||||||
config = json.load(fp)
|
|
||||||
config["MESSAGE_FORMAT"] = MESSAGE_FORMAT
|
|
||||||
with open(PATH_CONFIG, "w") as fp:
|
|
||||||
json.dump(config, fp, indent=4)
|
|
||||||
|
|
||||||
def slider_transparency_callback(self, value):
|
def slider_transparency_callback(self, value):
|
||||||
global TRANSPARENCY
|
self.parent.wm_attributes("-alpha", value/100)
|
||||||
TRANSPARENCY = value
|
self.parent.TRANSPARENCY = value
|
||||||
with open(PATH_CONFIG, "r") as fp:
|
save_json(self.parent.PATH_CONFIG, "TRANSPARENCY", self.parent.TRANSPARENCY)
|
||||||
config = json.load(fp)
|
|
||||||
config["TRANSPARENCY"] = TRANSPARENCY
|
|
||||||
with open(PATH_CONFIG, "w") as fp:
|
|
||||||
json.dump(config, fp, indent=4)
|
|
||||||
self.parent.wm_attributes("-alpha", TRANSPARENCY/100)
|
|
||||||
|
|
||||||
def optionmenu_translator_callback(self, choice):
|
def optionmenu_translator_callback(self, choice):
|
||||||
global CHOICE_TRANSLATOR
|
if self.parent.translator.authentication(choice, self.parent.AUTH_KEYS[choice]) is False:
|
||||||
CHOICE_TRANSLATOR = choice
|
self.parent.textbox_message_log.configure(state='normal')
|
||||||
with open(PATH_CONFIG, "r") as fp:
|
self.parent.textbox_message_log.insert("0.0", f"Auth Keyを設定してないか間違っています\n")
|
||||||
config = json.load(fp)
|
self.parent.textbox_message_log.configure(state='disabled')
|
||||||
config["CHOICE_TRANSLATOR"] = CHOICE_TRANSLATOR
|
else:
|
||||||
with open(PATH_CONFIG, "w") as fp:
|
self.optionmenu_source_language.configure(
|
||||||
json.dump(config, fp, indent=4)
|
values=self.parent.translator.languages[choice],
|
||||||
|
variable=customtkinter.StringVar(value=self.parent.translator.languages[choice][0]))
|
||||||
|
self.optionmenu_target_language.configure(
|
||||||
|
values=self.parent.translator.languages[choice],
|
||||||
|
variable=customtkinter.StringVar(value=self.parent.translator.languages[choice][1]))
|
||||||
|
|
||||||
def optionmenu_language_callback(self, choice):
|
self.parent.CHOICE_TRANSLATOR = choice
|
||||||
global TARGET_LANG
|
self.parent.SOURCE_LANG = self.parent.translator.languages[choice][0]
|
||||||
TARGET_LANG = choice
|
self.parent.TARGET_LANG = self.parent.translator.languages[choice][1]
|
||||||
with open(PATH_CONFIG, "r") as fp:
|
save_json(self.parent.PATH_CONFIG, "CHOICE_TRANSLATOR", self.parent.CHOICE_TRANSLATOR)
|
||||||
config = json.load(fp)
|
save_json(self.parent.PATH_CONFIG, "SOURCE_LANG", self.parent.SOURCE_LANG)
|
||||||
config["TARGET_LANG"] = TARGET_LANG
|
save_json(self.parent.PATH_CONFIG, "TARGET_LANG", self.parent.TARGET_LANG)
|
||||||
with open(PATH_CONFIG, "w") as fp:
|
|
||||||
json.dump(config, fp, indent=4)
|
def optionmenu_source_language_callback(self, choice):
|
||||||
|
self.parent.SOURCE_LANG = choice
|
||||||
|
save_json(self.parent.PATH_CONFIG, "SOURCE_LANG", self.parent.SOURCE_LANG)
|
||||||
|
|
||||||
|
def optionmenu_target_language_callback(self, choice):
|
||||||
|
self.parent.TARGET_LANG = choice
|
||||||
|
save_json(self.parent.PATH_CONFIG, "TARGET_LANG", self.parent.TARGET_LANG)
|
||||||
|
|
||||||
def optionmenu_theme_callback(self, choice):
|
def optionmenu_theme_callback(self, choice):
|
||||||
global APPEARANCE_THEME
|
customtkinter.set_appearance_mode(choice)
|
||||||
APPEARANCE_THEME = choice
|
|
||||||
with open(PATH_CONFIG, "r") as fp:
|
self.parent.APPEARANCE_THEME = choice
|
||||||
config = json.load(fp)
|
save_json(self.parent.PATH_CONFIG, "APPEARANCE_THEME", self.parent.APPEARANCE_THEME)
|
||||||
config["APPEARANCE_THEME"] = APPEARANCE_THEME
|
|
||||||
with open(PATH_CONFIG, "w") as fp:
|
|
||||||
json.dump(config, fp, indent=4)
|
|
||||||
customtkinter.set_appearance_mode(APPEARANCE_THEME)
|
|
||||||
|
|
||||||
def optionmenu_ui_scaling_callback(self, choice):
|
def optionmenu_ui_scaling_callback(self, choice):
|
||||||
global UI_SCALING
|
new_scaling_float = int(choice.replace("%", "")) / 100
|
||||||
UI_SCALING = choice
|
|
||||||
with open(PATH_CONFIG, "r") as fp:
|
|
||||||
config = json.load(fp)
|
|
||||||
config["UI_SCALING"] = UI_SCALING
|
|
||||||
with open(PATH_CONFIG, "w") as fp:
|
|
||||||
json.dump(config, fp, indent=4)
|
|
||||||
new_scaling_float = int(UI_SCALING.replace("%", "")) / 100
|
|
||||||
customtkinter.set_widget_scaling(new_scaling_float)
|
customtkinter.set_widget_scaling(new_scaling_float)
|
||||||
|
self.parent.UI_SCALING = choice
|
||||||
|
save_json(self.parent.PATH_CONFIG, "UI_SCALING", self.parent.UI_SCALING)
|
||||||
|
|
||||||
def optionmenu_font_family_callback(self, choice):
|
def optionmenu_font_family_callback(self, choice):
|
||||||
global FONT_FAMILY
|
self.parent.checkbox_translation.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
FONT_FAMILY = choice
|
self.parent.checkbox_foreground.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
with open(PATH_CONFIG, "r") as fp:
|
self.parent.textbox_message_log.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
config = json.load(fp)
|
self.parent.entry_message_box.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
config["FONT_FAMILY"] = FONT_FAMILY
|
|
||||||
with open(PATH_CONFIG, "w") as fp:
|
|
||||||
json.dump(config, fp, indent=4)
|
|
||||||
|
|
||||||
self.parent.checkbox_translation.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
|
||||||
self.parent.checkbox_foreground.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
|
||||||
self.parent.textbox_message_log.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
|
||||||
self.parent.entry_message_box.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
|
||||||
try:
|
try:
|
||||||
self.parent.information_window.textbox_information.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.parent.information_window.textbox_information.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
self.tabview_config._segmented_button.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.tabview_config._segmented_button.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
self.label_translator.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.label_translator.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
self.optionmenu_translator.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.optionmenu_translator.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
self.label_language.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.label_language.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
self.optionmenu_language.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.optionmenu_source_language.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
self.label_transparency.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.label_arrow.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
self.label_appearance_theme.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.optionmenu_target_language.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
self.optionmenu_appearance_theme.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.label_transparency.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
self.label_ui_scaling.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.label_appearance_theme.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
self.optionmenu_ui_scaling.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.optionmenu_appearance_theme.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
self.label_font_family.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.label_ui_scaling.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
self.optionmenu_font_family.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.optionmenu_ui_scaling.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
self.label_ip_address.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.label_font_family.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
self.entry_ip_address.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.optionmenu_font_family.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
self.label_port.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.label_ip_address.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
self.entry_port.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.entry_ip_address.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
self.label_authkey.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.label_port.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
self.entry_authkey.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.entry_port.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
self.label_message_format.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.label_authkey.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
self.entry_message_format.configure(font=customtkinter.CTkFont(family=FONT_FAMILY))
|
self.entry_authkey.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
|
self.label_message_format.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
|
self.entry_message_format.configure(font=customtkinter.CTkFont(family=choice))
|
||||||
|
|
||||||
|
self.parent.FONT_FAMILY = choice
|
||||||
|
save_json(self.parent.PATH_CONFIG, "FONT_FAMILY", self.parent.FONT_FAMILY)
|
||||||
|
|
||||||
class App(customtkinter.CTk):
|
class App(customtkinter.CTk):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
# init config
|
||||||
|
self.PATH_CONFIG = "./config.json"
|
||||||
|
self.OSC_IP_ADDRESS = "127.0.0.1"
|
||||||
|
self.OSC_PORT = 9000
|
||||||
|
self.ENABLE_TRANSLATION = True
|
||||||
|
self.CHOICE_TRANSLATOR = "DeepL(web)"
|
||||||
|
self.SOURCE_LANG = "JA"
|
||||||
|
self.TARGET_LANG = "EN"
|
||||||
|
self.ENABLE_FOREGROUND = False
|
||||||
|
self.AUTH_KEYS = {
|
||||||
|
"DeepL(web)": None,
|
||||||
|
"DeepL(auth)": None,
|
||||||
|
"Bing(web)": None,
|
||||||
|
"Google(web)": None,
|
||||||
|
}
|
||||||
|
self.MESSAGE_FORMAT = "[message]([translation])"
|
||||||
|
self.FONT_FAMILY = "Yu Gothic UI"
|
||||||
|
self.TRANSPARENCY = 100
|
||||||
|
self.APPEARANCE_THEME = "System"
|
||||||
|
self.UI_SCALING = "100%"
|
||||||
|
|
||||||
|
# load config
|
||||||
|
if os.path.isfile(self.PATH_CONFIG) is not False:
|
||||||
|
with open(self.PATH_CONFIG, 'r') as fp:
|
||||||
|
config = json.load(fp)
|
||||||
|
if "OSC_IP_ADDRESS" in config.keys():
|
||||||
|
self.OSC_IP_ADDRESS = config["OSC_IP_ADDRESS"]
|
||||||
|
if "OSC_PORT" in config.keys():
|
||||||
|
self.OSC_PORT = config["OSC_PORT"]
|
||||||
|
if "ENABLE_TRANSLATION" in config.keys():
|
||||||
|
self.ENABLE_TRANSLATION = config["ENABLE_TRANSLATION"]
|
||||||
|
if "CHOICE_TRANSLATOR" in config.keys():
|
||||||
|
self.CHOICE_TRANSLATOR = config["CHOICE_TRANSLATOR"]
|
||||||
|
if "SOURCE_LANG" in config.keys():
|
||||||
|
self.SOURCE_LANG = config["SOURCE_LANG"]
|
||||||
|
if "TARGET_LANG" in config.keys():
|
||||||
|
self.TARGET_LANG = config["TARGET_LANG"]
|
||||||
|
if "ENABLE_FOREGROUND" in config.keys():
|
||||||
|
self.ENABLE_FOREGROUND = config["ENABLE_FOREGROUND"]
|
||||||
|
if "AUTH_KEYS" in config.keys():
|
||||||
|
self.AUTH_KEYS = config["AUTH_KEYS"]
|
||||||
|
if "MESSAGE_FORMAT" in config.keys():
|
||||||
|
self.MESSAGE_FORMAT = config["MESSAGE_FORMAT"]
|
||||||
|
if "FONT_FAMILY" in config.keys():
|
||||||
|
self.FONT_FAMILY = config["FONT_FAMILY"]
|
||||||
|
if "TRANSPARENCY" in config.keys():
|
||||||
|
self.TRANSPARENCY = config["TRANSPARENCY"]
|
||||||
|
if "APPEARANCE_THEME" in config.keys():
|
||||||
|
self.APPEARANCE_THEME = config["APPEARANCE_THEME"]
|
||||||
|
if "UI_SCALING" in config.keys():
|
||||||
|
self.UI_SCALING = config["UI_SCALING"]
|
||||||
|
|
||||||
|
with open(self.PATH_CONFIG, 'w') as fp:
|
||||||
|
config = {
|
||||||
|
"OSC_IP_ADDRESS": self.OSC_IP_ADDRESS,
|
||||||
|
"OSC_PORT": self.OSC_PORT,
|
||||||
|
"ENABLE_TRANSLATION": self.ENABLE_TRANSLATION,
|
||||||
|
"CHOICE_TRANSLATOR": self.CHOICE_TRANSLATOR,
|
||||||
|
"SOURCE_LANG": self.SOURCE_LANG,
|
||||||
|
"TARGET_LANG": self.TARGET_LANG,
|
||||||
|
"ENABLE_FOREGROUND": self.ENABLE_FOREGROUND,
|
||||||
|
"AUTH_KEYS": self.AUTH_KEYS,
|
||||||
|
"MESSAGE_FORMAT": self.MESSAGE_FORMAT,
|
||||||
|
"FONT_FAMILY": self.FONT_FAMILY,
|
||||||
|
"TRANSPARENCY": self.TRANSPARENCY,
|
||||||
|
"APPEARANCE_THEME": self.APPEARANCE_THEME,
|
||||||
|
"UI_SCALING": self.UI_SCALING,
|
||||||
|
}
|
||||||
|
json.dump(config, fp, indent=4)
|
||||||
|
|
||||||
|
# init main window
|
||||||
self.iconbitmap(os.path.join(os.path.dirname(__file__), "img", "app.ico"))
|
self.iconbitmap(os.path.join(os.path.dirname(__file__), "img", "app.ico"))
|
||||||
self.title("VRCT")
|
self.title("VRCT")
|
||||||
self.geometry(f"{400}x{110}")
|
self.geometry(f"{400}x{110}")
|
||||||
@@ -538,144 +600,157 @@ class App(customtkinter.CTk):
|
|||||||
self.grid_columnconfigure(1, weight=1)
|
self.grid_columnconfigure(1, weight=1)
|
||||||
self.grid_rowconfigure(0, weight=1)
|
self.grid_rowconfigure(0, weight=1)
|
||||||
|
|
||||||
# sidebar left
|
# add sidebar left
|
||||||
self.sidebar_frame = customtkinter.CTkFrame(self, corner_radius=0)
|
self.sidebar_frame = customtkinter.CTkFrame(self, corner_radius=0)
|
||||||
self.sidebar_frame.grid(row=0, column=0, rowspan=4, sticky="nsw")
|
self.sidebar_frame.grid(row=0, column=0, rowspan=4, sticky="nsw")
|
||||||
self.sidebar_frame.grid_rowconfigure(5, weight=1)
|
self.sidebar_frame.grid_rowconfigure(5, weight=1)
|
||||||
|
|
||||||
# checkbox translation
|
# add checkbox translation
|
||||||
self.checkbox_translation = customtkinter.CTkCheckBox(
|
self.checkbox_translation = customtkinter.CTkCheckBox(
|
||||||
self.sidebar_frame,
|
self.sidebar_frame,
|
||||||
text="translation",
|
text="translation",
|
||||||
onvalue=True,
|
onvalue=True,
|
||||||
offvalue=False,
|
offvalue=False,
|
||||||
command=self.checkbox_translation_callback,
|
command=self.checkbox_translation_callback,
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.checkbox_translation.grid(row=0, column=0, columnspan=2 ,padx=10, pady=(5, 5), sticky="we")
|
self.checkbox_translation.grid(row=0, column=0, columnspan=2 ,padx=10, pady=(5, 5), sticky="we")
|
||||||
|
|
||||||
# checkbox foreground
|
# add checkbox foreground
|
||||||
self.checkbox_foreground = customtkinter.CTkCheckBox(
|
self.checkbox_foreground = customtkinter.CTkCheckBox(
|
||||||
self.sidebar_frame,
|
self.sidebar_frame,
|
||||||
text="foreground",
|
text="foreground",
|
||||||
onvalue=True,
|
onvalue=True,
|
||||||
offvalue=False,
|
offvalue=False,
|
||||||
command=self.checkbox_foreground_callback,
|
command=self.checkbox_foreground_callback,
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.checkbox_foreground.grid(row=1, column=0, columnspan=2 ,padx=10, pady=(5, 5), sticky="we")
|
self.checkbox_foreground.grid(row=1, column=0, columnspan=2 ,padx=10, pady=(5, 5), sticky="we")
|
||||||
|
|
||||||
# button information
|
# add button information
|
||||||
self.button_information = customtkinter.CTkButton(
|
self.button_information = customtkinter.CTkButton(
|
||||||
self.sidebar_frame,
|
self.sidebar_frame,
|
||||||
text="",
|
text="",
|
||||||
width=25,
|
width=25,
|
||||||
command=self.open_information,
|
command=self.button_information_callback,
|
||||||
image=customtkinter.CTkImage(Image.open(os.path.join(os.path.dirname(__file__), "img", "info-icon-white.png")))
|
image=customtkinter.CTkImage(Image.open(os.path.join(os.path.dirname(__file__), "img", "info-icon-white.png")))
|
||||||
)
|
)
|
||||||
self.button_information.grid(row=5, column=0, padx=(10, 5), pady=(5, 5), sticky="wse")
|
self.button_information.grid(row=5, column=0, padx=(10, 5), pady=(5, 5), sticky="wse")
|
||||||
self.information_window = None
|
self.information_window = None
|
||||||
|
|
||||||
# button config
|
# add button config
|
||||||
self.button_config = customtkinter.CTkButton(
|
self.button_config = customtkinter.CTkButton(
|
||||||
self.sidebar_frame,
|
self.sidebar_frame,
|
||||||
text="",
|
text="",
|
||||||
width=25,
|
width=25,
|
||||||
command=self.open_config,
|
command=self.button_config_callback,
|
||||||
image=customtkinter.CTkImage(Image.open(os.path.join(os.path.dirname(__file__), "img", "config-icon-white.png")))
|
image=customtkinter.CTkImage(Image.open(os.path.join(os.path.dirname(__file__), "img", "config-icon-white.png")))
|
||||||
)
|
)
|
||||||
self.button_config.grid(row=5, column=1, padx=(5, 10), pady=(5, 5), sticky="wse")
|
self.button_config.grid(row=5, column=1, padx=(5, 10), pady=(5, 5), sticky="wse")
|
||||||
self.config_window = None
|
self.config_window = None
|
||||||
|
|
||||||
# create textbox message log
|
# add textbox message log
|
||||||
self.textbox_message_log = customtkinter.CTkTextbox(
|
self.textbox_message_log = customtkinter.CTkTextbox(
|
||||||
self,
|
self,
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.textbox_message_log.grid(row=0, column=1, padx=(10, 10), pady=(10, 5), sticky="nsew")
|
self.textbox_message_log.grid(row=0, column=1, padx=(10, 10), pady=(10, 5), sticky="nsew")
|
||||||
self.textbox_message_log.configure(state='disabled')
|
self.textbox_message_log.configure(state='disabled')
|
||||||
|
|
||||||
# create entry message box
|
# add entry message box
|
||||||
self.entry_message_box = customtkinter.CTkEntry(
|
self.entry_message_box = customtkinter.CTkEntry(
|
||||||
self,
|
self,
|
||||||
placeholder_text="message",
|
placeholder_text="message",
|
||||||
font=customtkinter.CTkFont(family=FONT_FAMILY)
|
font=customtkinter.CTkFont(family=self.FONT_FAMILY)
|
||||||
)
|
)
|
||||||
self.entry_message_box.grid(row=1, column=1, columnspan=2, padx=(10, 10), pady=(5, 10), sticky="nsew")
|
self.entry_message_box.grid(row=1, column=1, columnspan=2, padx=(10, 10), pady=(5, 10), sticky="nsew")
|
||||||
|
|
||||||
# set default values
|
# set default values
|
||||||
if ENABLE_TRANSLATION:
|
## set checkbox enable translation
|
||||||
|
if self.ENABLE_TRANSLATION:
|
||||||
self.checkbox_translation.select()
|
self.checkbox_translation.select()
|
||||||
else:
|
else:
|
||||||
self.checkbox_translation.deselect()
|
self.checkbox_translation.deselect()
|
||||||
|
|
||||||
if ENABLE_FOREGROUND:
|
## set set checkbox enable foreground
|
||||||
|
if self.ENABLE_FOREGROUND:
|
||||||
self.checkbox_foreground.select()
|
self.checkbox_foreground.select()
|
||||||
self.attributes("-topmost", True)
|
self.attributes("-topmost", True)
|
||||||
else:
|
else:
|
||||||
self.checkbox_foreground.deselect()
|
self.checkbox_foreground.deselect()
|
||||||
self.attributes("-topmost", False)
|
self.attributes("-topmost", False)
|
||||||
|
|
||||||
|
## set bind entry message box
|
||||||
self.entry_message_box.bind("<Return>", self.entry_message_box_press_key_enter)
|
self.entry_message_box.bind("<Return>", self.entry_message_box_press_key_enter)
|
||||||
self.entry_message_box.bind("<Any-KeyPress>", self.entry_message_box_press_key_any)
|
self.entry_message_box.bind("<Any-KeyPress>", self.entry_message_box_press_key_any)
|
||||||
self.entry_message_box.bind("<Leave>", self.entry_message_box_leave)
|
self.entry_message_box.bind("<Leave>", self.entry_message_box_leave)
|
||||||
|
|
||||||
if TRANSLATOR is None:
|
## set translator instance
|
||||||
|
self.translator = Translator()
|
||||||
|
if self.translator.authentication(self.CHOICE_TRANSLATOR, self.AUTH_KEYS[self.CHOICE_TRANSLATOR]) is False:
|
||||||
# error update Auth key
|
# error update Auth key
|
||||||
self.textbox_message_log.configure(state='normal')
|
self.textbox_message_log.configure(state='normal')
|
||||||
self.textbox_message_log.insert("0.0", f"Auth Keyを設定してないか間違っています\n")
|
self.textbox_message_log.insert("0.0", f"Auth Keyを設定してないか間違っています\n")
|
||||||
self.textbox_message_log.configure(state='disabled')
|
self.textbox_message_log.configure(state='disabled')
|
||||||
|
|
||||||
self.wm_attributes("-alpha", TRANSPARENCY/100)
|
## set transparency for main window
|
||||||
|
self.wm_attributes("-alpha", self.TRANSPARENCY/100)
|
||||||
|
|
||||||
new_scaling_float = int(UI_SCALING.replace("%", "")) / 100
|
## set UI scale
|
||||||
|
new_scaling_float = int(self.UI_SCALING.replace("%", "")) / 100
|
||||||
customtkinter.set_widget_scaling(new_scaling_float)
|
customtkinter.set_widget_scaling(new_scaling_float)
|
||||||
|
|
||||||
def open_config(self):
|
## set UI theme
|
||||||
|
customtkinter.set_appearance_mode(self.APPEARANCE_THEME)
|
||||||
|
customtkinter.set_default_color_theme("blue")
|
||||||
|
|
||||||
|
def button_config_callback(self):
|
||||||
if self.config_window is None or not self.config_window.winfo_exists():
|
if self.config_window is None or not self.config_window.winfo_exists():
|
||||||
self.config_window = ToplevelWindowConfig(self)
|
self.config_window = ToplevelWindowConfig(self)
|
||||||
self.config_window.focus()
|
self.config_window.focus()
|
||||||
|
|
||||||
def open_information(self):
|
def button_information_callback(self):
|
||||||
if self.information_window is None or not self.information_window.winfo_exists():
|
if self.information_window is None or not self.information_window.winfo_exists():
|
||||||
self.information_window = ToplevelWindowInformation(self)
|
self.information_window = ToplevelWindowInformation(self)
|
||||||
self.information_window.focus()
|
self.information_window.focus()
|
||||||
|
|
||||||
def checkbox_translation_callback(self):
|
def checkbox_translation_callback(self):
|
||||||
global ENABLE_TRANSLATION
|
self.ENABLE_TRANSLATION = self.checkbox_translation.get()
|
||||||
ENABLE_TRANSLATION = self.checkbox_translation.get()
|
save_json(self.PATH_CONFIG, "ENABLE_TRANSLATION", self.ENABLE_TRANSLATION)
|
||||||
with open(PATH_CONFIG, "r") as fp:
|
|
||||||
config = json.load(fp)
|
|
||||||
config["ENABLE_TRANSLATION"] = ENABLE_TRANSLATION
|
|
||||||
with open(PATH_CONFIG, "w") as fp:
|
|
||||||
json.dump(config, fp, indent=4)
|
|
||||||
|
|
||||||
def checkbox_foreground_callback(self):
|
def checkbox_foreground_callback(self):
|
||||||
global ENABLE_FOREGROUND
|
value = self.checkbox_foreground.get()
|
||||||
ENABLE_FOREGROUND = self.checkbox_foreground.get()
|
|
||||||
with open(PATH_CONFIG, "r") as fp:
|
|
||||||
config = json.load(fp)
|
|
||||||
config["ENABLE_FOREGROUND"] = ENABLE_FOREGROUND
|
|
||||||
with open(PATH_CONFIG, "w") as fp:
|
|
||||||
json.dump(config, fp, indent=4)
|
|
||||||
|
|
||||||
if ENABLE_FOREGROUND:
|
if value:
|
||||||
self.attributes("-topmost", True)
|
self.attributes("-topmost", True)
|
||||||
else:
|
else:
|
||||||
self.attributes("-topmost", False)
|
self.attributes("-topmost", False)
|
||||||
|
|
||||||
|
self.ENABLE_FOREGROUND = value
|
||||||
|
save_json(self.PATH_CONFIG, "ENABLE_FOREGROUND", self.ENABLE_FOREGROUND)
|
||||||
|
|
||||||
def entry_message_box_press_key_enter(self, event):
|
def entry_message_box_press_key_enter(self, event):
|
||||||
if ENABLE_FOREGROUND:
|
if self.ENABLE_FOREGROUND:
|
||||||
self.attributes("-topmost", True)
|
self.attributes("-topmost", True)
|
||||||
|
|
||||||
message = self.entry_message_box.get()
|
message = self.entry_message_box.get()
|
||||||
if len(message) > 0:
|
if len(message) > 0:
|
||||||
# translate
|
# translate
|
||||||
if (self.checkbox_translation.get() is True) and (TRANSLATOR is not None):
|
if self.checkbox_translation.get() is False:
|
||||||
result = TRANSLATOR.translate_text(message, target_lang=TARGET_LANG)
|
|
||||||
chat_message = MESSAGE_FORMAT.replace("[message]", message).replace("[translation]", result.text)
|
|
||||||
else:
|
|
||||||
chat_message = f"{message}"
|
chat_message = f"{message}"
|
||||||
|
elif (self.translator.translator_status[self.CHOICE_TRANSLATOR] is False) or (self.SOURCE_LANG == "None") or (self.TARGET_LANG == "None"):
|
||||||
|
self.textbox_message_log.configure(state='normal')
|
||||||
|
self.textbox_message_log.insert("0.0", f"Auth Keyもしくは言語の設定が間違っています\n")
|
||||||
|
self.textbox_message_log.configure(state='disabled')
|
||||||
|
chat_message = f"{message}"
|
||||||
|
else:
|
||||||
|
result = self.translator.translate(
|
||||||
|
translator_name=self.CHOICE_TRANSLATOR,
|
||||||
|
source_language=self.SOURCE_LANG,
|
||||||
|
target_language=self.TARGET_LANG,
|
||||||
|
message=message
|
||||||
|
)
|
||||||
|
chat_message = self.MESSAGE_FORMAT.replace("[message]", message).replace("[translation]", result)
|
||||||
|
|
||||||
# send OSC message
|
# send OSC message
|
||||||
message = osc_message_builder.OscMessageBuilder(address="/chatbox/input")
|
message = osc_message_builder.OscMessageBuilder(address="/chatbox/input")
|
||||||
@@ -683,7 +758,7 @@ class App(customtkinter.CTk):
|
|||||||
message.add_arg(True)
|
message.add_arg(True)
|
||||||
message.add_arg(True)
|
message.add_arg(True)
|
||||||
message = message.build()
|
message = message.build()
|
||||||
client = udp_client.SimpleUDPClient(OSC_IP_ADDRESS, OSC_PORT)
|
client = udp_client.SimpleUDPClient(self.OSC_IP_ADDRESS, self.OSC_PORT)
|
||||||
client.send(message)
|
client.send(message)
|
||||||
|
|
||||||
# update textbox message log
|
# update textbox message log
|
||||||
@@ -695,11 +770,11 @@ class App(customtkinter.CTk):
|
|||||||
self.entry_message_box.delete(0, customtkinter.END)
|
self.entry_message_box.delete(0, customtkinter.END)
|
||||||
|
|
||||||
def entry_message_box_press_key_any(self, event):
|
def entry_message_box_press_key_any(self, event):
|
||||||
if ENABLE_FOREGROUND:
|
if self.ENABLE_FOREGROUND:
|
||||||
self.attributes("-topmost", False)
|
self.attributes("-topmost", False)
|
||||||
|
|
||||||
def entry_message_box_leave(self, event):
|
def entry_message_box_leave(self, event):
|
||||||
if ENABLE_FOREGROUND:
|
if self.ENABLE_FOREGROUND:
|
||||||
self.attributes("-topmost", True)
|
self.attributes("-topmost", True)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user