-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
73 lines (59 loc) · 2.07 KB
/
run.py
File metadata and controls
73 lines (59 loc) · 2.07 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
65
66
67
68
69
70
71
72
73
import sys
import os
from PySide6.QtWidgets import QApplication
from PySide6.QtGui import QFont, QIcon # 将QFont导入提前
from app.views.main_window import MainWindow
from app.models.database import init_db, migrate_db, Base
import logging
#import matplotlib as mpl
def main():
# 添加平台检测
import platform
is_mac = platform.system() == 'Darwin'
is_windows = platform.system() == 'Windows'
app = QApplication(sys.argv)
# 设置字体
font = QFont('Microsoft YaHei')
if is_mac:
font.setPixelSize(12)
elif is_windows:
font.setPixelSize(12)
app.setFont(font)
# 设置日志
logging.basicConfig(level=logging.INFO)
#mpl.rcParams['font.sans-serif'] = ['Microsoft YaHei', 'SimHei', 'Arial']
#mpl.rcParams['axes.unicode_minus'] = False
# 设置应用程序图标
icon_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'app', 'assets', 'icon.ico'))
# print(f"图标路径: {icon_path}") # Removed debug print
if os.path.exists(icon_path):
app.setWindowIcon(QIcon(icon_path))
else:
print(f"图标文件不存在: {icon_path}")
# 获取数据库路径
if getattr(sys, 'frozen', False):
base_dir = os.path.dirname(sys.executable)
else:
# 如果是源码运行
base_dir = os.path.dirname(__file__)
db_path = os.path.join(base_dir, 'database', 'database.db')
# 确保数据库目录存在
db_dir = os.path.dirname(db_path)
if not os.path.exists(db_dir):
os.makedirs(db_dir)
# 初始化数据库
engine = init_db(db_path)
# 检查数据库是否存在,不存在则初始化
if not os.path.exists(db_path):
logging.info("初始化数据库")
Base.metadata.create_all(engine)
else:
# 如果数据库已存在,执行迁移
logging.info("执行数据库迁移")
migrate_db(engine)
# 创建主窗口
window = MainWindow(engine)
window.show()
sys.exit(app.exec())
if __name__ == '__main__':
main()