[Update] Main Window: Message Box. メッセージ入力欄のサイズを変更できるように。厳密な計算はしてません。

【見た目への影響大】デフォルトのチャット入力欄を少し大きくしました。(もちろん変更できる)
テキストボックスとの比率としているので、Windowサイズを変更すると、それに合わせて可変します。
CTkEntryからCTkTextboxに変更しました。プレースホルダーの使用が厳しくなったので廃止しました。最小にしても、入力中の位置が中央にならないなど、デザインが若干崩れましたが許容しました。
This commit is contained in:
Sakamoto Shiina
2023-12-29 01:24:54 +09:00
parent 5e16d319e3
commit 7c23adfc24
10 changed files with 85 additions and 15 deletions

View File

@@ -244,6 +244,17 @@ class Config:
self._TEXTBOX_UI_SCALING = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
@json_serializable('MESSAGE_BOX_RATIO')
def MESSAGE_BOX_RATIO(self):
return self._MESSAGE_BOX_RATIO
@MESSAGE_BOX_RATIO.setter
def MESSAGE_BOX_RATIO(self, value):
if isinstance(value, int) and 1 <= value <= 99:
self._MESSAGE_BOX_RATIO = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
@json_serializable('FONT_FAMILY')
def FONT_FAMILY(self):
@@ -626,6 +637,7 @@ class Config:
self._APPEARANCE_THEME = "System"
self._UI_SCALING = "100%"
self._TEXTBOX_UI_SCALING = 100
self._MESSAGE_BOX_RATIO = 10
self._FONT_FAMILY = "Yu Gothic UI"
self._UI_LANGUAGE = "en"
self._CHOICE_MIC_HOST = getDefaultInputDevice()["host"]["name"]

View File

@@ -214,7 +214,7 @@ def sendChatMessage(message):
if config.ENABLE_AUTO_CLEAR_MESSAGE_BOX is True:
view.clearMessageBox()
def messageBoxPressKeyEnter(e):
def messageBoxPressKeyEnter():
model.oscStopSendTyping()
message = view.getTextFromMessageBox()
sendChatMessage(message)
@@ -403,6 +403,11 @@ def callbackSetTextboxUiScaling(value):
config.TEXTBOX_UI_SCALING = int(value)
view.setMainWindowTextboxUiSize(config.TEXTBOX_UI_SCALING/100)
def callbackSetMessageBoxRatio(value):
print("callbackSetMessageBoxRatio", int(value))
config.MESSAGE_BOX_RATIO = int(value)
view.setMainWindowMessageBoxRatio(config.MESSAGE_BOX_RATIO)
def callbackSetFontFamily(value):
print("callbackSetFontFamily", value)
config.FONT_FAMILY = value
@@ -836,6 +841,7 @@ def createMainWindow():
"callback_set_appearance": callbackSetAppearance,
"callback_set_ui_scaling": callbackSetUiScaling,
"callback_set_textbox_ui_scaling": callbackSetTextboxUiScaling,
"callback_set_message_box_ratio": callbackSetMessageBoxRatio,
"callback_set_font_family": callbackSetFontFamily,
"callback_set_ui_language": callbackSetUiLanguage,

View File

@@ -103,6 +103,10 @@ config_window:
label: Text Box Font Size
desc: You can adjust the font size used in the logs relative to the UI size.
message_box_ratio:
label: Message Box Size
desc: "You can change the size of the input message box. It is in ratio to the text box.\n*No exact calculations."
font_family:
label: Font Family

View File

@@ -100,6 +100,10 @@ config_window:
label: テキストボックス フォントサイズ
desc: ログに表示されるフォントのサイズを、UIサイズを基準にして倍率を変えられます。
message_box_ratio:
label: メッセージ入力欄のサイズ
desc: "メッセージ入力欄のサイズを変更できます。テキストボックスとの比率となっています。\n※厳密な計算はしていません。"
font_family:
label: 使用フォント

33
view.py
View File

@@ -220,6 +220,14 @@ class View():
CALLBACK_BUTTON_PRESS_TEXTBOX_UI_SCALING=self._closeTheCoverOfMainWindow,
CALLBACK_BUTTON_RELEASE_TEXTBOX_UI_SCALING=self._openTheCoverOfMainWindow,
VAR_LABEL_MESSAGE_BOX_RATIO=StringVar(value=i18n.t("config_window.message_box_ratio.label")),
VAR_DESC_MESSAGE_BOX_RATIO=StringVar(value=i18n.t("config_window.message_box_ratio.desc")),
SLIDER_RANGE_MESSAGE_BOX_RATIO=(1, 99),
CALLBACK_SET_MESSAGE_BOX_RATIO=None,
VAR_MESSAGE_BOX_RATIO=IntVar(value=config.MESSAGE_BOX_RATIO),
CALLBACK_BUTTON_PRESS_MESSAGE_BOX_RATIO=self._closeTheCoverOfMainWindow,
CALLBACK_BUTTON_RELEASE_MESSAGE_BOX_RATIO=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(),
@@ -480,8 +488,12 @@ class View():
self.view_variable.CALLBACK_SELECTED_LANGUAGE_PRESET_TAB = main_window_registers.get("callback_selected_language_preset_tab", None)
def adjustedMessageBoxReturnFunction(_e):
main_window_registers.get("message_box_bind_Return")()
return "break"
entry_message_box = getattr(vrct_gui, "entry_message_box")
entry_message_box.bind("<Return>", main_window_registers.get("message_box_bind_Return"))
entry_message_box.bind("<Return>", adjustedMessageBoxReturnFunction)
entry_message_box.bind("<Any-KeyPress>", main_window_registers.get("message_box_bind_Any_KeyPress"))
@@ -512,6 +524,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_MESSAGE_BOX_RATIO = config_window_registers.get("callback_set_message_box_ratio", 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)
@@ -571,6 +584,7 @@ class View():
self.enableConfigWindowCompactMode()
vrct_gui.config_window.setting_box_compact_mode_switch_box.select()
self.setMainWindowMessageBoxRatio(config.MESSAGE_BOX_RATIO)
if config.CHOICE_MIC_HOST == "NoHost":
self.view_variable.VAR_MIC_HOST.set("No Mic Host Detected")
@@ -774,7 +788,7 @@ class View():
# Common
@staticmethod
def _clearEntryBox(entry_widget):
entry_widget.delete(0, CTK_END)
entry_widget.delete("1.0", "end-1c")
def clearErrorMessage(self):
vrct_gui._clearErrorMessage()
@@ -1063,6 +1077,19 @@ class View():
def setMainWindowTextboxUiSize(custom_font_size_scale:float):
vrct_gui.print_to_textbox.setTagsSettings(custom_font_size_scale=custom_font_size_scale)
@staticmethod
def setMainWindowMessageBoxRatio(message_box_ratio:int):
if message_box_ratio <= 0 or message_box_ratio > 99:
raise ValueError("Input must be between 1 and 99 (inclusive)")
vrct_gui.main_bg_container.grid_rowconfigure(tuple(range(1, 101)), weight=1)
textbox_ratio = int(100 - message_box_ratio)
message_box_row = int(textbox_ratio + 1)
message_box_rowwpan = int(100 - textbox_ratio)
# print(textbox_ratio, message_box_row, message_box_rowwpan)
vrct_gui.main_textbox_container.grid(row=1, rowspan=textbox_ratio, column=0, sticky="nsew")
vrct_gui.main_entry_message_container.grid(row=message_box_row, rowspan=message_box_rowwpan, column=0, sticky="nsew")
# Function
def _adjustUiSizeAndRestart(self):
current_percentage = int(config.UI_SCALING.replace("%",""))
@@ -1394,7 +1421,7 @@ class View():
# Message Box
@staticmethod
def getTextFromMessageBox():
return vrct_gui.entry_message_box.get()
return vrct_gui.entry_message_box.get('1.0', CTK_END)
def clearMessageBox(self):
self._clearEntryBox(vrct_gui.entry_message_box)

View File

@@ -141,9 +141,11 @@ def _changeMainWindowWidgetsStatus(vrct_gui, settings, view_variable, status, ta
case "entry_message_box":
if status == "disabled":
vrct_gui.entry_message_box.configure(state="disabled", placeholder_text_color=settings.ctm.TEXTBOX_ENTRY_PLACEHOLDER_DISABLED_COLOR, text_color=settings.ctm.TEXTBOX_ENTRY_TEXT_DISABLED_COLOR)
pass
vrct_gui.entry_message_box.configure(state="disabled", text_color=settings.ctm.TEXTBOX_ENTRY_TEXT_DISABLED_COLOR)
elif status == "normal":
vrct_gui.entry_message_box.configure(state="normal", placeholder_text_color=settings.ctm.TEXTBOX_ENTRY_PLACEHOLDER_COLOR, text_color=settings.ctm.TEXTBOX_ENTRY_TEXT_COLOR)
pass
vrct_gui.entry_message_box.configure(state="normal", text_color=settings.ctm.TEXTBOX_ENTRY_TEXT_COLOR)
case _:

View File

@@ -21,6 +21,9 @@ def createSettingBox_Appearance(setting_box_wrapper, config_window, settings, vi
def slider_text_box_ui_scaling_callback(value):
callFunctionIfCallable(view_variable.CALLBACK_SET_TEXTBOX_UI_SCALING, value)
def slider_message_box_ratio_callback(value):
callFunctionIfCallable(view_variable.CALLBACK_SET_MESSAGE_BOX_RATIO, value)
def optionmenu_font_family_callback(value):
callFunctionIfCallable(view_variable.CALLBACK_SET_FONT_FAMILY, value)
@@ -82,6 +85,19 @@ def createSettingBox_Appearance(setting_box_wrapper, config_window, settings, vi
config_window.sb__textbox_uis_scaling.grid(row=row)
row+=1
config_window.sb__message_box_ratio = createSettingBoxSlider(
for_var_label_text=view_variable.VAR_LABEL_MESSAGE_BOX_RATIO,
for_var_desc_text=view_variable.VAR_DESC_MESSAGE_BOX_RATIO,
slider_attr_name="sb__slider_message_box_ratio",
slider_range=view_variable.SLIDER_RANGE_MESSAGE_BOX_RATIO,
command=lambda value: slider_message_box_ratio_callback(value),
variable=view_variable.VAR_MESSAGE_BOX_RATIO,
slider_bind__ButtonPress=view_variable.CALLBACK_BUTTON_PRESS_MESSAGE_BOX_RATIO,
slider_bind__ButtonRelease=view_variable.CALLBACK_BUTTON_RELEASE_MESSAGE_BOX_RATIO,
sliderTooltipFormatter=view_variable.CALLBACK_SLIDER_TOOLTIP_PERCENTAGE_FORMATTER,
)
config_window.sb__message_box_ratio.grid(row=row)
row+=1
config_window.sb__font_family = createSettingBoxDropdownMenu(
for_var_label_text=view_variable.VAR_LABEL_FONT_FAMILY,

View File

@@ -1,23 +1,22 @@
from customtkinter import CTkFont, CTkFrame, CTkEntry
from customtkinter import CTkFont, CTkFrame, CTkTextbox
def createEntryMessageBox(settings, main_window):
main_window.main_entry_message_container = CTkFrame(main_window.main_bg_container, corner_radius=0, fg_color=settings.ctm.MAIN_BG_COLOR, width=0, height=0)
main_window.main_entry_message_container.grid(row=2, column=0, sticky="ew")
main_window.main_entry_message_container.grid(row=2, column=0, sticky="nsew")
main_window.main_entry_message_container.grid_columnconfigure(0, weight=1)
main_window.entry_message_box = CTkEntry(
main_window.main_entry_message_container.grid_rowconfigure(0, weight=1)
main_window.entry_message_box = CTkTextbox(
main_window.main_entry_message_container,
border_color=settings.ctm.TEXTBOX_ENTRY_BORDER_COLOR,
fg_color=settings.ctm.TEXTBOX_ENTRY_BG_COLOR,
text_color=settings.ctm.TEXTBOX_ENTRY_TEXT_COLOR,
placeholder_text="Enter your message...",
placeholder_text_color=settings.ctm.TEXTBOX_ENTRY_PLACEHOLDER_COLOR,
height=settings.uism.TEXTBOX_ENTRY_HEIGHT,
border_width=settings.uism.TEXTBOX_ENTRY_BORDER_SIZE,
height=0,
font=CTkFont(family=settings.FONT_FAMILY, size=settings.uism.TEXTBOX_ENTRY_FONT_SIZE, weight="normal"),
)
main_window.entry_message_box.grid(row=0, column=0, padx=settings.uism.TEXTBOX_ENTRY_PADX, pady=settings.uism.TEXTBOX_ENTRY_PADY, sticky="nsew")
main_window.entry_message_box._entry.grid(padx=settings.uism.TEXTBOX_ENTRY_IPADX, pady=settings.uism.TEXTBOX_ENTRY_IPADY)
def messageBoxAnyKeyPress(e):

View File

@@ -142,6 +142,7 @@ def createTextbox(settings, main_window, view_variable):
fg_color=settings.ctm.TEXTBOX_BG_COLOR,
text_color="lime", # Textbox's text_color is set when printing. so this is for prevent from non-setting text_color like the gloves used in food factories are blue.
wrap="word",
height=0,
))
textbox_widget = getattr(main_window, textbox_setting["textbox_attr_name"])
textbox_widget.grid(row=0, column=0, padx=settings.uism.TEXTBOX_PADX, pady=0, sticky="nsew")

View File

@@ -50,11 +50,10 @@ class UiScalingManager():
self.main.TEXTBOX_FONT_SIZE__MAIN_TEXT_FONT = self._calculateUiSize(16)
self.main.TEXTBOX_ENTRY_FONT_SIZE = self._calculateUiSize(16)
self.main.TEXTBOX_ENTRY_BORDER_SIZE = self._calculateUiSize(2, is_allowed_odd=True)
self.main.TEXTBOX_ENTRY_HEIGHT = self._calculateUiSize(40)
self.main.TEXTBOX_ENTRY_PADX = self.main.TEXTBOX_PADX
self.main.TEXTBOX_ENTRY_PADY = self._calculateUiSize(10)
self.main.TEXTBOX_ENTRY_IPADX = self._calculateUiSize(14)
self.main.TEXTBOX_ENTRY_IPADY = (self._calculateUiSize(2, True), self._calculateUiSize(3, True))
# Sidebar