Files
cmshoppe/app/gui/__init__.py
T

64 lines
2.1 KiB
Python
Raw Normal View History

2026-07-02 16:47:37 +08:00
"""PySide6 GUI package entry point."""
from __future__ import annotations
import os
import sys
from .. import appconfig
2026-07-02 16:47:37 +08:00
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,
2026-07-04 16:29:15 +08:00
CMHubSettingsWorker,
2026-07-02 16:47:37 +08:00
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):
2026-07-07 09:52:51 +08:00
raise RuntimeError("蝦皮圈優化助手 GUI 无法启动:当前 Python 环境未安装 PySide6。")
2026-07-02 16:47:37 +08:00
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:
2026-07-07 09:52:51 +08:00
print("蝦皮圈優化助手 GUI 无法启动:当前 Python 环境未安装 PySide6。")
2026-07-02 16:47:37 +08:00
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
2026-07-02 16:47:37 +08:00
window = MainWindow()
window.show()
2026-07-07 09:52:51 +08:00
return app.exec()