这是使用PyQT5作为UI的首次提交,将后端和UI合并到1个工程中,统一使用了Python,没有使用JS和HTML
This commit is contained in:
2
UI/controllers/__init__.py
Normal file
2
UI/controllers/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
57
UI/controllers/main_controller.py
Normal file
57
UI/controllers/main_controller.py
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
主控制器,负责协调各个模块和数据管理
|
||||
"""
|
||||
|
||||
from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal, pyqtSlot
|
||||
from models.monitor_model import MonitorModel
|
||||
from models.dut_model import DUTModel
|
||||
from models.system_model import SystemModel
|
||||
|
||||
|
||||
class MainController(QObject):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
# 初始化各个数据模型
|
||||
self._monitor_model = MonitorModel()
|
||||
self._dut_model = DUTModel()
|
||||
self._system_model = SystemModel()
|
||||
|
||||
# 导航属性
|
||||
self._current_view = "test_arrangement" # 默认视图
|
||||
|
||||
# 信号定义
|
||||
currentViewChanged = pyqtSignal()
|
||||
|
||||
# 属性访问器
|
||||
@pyqtProperty('QString', notify=currentViewChanged)
|
||||
def currentView(self):
|
||||
return self._current_view
|
||||
|
||||
@currentView.setter
|
||||
def setCurrentView(self, view):
|
||||
if self._current_view != view:
|
||||
self._current_view = view
|
||||
self.currentViewChanged.emit()
|
||||
|
||||
# 模型访问器
|
||||
@pyqtProperty('QObject*', constant=True)
|
||||
def monitorModel(self):
|
||||
return self._monitor_model
|
||||
|
||||
@pyqtProperty('QObject*', constant=True)
|
||||
def dutModel(self):
|
||||
return self._dut_model
|
||||
|
||||
@pyqtProperty('QObject*', constant=True)
|
||||
def systemModel(self):
|
||||
return self._system_model
|
||||
|
||||
# 视图切换方法
|
||||
@pyqtSlot(str)
|
||||
def switchView(self, view_name):
|
||||
"""切换视图"""
|
||||
self.setCurrentView = view_name
|
||||
Reference in New Issue
Block a user