From 8cffee569a4fb0a8310a1dac45855f82f8d2370e Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Tue, 24 Oct 2023 16:07:29 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[Refactor]=20Textbox=E3=81=AEUi=20Size?= =?UTF-8?q?=E3=82=92=E7=8B=AC=E7=AB=8B=E3=81=95=E3=81=9B=E3=82=8B=E3=81=9F?= =?UTF-8?q?=E3=82=81=E3=81=AE=E6=BA=96=E5=82=99=E3=81=A7=E3=83=AA=E3=83=95?= =?UTF-8?q?=E3=82=A1=E3=82=AF=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0=E3=80=82?= =?UTF-8?q?=E3=82=AF=E3=83=A9=E3=82=B9=E3=81=AA=E3=81=A9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- view.py | 6 +- vrct_gui/_printToTextbox.py | 150 ++++++++++++++++------- vrct_gui/ui_managers/UiScalingManager.py | 8 +- vrct_gui/ui_utils/ui_utils.py | 8 ++ vrct_gui/vrct_gui.py | 18 +-- 5 files changed, 132 insertions(+), 58 deletions(-) diff --git a/view.py b/view.py index 6a5ff860..51215f7a 100644 --- a/view.py +++ b/view.py @@ -517,7 +517,7 @@ class View(): # Insert sample conversation for testing. - # self._insertSampleConversationToTextbox() + self._insertSampleConversationToTextbox() @@ -1054,11 +1054,11 @@ class View(): @staticmethod - def _printToTextbox_Info(info_message): + def _printToTextbox_Info(info_message, **kwargs): vrct_gui._printToTextbox( target_type="SYSTEM", original_message=info_message, - # translated_message="", + **kwargs, ) diff --git a/vrct_gui/_printToTextbox.py b/vrct_gui/_printToTextbox.py index 943b047d..ddc4b411 100644 --- a/vrct_gui/_printToTextbox.py +++ b/vrct_gui/_printToTextbox.py @@ -1,66 +1,116 @@ from datetime import datetime from customtkinter import CTkFont +from .ui_utils import calculateUiSize -def _printToTextbox(vrct_gui, - settings, - target_type, - original_message=None, - translated_message=None, - tags=None, - disable_print_to_textbox_all:bool=False, - ): +class _PrintToTextbox(): + def __init__( + self, + vrct_gui, + settings, + ): - now_raw_data = datetime.now() - # now = now_raw_data.strftime("%H:%M:%S") - now_hm = now_raw_data.strftime("%H:%M") - # set target textbox widget + self.vrct_gui = vrct_gui + self.settings = settings - is_only_one_message = True if original_message is None or translated_message is None or translated_message == "" else False - - match (target_type): - case "SYSTEM": - target_textbox = vrct_gui.textbox_system - case "SENT": - target_textbox = vrct_gui.textbox_sent - case "RECEIVED": - target_textbox = vrct_gui.textbox_received - case (_): - raise ValueError(f"No matching case for target_type: {target_type}") + self._DEFAULT_TEXTBOX_FIRST_INSERT_SPACING = self.settings.uism.TEXTBOX_FIRST_INSERT_SPACING + self._DEFAULT_TEXTBOX_FONT_SIZE__LABEL = self.settings.uism.TEXTBOX_FONT_SIZE__LABEL + self._DEFAULT_TEXTBOX_FONT_SIZE__TIMESTAMP = self.settings.uism.TEXTBOX_FONT_SIZE__TIMESTAMP + self._DEFAULT_TEXTBOX_FONT_SIZE__SYSTEM_TEXT_FONT = self.settings.uism.TEXTBOX_FONT_SIZE__SYSTEM_TEXT_FONT + self._DEFAULT_TEXTBOX_FONT_SIZE__SECONDARY_TEXT_FONT = self.settings.uism.TEXTBOX_FONT_SIZE__SECONDARY_TEXT_FONT + self._DEFAULT_TEXTBOX_FONT_SIZE__MAIN_TEXT_FONT = self.settings.uism.TEXTBOX_FONT_SIZE__MAIN_TEXT_FONT - def printEachTextbox(target_textbox): + + self.textbox_first_insert_spacing = None + self.textbox_font_size__label = None + self.textbox_font_size__timestamp = None + self.textbox_font_size__system_text_font = None + self.textbox_font_size__secondary_text_font = None + self.textbox_font_size__main_text_font = None + + + self.all_textbox_widgets = [self.vrct_gui.textbox_all, self.vrct_gui.textbox_system, self.vrct_gui.textbox_sent, self.vrct_gui.textbox_received] + + + self.setTagsSettings() + + + def printToTextbox(self, target_type, original_message=None, translated_message=None, to_print_to_textbox_all:bool=True): + self._printEachTextbox( + target_textbox=self._getTargetTextboxWidget(target_type), + print_type=target_type, + original_message=original_message, + translated_message=translated_message, + ) + + # To automatically print the same log to the textbox_all widget as well. + if to_print_to_textbox_all is True: + self._printEachTextbox( + target_textbox=self._getTargetTextboxWidget("ALL"), + print_type=target_type, + original_message=original_message, + translated_message=translated_message, + ) + + def setTagsSettings(self, custom_font_size_scale:float=1.0): + # Calculate Textbox's ui size by default size * textbox_ui_scale + self.textbox_first_insert_spacing = calculateUiSize(self._DEFAULT_TEXTBOX_FIRST_INSERT_SPACING, custom_font_size_scale) + self.textbox_font_size__label = calculateUiSize(self._DEFAULT_TEXTBOX_FONT_SIZE__LABEL, custom_font_size_scale) + self.textbox_font_size__timestamp = calculateUiSize(self._DEFAULT_TEXTBOX_FONT_SIZE__TIMESTAMP, custom_font_size_scale) + self.textbox_font_size__system_text_font = calculateUiSize(self._DEFAULT_TEXTBOX_FONT_SIZE__SYSTEM_TEXT_FONT, custom_font_size_scale) + self.textbox_font_size__secondary_text_font = calculateUiSize(self._DEFAULT_TEXTBOX_FONT_SIZE__SECONDARY_TEXT_FONT, custom_font_size_scale) + self.textbox_font_size__main_text_font = calculateUiSize(self._DEFAULT_TEXTBOX_FONT_SIZE__MAIN_TEXT_FONT, custom_font_size_scale) + + for each_textbox_widget in self.all_textbox_widgets: + self._setTagsSettings(target_textbox=each_textbox_widget) + + + def _setTagsSettings(self, target_textbox): target_textbox.tag_config("JUSTIFY_CENTER", justify="center") target_textbox.tag_config("JUSTIFY_RIGHT", justify="right") target_textbox.tag_config("JUSTIFY_LEFT", justify="left") # common tag settings # target_textbox._textbox.tag_configure("START", spacing1=16) - target_textbox._textbox.tag_configure("LABEL", font=CTkFont(family=settings.FONT_FAMILY, size=settings.uism.TEXTBOX_FONT_SIZE__LABEL, weight="normal")) - target_textbox._textbox.tag_configure("TIMESTAMP", font=CTkFont(family=settings.FONT_FAMILY, size=settings.uism.TEXTBOX_FONT_SIZE__TIMESTAMP, weight="normal"), foreground=settings.ctm.TEXTBOX_TIMESTAMP_TEXT_COLOR) - target_textbox._textbox.tag_configure("SECONDARY_TEXT_FONT", font=CTkFont(family=settings.FONT_FAMILY, size=settings.uism.TEXTBOX_FONT_SIZE__SECONDARY_TEXT_FONT, weight="normal")) - target_textbox._textbox.tag_configure("MAIN_TEXT_FONT", font=CTkFont(family=settings.FONT_FAMILY, size=settings.uism.TEXTBOX_FONT_SIZE__MAIN_TEXT_FONT, weight="normal")) + target_textbox.tag_config("FIRST_INSERT_SPACING", spacing1=self.textbox_first_insert_spacing) + target_textbox._textbox.tag_configure("LABEL", font=CTkFont(family=self.settings.FONT_FAMILY, size=self.textbox_font_size__label, weight="normal")) + target_textbox._textbox.tag_configure("TIMESTAMP", font=CTkFont(family=self.settings.FONT_FAMILY, size=self.textbox_font_size__timestamp, weight="normal"), foreground=self.settings.ctm.TEXTBOX_TIMESTAMP_TEXT_COLOR) + target_textbox._textbox.tag_configure("SECONDARY_TEXT_FONT", font=CTkFont(family=self.settings.FONT_FAMILY, size=self.textbox_font_size__secondary_text_font, weight="normal")) + target_textbox._textbox.tag_configure("MAIN_TEXT_FONT", font=CTkFont(family=self.settings.FONT_FAMILY, size=self.textbox_font_size__main_text_font, weight="normal")) # System Tag Settings - target_textbox.tag_config("FIRST_INSERT_SPACING", spacing1=settings.uism.TEXTBOX_FIRST_INSERT_SPACING) - target_textbox.tag_config("SYSTEM_TAG", foreground=settings.ctm.TEXTBOX_SYSTEM_TAG_TEXT_COLOR) - target_textbox.tag_config("SYSTEM_TEXT", foreground=settings.ctm.TEXTBOX_TEXT_SUB_COLOR) - target_textbox._textbox.tag_configure("SYSTEM_TEXT_FONT", font=CTkFont(family=settings.FONT_FAMILY, size=settings.uism.TEXTBOX_FONT_SIZE__SYSTEM_TEXT_FONT, weight="normal")) + target_textbox.tag_config("SYSTEM_TAG", foreground=self.settings.ctm.TEXTBOX_SYSTEM_TAG_TEXT_COLOR) + target_textbox.tag_config("SYSTEM_TEXT", foreground=self.settings.ctm.TEXTBOX_TEXT_SUB_COLOR) + target_textbox._textbox.tag_configure("SYSTEM_TEXT_FONT", font=CTkFont(family=self.settings.FONT_FAMILY, size=self.textbox_font_size__system_text_font, weight="normal")) # Sent Tag Settings - target_textbox.tag_config("SENT_TAG", foreground=settings.ctm.TEXTBOX_SENT_TAG_TEXT_COLOR) - target_textbox.tag_config("SENT_TEXT", foreground=settings.ctm.TEXTBOX_TEXT_COLOR) - target_textbox.tag_config("SENT_SUB_TEXT", foreground=settings.ctm.TEXTBOX_TEXT_SUB_COLOR) + target_textbox.tag_config("SENT_TAG", foreground=self.settings.ctm.TEXTBOX_SENT_TAG_TEXT_COLOR) + target_textbox.tag_config("SENT_TEXT", foreground=self.settings.ctm.TEXTBOX_TEXT_COLOR) + target_textbox.tag_config("SENT_SUB_TEXT", foreground=self.settings.ctm.TEXTBOX_TEXT_SUB_COLOR) # Received Tag Settings - target_textbox.tag_config("RECEIVED_TAG", foreground=settings.ctm.TEXTBOX_RECEIVED_TAG_TEXT_COLOR) - target_textbox.tag_config("RECEIVED_TEXT", foreground=settings.ctm.TEXTBOX_TEXT_COLOR) - target_textbox.tag_config("RECEIVED_SUB_TEXT", foreground=settings.ctm.TEXTBOX_TEXT_SUB_COLOR) + target_textbox.tag_config("RECEIVED_TAG", foreground=self.settings.ctm.TEXTBOX_RECEIVED_TAG_TEXT_COLOR) + target_textbox.tag_config("RECEIVED_TEXT", foreground=self.settings.ctm.TEXTBOX_TEXT_COLOR) + target_textbox.tag_config("RECEIVED_SUB_TEXT", foreground=self.settings.ctm.TEXTBOX_TEXT_SUB_COLOR) + + + def _printEachTextbox( + self, + target_textbox, + print_type, + original_message, + translated_message, + ): + now_raw_data = datetime.now() + now_hm = now_raw_data.strftime("%H:%M") + + is_only_one_message = True if original_message is None or translated_message is None or translated_message == "" else False FAKE_MARGIN = " " # insert target_textbox.configure(state="normal") target_textbox.insert("end", "\n") - match (target_type): + match (print_type): case "SYSTEM": target_textbox.insert("end", "System", ("SYSTEM_TAG", "FIRST_INSERT_SPACING", "JUSTIFY_CENTER", "LABEL")) target_textbox.insert("end", FAKE_MARGIN+original_message+FAKE_MARGIN, ("SYSTEM_TEXT", "SYSTEM_TEXT_FONT", "JUSTIFY_CENTER")) @@ -92,7 +142,23 @@ def _printToTextbox(vrct_gui, target_textbox.configure(state="disabled") target_textbox.see("end") - printEachTextbox(target_textbox) - # To automatically print the same log to the textbox_all widget as well. - if disable_print_to_textbox_all is not True: printEachTextbox(vrct_gui.textbox_all) \ No newline at end of file + + + + + + def _getTargetTextboxWidget(self, target_type): + match (target_type): + case "ALL": + target_textbox = self.vrct_gui.textbox_all + case "SYSTEM": + target_textbox = self.vrct_gui.textbox_system + case "SENT": + target_textbox = self.vrct_gui.textbox_sent + case "RECEIVED": + target_textbox = self.vrct_gui.textbox_received + case (_): + raise ValueError(f"No matching case for target_type: {target_type}") + + return target_textbox \ No newline at end of file diff --git a/vrct_gui/ui_managers/UiScalingManager.py b/vrct_gui/ui_managers/UiScalingManager.py index dc385b34..8f5a9c09 100644 --- a/vrct_gui/ui_managers/UiScalingManager.py +++ b/vrct_gui/ui_managers/UiScalingManager.py @@ -1,5 +1,7 @@ from types import SimpleNamespace +from ..ui_utils import calculateUiSize + class UiScalingManager(): def __init__(self, scaling_percentage): scaling_float = int(scaling_percentage.replace("%", "")) / 100 @@ -274,11 +276,7 @@ class UiScalingManager(): def _calculateUiSize(self, default_size, is_allowed_odd:bool=False, is_zero_allowed:bool=False): - size = int(default_size * self.SCALING_FLOAT) - size += 1 if not is_allowed_odd and size % 2 != 0 else 0 - if size <= 0: - size = 0 if is_zero_allowed else 1 - + size = calculateUiSize(default_size, self.SCALING_FLOAT, is_allowed_odd, is_zero_allowed) return size @staticmethod diff --git a/vrct_gui/ui_utils/ui_utils.py b/vrct_gui/ui_utils/ui_utils.py index bf64a985..5138fb5c 100644 --- a/vrct_gui/ui_utils/ui_utils.py +++ b/vrct_gui/ui_utils/ui_utils.py @@ -42,6 +42,14 @@ def getLongestText(text_list:list): longest_text = text return longest_text +def calculateUiSize(default_size, scaling_float, is_allowed_odd:bool=False, is_zero_allowed:bool=False): + size = int(default_size * scaling_float) + size += 1 if not is_allowed_odd and size % 2 != 0 else 0 + if size <= 0: + size = 0 if is_zero_allowed else 1 + + return size + def bindEnterAndLeaveColor(target_widgets, enter_color, leave_color): for target_widget in target_widgets: target_widget.bind("", lambda e, widgets=target_widgets: [w.configure(fg_color=enter_color) for w in widgets], "+") diff --git a/vrct_gui/vrct_gui.py b/vrct_gui/vrct_gui.py index 06f5f4f5..b423cb1d 100644 --- a/vrct_gui/vrct_gui.py +++ b/vrct_gui/vrct_gui.py @@ -8,7 +8,7 @@ from ._CreateDropdownMenuWindow import _CreateDropdownMenuWindow from ._changeMainWindowWidgetsStatus import _changeMainWindowWidgetsStatus from ._changeConfigWindowWidgetsStatus import _changeConfigWindowWidgetsStatus from ._CreateConfirmationModal import _CreateConfirmationModal -from ._printToTextbox import _printToTextbox +from ._PrintToTextbox import _PrintToTextbox from .main_window import createMainWindowWidgets from .config_window import ConfigWindow @@ -133,6 +133,12 @@ class VRCT_GUI(CTk): modal_type="information" ) + self.print_to_textbox = _PrintToTextbox( + vrct_gui=self, + settings=self.settings.main, + ) + + def _startMainLoop(self): @@ -229,14 +235,10 @@ class VRCT_GUI(CTk): target_names=target_names, ) - def _printToTextbox(self, target_type, original_message=None, translated_message=None): - _printToTextbox( - vrct_gui=self, - settings=self.settings.main, + def _printToTextbox(self, target_type, **kwargs): + self.print_to_textbox.printToTextbox( target_type=target_type, - original_message=original_message, - translated_message=translated_message, - tags=target_type, + **kwargs ) def _setDefaultActiveLanguagePresetTab(self, tab_no:str): From 8f2934e5101953492e195b9127be3fd7420a5b98 Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Tue, 24 Oct 2023 18:12:39 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[Update]=20=E3=83=86=E3=82=AD=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=83=9C=E3=83=83=E3=82=AF=E3=82=B9=E3=81=AE=E3=83=95?= =?UTF-8?q?=E3=82=A9=E3=83=B3=E3=83=88=E3=82=B5=E3=82=A4=E3=82=BA=E3=82=92?= =?UTF-8?q?=E3=80=81UI=E5=85=A8=E4=BD=93=E3=81=AE=E3=82=B5=E3=82=A4?= =?UTF-8?q?=E3=82=BA=E3=81=A8=E3=81=AF=E5=88=A5=E3=81=A7=E3=83=A6=E3=83=BC?= =?UTF-8?q?=E3=82=B6=E3=83=BC=E3=81=8C=E5=A4=89=E3=81=88=E3=82=89=E3=82=8C?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=80=82=20(UI=20size,=20s?= =?UTF-8?q?caling=E3=82=92=E5=9F=BA=E6=BA=96=E3=81=A8=E3=81=97=E3=81=9F?= =?UTF-8?q?=E5=80=8D=E7=8E=87)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 12 ++++++++++++ controller.py | 6 ++++++ locales/en.yml | 4 ++++ locales/ja.yml | 4 ++++ view.py | 14 +++++++++++++- vrct_gui/_printToTextbox.py | 6 +++++- .../createSettingBox_Appearance.py | 16 ++++++++++++++++ vrct_gui/vrct_gui.py | 1 + 8 files changed, 61 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index 65f8fa15..afd25f43 100644 --- a/config.py +++ b/config.py @@ -225,6 +225,17 @@ class Config: self._UI_SCALING = value saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + @property + @json_serializable('TEXTBOX_UI_SCALING') + def TEXTBOX_UI_SCALING(self): + return self._TEXTBOX_UI_SCALING + + @TEXTBOX_UI_SCALING.setter + def TEXTBOX_UI_SCALING(self, value): + if type(value) is int and 50 <= value <= 200: + self._TEXTBOX_UI_SCALING = value + saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + @property @json_serializable('FONT_FAMILY') def FONT_FAMILY(self): @@ -546,6 +557,7 @@ class Config: self._TRANSPARENCY = 100 self._APPEARANCE_THEME = "System" self._UI_SCALING = "100%" + self._TEXTBOX_UI_SCALING = 100 self._FONT_FAMILY = "Yu Gothic UI" self._UI_LANGUAGE = "en" self._CHOICE_MIC_HOST = getDefaultInputDevice()["host"]["name"] diff --git a/controller.py b/controller.py index d8dfc1fb..f3ee030d 100644 --- a/controller.py +++ b/controller.py @@ -352,6 +352,11 @@ def callbackSetUiScaling(value): print("callbackSetUiScaling_new_scaling_float", new_scaling_float) view.showRestartButtonIfRequired() +def callbackSetTextboxUiScaling(value): + print("callbackSetTextboxUiScaling", int(value)) + config.TEXTBOX_UI_SCALING = int(value) + view.setMainWindowTextboxUiSize(config.TEXTBOX_UI_SCALING/100) + def callbackSetFontFamily(value): print("callbackSetFontFamily", value) config.FONT_FAMILY = value @@ -694,6 +699,7 @@ def createMainWindow(): "callback_set_transparency": callbackSetTransparency, "callback_set_appearance": callbackSetAppearance, "callback_set_ui_scaling": callbackSetUiScaling, + "callback_set_textbox_ui_scaling": callbackSetTextboxUiScaling, "callback_set_font_family": callbackSetFontFamily, "callback_set_ui_language": callbackSetUiLanguage, diff --git a/locales/en.yml b/locales/en.yml index 3e5c4aff..3af662cf 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -95,6 +95,10 @@ config_window: ui_size: label: UI Size + textbox_ui_size: + label: Text Box Font Size + desc: You can adjust the font size used in the logs relative to the UI size. + font_family: label: Font Family diff --git a/locales/ja.yml b/locales/ja.yml index 952dbfc3..e608c2b2 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -95,6 +95,10 @@ config_window: ui_size: label: UIサイズ + textbox_ui_size: + label: テキストボックス フォントサイズ + desc: ログに表示されるフォントのサイズを、UIサイズを基準にして倍率を変えられます。 + font_family: label: 使用フォント diff --git a/view.py b/view.py index 51215f7a..6f70b83c 100644 --- a/view.py +++ b/view.py @@ -211,6 +211,14 @@ class View(): CALLBACK_SET_UI_SCALING=None, VAR_UI_SCALING=StringVar(value=config.UI_SCALING), + VAR_LABEL_TEXTBOX_UI_SCALING=StringVar(value=i18n.t("config_window.textbox_ui_size.label")), + VAR_DESC_TEXTBOX_UI_SCALING=StringVar(value=i18n.t("config_window.textbox_ui_size.desc")), + SLIDER_RANGE_TEXTBOX_UI_SCALING=(50, 200), + CALLBACK_SET_TEXTBOX_UI_SCALING=None, + VAR_TEXTBOX_UI_SCALING=IntVar(value=config.TEXTBOX_UI_SCALING), + CALLBACK_BUTTON_PRESS_TEXTBOX_UI_SCALING=self._closeTheCoverOfMainWindow, + CALLBACK_BUTTON_RELEASE_TEXTBOX_UI_SCALING=self._openTheCoverOfMainWindow, + VAR_LABEL_FONT_FAMILY=StringVar(value=i18n.t("config_window.font_family.label")), VAR_DESC_FONT_FAMILY=None, LIST_FONT_FAMILY=self.getAvailableFonts(), @@ -432,6 +440,7 @@ class View(): self.view_variable.CALLBACK_SET_APPEARANCE = config_window_registers.get("callback_set_appearance", None) self.view_variable.CALLBACK_SET_UI_SCALING = config_window_registers.get("callback_set_ui_scaling", None) + self.view_variable.CALLBACK_SET_TEXTBOX_UI_SCALING = config_window_registers.get("callback_set_textbox_ui_scaling", None) self.view_variable.CALLBACK_SET_FONT_FAMILY = config_window_registers.get("callback_set_font_family", None) self.view_variable.CALLBACK_SET_UI_LANGUAGE = config_window_registers.get("callback_set_ui_language", None) @@ -517,7 +526,7 @@ class View(): # Insert sample conversation for testing. - self._insertSampleConversationToTextbox() + # self._insertSampleConversationToTextbox() @@ -776,6 +785,9 @@ class View(): def setMainWindowTransparency(transparency:float): vrct_gui.wm_attributes("-alpha", transparency) + @staticmethod + def setMainWindowTextboxUiSize(custom_font_size_scale:float): + vrct_gui.print_to_textbox.setTagsSettings(custom_font_size_scale=custom_font_size_scale) # Function def _adjustUiSizeAndRestart(self): diff --git a/vrct_gui/_printToTextbox.py b/vrct_gui/_printToTextbox.py index ddc4b411..6d68cfdc 100644 --- a/vrct_gui/_printToTextbox.py +++ b/vrct_gui/_printToTextbox.py @@ -7,10 +7,12 @@ class _PrintToTextbox(): self, vrct_gui, settings, + init_scaling:float, ): self.vrct_gui = vrct_gui self.settings = settings + self.init_scaling = init_scaling self._DEFAULT_TEXTBOX_FIRST_INSERT_SPACING = self.settings.uism.TEXTBOX_FIRST_INSERT_SPACING self._DEFAULT_TEXTBOX_FONT_SIZE__LABEL = self.settings.uism.TEXTBOX_FONT_SIZE__LABEL @@ -32,7 +34,7 @@ class _PrintToTextbox(): self.all_textbox_widgets = [self.vrct_gui.textbox_all, self.vrct_gui.textbox_system, self.vrct_gui.textbox_sent, self.vrct_gui.textbox_received] - self.setTagsSettings() + self.setTagsSettings(self.init_scaling) def printToTextbox(self, target_type, original_message=None, translated_message=None, to_print_to_textbox_all:bool=True): @@ -63,6 +65,8 @@ class _PrintToTextbox(): for each_textbox_widget in self.all_textbox_widgets: self._setTagsSettings(target_textbox=each_textbox_widget) + each_textbox_widget.see("end") + def _setTagsSettings(self, target_textbox): diff --git a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_appearance/createSettingBox_Appearance.py b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_appearance/createSettingBox_Appearance.py index cc33684c..d0a30746 100644 --- a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_appearance/createSettingBox_Appearance.py +++ b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_appearance/createSettingBox_Appearance.py @@ -18,6 +18,9 @@ def createSettingBox_Appearance(setting_box_wrapper, config_window, settings, vi def optionmenu_ui_scaling_callback(value): callFunctionIfCallable(view_variable.CALLBACK_SET_UI_SCALING, value) + def slider_text_box_ui_scaling_callback(value): + callFunctionIfCallable(view_variable.CALLBACK_SET_TEXTBOX_UI_SCALING, value) + def optionmenu_font_family_callback(value): callFunctionIfCallable(view_variable.CALLBACK_SET_FONT_FAMILY, value) @@ -64,6 +67,19 @@ def createSettingBox_Appearance(setting_box_wrapper, config_window, settings, vi config_window.sb__ui_scaling.grid(row=row) row+=1 + config_window.sb__textbox_uis_scaling = createSettingBoxSlider( + for_var_label_text=view_variable.VAR_LABEL_TEXTBOX_UI_SCALING, + for_var_desc_text=view_variable.VAR_DESC_TEXTBOX_UI_SCALING, + slider_attr_name="sb__slider_transparency", + slider_range=view_variable.SLIDER_RANGE_TEXTBOX_UI_SCALING, + command=lambda value: slider_text_box_ui_scaling_callback(value), + variable=view_variable.VAR_TEXTBOX_UI_SCALING, + slider_bind__ButtonPress=view_variable.CALLBACK_BUTTON_PRESS_TEXTBOX_UI_SCALING, + slider_bind__ButtonRelease=view_variable.CALLBACK_BUTTON_RELEASE_TEXTBOX_UI_SCALING, + ) + config_window.sb__textbox_uis_scaling.grid(row=row) + row+=1 + config_window.sb__font_family = createSettingBoxDropdownMenu( for_var_label_text=view_variable.VAR_LABEL_FONT_FAMILY, diff --git a/vrct_gui/vrct_gui.py b/vrct_gui/vrct_gui.py index b423cb1d..da9939dd 100644 --- a/vrct_gui/vrct_gui.py +++ b/vrct_gui/vrct_gui.py @@ -136,6 +136,7 @@ class VRCT_GUI(CTk): self.print_to_textbox = _PrintToTextbox( vrct_gui=self, settings=self.settings.main, + init_scaling=(self._view_variable.VAR_TEXTBOX_UI_SCALING.get()/100) ) From c6d52f05c53029186d5c133bef81583e62b9bd84 Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Tue, 24 Oct 2023 19:39:32 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[Update]=20Config=20Window:=20Slider?= =?UTF-8?q?=E7=B3=BB=E3=81=ABtooltip=E8=BF=BD=E5=8A=A0=E3=80=82Thanks=20of?= =?UTF-8?q?=20Akascape.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 3 ++- .../setting_box_containers/_SettingBoxGenerator.py | 11 +++++++++++ vrct_gui/ui_managers/ColorThemeManager.py | 2 ++ vrct_gui/ui_managers/UiScalingManager.py | 1 + 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a399733d..42f4be2c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ customtkinter == 5.2.0 deepl == 1.15.0 flashtext == 2.7 pyyaml == 6.0.1 -python-i18n == 0.3.9 \ No newline at end of file +python-i18n == 0.3.9 +CTkToolTip == 0.8 \ No newline at end of file diff --git a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/_SettingBoxGenerator.py b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/_SettingBoxGenerator.py index f11c56b5..100b761a 100644 --- a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/_SettingBoxGenerator.py +++ b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/_SettingBoxGenerator.py @@ -3,6 +3,7 @@ from types import SimpleNamespace from typing import Union from customtkinter import CTkOptionMenu, CTkFont, CTkFrame, CTkLabel, CTkRadioButton, CTkEntry, CTkSlider, CTkSwitch, CTkCheckBox, CTkProgressBar +from CTkToolTip import * from vrct_gui.ui_utils import createButtonWithImage, getLatestWidth, createOptionMenuBox from vrct_gui import vrct_gui @@ -260,11 +261,21 @@ class _SettingBoxGenerator(): ) setattr(self.config_window, slider_attr_name, slider_widget) + slider_tooltip = CTkToolTip( + slider_widget, + message=variable.get(), + delay=0, + bg_color=self.settings.ctm.SB__SLIDER_TOOLTIP_BG_COLOR, + text_color=self.settings.ctm.SB__SLIDER_TOOLTIP_TEXT_COLOR, + font=CTkFont(family=self.settings.FONT_FAMILY, size=self.settings.uism.SB__SLIDER_TOOLTIP_FONT_SIZE, weight="normal"), + ) + slider_widget.grid(row=1, column=SETTING_BOX_COLUMN, sticky="e") if slider_bind__ButtonPress is not None: def adjusted_slider_bind__ButtonPress(_e): command(_e) + slider_tooltip.configure(message=slider_widget.get()) slider_bind__ButtonPress() slider_widget.configure(command=adjusted_slider_bind__ButtonPress) diff --git a/vrct_gui/ui_managers/ColorThemeManager.py b/vrct_gui/ui_managers/ColorThemeManager.py index ab55e996..19f9f884 100644 --- a/vrct_gui/ui_managers/ColorThemeManager.py +++ b/vrct_gui/ui_managers/ColorThemeManager.py @@ -282,6 +282,8 @@ class ColorThemeManager(): self.config_window.SB__SLIDER_PROGRESS_BG_COLOR = self.DARK_500_COLOR self.config_window.SB__SLIDER_BUTTON_COLOR = self.DARK_700_COLOR self.config_window.SB__SLIDER_BUTTON_HOVERED_COLOR = self.DARK_600_COLOR + self.config_window.SB__SLIDER_TOOLTIP_BG_COLOR = self.DARK_850_COLOR + self.config_window.SB__SLIDER_TOOLTIP_TEXT_COLOR = self.DARK_200_COLOR self.config_window.SB__SWITCH_BOX_BG_COLOR = self.DARK_800_COLOR self.config_window.SB__SWITCH_BOX_ACTIVE_BG_COLOR = self.PRIMARY_500_COLOR diff --git a/vrct_gui/ui_managers/UiScalingManager.py b/vrct_gui/ui_managers/UiScalingManager.py index 8f5a9c09..fae26c79 100644 --- a/vrct_gui/ui_managers/UiScalingManager.py +++ b/vrct_gui/ui_managers/UiScalingManager.py @@ -262,6 +262,7 @@ class UiScalingManager(): self.config_window.SB__SLIDER_WIDTH = self._calculateUiSize(200) self.config_window.SB__SLIDER_HEIGHT = self._calculateUiSize(16) + self.config_window.SB__SLIDER_TOOLTIP_FONT_SIZE = self._calculateUiSize(16) self.config_window.SB__PROGRESSBAR_X_SLIDER__ENTRY_WIDTH = self.config_window.RESPONSIVE_UI_SIZE_INT_50 self.config_window.SB__PROGRESSBAR_X_SLIDER__ENTRY_HEIGHT = self.config_window.SB__ENTRY_HEIGHT From b7af5699961407d756b90a9fdfb524f53627c189 Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Tue, 24 Oct 2023 20:29:22 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[Update]=20Config=20Window:=20slider=20tool?= =?UTF-8?q?tips.=20=E3=82=B9=E3=83=86=E3=83=83=E3=83=97=E3=82=921=E3=81=9A?= =?UTF-8?q?=E3=81=A4=E3=81=AB=E3=81=97=E3=81=A6=E3=80=81=E3=81=95=E3=82=89?= =?UTF-8?q?=E3=81=AB=E3=83=91=E3=83=BC=E3=82=BB=E3=83=B3=E3=83=86=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E8=A1=A8=E8=A8=98=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils.py | 5 ++++- view.py | 4 +++- .../setting_box_containers/_SettingBoxGenerator.py | 14 +++++++++++--- .../createSettingBox_Appearance.py | 2 ++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/utils.py b/utils.py index 6efe6d0a..242faf15 100644 --- a/utils.py +++ b/utils.py @@ -26,4 +26,7 @@ def generatePercentageStringsList(start=40, end=200, step=10): strings = [] for percent in range(start, end + 1, step): strings.append(f"{percent}%") - return strings \ No newline at end of file + return strings + +def intToPercentageStringsFormatter(value:int): + return f"{value}%" \ No newline at end of file diff --git a/view.py b/view.py index 6f70b83c..2a309a06 100644 --- a/view.py +++ b/view.py @@ -10,7 +10,7 @@ from languages import selectable_languages from customtkinter import StringVar, IntVar, BooleanVar, END as CTK_END, get_appearance_mode from vrct_gui.ui_managers import ColorThemeManager, ImageFileManager, UiScalingManager from vrct_gui import vrct_gui -from utils import callFunctionIfCallable, generatePercentageStringsList +from utils import callFunctionIfCallable, generatePercentageStringsList, intToPercentageStringsFormatter from config import config @@ -176,6 +176,8 @@ class View(): VAR_CONFIG_WINDOW_COMPACT_MODE_LABEL=StringVar(value=i18n.t("config_window.compact_mode")), VAR_CONFIG_WINDOW_RESTART_BUTTON_LABEL=StringVar(value=i18n.t("config_window.restart_message")), + CALLBACK_SLIDER_TOOLTIP_PERCENTAGE_FORMATTER=intToPercentageStringsFormatter, + # Side Menu Labels VAR_SIDE_MENU_LABEL_APPEARANCE=StringVar(value=i18n.t("config_window.side_menu_labels.appearance")), diff --git a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/_SettingBoxGenerator.py b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/_SettingBoxGenerator.py index 100b761a..3c152958 100644 --- a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/_SettingBoxGenerator.py +++ b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/_SettingBoxGenerator.py @@ -239,11 +239,14 @@ class _SettingBoxGenerator(): slider_number_of_steps: Union[int, None] = None, slider_bind__ButtonPress=None, - slider_bind__ButtonRelease=None + slider_bind__ButtonRelease=None, + sliderTooltipFormatter=None, ): (setting_box_frame, setting_box_item_frame) = self._createSettingBoxFrame(slider_attr_name, for_var_label_text, for_var_desc_text) + if slider_number_of_steps is None: + slider_number_of_steps = int(slider_range[1] - slider_range[0]) slider_widget = CTkSlider( setting_box_item_frame, @@ -261,9 +264,14 @@ class _SettingBoxGenerator(): ) setattr(self.config_window, slider_attr_name, slider_widget) + def getSliderValueWAfterFormatting(): + return sliderTooltipFormatter(variable.get()) if sliderTooltipFormatter else variable.get() + + + slider_tooltip = CTkToolTip( slider_widget, - message=variable.get(), + message=getSliderValueWAfterFormatting(), delay=0, bg_color=self.settings.ctm.SB__SLIDER_TOOLTIP_BG_COLOR, text_color=self.settings.ctm.SB__SLIDER_TOOLTIP_TEXT_COLOR, @@ -275,7 +283,7 @@ class _SettingBoxGenerator(): if slider_bind__ButtonPress is not None: def adjusted_slider_bind__ButtonPress(_e): command(_e) - slider_tooltip.configure(message=slider_widget.get()) + slider_tooltip.configure(message=getSliderValueWAfterFormatting()) slider_bind__ButtonPress() slider_widget.configure(command=adjusted_slider_bind__ButtonPress) diff --git a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_appearance/createSettingBox_Appearance.py b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_appearance/createSettingBox_Appearance.py index d0a30746..dd5f68ab 100644 --- a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_appearance/createSettingBox_Appearance.py +++ b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_appearance/createSettingBox_Appearance.py @@ -38,6 +38,7 @@ def createSettingBox_Appearance(setting_box_wrapper, config_window, settings, vi variable=view_variable.VAR_TRANSPARENCY, slider_bind__ButtonPress=view_variable.CALLBACK_BUTTON_PRESS_TRANSPARENCY, slider_bind__ButtonRelease=view_variable.CALLBACK_BUTTON_RELEASE_TRANSPARENCY, + sliderTooltipFormatter=view_variable.CALLBACK_SLIDER_TOOLTIP_PERCENTAGE_FORMATTER, ) config_window.sb__transparency.grid(row=row) row+=1 @@ -76,6 +77,7 @@ def createSettingBox_Appearance(setting_box_wrapper, config_window, settings, vi variable=view_variable.VAR_TEXTBOX_UI_SCALING, slider_bind__ButtonPress=view_variable.CALLBACK_BUTTON_PRESS_TEXTBOX_UI_SCALING, slider_bind__ButtonRelease=view_variable.CALLBACK_BUTTON_RELEASE_TEXTBOX_UI_SCALING, + sliderTooltipFormatter=view_variable.CALLBACK_SLIDER_TOOLTIP_PERCENTAGE_FORMATTER, ) config_window.sb__textbox_uis_scaling.grid(row=row) row+=1