This commit is contained in:
2025-11-23 20:41:50 +08:00
commit f7d5b7be07
65 changed files with 14986 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
窗口工具模块
负责窗口样式设置和对话框配置
"""
import ctypes
from .icon_utils import setup_dialog_icon
def set_dark_title_bar(window):
"""设置窗口为深色标题栏Windows 10/11
Args:
window: 窗口对象
"""
try:
hwnd = ctypes.windll.user32.GetParent(window.winfo_id())
DWMWA_USE_IMMERSIVE_DARK_MODE = 20
value = ctypes.c_int(2)
ctypes.windll.dwmapi.DwmSetWindowAttribute(
hwnd,
DWMWA_USE_IMMERSIVE_DARK_MODE,
ctypes.byref(value),
ctypes.sizeof(value)
)
except Exception as e:
print(f"Failed to set dark title bar: {e}")
def setup_dialog_window(dialog, title: str, width: int, height: int, parent=None, center: bool = True):
"""统一配置对话框窗口
Args:
dialog: 对话框对象
title: 窗口标题
width: 窗口宽度
height: 窗口高度
parent: 父窗口(可选)
center: 是否居中显示,默认 True
Returns:
配置好的对话框对象
"""
dialog.title(title)
dialog.geometry(f"{width}x{height}")
dialog.configure(fg_color="#2b2b2b")
# 设置图标
setup_dialog_icon(dialog)
# 设置为模态
if parent:
dialog.transient(parent)
dialog.grab_set()
# 设置深色标题栏
dialog.after(10, lambda: set_dark_title_bar(dialog))
# 居中显示
if center:
dialog.update_idletasks()
x = (dialog.winfo_screenwidth() // 2) - (width // 2)
y = (dialog.winfo_screenheight() // 2) - (height // 2)
dialog.geometry(f"{width}x{height}+{x}+{y}")
return dialog