[Update] 各Window表示時に画面の中央に配置するように。(それによって一瞬再配置が見えるので、誤魔化し用でもある)フェードインアニメーション追加とそれら関数の汎用化。

This commit is contained in:
Sakamoto Shiina
2023-10-11 23:11:59 +09:00
parent 8185050ea2
commit 3e6bce367c
4 changed files with 49 additions and 23 deletions

View File

@@ -9,7 +9,7 @@ class _CreateModalWindow(CTkToplevel):
self.title("")
self.overrideredirect(True)
self.wm_attributes("-alpha", 0.5)
# self.wm_attributes("-alpha", 0.5)
self.wm_attributes("-toolwindow", True)
self.attach_window = attach_window

View File

@@ -1,6 +1,5 @@
from customtkinter import CTkImage, CTkLabel, CTkToplevel
from ..ui_utils import openImageKeepAspectRatio, getImageFileFromUiUtils
from time import sleep
from ..ui_utils import openImageKeepAspectRatio, getImageFileFromUiUtils, setGeometryToCenterOfScreen, fadeInAnimation
class SplashWindow(CTkToplevel):
def __init__(self):
@@ -12,7 +11,7 @@ class SplashWindow(CTkToplevel):
sw=self.winfo_screenwidth()
sh=self.winfo_screenheight()
# sh=self.winfo_screenheight()
pw=int(sw/4)
@@ -26,25 +25,14 @@ class SplashWindow(CTkToplevel):
fg_color="#292a2d",
image=CTkImage(img, size=(desired_width, height))
)
label.grid(row=1, column=1)
geometry_width=desired_width+int(desired_width*0.2)
geometry_height=height+int(height*0.5)
self.geometry(str(geometry_width)+"x"+str(geometry_height)+"+"+str((sw-geometry_width)//2)+"+"+str((sh-geometry_height)//2))
label.grid(row=1, column=1, padx=int(desired_width/7), pady=int(height/3))
def showSplash(self):
self.attributes("-alpha", 0)
self.deiconify()
for i in range(0,91,20):
if not self.winfo_exists():
break
self.attributes("-alpha", i/100)
self.update()
sleep(1/50)
self.attributes("-alpha", 1)
setGeometryToCenterOfScreen(root_widget=self)
fadeInAnimation(self, steps=5, interval=0.02)
def destroySplash(self):

View File

@@ -1,5 +1,6 @@
from os import path as os_path
from PIL.Image import open as Image_open, LANCZOS
from time import sleep
from customtkinter import CTkFrame, CTkLabel, CTkImage, CTkFont
@@ -199,4 +200,30 @@ def applyUiScalingAndFixTheBugScrollBar(scrollbar_widget, padx, width):
# This is for CustomTkinter's spec change or bug fix.
scrollbar_widget._scrollbar.configure(height=0)
scrollbar_widget._scrollbar.configure(width=width)
scrollbar_widget._scrollbar.configure(width=width)
def setGeometryToCenterOfScreen(root_widget):
root_widget.update()
sw=root_widget.winfo_screenwidth()
sh=root_widget.winfo_screenheight()
geometry_width = root_widget.winfo_width()
geometry_height = root_widget.winfo_height()
root_widget.geometry(str(geometry_width)+"x"+str(geometry_height)+"+"+str((sw-geometry_width)//2)+"+"+str((sh-geometry_height)//2))
def fadeInAnimation(root_widget, steps:int=10, interval:float=0.1, max_alpha:float=1):
alpha_steps = 100
alpha_steps*=max_alpha
step_size = alpha_steps/steps
root_widget.attributes("-alpha", 0)
num = 0
while num < alpha_steps:
if not root_widget.winfo_exists():
break
root_widget.attributes("-alpha", num / 100)
root_widget.update()
sleep(interval)
num += step_size
root_widget.attributes("-alpha", max_alpha)

View File

@@ -11,7 +11,7 @@ from ._printToTextbox import _printToTextbox
from .main_window import createMainWindowWidgets
from .config_window import ConfigWindow
from .ui_utils import _setDefaultActiveTab, getLatestHeight
from .ui_utils import _setDefaultActiveTab, getLatestHeight, setGeometryToCenterOfScreen, fadeInAnimation
from utils import callFunctionIfCallable
@@ -20,14 +20,16 @@ class VRCT_GUI(CTk):
super().__init__()
self.withdraw()
self.adjusted_event=None
self.is_config_window_already_opened_once=False
self.BIND_CONFIGURE_ADJUSTED_GEOMETRY_FUNC_ID=None
self.BIND_FOCUS_IN_MODAL_WINDOW_LIFT_CONFIG_WINDOW_FUNC_ID=None
def _showGUI(self):
self.attributes("-alpha", 0)
self.deiconify()
self.update()
self.geometry("{}x{}".format(self.winfo_width(), self.winfo_height()))
setGeometryToCenterOfScreen(root_widget=self)
fadeInAnimation(self, steps=5, interval=0.008)
def _createGUI(self, settings, view_variable):
self.settings = settings
@@ -109,11 +111,20 @@ class VRCT_GUI(CTk):
callFunctionIfCallable(self._view_variable.CALLBACK_OPEN_CONFIG_WINDOW)
self._adjustToMainWindowGeometry()
self.modal_window.attributes("-alpha", 0)
self.modal_window.deiconify()
fadeInAnimation(self.modal_window, steps=5, interval=0.005, max_alpha=0.5)
self.BIND_CONFIGURE_ADJUSTED_GEOMETRY_FUNC_ID = self.bind("<Configure>", self._adjustToMainWindowGeometry, "+")
self.BIND_FOCUS_IN_MODAL_WINDOW_LIFT_CONFIG_WINDOW_FUNC_ID = self.modal_window.bind("<FocusIn>", lambda _e: self.config_window.lift(), "+")
self.config_window.attributes("-alpha", 0)
self.config_window.deiconify()
if self.is_config_window_already_opened_once is False:
setGeometryToCenterOfScreen(self.config_window)
self.is_config_window_already_opened_once = True
fadeInAnimation(self.config_window, steps=5, interval=0.005)
self.config_window.attributes("-alpha", 1)
self.config_window.focus_set()
def _closeConfigWindow(self):