fix:优化一些命名规范
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
from nicegui import ui, app, run, native
|
||||
from loguru import logger
|
||||
|
||||
from screeninfo import get_monitors
|
||||
import traceback
|
||||
|
||||
from loguru import logger
|
||||
from nicegui import ui, app, run, native
|
||||
from screeninfo import get_monitors
|
||||
|
||||
from config.config import load_config
|
||||
# 导入我们的模块
|
||||
from ui.core.logger import setup_logger
|
||||
from utils.font_utils import install_fonts_from_directory
|
||||
from ui.views.home_page import create_home_page
|
||||
from ui.views.config_page import create_config_page
|
||||
from ui.views.home_page import create_home_page
|
||||
from utils.font_utils import install_fonts_from_directory
|
||||
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
sys.stderr.reconfigure(encoding='utf-8')
|
||||
@@ -20,6 +20,7 @@ config = load_config("config.toml")
|
||||
|
||||
setup_logger()
|
||||
|
||||
|
||||
# === 关键修改:定义一个获取路径的通用函数 ===
|
||||
def get_path(relative_path):
|
||||
"""
|
||||
@@ -47,42 +48,46 @@ def calculate_window_size():
|
||||
m = monitors[0]
|
||||
screen_width = m.width
|
||||
screen_height = m.height
|
||||
|
||||
|
||||
# 设置窗口宽度为屏幕宽度的 30%
|
||||
target_width = int(screen_width * 0.30)
|
||||
# 设置窗口高度为屏幕高度的 60%
|
||||
target_height = int(screen_height * 0.60)
|
||||
|
||||
|
||||
# 确保窗口有一个合理的最小值 (例如 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"))
|
||||
app.add_static_files('/assets', static_dir)
|
||||
|
||||
|
||||
# 3. 页面路由
|
||||
@ui.page('/')
|
||||
def index_page():
|
||||
create_home_page()
|
||||
|
||||
|
||||
@ui.page('/config')
|
||||
def config_page():
|
||||
create_config_page()
|
||||
|
||||
|
||||
# 4. 启动时钩子
|
||||
async def startup_check():
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user