[Update] Main Window: Add Restore the main window position feature. VRCT終了時(メイン画面のXを押した時)の画面位置とサイズを記録し、次回起動時に同じ場所同じサイズで表示させる機能を追加。デフォルトでオンです。

※次回アプデ後の初期起動時はみんな、一番左上端座標x-0 y-0で表示されます。この設定をオフにすると常に画面中央(今まで通り)に表示されます。
This commit is contained in:
Sakamoto Shiina
2023-12-30 17:25:29 +09:00
parent 4eeb76f9fb
commit 38edeaebf3
8 changed files with 105 additions and 9 deletions

View File

@@ -280,6 +280,30 @@ class Config:
self._UI_LANGUAGE = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
@json_serializable('ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY')
def ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY(self):
return self._ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY
@ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY.setter
def ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY(self, value):
if isinstance(value, bool):
self._ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
@json_serializable('MAIN_WINDOW_GEOMETRY')
def MAIN_WINDOW_GEOMETRY(self):
return self._MAIN_WINDOW_GEOMETRY
@MAIN_WINDOW_GEOMETRY.setter
def MAIN_WINDOW_GEOMETRY(self, value):
if isinstance(value, dict) and set(value.keys()) == set(self.MAIN_WINDOW_GEOMETRY.keys()):
for key, value in value.items():
if isinstance(value, str):
self._MAIN_WINDOW_GEOMETRY[key] = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, self.MAIN_WINDOW_GEOMETRY)
@property
@json_serializable('CHOICE_MIC_HOST')
def CHOICE_MIC_HOST(self):
@@ -640,6 +664,13 @@ class Config:
self._MESSAGE_BOX_RATIO = 10
self._FONT_FAMILY = "Yu Gothic UI"
self._UI_LANGUAGE = "en"
self._ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY = True
self._MAIN_WINDOW_GEOMETRY = {
"x_pos": "0",
"y_pos": "0",
"width": "870",
"height": "640",
}
self._CHOICE_MIC_HOST = getDefaultInputDevice()["host"]["name"]
self._CHOICE_MIC_DEVICE = getDefaultInputDevice()["device"]["name"]
self._INPUT_MIC_ENERGY_THRESHOLD = 300

View File

@@ -23,6 +23,10 @@ def callbackFilepathConfigFile():
print("callbackFilepathConfigFile", config.LOCAL_PATH.replace('/', '\\'))
Popen(['explorer', config.LOCAL_PATH.replace('/', '\\')], shell=True)
def callbackQuitVrct():
main_window_geometry = view.getMainWindowGeometry()
config.MAIN_WINDOW_GEOMETRY = main_window_geometry
def messageFormatter(format_type:str, translation, message):
if format_type == "RECEIVED":
FORMAT_WITH_T = config.RECEIVED_MESSAGE_FORMAT_WITH_T
@@ -420,6 +424,9 @@ def callbackSetUiLanguage(value):
config.UI_LANGUAGE = value
view.showRestartButtonIfRequired(locale=config.UI_LANGUAGE)
def callbackSetEnableRestoreMainWindowGeometry(value):
print("callbackSetEnableAutoClearMessageBox", value)
config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY = value
# Translation Tab
def callbackSetDeeplAuthkey(value):
@@ -803,6 +810,7 @@ def createMainWindow():
"callback_restart_software": callbackRestartSoftware,
"callback_filepath_logs": callbackFilepathLogs,
"callback_filepath_config_file": callbackFilepathConfigFile,
"callback_quit_vrct": callbackQuitVrct,
},
window_action_registers={
@@ -844,6 +852,7 @@ def createMainWindow():
"callback_set_message_box_ratio": callbackSetMessageBoxRatio,
"callback_set_font_family": callbackSetFontFamily,
"callback_set_ui_language": callbackSetUiLanguage,
"callback_set_enable_restore_main_window_geometry": callbackSetEnableRestoreMainWindowGeometry,
# Translation Tab
"callback_set_deepl_authkey": callbackSetDeeplAuthkey,

View File

@@ -113,6 +113,10 @@ config_window:
ui_language:
label: UI Language
to_restore_main_window_geometry:
label: Remember The Main Window Position
desc: Restore the position and size of the previous window upon startup.
deepl_auth_key:
label: DeepL Auth Key

View File

@@ -110,6 +110,10 @@ config_window:
ui_language:
label: UIの言語 / UI Language
to_restore_main_window_geometry:
label: メイン画面の位置を記憶する
desc: 起動時、前回の画面の位置とサイズを復元します。
deepl_auth_key:
label: DeepL 認証キー

29
view.py
View File

@@ -45,6 +45,13 @@ class View():
self.settings.main = SimpleNamespace(
ctm=all_ctm.main,
uism=all_uism.main,
geometry=SimpleNamespace(
width=config.MAIN_WINDOW_GEOMETRY["width"],
height=config.MAIN_WINDOW_GEOMETRY["height"],
x_pos=config.MAIN_WINDOW_GEOMETRY["x_pos"],
y_pos=config.MAIN_WINDOW_GEOMETRY["y_pos"],
),
to_restore_main_window_geometry=config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY,
**common_args
)
@@ -84,7 +91,8 @@ class View():
CALLBACK_OPEN_FILEPATH_LOGS=None,
CALLBACK_OPEN_FILEPATH_CONFIG_FILE=None,
CALLBACK_QUIT_VRCT=vrct_gui._quitVRCT,
CALLBACK_DELETE_MAIN_WINDOW=self.quitVRCT,
CALLBACK_QUIT_VRCT=None,
CALLBACK_WHEN_DETECT_WINDOW_OVERED_SIZE=self._showDisplayOverUiSizeConfirmationModal,
@@ -240,6 +248,10 @@ class View():
CALLBACK_SET_UI_LANGUAGE=None,
VAR_UI_LANGUAGE=StringVar(value=selectable_languages[config.UI_LANGUAGE]),
VAR_LABEL_ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY=StringVar(value=i18n.t("config_window.to_restore_main_window_geometry.label")),
VAR_DESC_ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY=StringVar(value=i18n.t("config_window.to_restore_main_window_geometry.desc")),
CALLBACK_SET_ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY=None,
VAR_ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY=BooleanVar(value=config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY),
# Translation Tab
VAR_LABEL_DEEPL_AUTH_KEY=StringVar(value=i18n.t("config_window.deepl_auth_key.label")),
@@ -463,6 +475,7 @@ class View():
self.view_variable.CALLBACK_RESTART_SOFTWARE=common_registers.get("callback_restart_software", None)
self.view_variable.CALLBACK_OPEN_FILEPATH_LOGS=common_registers.get("callback_filepath_logs", None)
self.view_variable.CALLBACK_OPEN_FILEPATH_CONFIG_FILE=common_registers.get("callback_filepath_config_file", None)
self.view_variable.CALLBACK_QUIT_VRCT=common_registers.get("callback_quit_vrct", None)
if window_action_registers is not None:
@@ -527,6 +540,7 @@ class View():
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)
self.view_variable.CALLBACK_SET_ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY = config_window_registers.get("callback_set_enable_restore_main_window_geometry", None)
# Translation Tab
@@ -760,7 +774,9 @@ class View():
vrct_gui._showGUI()
vrct_gui._startMainLoop()
def quitVRCT(self):
callFunctionIfCallable(self.view_variable.CALLBACK_QUIT_VRCT)
vrct_gui._quitVRCT()
# Common
@staticmethod
@@ -774,6 +790,15 @@ class View():
def openWebPage(url:str):
webbrowser.open_new_tab(url)
@staticmethod
def getMainWindowGeometry():
result = {
"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
# Open Webpage Functions
def openWebPage_Booth(self):

View File

@@ -6,6 +6,7 @@ def createSettingBox_Appearance(setting_box_wrapper, config_window, settings, vi
sbg = _SettingBoxGenerator(setting_box_wrapper, config_window, settings, view_variable)
createSettingBoxDropdownMenu = sbg.createSettingBoxDropdownMenu
createSettingBoxSlider = sbg.createSettingBoxSlider
createSettingBoxCheckbox = sbg.createSettingBoxCheckbox
# 関数名は変えるかもしれない。
# テーマ変更、フォント変更時、 Widget再生成か再起動かは検討中
@@ -30,6 +31,8 @@ def createSettingBox_Appearance(setting_box_wrapper, config_window, settings, vi
def optionmenu_ui_language_callback(value):
callFunctionIfCallable(view_variable.CALLBACK_SET_UI_LANGUAGE, value)
def checkbox_enable_restore_main_window_geometry_callback(checkbox_box_widget):
callFunctionIfCallable(view_variable.CALLBACK_SET_ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY, checkbox_box_widget.get())
row=0
config_window.sb__transparency = createSettingBoxSlider(
@@ -119,5 +122,15 @@ def createSettingBox_Appearance(setting_box_wrapper, config_window, settings, vi
command=lambda value: optionmenu_ui_language_callback(value),
variable=view_variable.VAR_UI_LANGUAGE,
)
config_window.sb__ui_language.grid(row=row, pady=0)
config_window.sb__ui_language.grid(row=row)
row+=1
config_window.sb__enable_restore_main_window_geometry = createSettingBoxCheckbox(
for_var_label_text=view_variable.VAR_LABEL_ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY,
for_var_desc_text=view_variable.VAR_DESC_ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY,
checkbox_attr_name="sb__checkbox_enable_restore_main_window_geometry",
command=lambda: checkbox_enable_restore_main_window_geometry_callback(config_window.sb__checkbox_enable_restore_main_window_geometry),
variable=view_variable.VAR_ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY,
)
config_window.sb__enable_restore_main_window_geometry.grid(row=row, pady=0)
row+=1

View File

@@ -6,7 +6,7 @@ from utils import callFunctionIfCallable
from ..ui_utils import createButtonWithImage, getImagePath, bindButtonFunctionAndColor
def createMainWindowWidgets(vrct_gui, settings, view_variable):
vrct_gui.protocol("WM_DELETE_WINDOW", lambda: callFunctionIfCallable(view_variable.CALLBACK_QUIT_VRCT))
vrct_gui.protocol("WM_DELETE_WINDOW", lambda: callFunctionIfCallable(view_variable.CALLBACK_DELETE_MAIN_WINDOW))
vrct_gui.iconbitmap(getImagePath("vrct_logo_mark_black.ico"))

View File

@@ -43,11 +43,21 @@ class VRCT_GUI(CTk):
def _showGUI(self):
self.attributes("-alpha", 0)
self.deiconify()
self.geometry("{}x{}".format(
self.settings.main.uism.MAIN_AREA_MIN_WIDTH + self.settings.main.uism.SIDEBAR_MIN_WIDTH,
self.winfo_height()
))
setGeometryToCenterOfScreen(root_widget=self)
if self.settings.main.to_restore_main_window_geometry is True:
self.geometry("{}x{}+{}+{}".format(
self.settings.main.geometry.width,
self.settings.main.geometry.height,
self.settings.main.geometry.x_pos,
self.settings.main.geometry.y_pos,
))
else:
self.geometry("{}x{}".format(
self.settings.main.uism.MAIN_AREA_MIN_WIDTH + self.settings.main.uism.SIDEBAR_MIN_WIDTH,
self.winfo_height()
))
setGeometryToCenterOfScreen(root_widget=self)
if self._view_variable.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE is True:
self._enableMainWindowSidebarCompactMode()
fadeInAnimation(self, steps=5, interval=0.008)