diff --git a/controller.py b/controller.py index ce31b75b..5b7e1478 100644 --- a/controller.py +++ b/controller.py @@ -4,14 +4,16 @@ from threading import Thread from config import config from model import model from view import view -from utils import getKeyByValue, isUniqueStrings +from utils import getKeyByValue, isUniqueStrings, strPctToInt import argparse # Common def callbackUpdateSoftware(): + setMainWindowGeometry() model.updateSoftware() def callbackRestartSoftware(): + setMainWindowGeometry() model.reStartSoftware() def callbackFilepathLogs(): @@ -23,7 +25,17 @@ def callbackFilepathConfigFile(): Popen(['explorer', config.LOCAL_PATH.replace('/', '\\')], shell=True) def callbackQuitVrct(): - main_window_geometry = view.getMainWindowGeometry() + setMainWindowGeometry() + +def setMainWindowGeometry(): + PRE_SCALING_INT = strPctToInt(view.getPreUiScaling()) + NEW_SCALING_INT = strPctToInt(config.UI_SCALING) + MULTIPLY_FLOAT = (NEW_SCALING_INT / PRE_SCALING_INT) + main_window_geometry = view.getMainWindowGeometry(return_int=True) + main_window_geometry["width"] = str(int(main_window_geometry["width"] * MULTIPLY_FLOAT)) + main_window_geometry["height"] = str(int(main_window_geometry["height"] * MULTIPLY_FLOAT)) + main_window_geometry["x_pos"] = str(main_window_geometry["x_pos"]) + main_window_geometry["y_pos"] = str(main_window_geometry["y_pos"]) config.MAIN_WINDOW_GEOMETRY = main_window_geometry def messageFormatter(format_type:str, translation, message): @@ -398,7 +410,7 @@ def callbackSetAppearance(value): def callbackSetUiScaling(value): print("callbackSetUiScaling", value) config.UI_SCALING = value - new_scaling_float = int(value.replace("%", "")) / 100 + new_scaling_float = strPctToInt(value) / 100 print("callbackSetUiScaling_new_scaling_float", new_scaling_float) view.showRestartButtonIfRequired() diff --git a/utils.py b/utils.py index 87b7d981..6a05a08d 100644 --- a/utils.py +++ b/utils.py @@ -30,9 +30,12 @@ def generatePercentageStringsList(start:int, end:int, step:int): strings.append(f"{percent}%") return strings -def intToPercentageStringsFormatter(value:int): +def intToPctStr(value:int): return f"{value}%" +def strPctToInt(value:str): + return int(value.replace("%", "")) + def isUniqueStrings(unique_strings:Union[str, list], input_string:str, require=False): import re if isinstance(unique_strings, str): diff --git a/view.py b/view.py index 2d41cf5f..3381917c 100644 --- a/view.py +++ b/view.py @@ -8,7 +8,7 @@ import i18n from customtkinter import StringVar, IntVar, BooleanVar, get_appearance_mode from vrct_gui.ui_managers import ColorThemeManager, UiScalingManager from vrct_gui import vrct_gui -from utils import callFunctionIfCallable, intToPercentageStringsFormatter +from utils import callFunctionIfCallable, intToPctStr from config import config @@ -183,7 +183,7 @@ 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, + CALLBACK_SLIDER_TOOLTIP_PERCENTAGE_FORMATTER=intToPctStr, # Side Menu Labels @@ -796,14 +796,24 @@ class View(): webbrowser.open_new_tab(url) @staticmethod - def getMainWindowGeometry(): - result = { + def getMainWindowGeometry(return_int:bool=False): + if return_int is True: + return { + "width": vrct_gui.winfo_toplevel().winfo_width(), + "height": vrct_gui.winfo_toplevel().winfo_height(), + "x_pos": vrct_gui.winfo_toplevel().winfo_x(), + "y_pos": vrct_gui.winfo_toplevel().winfo_y(), + } + + return { "width": str(vrct_gui.winfo_toplevel().winfo_width()), "height": str(vrct_gui.winfo_toplevel().winfo_height()), "x_pos": str(vrct_gui.winfo_toplevel().winfo_x()), "y_pos": str(vrct_gui.winfo_toplevel().winfo_y()), } - return result + + def getPreUiScaling(self): + return self.restart_required_configs_pre_data.ui_scaling # Open Webpage Functions def openWebPage_Booth(self):