|
|
|
import sys
|
|
|
|
|
|
|
|
from PyQt5.QtWidgets import QApplication, QMainWindow, QDockWidget, QToolBar, QAction, QTabWidget, QGridLayout
|
|
|
|
from PyQt5.QtCore import Qt, QTimer
|
|
|
|
from PyQt5.QtGui import QIcon
|
|
|
|
from utils.DBModels.BaseModel import *
|
|
|
|
from model.ClientModel.Client import Client
|
|
|
|
from UI.DeviceWidget import DeviceWidget
|
|
|
|
from model.ProjectModel.DeviceManage import DevicesManange
|
|
|
|
|
|
|
|
class CommonHelper:
|
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def readQss(style):
|
|
|
|
with open(style,"r") as f:
|
|
|
|
return f.read()
|
|
|
|
|
|
|
|
|
|
|
|
class MainWindow(QMainWindow):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.devicesManange = DevicesManange()
|
|
|
|
self.initUI()
|
|
|
|
|
|
|
|
def initUI(self):
|
|
|
|
|
|
|
|
self.protocolTimer = QTimer()
|
|
|
|
self.protocolTimer.timeout.connect(self.readValues)
|
|
|
|
|
|
|
|
self.toolbar = QToolBar()
|
|
|
|
self.addToolBar(self.toolbar)
|
|
|
|
|
|
|
|
self.startProtocolBtn = QAction(self)
|
|
|
|
self.startProtocolBtn.setObjectName("startProtocolBtn")
|
|
|
|
self.startProtocolBtn.setIcon(QIcon('Static/startProtocol.png'))
|
|
|
|
self.startProtocolBtn.setIconText('开始通讯')
|
|
|
|
self.startProtocolBtn.setCheckable(True)
|
|
|
|
self.startProtocolBtn.triggered.connect(self.startProtocol)
|
|
|
|
|
|
|
|
self.loadProjectBtn = QAction('导入工程', self)
|
|
|
|
self.loadProjectBtn.setObjectName("loadProjectBtn")
|
|
|
|
self.loadProjectBtn.triggered.connect(self.loadProject)
|
|
|
|
|
|
|
|
# self.toolbar.addAction(self.loadProjectBtn)
|
|
|
|
self.toolbar.addAction(self.startProtocolBtn)
|
|
|
|
|
|
|
|
dpMasterDockWidget = QDockWidget('DP主站')
|
|
|
|
dpMasterDockWidget.setWidget(DeviceWidget(dpMasterDockWidget, self.devicesManange))
|
|
|
|
dpMasterDockWidget.setFeatures(QDockWidget.DockWidgetMovable | QDockWidget.DockWidgetFloatable) # type: ignore
|
|
|
|
|
|
|
|
dpSlaveDockWidget = QDockWidget('DP从站')
|
|
|
|
dpSlaveDockWidget.setWidget(DeviceWidget(dpSlaveDockWidget, self.devicesManange))
|
|
|
|
dpSlaveDockWidget.setFeatures(QDockWidget.DockWidgetMovable | QDockWidget.DockWidgetFloatable) # type: ignore
|
|
|
|
|
|
|
|
paMasterDockWidget = QDockWidget('PA主站')
|
|
|
|
paMasterDockWidget.setWidget(DeviceWidget(paMasterDockWidget, self.devicesManange))
|
|
|
|
paMasterDockWidget.setFeatures(QDockWidget.DockWidgetMovable | QDockWidget.DockWidgetFloatable) # type: ignore
|
|
|
|
|
|
|
|
paSlaveDockWidget = QDockWidget('PA从站')
|
|
|
|
paSlaveDockWidget.setWidget(DeviceWidget(paSlaveDockWidget, self.devicesManange))
|
|
|
|
paSlaveDockWidget.setFeatures(QDockWidget.DockWidgetMovable | QDockWidget.DockWidgetFloatable) # type: ignore
|
|
|
|
|
|
|
|
self.addDockWidget(Qt.TopDockWidgetArea, dpMasterDockWidget) # type: ignore
|
|
|
|
self.addDockWidget(Qt.TopDockWidgetArea, dpSlaveDockWidget) # type: ignore
|
|
|
|
self.addDockWidget(Qt.BottomDockWidgetArea, paMasterDockWidget) # type: ignore
|
|
|
|
self.addDockWidget(Qt.BottomDockWidgetArea, paSlaveDockWidget) # type: ignore
|
|
|
|
|
|
|
|
self.setWindowIcon(QIcon('Static/zhjt.ico'))
|
|
|
|
self.setWindowTitle("PROFIBUS")
|
|
|
|
self.resize(800, 600)
|
|
|
|
# self.showMaximized()
|
|
|
|
|
|
|
|
def startProtocol(self):
|
|
|
|
if self.startProtocolBtn.isCheckable():
|
|
|
|
self.startProtocolBtn.setText('停止通讯')
|
|
|
|
self.startProtocolBtn.setCheckable(False)
|
|
|
|
self.protocolTimer.start(500)
|
|
|
|
|
|
|
|
else:
|
|
|
|
self.startProtocolBtn.setText('开始通讯')
|
|
|
|
self.startProtocolBtn.setCheckable(True)
|
|
|
|
self.protocolTimer.stop()
|
|
|
|
|
|
|
|
def readValues(self):
|
|
|
|
self.devicesManange.readAreas()
|
|
|
|
dockWidgets = self.findChildren(QDockWidget) #找到四个dockWidget窗口
|
|
|
|
for dockWidget in dockWidgets:
|
|
|
|
if dockWidget.widget().deviceTabWidget.currentWidget().objectName() == 'initWidget':
|
|
|
|
print(dockWidget.widget().deviceTabWidget.currentWidget().objectName())
|
|
|
|
continue
|
|
|
|
|
|
|
|
areaTabWidget = dockWidget.widget().deviceTabWidget.currentWidget()#判断四个窗口里是否有deviceTabWidget
|
|
|
|
if areaTabWidget.currentWidget().objectName() == 'initWidget':
|
|
|
|
print(2)
|
|
|
|
continue
|
|
|
|
if areaTabWidget.currentWidget().state:
|
|
|
|
print(3)
|
|
|
|
continue
|
|
|
|
|
|
|
|
# masterAndSlave = dockWidget.windowTitle()[2:5]
|
|
|
|
# proType = dockWidget.windowTitle()
|
|
|
|
# dataType = dataTypeCombox.currentText()
|
|
|
|
# dataTypeAndModel = masterAndSlave + dataType
|
|
|
|
|
|
|
|
# if dataTypeAndModel in ['主站AI', '主站DI', '从站AO', '从站DO']:
|
|
|
|
# devicecurIndex = deviceTabWidget.currentIndex()
|
|
|
|
# deviceTabText = deviceTabWidget.tabText(devicecurIndex)
|
|
|
|
# try:
|
|
|
|
areacurindex = areaTabWidget.currentIndex()
|
|
|
|
# deviceName = deviceTabText + proType
|
|
|
|
buttonlayoutWidget = areaTabWidget.currentWidget().buttonWidgets#获取buttonlayout
|
|
|
|
buttonlayoutWidget.readValues(curIndex = areacurindex)
|
|
|
|
# except Exception as e:
|
|
|
|
# print(e)
|
|
|
|
|
|
|
|
|
|
|
|
def loadProject(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
Client.initDB()
|
|
|
|
window = MainWindow()
|
|
|
|
|
|
|
|
window.show()
|
|
|
|
sys.exit(app.exec_())
|