64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
"""PySide6 GUI package entry point."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
|
|
from .. import appconfig
|
|
from . import widgets as _widgets
|
|
from .widgets import *
|
|
|
|
QT_IMPORT_ERROR = _widgets.QT_IMPORT_ERROR
|
|
QMessageBox = _widgets._RawQMessageBox
|
|
run_worker = _widgets._raw_run_worker if QT_IMPORT_ERROR is None else _widgets.run_worker
|
|
|
|
if QT_IMPORT_ERROR is None:
|
|
from .models import ApplyTaskTableModel, GenerateTaskTableModel, TaskTableModel
|
|
from .workers import (
|
|
AccountLoginCheckWorker,
|
|
AIModelTestWorker,
|
|
CMHubSettingsWorker,
|
|
ApplyWorker,
|
|
CollectWorker,
|
|
GenerateWorker,
|
|
WriteBackWorker,
|
|
)
|
|
from .tabs.accounts import AccountDialog, AccountsTab
|
|
from .tabs.apply import ApplyTab
|
|
from .tabs.collect import CollectTab
|
|
from .tabs.generate import GenerateTab
|
|
from .tabs.settings import SettingsTab
|
|
from .main_window import MainWindow
|
|
else:
|
|
class MainWindow(QMainWindow):
|
|
def __init__(self):
|
|
raise RuntimeError("蝦皮圈優化助手 GUI 无法启动:当前 Python 环境未安装 PySide6。")
|
|
|
|
|
|
def _ensure_offscreen_for_headless_tests():
|
|
if "PYTEST_CURRENT_TEST" in os.environ and "QT_QPA_PLATFORM" not in os.environ:
|
|
os.environ["QT_QPA_PLATFORM"] = "offscreen"
|
|
|
|
|
|
def main() -> int:
|
|
if QT_IMPORT_ERROR is not None:
|
|
print("蝦皮圈優化助手 GUI 无法启动:当前 Python 环境未安装 PySide6。")
|
|
return 1
|
|
_ensure_offscreen_for_headless_tests()
|
|
app = QApplication.instance() or QApplication(sys.argv)
|
|
try:
|
|
appconfig.prepare_data_dir()
|
|
except appconfig.DataMigrationConflictError as exc:
|
|
QMessageBox.critical(None, "数据迁移冲突", str(exc))
|
|
return 1
|
|
except appconfig.DataDirectoryWriteError as exc:
|
|
QMessageBox.critical(None, "数据目录不可写", str(exc))
|
|
return 1
|
|
except appconfig.ConfigError as exc:
|
|
QMessageBox.critical(None, "启动配置错误", str(exc))
|
|
return 1
|
|
window = MainWindow()
|
|
window.show()
|
|
return app.exec()
|