fix:修改页面滚动条样式
This commit is contained in:
@@ -4,6 +4,8 @@ import sys
|
||||
from nicegui import ui, app, run, native
|
||||
from loguru import logger
|
||||
|
||||
from screeninfo import get_monitors
|
||||
|
||||
# 导入我们的模块
|
||||
from config.config import load_config
|
||||
from ui.core.logger import setup_logger
|
||||
@@ -33,6 +35,40 @@ def get_path(relative_path):
|
||||
return os.path.join(base_path, relative_path)
|
||||
|
||||
|
||||
def calculate_window_size():
|
||||
"""
|
||||
获取主屏幕分辨率,并计算一个基于百分比的 NiceGUI 窗口大小。
|
||||
"""
|
||||
try:
|
||||
# 尝试获取所有显示器信息
|
||||
monitors = get_monitors()
|
||||
if monitors:
|
||||
# 假设第一个是主显示器
|
||||
m = monitors[0]
|
||||
screen_width = m.width
|
||||
screen_height = m.height
|
||||
|
||||
# 设置窗口宽度为屏幕宽度的 70%
|
||||
target_width = int(screen_width * 0.70)
|
||||
# 设置窗口高度为屏幕高度的 80%
|
||||
target_height = int(screen_height * 0.80)
|
||||
|
||||
# 确保窗口有一个合理的最小值 (例如 800x600)
|
||||
min_width = 800
|
||||
min_height = 700
|
||||
|
||||
target_width = max(target_width, min_width)
|
||||
target_height = max(target_height, min_height)
|
||||
|
||||
logger.info(f"屏幕分辨率: {screen_width}x{screen_height}")
|
||||
logger.info(f"设置窗口大小为: {target_width}x{target_height}")
|
||||
|
||||
return (target_width, target_height)
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"无法获取屏幕分辨率 ({e}),使用默认大小 (900, 900)")
|
||||
return (900, 900) # 失败时的默认值
|
||||
|
||||
# 1. 挂载静态资源 (CSS/图片)
|
||||
# 注意:这里使用 get_path 确保打包后能找到
|
||||
static_dir = get_path(os.path.join("ui", "assets"))
|
||||
@@ -59,10 +95,11 @@ async def startup_check():
|
||||
app.on_startup(startup_check)
|
||||
|
||||
if __name__ in {"__main__", "__mp_main__"}:
|
||||
calculated_size = calculate_window_size()
|
||||
ui.run(
|
||||
title="尚城幼儿园成长报告助手",
|
||||
native=True,
|
||||
window_size=(900, 900),
|
||||
window_size=calculated_size,
|
||||
port=native.find_open_port(), # 自动寻找端口
|
||||
reload=False
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user