[bugfix] Main Window, Cover Window: メイン画面に追従しないバグなど修正。追従する関数やイベント登録もcover windowクラス内に押し込み。

This commit is contained in:
Sakamoto Shiina
2023-10-20 06:00:18 +09:00
parent f668686daf
commit 55db1c2e75
3 changed files with 33 additions and 23 deletions

View File

@@ -1,12 +1,15 @@
from customtkinter import CTkToplevel, CTkFrame, CTkLabel, CTkFont
from .ui_utils import fadeInAnimation
from utils import makeEven
class _CreateWindowCover(CTkToplevel):
def __init__(self, attach_window, settings, view_variable):
super().__init__()
self.withdraw()
self.BIND_CONFIGURE_ADJUSTED_GEOMETRY_FUNC_ID=None
self.BIND_FOCUS_IN_FUNC_ID=None
self.title("")
self.overrideredirect(True)
@@ -40,7 +43,14 @@ class _CreateWindowCover(CTkToplevel):
self.cover_container_label_wrapper.place(relx=0.5, rely=0.5, anchor="center")
def show(self):
def show(self, bind_focusin=None):
self.BIND_CONFIGURE_ADJUSTED_GEOMETRY_FUNC_ID = self.attach_window.bind("<Configure>", self._adjustToMainWindowGeometry, "+")
if bind_focusin is not None:
self.BIND_FOCUS_IN_FUNC_ID = self.bind("<FocusIn>", lambda _e: bind_focusin(), "+")
else:
self.BIND_FOCUS_IN_FUNC_ID = None
self.attributes("-alpha", 0)
self.deiconify()
self.attach_window.update_idletasks()
@@ -52,5 +62,22 @@ class _CreateWindowCover(CTkToplevel):
fadeInAnimation(self, steps=5, interval=0.005, max_alpha=0.5)
def hide(self):
self.attach_window.unbind("<Configure>", self.BIND_CONFIGURE_ADJUSTED_GEOMETRY_FUNC_ID)
if self.BIND_FOCUS_IN_FUNC_ID is not None:
self.unbind("<FocusIn>", self.BIND_FOCUS_IN_FUNC_ID)
self.withdraw()
def _adjustToMainWindowGeometry(self, e=None):
self.attach_window.update_idletasks()
x_pos = self.attach_window.winfo_rootx()
y_pos = self.attach_window.winfo_rooty()
width_new = makeEven(self.attach_window.winfo_width())
height_new = makeEven(self.attach_window.winfo_height())
self.geometry("{}x{}+{}+{}".format(width_new, height_new, x_pos, y_pos))
self.lift()