-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
68 lines (57 loc) · 1.96 KB
/
main.py
File metadata and controls
68 lines (57 loc) · 1.96 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
# -*- coding: utf-8 -*-
"""
主程序入口
用途:
启动 PySide6 应用,加载主界面 MosaicTool。
使用场景:
直接运行 main.py 启动图片马赛克工具。
"""
import sys
import json
import os
from PySide6.QtWidgets import QApplication
from PySide6.QtCore import QCoreApplication
from src.gui.main_window import MainWindow
from src.constants.config import APP_NAME, ORGANIZATION_NAME, APP_VERSION, DEFAULT_LANGUAGE, LANGUAGE_CONFIG_FILE
from src.localization import set_language, tr
def load_language_config():
"""加载语言配置文件"""
try:
if os.path.exists(LANGUAGE_CONFIG_FILE):
with open(LANGUAGE_CONFIG_FILE, 'r', encoding='utf-8') as f:
config = json.load(f)
return config.get('language', DEFAULT_LANGUAGE)
except Exception:
pass
# 如果没有保存的配置文件,检测系统语言
try:
from src.localization.translator import translator
return translator.get_system_language()
except Exception:
pass
return DEFAULT_LANGUAGE
def save_language_config(language_code):
"""保存语言配置"""
try:
config = {'language': language_code}
with open(LANGUAGE_CONFIG_FILE, 'w', encoding='utf-8') as f:
json.dump(config, f, ensure_ascii=False, indent=2)
except Exception:
pass
def main():
"""
应用程序主入口,初始化并启动主窗口。
"""
app = QApplication(sys.argv)
# 初始化本地化系统
saved_language = load_language_config()
set_language(saved_language)
# 设置应用元数据(使用翻译后的名称)
QCoreApplication.setApplicationName(tr('app_name', APP_NAME))
QCoreApplication.setOrganizationName(tr('organization_name', ORGANIZATION_NAME))
QCoreApplication.setApplicationVersion(APP_VERSION)
window = MainWindow()
window.show()
sys.exit(app.exec())
if __name__ == "__main__":
main()