Setting box: add items UI Scaling, Font Family, UI Language. add the function get_key_by_value to utils.py. and fixed a bit

This commit is contained in:
Sakamoto Shiina
2023-08-28 14:43:34 +09:00
parent 9ec37061e5
commit 84d76ed9a4
2 changed files with 61 additions and 134 deletions

View File

@@ -3,4 +3,10 @@ from PIL.Image import open as Image_open
def getImageFile(file_name):
img = Image_open(os_path.join(os_path.dirname(__file__), "img", file_name))
return img
return img
def get_key_by_value(dictionary, value):
for key, val in dictionary.items():
if val == value:
return key
return None

View File

@@ -1,6 +1,9 @@
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 ..SettingBoxGenerator import SettingBoxGenerator
@@ -13,12 +16,7 @@ def createSettingBox_Appearance(setting_box_wrapper, config_window, settings):
sbg = SettingBoxGenerator(config_window, settings)
createSettingBoxDropdownMenu = sbg.createSettingBoxDropdownMenu
createSettingBoxSwitch = sbg.createSettingBoxSwitch
createSettingBoxCheckbox = sbg.createSettingBoxCheckbox
createSettingBoxSlider = sbg.createSettingBoxSlider
createSettingBoxProgressbarXSlider = sbg.createSettingBoxProgressbarXSlider
createSettingBoxEntry = sbg.createSettingBoxEntry
# 関数名は変えるかもしれない。
@@ -32,13 +30,22 @@ def createSettingBox_Appearance(setting_box_wrapper, config_window, settings):
def optionmenu_appearance_theme_callback(value):
config.APPEARANCE_THEME = value
def optionmenu_ui_scaling_callback(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
def optionmenu_ui_language_callback(value):
config.UI_LANGUAGE = get_key_by_value(selectable_languages, value)
row=0
config_window.sb__transparency = createSettingBoxSlider(
parent_widget=setting_box_wrapper,
label_text="Transparency",
desc_text="It will change window's transparency. 50% to 100%. (Default: 100%)",
desc_text="Change the window's transparency. 50% to 100%. (Default: 100%)",
slider_attr_name="sb__transparency_slider",
slider_range=(50, 100),
command=lambda value: slider_transparency_callback(value),
@@ -48,13 +55,12 @@ def createSettingBox_Appearance(setting_box_wrapper, config_window, settings):
row+=1
config_window.sb__appearance_theme = createSettingBoxDropdownMenu(
parent_widget=setting_box_wrapper,
label_text="Theme",
desc_text="You can choose the color theme from \"Light\" and \"Dark\". If you select \"System\", It will adjust based on your Windows theme. (Default: System)",
desc_text="Change the color theme from \"Light\" and \"Dark\". If you select \"System\", It will adjust based on your Windows theme. (Default: System)",
optionmenu_attr_name="sb__appearance_theme_optionmenu",
dropdown_menu_attr_name="sb__appearance_theme_optionmenu_dropdown",
dropdown_menu_attr_name="sb__appearance_theme_dropdown",
dropdown_menu_values=["Light", "Dark", "System"],
command=lambda value: optionmenu_appearance_theme_callback(value),
variable=StringVar(value=config.APPEARANCE_THEME)
@@ -63,131 +69,46 @@ def createSettingBox_Appearance(setting_box_wrapper, config_window, settings):
row+=1
# config_window.sb__dropdown_menu_2 = createSettingBoxDropdownMenu(
# parent_widget=setting_box_wrapper,
# label_text="Option Menu",
# desc_text="Select your preferences from the options menu.\nYou can choose your preferred language.",
# optionmenu_attr_name="optionmenu_attr_name_2",
# dropdown_menu_attr_name="dropdown_menu_attr_name_1",
# dropdown_menu_values=["tt", "Japanese", "English"],
# command=lambda value: dropdownMenuFun(value, config_window.optionmenu_attr_name_2, config_window.dropdown_menu_attr_name_1),
# variable=StringVar(value=config.INPUT_SOURCE_LANG)
# )
# config_window.sb__dropdown_menu_2.grid(row=row)
# row+=1
# config_window.sb__switch_1 = createSettingBoxSwitch(
# parent_widget=setting_box_wrapper,
# label_text="Switch",
# desc_text="Turning this switch on will bring happiness.\nAs for turning it off... I leave that to your imagination",
# switch_attr_name="switch_attr_name_1",
# command=lambda: switchFun(config_window.switch_attr_name_1),
# is_checked=True,
# )
# config_window.sb__switch_1.grid(row=row)
# row+=1
# config_window.sb__checkbox_1 = createSettingBoxCheckbox(
# parent_widget=setting_box_wrapper,
# label_text="Checkbox",
# desc_text="Checkbox ticked, a checkmark.",
# checkbox_attr_name="checkbox_attr_name_1",
# command=lambda: checkboxFun(config_window.checkbox_attr_name_1),
# is_checked=False,
# )
# config_window.sb__checkbox_1.grid(row=row)
# row+=1
# config_window.sb__slider_1 = createSettingBoxSlider(
# parent_widget=setting_box_wrapper,
# label_text="Slider",
# desc_text="Adjust using the slider; the balance is up to you.",
# slider_attr_name="slider_attr_name_1",
# slider_range=(0, config_window.MAX_SPEAKER_ENERGY_THRESHOLD),
# slider_number_of_steps=config_window.MAX_SPEAKER_ENERGY_THRESHOLD,
# command=lambda value: sliderFun(value, config_window.slider_attr_name_1),
# variable=IntVar(value=config_window.INPUT_SPEAKER_ENERGY_THRESHOLD),
# )
# config_window.sb__slider_1.grid(row=row)
# row+=1
config_window.sb__ui_scaling = createSettingBoxDropdownMenu(
parent_widget=setting_box_wrapper,
label_text="UI Size",
desc_text="(Default: 100%)",
optionmenu_attr_name="sb__ui_scaling_optionmenu",
dropdown_menu_attr_name="sb__ui_scaling_dropdown",
dropdown_menu_values=["80%", "90%", "100%", "110%", "120%"],
command=lambda value: optionmenu_ui_scaling_callback(value),
variable=StringVar(value=config.UI_SCALING)
)
config_window.sb__ui_scaling.grid(row=row)
row+=1
# config_window.sb__progressbar_x_slider_1 = createSettingBoxProgressbarXSlider(
# parent_widget=setting_box_wrapper,
# label_text="Progressbar and Slider for check the threshold",
# desc_text="just the slider to modify the threshold for activating voice input.\nPress the microphone button to start input, and you can adjust it while monitoring the actual volume.",
# command=set_input_threshold, # ?
# variable=IntVar(value=config.INPUT_MIC_ENERGY_THRESHOLD),
# entry_attr_name="progressbar_x_slider__entry_attr_name_1",
# font_families = list(tk_font.families())
config_window.sb__font_family = createSettingBoxDropdownMenu(
parent_widget=setting_box_wrapper,
label_text="Font Family",
desc_text="(Default: Yu Gothic UI)",
optionmenu_attr_name="sb__font_family_optionmenu",
dropdown_menu_attr_name="sb__font_family_dropdown",
dropdown_menu_values=["Font A", "Font B"],
# dropdown_menu_values=font_families,
command=lambda value: optionmenu_font_family_callback(value),
variable=StringVar(value=config.FONT_FAMILY)
)
config_window.sb__font_family.grid(row=row)
row+=1
# slider_attr_name="progressbar_x_slider__slider_attr_name_1",
# slider_range=(0, config_window.MAX_SPEAKER_ENERGY_THRESHOLD),
# slider_number_of_steps=config_window.MAX_SPEAKER_ENERGY_THRESHOLD,
# progressbar_attr_name="progressbar_x_slider__progressbar_attr_name_1",
# passive_button_attr_name="progressbar_x_slider__passive_button_attr_name_1",
# passive_button_command=lambda e: checkbox_input_speaker_threshold_check_callback(
# e,
# config_window.progressbar_x_slider__passive_button_attr_name_1,
# config_window.progressbar_x_slider__active_button_attr_name_1,
# is_turned_on=True,
# ),
# active_button_attr_name="progressbar_x_slider__active_button_attr_name_1",
# active_button_command=lambda e: checkbox_input_speaker_threshold_check_callback(
# e,
# config_window.progressbar_x_slider__passive_button_attr_name_1,
# config_window.progressbar_x_slider__active_button_attr_name_1,
# is_turned_on=False,
# ),
# button_image_filename="mic_icon_white.png"
# )
# config_window.sb__progressbar_x_slider_1.grid(row=row)
# row+=1
# config_window.sb__progressbar_x_slider_2 = createSettingBoxProgressbarXSlider(
# parent_widget=setting_box_wrapper,
# label_text="Progressbar and Slider for check the threshold2",
# desc_text="just the slider to modify the threshold for activating voice input.\nPress the microphone button to start input, and you can adjust it while monitoring the actual volume.",
# command=set_input_threshold, # ?
# variable=IntVar(value=config.INPUT_SPEAKER_ENERGY_THRESHOLD),
# entry_attr_name="progressbar_x_slider__entry_attr_name_2",
# slider_attr_name="progressbar_x_slider__slider_attr_name_2",
# slider_range=(0, config_window.MAX_SPEAKER_ENERGY_THRESHOLD),
# slider_number_of_steps=config_window.MAX_SPEAKER_ENERGY_THRESHOLD,
# progressbar_attr_name="progressbar_x_slider__progressbar_attr_name_2",
# passive_button_attr_name="progressbar_x_slider__passive_button_attr_name_2",
# passive_button_command=lambda e: checkbox_input_speaker_threshold_check_callback(
# e,
# config_window.progressbar_x_slider__passive_button_attr_name_2,
# config_window.progressbar_x_slider__active_button_attr_name_2,
# is_turned_on=True,
# ),
# active_button_attr_name="progressbar_x_slider__active_button_attr_name_2",
# active_button_command=lambda e: checkbox_input_speaker_threshold_check_callback(
# e,
# config_window.progressbar_x_slider__passive_button_attr_name_2,
# config_window.progressbar_x_slider__active_button_attr_name_2,
# is_turned_on=False,
# ),
# button_image_filename="headphones_icon_white.png"
# )
# config_window.sb__progressbar_x_slider_2.grid(row=row)
# row+=1
# config_window.sb__entry_1 = createSettingBoxEntry(
# parent_widget=setting_box_wrapper,
# label_text="Entry",
# desc_text="Please input a numerical value.",
# entry_attr_name="entry_attr_name_1",
# entry_width=settings.uism.SB__ENTRY_WIDTH_100,
# entry_bind__Any_KeyRelease=lambda value: entryFun(value, config_window.entry_attr_name_1),
# entry_textvariable=IntVar(value=config_window.INPUT_MIC_PHRASE_TIMEOUT),
# )
# config_window.sb__entry_1.grid(row=row, pady=0)
# row+=1
selectable_languages_values = list(selectable_languages.values())
config_window.sb__ui_language = createSettingBoxDropdownMenu(
parent_widget=setting_box_wrapper,
label_text="UI Language",
desc_text="(Default: English)",
optionmenu_attr_name="sb__ui_language_optionmenu",
dropdown_menu_attr_name="sb__ui_language_dropdown",
dropdown_menu_values=selectable_languages_values,
command=lambda value: optionmenu_ui_language_callback(value),
variable=StringVar(value=selectable_languages[config.UI_LANGUAGE]),
)
config_window.sb__ui_language.grid(row=row)
row+=1