feat: 完成PySide6主窗口骨架

- 实现 MainWindow + 固定顺序五 Tab QTabWidget + 状态栏

- 新增 offscreen GUI 单元测试覆盖 Tab 顺序和状态栏切换

- 缺 PySide6 时提供明确启动错误,避免无声失败

- 更新任务看板、API 合约、当前状态和进度记录
This commit is contained in:
chengma
2026-06-27 09:56:53 +08:00
parent 6d821f89e2
commit b8318c881d
6 changed files with 147 additions and 14 deletions
+76 -6
View File
@@ -1,10 +1,80 @@
"""GUI entry point placeholder.
"""PySide6 GUI entry point."""
The real PySide6 main window is implemented by task T-104.
"""
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"
def main() -> int:
print("cmshopee GUI 尚未实现:请继续执行 T-104 构建 PySide6 主窗口。")
return 0
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()