refactor: split gui into package
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
"""PySide6 GUI package entry point."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
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,
|
||||
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("PySide6 未安装,无法启动 GUI")
|
||||
|
||||
|
||||
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("cmshopee GUI 无法启动:当前 Python 环境未安装 PySide6。")
|
||||
return 1
|
||||
_ensure_offscreen_for_headless_tests()
|
||||
app = QApplication.instance() or QApplication(sys.argv)
|
||||
window = MainWindow()
|
||||
window.show()
|
||||
return app.exec()
|
||||
Reference in New Issue
Block a user