refactor: 拆分页面 UI 模块 (#3)
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
"""应用与主窗口装配。
|
||||
|
||||
本文件只负责把窗口、导航和页面拼起来,不写业务逻辑。
|
||||
|
||||
改动本文件前必读 `client/AGENTS.md`。以下几条最容易踩:
|
||||
|
||||
- 图标一律用 `FluentIcon`,**不得使用表情符号充当图标**。
|
||||
- 不得在这里发起 Admin 请求、SQLite 长查询或 uiautomator2 调用,
|
||||
这些会卡死 Qt 主线程。业务事件放到各页面的 `*_ui_event.py`。
|
||||
- 页面的 `objectName` 必须唯一且稳定,改名会破坏导航。
|
||||
- 用布局和伸缩项排版,**不要用固定坐标**。
|
||||
- 不要用全局 QSS 覆盖 Fluent 控件;局部样式必须保留悬停、按下、
|
||||
焦点和禁用四种状态。
|
||||
- 需要文件路径时走 `data_dir()` / `app_dir()`,不要硬编码,
|
||||
见 `docs/client/03-data-model.md` §2.2。
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
from qfluentwidgets import (
|
||||
FluentIcon as FIF,
|
||||
FluentWindow,
|
||||
NavigationItemPosition,
|
||||
Theme,
|
||||
setTheme,
|
||||
)
|
||||
|
||||
from .pdd_ui import PDDTaskPage
|
||||
from .settings_ui import DevicePage, SettingsPage
|
||||
|
||||
|
||||
class MainWindow(FluentWindow):
|
||||
"""应用主窗口。"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.pddTaskPage = PDDTaskPage(self)
|
||||
self.devicePage = DevicePage(self)
|
||||
self.settingsPage = SettingsPage(self)
|
||||
|
||||
self.addSubInterface(self.pddTaskPage, FIF.HOME, "pdd")
|
||||
self.addSubInterface(self.devicePage, FIF.IOT, "设备")
|
||||
self.addSubInterface(
|
||||
self.settingsPage,
|
||||
FIF.SETTING,
|
||||
"设置",
|
||||
NavigationItemPosition.BOTTOM,
|
||||
)
|
||||
|
||||
self.setWindowTitle("采集采购工具")
|
||||
self.setMinimumSize(820, 560)
|
||||
self.resize(1040, 680)
|
||||
self._moveToScreenCenter()
|
||||
|
||||
def _moveToScreenCenter(self):
|
||||
screen = QApplication.primaryScreen()
|
||||
if screen is None:
|
||||
return
|
||||
|
||||
frame = self.frameGeometry()
|
||||
frame.moveCenter(screen.availableGeometry().center())
|
||||
self.move(frame.topLeft())
|
||||
|
||||
|
||||
def ui_main():
|
||||
"""启动桌面应用。"""
|
||||
|
||||
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
|
||||
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
setTheme(Theme.AUTO)
|
||||
|
||||
window = MainWindow()
|
||||
window.show()
|
||||
return app.exec_()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(ui_main())
|
||||
Reference in New Issue
Block a user