[Update] model.pyからprint_textboxをすべて引き剥がした。

UIの依存関係はなくなったはず
This commit is contained in:
misygauziya
2023-08-19 19:09:01 +09:00
parent e3a37c576c
commit 31e786f2a8
4 changed files with 184 additions and 143 deletions

View File

@@ -1,13 +1,20 @@
from json import load, dump
import inspect
from os import path as os_path
from json import load as json_load
from json import dump as json_dump
import tkinter as tk
from tkinter import font
from utils import save_json
from languages import transcription_lang, translators, translation_lang, selectable_languages
from audio_utils import get_input_device_list, get_output_device_list, get_default_input_device, get_default_output_device
def saveJson(path, key, value):
with open(path, "r") as fp:
json_data = load(fp)
json_data[key] = value
with open(path, "w") as fp:
dump(json_data, fp, indent=4)
class Config:
_instance = None
@@ -70,7 +77,7 @@ class Config:
def TRANSPARENCY(self, value):
if type(value) is int and 0 <= value <= 100:
self._TRANSPARENCY = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def APPEARANCE_THEME(self):
@@ -80,7 +87,7 @@ class Config:
def APPEARANCE_THEME(self, value):
if value in ["Light", "Dark", "System"]:
self._APPEARANCE_THEME = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def UI_SCALING(self):
@@ -90,7 +97,7 @@ class Config:
def UI_SCALING(self, value):
if value in ["80%", "90%", "100%", "110%", "120%"]:
self._UI_SCALING = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def FONT_FAMILY(self):
@@ -102,7 +109,7 @@ class Config:
root.withdraw()
if value in list(font.families()):
self._FONT_FAMILY = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
root.destroy()
@property
@@ -113,7 +120,7 @@ class Config:
def UI_LANGUAGE(self, value):
if value in list(selectable_languages.keys()):
self._UI_LANGUAGE = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def CHOICE_TRANSLATOR(self):
@@ -123,7 +130,7 @@ class Config:
def CHOICE_TRANSLATOR(self, value):
if value in translators:
self._CHOICE_TRANSLATOR = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_SOURCE_LANG(self):
@@ -133,7 +140,7 @@ class Config:
def INPUT_SOURCE_LANG(self, value):
if value in list(translation_lang[self.CHOICE_TRANSLATOR]["source"].keys()):
self._INPUT_SOURCE_LANG = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_TARGET_LANG(self):
@@ -143,7 +150,7 @@ class Config:
def INPUT_TARGET_LANG(self, value):
if value in list(translation_lang[self.CHOICE_TRANSLATOR]["target"].keys()):
self._INPUT_TARGET_LANG = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def OUTPUT_SOURCE_LANG(self):
@@ -153,7 +160,7 @@ class Config:
def OUTPUT_SOURCE_LANG(self, value):
if value in list(translation_lang[self.CHOICE_TRANSLATOR]["source"].keys()):
self._OUTPUT_SOURCE_LANG = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def OUTPUT_TARGET_LANG(self):
@@ -163,7 +170,7 @@ class Config:
def OUTPUT_TARGET_LANG(self, value):
if value in list(translation_lang[self.CHOICE_TRANSLATOR]["target"].keys()):
self._OUTPUT_TARGET_LANG = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def CHOICE_MIC_HOST(self):
@@ -173,7 +180,7 @@ class Config:
def CHOICE_MIC_HOST(self, value):
if value in [host for host in get_input_device_list().keys()]:
self._CHOICE_MIC_HOST = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def CHOICE_MIC_DEVICE(self):
@@ -183,7 +190,7 @@ class Config:
def CHOICE_MIC_DEVICE(self, value):
if value in [device["name"] for device in get_input_device_list()[self.CHOICE_MIC_HOST]]:
self._CHOICE_MIC_DEVICE = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_MIC_VOICE_LANGUAGE(self):
@@ -193,7 +200,7 @@ class Config:
def INPUT_MIC_VOICE_LANGUAGE(self, value):
if value in list(transcription_lang.keys()):
self._INPUT_MIC_VOICE_LANGUAGE = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_MIC_ENERGY_THRESHOLD(self):
@@ -203,7 +210,7 @@ class Config:
def INPUT_MIC_ENERGY_THRESHOLD(self, value):
if type(value) is int:
self._INPUT_MIC_ENERGY_THRESHOLD = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD(self):
@@ -213,7 +220,7 @@ class Config:
def INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD(self, value):
if type(value) is bool:
self._INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_MIC_RECORD_TIMEOUT(self):
@@ -223,7 +230,7 @@ class Config:
def INPUT_MIC_RECORD_TIMEOUT(self, value):
if type(value) is int:
self._INPUT_MIC_RECORD_TIMEOUT = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_MIC_PHRASE_TIMEOUT(self):
@@ -233,7 +240,7 @@ class Config:
def INPUT_MIC_PHRASE_TIMEOUT(self, value):
if type(value) is int:
self._INPUT_MIC_PHRASE_TIMEOUT = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_MIC_MAX_PHRASES(self):
@@ -243,7 +250,7 @@ class Config:
def INPUT_MIC_MAX_PHRASES(self, value):
if type(value) is int:
self._INPUT_MIC_MAX_PHRASES = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_MIC_WORD_FILTER(self):
@@ -253,7 +260,7 @@ class Config:
def INPUT_MIC_WORD_FILTER(self, value):
if type(value) is list:
self._INPUT_MIC_WORD_FILTER = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def CHOICE_SPEAKER_DEVICE(self):
@@ -265,7 +272,7 @@ class Config:
speaker_device = [device for device in get_output_device_list() if device["name"] == value][0]
if get_default_output_device()["index"] == speaker_device["index"]:
self._CHOICE_SPEAKER_DEVICE = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_SPEAKER_VOICE_LANGUAGE(self):
@@ -275,7 +282,7 @@ class Config:
def INPUT_SPEAKER_VOICE_LANGUAGE(self, value):
if value in list(transcription_lang.keys()):
self._INPUT_SPEAKER_VOICE_LANGUAGE = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_SPEAKER_ENERGY_THRESHOLD(self):
@@ -285,7 +292,7 @@ class Config:
def INPUT_SPEAKER_ENERGY_THRESHOLD(self, value):
if type(value) is int:
self._INPUT_SPEAKER_ENERGY_THRESHOLD = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD(self):
@@ -295,7 +302,7 @@ class Config:
def INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD(self, value):
if type(value) is bool:
self._INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_SPEAKER_RECORD_TIMEOUT(self):
@@ -305,7 +312,7 @@ class Config:
def INPUT_SPEAKER_RECORD_TIMEOUT(self, value):
if type(value) is int:
self._INPUT_SPEAKER_RECORD_TIMEOUT = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_SPEAKER_PHRASE_TIMEOUT(self):
@@ -315,7 +322,7 @@ class Config:
def INPUT_SPEAKER_PHRASE_TIMEOUT(self, value):
if type(value) is int:
self._INPUT_SPEAKER_PHRASE_TIMEOUT = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_SPEAKER_MAX_PHRASES(self):
@@ -325,7 +332,7 @@ class Config:
def INPUT_SPEAKER_MAX_PHRASES(self, value):
if type(value) is int:
self._INPUT_SPEAKER_MAX_PHRASES = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def OSC_IP_ADDRESS(self):
@@ -335,7 +342,7 @@ class Config:
def OSC_IP_ADDRESS(self, value):
if type(value) is str:
self._OSC_IP_ADDRESS = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def OSC_PORT(self):
@@ -345,7 +352,7 @@ class Config:
def OSC_PORT(self, value):
if type(value) is int:
self._OSC_PORT = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def AUTH_KEYS(self):
@@ -357,7 +364,7 @@ class Config:
for key, value in value.items():
if type(value) is str:
self._AUTH_KEYS[key] = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, self.AUTH_KEYS)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, self.AUTH_KEYS)
@property
def MESSAGE_FORMAT(self):
@@ -367,7 +374,7 @@ class Config:
def MESSAGE_FORMAT(self, value):
if type(value) is str:
self._MESSAGE_FORMAT = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def ENABLE_AUTO_CLEAR_CHATBOX(self):
@@ -377,7 +384,7 @@ class Config:
def ENABLE_AUTO_CLEAR_CHATBOX(self, value):
if type(value) is bool:
self._ENABLE_AUTO_CLEAR_CHATBOX = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def ENABLE_NOTICE_XSOVERLAY(self):
@@ -387,7 +394,7 @@ class Config:
def ENABLE_NOTICE_XSOVERLAY(self, value):
if type(value) is bool:
self._ENABLE_NOTICE_XSOVERLAY = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def ENABLE_OSC(self):