-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.pyw
More file actions
64 lines (50 loc) · 1.72 KB
/
app.pyw
File metadata and controls
64 lines (50 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -----------------------------------------------------------------------------
# 功能: 应用程序主入口 (优化版)
# 优化内容:
# 1. 关闭debug模式提升启动速度
# 2. 优化窗口创建参数
# 3. 添加启动时间监控
# -----------------------------------------------------------------------------
import sys
import os
import time
import webview
from pathlib import Path
# 记录启动时间
start_time = time.time()
# --- 解决模块导入问题的关键代码 ---
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
# 延迟导入,提升启动速度
from src.main_api import Api
def main():
"""应用程序主函数"""
api_instance = Api()
ui_file = Path(__file__).resolve().parent / 'ui' / 'ui.html'
if not ui_file.exists():
raise FileNotFoundError(f'UI 文件未找到: {ui_file}')
window = webview.create_window(
'LLM 图像扫描与导出 (PyWebView)',
ui_file.as_uri(),
js_api=api_instance,
width=1250,
height=850,
resizable=True,
confirm_close=True,
shadow=True,
text_select=False,
hidden=True
)
api_instance._window = window
def handle_window_loaded():
"""前端加载完成后再显示窗口,确保界面一次性呈现"""
init_duration = time.time() - start_time
print(f"前端加载完成,耗时: {init_duration:.2f}s")
try:
window.evaluate_js("window.dispatchEvent(new Event('pywebviewready'))")
except Exception as exc:
print(f"派发前端就绪事件失败: {exc}")
window.show()
window.events.loaded += handle_window_loaded
webview.start(debug=False)
if __name__ == '__main__':
main()