2026-06-27 09:56:53 +08:00
|
|
|
"""PySide6 GUI entry point."""
|
2026-06-26 17:24:23 +08:00
|
|
|
|
2026-06-27 09:56:53 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
from PySide6.QtWidgets import (
|
|
|
|
|
QApplication,
|
|
|
|
|
QMainWindow,
|
|
|
|
|
QTabWidget,
|
|
|
|
|
QVBoxLayout,
|
|
|
|
|
QWidget,
|
|
|
|
|
)
|
|
|
|
|
QT_IMPORT_ERROR = None
|
|
|
|
|
except ModuleNotFoundError as exc:
|
|
|
|
|
QApplication = None
|
|
|
|
|
QMainWindow = object
|
|
|
|
|
QTabWidget = None
|
|
|
|
|
QVBoxLayout = None
|
|
|
|
|
QWidget = object
|
|
|
|
|
QT_IMPORT_ERROR = exc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TAB_TITLES = [
|
|
|
|
|
"① 导入采集",
|
|
|
|
|
"② AI生成",
|
|
|
|
|
"③ 更新shopee",
|
|
|
|
|
"④ 账号管理",
|
|
|
|
|
"⑤ 设置",
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if QT_IMPORT_ERROR is None:
|
|
|
|
|
class MainWindow(QMainWindow):
|
|
|
|
|
"""Main application window with the fixed five-tab workflow."""
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super().__init__()
|
|
|
|
|
self.setWindowTitle("cmshopee")
|
|
|
|
|
self.resize(1180, 760)
|
|
|
|
|
self.tabs = QTabWidget()
|
|
|
|
|
self.tabs.setObjectName("mainTabs")
|
|
|
|
|
self.tabs.currentChanged.connect(self._on_tab_changed)
|
|
|
|
|
for title in TAB_TITLES:
|
|
|
|
|
self.tabs.addTab(self._build_placeholder_tab(title), title)
|
|
|
|
|
self.setCentralWidget(self.tabs)
|
|
|
|
|
self.statusBar().showMessage("就绪")
|
|
|
|
|
|
|
|
|
|
def _build_placeholder_tab(self, title):
|
|
|
|
|
widget = QWidget()
|
|
|
|
|
widget.setObjectName(title)
|
|
|
|
|
layout = QVBoxLayout(widget)
|
|
|
|
|
layout.setContentsMargins(18, 18, 18, 18)
|
|
|
|
|
layout.addStretch(1)
|
|
|
|
|
return widget
|
|
|
|
|
|
|
|
|
|
def _on_tab_changed(self, index):
|
|
|
|
|
self.statusBar().showMessage(f"当前:{self.tabs.tabText(index)}")
|
|
|
|
|
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"
|
2026-06-26 17:24:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> int:
|
2026-06-27 09:56:53 +08:00
|
|
|
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()
|