Merge branch 'ui_update_swap_languages' into develop

This commit is contained in:
Sakamoto Shiina
2023-11-06 06:24:25 +09:00
7 changed files with 82 additions and 11 deletions

View File

@@ -230,6 +230,15 @@ def setTargetLanguageAndCountry(select):
config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE)
view.printToTextbox_selectedTargetLanguages(select)
def swapYourLanguageAndTargetLanguage():
your_language = config.SELECTED_TAB_YOUR_LANGUAGES[config.SELECTED_TAB_NO]
target_language = config.SELECTED_TAB_TARGET_LANGUAGES[config.SELECTED_TAB_NO]
setYourLanguageAndCountry(target_language)
setTargetLanguageAndCountry(your_language)
# Update Selected Languages for UI
view.updateGuiVariableByPresetTabNo(config.SELECTED_TAB_NO)
def callbackSelectedLanguagePresetTab(selected_tab_no):
config.SELECTED_TAB_NO = selected_tab_no
view.updateGuiVariableByPresetTabNo(config.SELECTED_TAB_NO)
@@ -710,6 +719,7 @@ def createMainWindow():
"callback_your_language": setYourLanguageAndCountry,
"callback_target_language": setTargetLanguageAndCountry,
"values": model.getListLanguageAndCountry(),
"callback_swap_languages": swapYourLanguageAndTargetLanguage,
"callback_selected_language_preset_tab": callbackSelectedLanguagePresetTab,
"message_box_bind_Return": messageBoxPressKeyEnter,

View File

@@ -7,6 +7,7 @@ main_window:
language_settings: Language Settings
your_language: Your Language
both_direction_desc: Translate Each Other
swap_button_label: Swap Languages
target_language: Target Language
textbox_tab_all: All

View File

@@ -7,6 +7,7 @@ main_window:
language_settings: 言語設定
your_language: あなたの言語
both_direction_desc: 双方向に翻訳
swap_button_label: 言語を入れ替え
target_language: 相手の言語
textbox_tab_all: 全て

View File

@@ -140,6 +140,8 @@ class View():
CALLBACK_SELECTED_YOUR_LANGUAGE=None,
VAR_LABEL_BOTH_DIRECTION_DESC=StringVar(value=i18n.t("main_window.both_direction_desc")),
VAR_LABEL_BOTH_DIRECTION_SWAP_BUTTON=StringVar(value=i18n.t("main_window.swap_button_label")),
CALLBACK_SWAP_LANGUAGES=None,
VAR_LABEL_TARGET_LANGUAGE=StringVar(value=i18n.t("main_window.target_language")),
VAR_TARGET_LANGUAGE = StringVar(value="English\n(United States)"),
@@ -418,6 +420,7 @@ class View():
self.view_variable.CALLBACK_SELECTED_YOUR_LANGUAGE = main_window_registers.get("callback_your_language", None)
self.view_variable.CALLBACK_SELECTED_TARGET_LANGUAGE = main_window_registers.get("callback_target_language", None)
main_window_registers.get("values", None) and self.updateList_selectableLanguages(main_window_registers["values"])
self.view_variable.CALLBACK_SWAP_LANGUAGES = main_window_registers.get("callback_swap_languages", None)
self.view_variable.CALLBACK_SELECTED_LANGUAGE_PRESET_TAB = main_window_registers.get("callback_selected_language_preset_tab", None)

View File

@@ -1,6 +1,6 @@
from customtkinter import CTkFont, CTkFrame, CTkLabel, CTkImage
from ....ui_utils import bindEnterAndLeaveColor, bindButtonPressColor, bindButtonReleaseFunction, switchActiveTabAndPassiveTab, switchTabsColor, createOptionMenuBox
from ....ui_utils import bindEnterAndLeaveColor, bindButtonPressColor, bindButtonReleaseFunction, switchActiveTabAndPassiveTab, switchTabsColor, createOptionMenuBox, bindButtonFunctionAndColor, bindEnterAndLeaveFunction
from utils import callFunctionIfCallable
@@ -226,36 +226,85 @@ def createSidebarLanguagesSettings(settings, main_window, view_variable):
# Both direction arrow icon
main_window.sls__arrow_direction_box = CTkFrame(main_window.sls__box_frame, corner_radius=0, fg_color=settings.ctm.SLS__BG_COLOR, width=0, height=0)
main_window.sls__arrow_direction_box.grid(row=3, column=0, pady=settings.uism.SLS__BOX_ARROWS_PADY,sticky="ew")
main_window.sls__arrow_direction_box.grid(row=3, column=0, pady=settings.uism.SLS__BOX_ARROWS_PADY, sticky="ew")
main_window.sls__arrow_direction_box.grid_columnconfigure((0,4), weight=1)
main_window.sls__arrow_direction_box.grid_columnconfigure((0,2), weight=0, minsize=settings.uism.SLS__BOX_ARROWS_SWAP_BUTTON_PADX)
main_window.sls__arrow_direction_box.grid_columnconfigure(1, weight=1)
main_window.sls__arrow_direction_swap_box = CTkFrame(main_window.sls__arrow_direction_box, corner_radius=settings.uism.SLS__BOX_ARROWS_SWAP_BUTTON_CORNER_RADIUS, fg_color=settings.ctm.SLS__BG_COLOR, width=0, height=0, cursor="hand2")
main_window.sls__arrow_direction_swap_box.grid(row=0, column=1, ipady=settings.uism.SLS__BOX_ARROWS_SWAP_BUTTON_IPADY, sticky="ew")
main_window.sls__arrow_direction_swap_box.grid_rowconfigure((0,2), weight=1)
main_window.sls__arrow_direction_swap_box.grid_columnconfigure(1, weight=1)
main_window.sls__both_direction_up = CTkLabel(
main_window.sls__arrow_direction_box,
main_window.sls__arrow_direction_swap_box,
text=None,
height=0,
image=CTkImage((settings.image_file.NARROW_ARROW_DOWN).rotate(180),size=settings.uism.SLS__BOX_ARROWS_IMAGE_SIZE)
)
main_window.sls__both_direction_up.grid(row=0, column=1, pady=0)
main_window.sls__both_direction_up.grid(row=1, column=0, padx=(settings.uism.SLS__BOX_ARROWS_SWAP_BUTTON_IPADX, 0), pady=0)
main_window.sls__both_direction_desc = CTkLabel(
main_window.sls__arrow_direction_box,
main_window.sls__arrow_direction_swap_box,
textvariable=view_variable.VAR_LABEL_BOTH_DIRECTION_DESC,
height=0,
font=CTkFont(family=settings.FONT_FAMILY, size=settings.uism.SLS__BOX_ARROWS_DESC_FONT_SIZE, weight="normal"),
text_color=settings.ctm.SLS__BOX_ARROWS_TEXT_COLOR,
)
main_window.sls__both_direction_desc.grid(row=0, column=2, padx=settings.uism.SLS__BOX_ARROWS_DESC_PADX)
main_window.sls__both_direction_desc.grid(row=1, column=1, padx=settings.uism.SLS__BOX_ARROWS_DESC_PADX)
main_window.sls__both_direction_label_down = CTkLabel(
main_window.sls__arrow_direction_box,
main_window.sls__both_direction_down = CTkLabel(
main_window.sls__arrow_direction_swap_box,
text=None,
height=0,
image=CTkImage((settings.image_file.NARROW_ARROW_DOWN).rotate(0),size=settings.uism.SLS__BOX_ARROWS_IMAGE_SIZE)
)
main_window.sls__both_direction_label_down.grid(row=0, column=3)
main_window.sls__both_direction_down.grid(row=1, column=2, padx=(0, settings.uism.SLS__BOX_ARROWS_SWAP_BUTTON_IPADX))
def adjustedCommand_ButtonReleased():
callFunctionIfCallable(view_variable.CALLBACK_SWAP_LANGUAGES)
bindButtonFunctionAndColor(
target_widgets=[
main_window.sls__arrow_direction_swap_box,
main_window.sls__both_direction_up,
main_window.sls__both_direction_desc,
main_window.sls__both_direction_down
],
enter_color=settings.ctm.SLS__BOX_ARROWS_SWAP_BUTTON_HOVERED_COLOR,
leave_color=settings.ctm.SLS__BG_COLOR,
clicked_color=settings.ctm.SLS__BOX_ARROWS_SWAP_BUTTON_CLICKED_COLOR,
buttonReleasedFunction=lambda _e: adjustedCommand_ButtonReleased(),
)
def adjustedCommand_Entered():
main_window.sls__both_direction_desc.configure(
textvariable=view_variable.VAR_LABEL_BOTH_DIRECTION_SWAP_BUTTON,
text_color=settings.ctm.SLS__BOX_ARROWS_SWAP_BUTTON_TEXT_COLOR,
)
def adjustedCommand_Leaved():
main_window.sls__both_direction_desc.configure(
textvariable=view_variable.VAR_LABEL_BOTH_DIRECTION_DESC,
text_color=settings.ctm.SLS__BOX_ARROWS_TEXT_COLOR,
)
bindEnterAndLeaveFunction(
target_widgets=[
main_window.sls__arrow_direction_swap_box,
main_window.sls__both_direction_up,
main_window.sls__both_direction_desc,
main_window.sls__both_direction_down
],
enterFunction=lambda _e: adjustedCommand_Entered(),
leaveFunction=lambda _e: adjustedCommand_Leaved(),
)

View File

@@ -78,6 +78,9 @@ def _darkTheme(base_color):
SLS__BOX_BG_COLOR = base_color.DARK_825_COLOR,
SLS__BOX_SECTION_TITLE_TEXT_COLOR = base_color.DARK_400_COLOR,
SLS__BOX_ARROWS_TEXT_COLOR = base_color.DARK_500_COLOR,
SLS__BOX_ARROWS_SWAP_BUTTON_TEXT_COLOR = base_color.DARK_BASIC_TEXT_COLOR,
SLS__BOX_ARROWS_SWAP_BUTTON_HOVERED_COLOR = base_color.DARK_750_COLOR,
SLS__BOX_ARROWS_SWAP_BUTTON_CLICKED_COLOR = base_color.DARK_850_COLOR,
SLS__OPTIONMENU_BG_COLOR = base_color.DARK_888_COLOR,
SLS__OPTIONMENU_HOVERED_BG_COLOR = base_color.DARK_875_COLOR,

View File

@@ -94,7 +94,11 @@ class UiScalingManager():
self.main.SLS__BOX_OPTION_MENU_IPADY = self._calculateUiSize(2)
self.main.SLS__BOX_OPTION_MENU_ARROW_IMAGE_SIZE = (self._calculateUiSize(20), self._calculateUiSize(20))
# self.main.SLS__BOX_OPTION_MENU_WIDTH = self._calculateUiSize(200)
self.main.SLS__BOX_ARROWS_PADY = self._calculateUiSize(10)
self.main.SLS__BOX_ARROWS_PADY = self._calculateUiSize(4)
self.main.SLS__BOX_ARROWS_SWAP_BUTTON_CORNER_RADIUS = self._calculateUiSize(6)
self.main.SLS__BOX_ARROWS_SWAP_BUTTON_PADX = self._calculateUiSize(20)
self.main.SLS__BOX_ARROWS_SWAP_BUTTON_IPADX = self._calculateUiSize(8)
self.main.SLS__BOX_ARROWS_SWAP_BUTTON_IPADY = self._calculateUiSize(6)
self.main.SLS__BOX_ARROWS_IMAGE_SIZE = self.dupTuple(self._calculateUiSize(16))
self.main.SLS__BOX_ARROWS_DESC_FONT_SIZE = self._calculateUiSize(12)
self.main.SLS__BOX_ARROWS_DESC_PADX = self._calculateUiSize(6)