0205更新
parent
5a18962b20
commit
9df90d56a6
@ -1,9 +1,109 @@
|
|||||||
|
|
||||||
QMdiSubWindow {
|
QMdiSubWindow {
|
||||||
|
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
QPushButton#deviceAddButton, QPushButton#addareabutton {
|
||||||
|
|
||||||
|
color: #328ffc;
|
||||||
|
|
||||||
|
font-size: 17px;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
QTabBar::close-button {
|
||||||
|
|
||||||
|
image: url(Static/close.png);
|
||||||
|
|
||||||
|
subcontrol-origin: padding;
|
||||||
|
|
||||||
|
margin-top: 2px;
|
||||||
|
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTabBar::close-button:hover {
|
||||||
|
|
||||||
|
background-color: #cccccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QTabBar::tab:hover {
|
||||||
|
|
||||||
|
background-color: #809ac2;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QTabBar::tab{
|
||||||
|
|
||||||
|
background: #cbdeec;
|
||||||
|
|
||||||
|
border: 2px;
|
||||||
|
|
||||||
|
min-width: 200px;
|
||||||
|
|
||||||
|
min-height: 30px;
|
||||||
|
|
||||||
|
font: 17px;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
font-family: ".SFNSDisplay-Regular";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
QTabBar#areaTabBar::tab{
|
||||||
|
|
||||||
|
min-width: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
QTabBar::tab:selected {
|
||||||
|
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
|
||||||
|
font: bold;
|
||||||
|
|
||||||
|
border-radius: 3px;
|
||||||
|
|
||||||
|
margin-bottom: -4px
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QTabWidget#deviceTabWidget::pane {
|
||||||
|
|
||||||
|
border: 1px solid #a8a8a8;
|
||||||
|
|
||||||
|
border-radius: 3px;
|
||||||
|
|
||||||
|
margin: 2px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QDockWidget{
|
||||||
|
|
||||||
|
font: 18px;
|
||||||
|
|
||||||
|
font: bold;
|
||||||
|
|
||||||
|
font-family: ".SFNSDisplay-Regular";
|
||||||
|
}
|
||||||
|
|
||||||
|
QDockWidget::title{
|
||||||
|
|
||||||
|
background-color: #cbdeec;
|
||||||
|
color: white;
|
||||||
|
|
||||||
|
text-align: center;
|
||||||
|
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 242 B |
@ -0,0 +1,45 @@
|
|||||||
|
from PyQt5.QtWidgets import QDialog, QFormLayout, QLineEdit, QDialogButtonBox, QMessageBox
|
||||||
|
from PyQt5.QtGui import QIcon
|
||||||
|
from PyQt5.QtCore import Qt
|
||||||
|
|
||||||
|
class DeviceDialog(QDialog):
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
|
||||||
|
self.initUI()
|
||||||
|
|
||||||
|
def initUI(self):
|
||||||
|
layout = QFormLayout()
|
||||||
|
|
||||||
|
deviceName = QLineEdit()
|
||||||
|
deviceName.setObjectName('deviceName')
|
||||||
|
|
||||||
|
layout.addRow("设备名:", deviceName)
|
||||||
|
|
||||||
|
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
||||||
|
ok_button = button_box.button(QDialogButtonBox.Ok)
|
||||||
|
ok_button.setText("确定") # 设置Ok按钮的文本
|
||||||
|
|
||||||
|
cancel_button = button_box.button(QDialogButtonBox.Cancel)
|
||||||
|
cancel_button.setText("取消") # 设置Cancel按钮的文本
|
||||||
|
|
||||||
|
button_box.accepted.connect(self.check_input)
|
||||||
|
button_box.rejected.connect(self.reject)
|
||||||
|
|
||||||
|
layout.addRow(button_box)
|
||||||
|
|
||||||
|
self.setWindowIcon(QIcon('Static/zhjt.ico'))
|
||||||
|
self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # 去掉标题栏的问号
|
||||||
|
self.setLayout(layout)
|
||||||
|
self.setWindowTitle("设备信息")
|
||||||
|
|
||||||
|
def getParameters(self):
|
||||||
|
deviceName = self.findChild(QLineEdit, "deviceName").text()
|
||||||
|
return deviceName
|
||||||
|
|
||||||
|
def check_input(self):
|
||||||
|
deviceName = self.getParameters()
|
||||||
|
if not deviceName:
|
||||||
|
QMessageBox.warning(self, '警告', '请输入设备名')
|
||||||
|
else:
|
||||||
|
self.accept() # 所有输入都是数字且不为空时接受对话框
|
||||||
@ -1,74 +1,158 @@
|
|||||||
from PyQt5.QtWidgets import QDialog, QFormLayout, QLineEdit, QComboBox, QDialogButtonBox, QMessageBox
|
import json
|
||||||
from PyQt5.QtGui import QPixmap, QIcon
|
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtWidgets import QMainWindow, QDialog, QTabWidget, QPushButton, QSpacerItem, QSizePolicy,QMessageBox, QHBoxLayout, QWidget
|
||||||
import sys
|
from PyQt5.QtGui import QIcon
|
||||||
import re
|
|
||||||
class DeviceDialog(QDialog):
|
from UI.DeviceDialogWidget import DeviceDialog
|
||||||
def __init__(self, parent=None):
|
|
||||||
super().__init__(parent)
|
from model.ProjectModel.DeviceManage import DevicesManange
|
||||||
|
from utils.DBModels.BaseModel import *
|
||||||
|
from UI.AreaTabWidget import AreaTabWidget
|
||||||
|
from utils.DBModels.DeviceModels import DeviceDB
|
||||||
|
from model.ProjectModel.DeviceManage import DevicesManange
|
||||||
|
from UI.DeviceDialogWidget import DeviceDialog
|
||||||
|
from model.ProjectModel.DeviceWidgetManage import DeviceWidgetManage
|
||||||
|
class DeviceWidget(QMainWindow):
|
||||||
|
def __init__(self, dockWidget):
|
||||||
|
super().__init__()
|
||||||
|
self.dockWidget = dockWidget
|
||||||
|
self.forceValues = []
|
||||||
self.initUI()
|
self.initUI()
|
||||||
|
|
||||||
|
|
||||||
def initUI(self):
|
def initUI(self):
|
||||||
layout = QFormLayout()
|
#获取DP、PA协议和主从模式
|
||||||
proType = QComboBox()
|
|
||||||
proType.addItems(['DP', 'PA'])
|
self.proType = self.dockWidget.windowTitle()[0:2]
|
||||||
proType.setObjectName('ProtocolType')
|
self.masterSlaveModel = self.dockWidget.windowTitle()[2:4]
|
||||||
masterSlaveModel = QComboBox()
|
|
||||||
masterSlaveModel.addItems(['主站', '从站'])
|
# self.deviceWidgetManage = DeviceWidgetManage()
|
||||||
masterSlaveModel.setObjectName('masterSlaveModel')
|
self.deviceTabWidget = QTabWidget(self)
|
||||||
|
self.deviceTabWidget.setObjectName('deviceTabWidget')
|
||||||
deviceName = QLineEdit()
|
|
||||||
deviceName.setObjectName('deviceName')
|
|
||||||
|
self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
|
||||||
pvUpperLimit = QLineEdit()
|
self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
|
||||||
pvUpperLimit.setObjectName('pvUpperLimit')
|
|
||||||
|
self.addDeviceButton = QPushButton('添加设备 ')
|
||||||
pvLowerLimit = QLineEdit()
|
self.addDeviceButton.setObjectName('deviceAddButton')
|
||||||
pvLowerLimit.setObjectName('pvLowerLimit')
|
self.addDeviceButton.setIcon(QIcon('Static/add.png'))
|
||||||
|
self.addDeviceButton.setFlat(True)
|
||||||
pvUnit = QLineEdit()
|
self.addDeviceButton.clicked.connect(self.addDeviceWidget)
|
||||||
pvUnit.setObjectName('pvUnit')
|
|
||||||
|
self.deviceTabWidget.setCornerWidget(self.addDeviceButton)
|
||||||
layout.addRow('协议类型', proType)
|
self.deviceTabWidget.setTabsClosable(True)
|
||||||
layout.addRow('主从模式', masterSlaveModel)
|
self.deviceTabWidget.tabCloseRequested.connect(self.closeTab)
|
||||||
layout.addRow("设备名:", deviceName)
|
|
||||||
layout.addRow("量程上限:", pvUpperLimit)
|
self.initWidget()
|
||||||
layout.addRow("量程下限:", pvLowerLimit)
|
|
||||||
layout.addRow("单位:", pvUnit)
|
# 设置主窗口的中心部分为 QTabWidget
|
||||||
|
self.setCentralWidget(self.deviceTabWidget)
|
||||||
|
|
||||||
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
def closeTab(self, index):
|
||||||
ok_button = button_box.button(QDialogButtonBox.Ok)
|
reply = QMessageBox.question(self, 'Confirmation', '确定删掉此设备吗?',
|
||||||
ok_button.setText("确定") # 设置Ok按钮的文本
|
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
|
||||||
cancel_button = button_box.button(QDialogButtonBox.Cancel)
|
if reply == QMessageBox.Yes:
|
||||||
cancel_button.setText("取消") # 设置Cancel按钮的文本
|
if index != -1:
|
||||||
|
self.deviceTabWidget.removeTab(index)
|
||||||
button_box.accepted.connect(self.check_input)
|
DeviceDB.deleteDevice(deviceName = self.deviceName)
|
||||||
button_box.rejected.connect(self.reject)
|
else:
|
||||||
|
return
|
||||||
layout.addRow(button_box)
|
if self.deviceTabWidget.count() == 0:
|
||||||
self.setWindowIcon(QIcon('Static/zhjt.ico'))
|
self.initWidget()
|
||||||
self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # 去掉标题栏的问号
|
|
||||||
self.setLayout(layout)
|
|
||||||
self.setWindowTitle("设备信息")
|
|
||||||
|
def addDeviceWidget(self,init = False,deviceName = None):
|
||||||
def getParameters(self):
|
if deviceName is None:
|
||||||
proType = self.findChild(QComboBox, "ProtocolType").currentText()
|
dialog = DeviceDialog()
|
||||||
masterSlaveModel = self.findChild(QComboBox, "masterSlaveModel").currentText()
|
if dialog.exec_() == QDialog.Accepted:
|
||||||
deviceName = self.findChild(QLineEdit, "deviceName").text()
|
self.titleName = dialog.getParameters()
|
||||||
pvUpperLimit = self.findChild(QLineEdit, "pvUpperLimit").text()
|
self.deviceName = self.titleName + self.dockWidget.windowTitle()
|
||||||
pvLowerLimit = self.findChild(QLineEdit, "pvLowerLimit").text()
|
DeviceDB().addDevice(deviceName = self.deviceName, proType = self.proType , masterSlaveModel = self.masterSlaveModel)
|
||||||
pvUnit = self.findChild(QLineEdit, "pvUnit").text()
|
areaTabWidget = AreaTabWidget(self)
|
||||||
return deviceName, proType, masterSlaveModel, pvUpperLimit, pvLowerLimit, pvUnit
|
if init:
|
||||||
|
self.deviceTabWidget.removeTab(0)
|
||||||
def check_input(self):
|
tabIndex = self.deviceTabWidget.count()
|
||||||
deviceName, proType, masterSlaveModel, pvUpperLimit, pvLowerLimit, pvUnit = self.getParameters()
|
self.deviceTabWidget.tabBar().setHidden(False)
|
||||||
|
self.deviceTabWidget.addTab(areaTabWidget,str(self.titleName))
|
||||||
if not pvUpperLimit or not pvLowerLimit or not pvUnit or not deviceName:
|
self.deviceTabWidget.setCurrentIndex(tabIndex)
|
||||||
QMessageBox.warning(self, '警告', '有值未输入。')
|
# self.deviceWidgetManage.addDevice(deviceName = self.deviceName, areaTabWidget=areaTabWidget, dockWidget=self.dockWidget)
|
||||||
elif not re.match(r'^[-+]?\d*\.?\d*$', pvUpperLimit) or not re.match(r'^[-+]?\d*\.?\d*$', pvLowerLimit):
|
else:
|
||||||
QMessageBox.warning(self, '警告', '请输入数字。')
|
return
|
||||||
elif pvUpperLimit < pvLowerLimit:
|
else:
|
||||||
QMessageBox.warning(self, '警告', '量程输入有误。')
|
self.deviceTabWidget.removeTab(0)
|
||||||
|
self.deviceName = deviceName
|
||||||
|
self.titleName = self.deviceName[:-4]
|
||||||
|
areaTabWidget = AreaTabWidget(self)
|
||||||
|
self.deviceTabWidget.tabBar().setHidden(False)
|
||||||
|
self.deviceTabWidget.addTab(areaTabWidget,str(self.titleName))
|
||||||
|
|
||||||
|
|
||||||
|
def initWidget(self):
|
||||||
|
widget = QWidget()
|
||||||
|
layout = QHBoxLayout()
|
||||||
|
addButton = QPushButton('添加设备')
|
||||||
|
addButton.clicked.connect(lambda: self.addDeviceWidget(True))
|
||||||
|
layout.addItem(self.horizontalSpacer)
|
||||||
|
layout.addWidget(addButton)
|
||||||
|
layout.addItem(self.horizontalSpacer)
|
||||||
|
widget.setLayout(layout)
|
||||||
|
self.deviceTabWidget.addTab(widget,'')
|
||||||
|
self.deviceTabWidget.tabBar().setHidden(True)
|
||||||
|
|
||||||
|
alldevices = DevicesManange.getAllDevice()
|
||||||
|
titleName = self.dockWidget.windowTitle()
|
||||||
|
if alldevices:
|
||||||
|
for devices in alldevices:
|
||||||
|
# self.devicesManange.addDevice(proType = devices[1], masterSlaveModel = devices[2], deviceName = devices[0])
|
||||||
|
deviceName = devices[0]
|
||||||
|
if titleName in deviceName:
|
||||||
|
self.addDeviceWidget(deviceName=deviceName)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def initAreaWidget(self, mdiarea):
|
||||||
|
alldevices = DevicesManange.getAllDevice()
|
||||||
|
for devices in alldevices:
|
||||||
|
areas = devices[3]
|
||||||
|
|
||||||
|
deviceWidget = self.deviceWidget(devices[0], mdiarea) #新建deviceWidget
|
||||||
|
areaTabWidget = deviceWidget.widget().widget().centralWidget() # type: ignore
|
||||||
|
self.devicesManange.addDevice(proType = devices[1], masterSlaveModel = devices[2], deviceName = devices[0], deviceWidget = deviceWidget, areaTabWidget = areaTabWidget) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
|
if areas is not None:
|
||||||
|
areas = json.loads(areas)
|
||||||
|
for area in areas:
|
||||||
|
dataType, order = self.tran(area["type"], area["order"])
|
||||||
|
channelBytes = area["bytes"]
|
||||||
|
dev = self.devicesManange.getDevice(deviceName = devices[0])
|
||||||
|
dev.addArea(type = area["type"], order = area["order"], bytes = int(channelBytes), nums = 1) #添加area
|
||||||
|
areaTabWidget.initAreaTab(dataType, order, channelBytes)
|
||||||
|
self.devicesManange.recalculateAddress()
|
||||||
|
|
||||||
|
def createDeciveWidget(self, mdiarea):
|
||||||
|
dialog = DeviceDialog()
|
||||||
|
|
||||||
|
if dialog.exec_() == QDialog.Accepted:
|
||||||
|
deviceName, proType, masterSlaveModel, pvUpperLimit, pvLowerLimit, pvUnit = dialog.getParameters()
|
||||||
|
windowTitle = deviceName + ' ' + proType + masterSlaveModel + ' ' + pvLowerLimit + '-' + pvUpperLimit + pvUnit
|
||||||
|
DeviceDB().addDevice(deviceName = windowTitle, proType = proType, masterSlaveModel = masterSlaveModel, pvUpperLimit=pvUpperLimit, pvLowerLimit=pvLowerLimit, pvUnit=pvUnit)
|
||||||
|
deviceWidget = self.deviceWidget(windowTitle, mdiarea)
|
||||||
|
areaTabWidget = deviceWidget.widget().widget().centralWidget()
|
||||||
|
self.devicesManange.addDevice(proType = proType, masterSlaveModel = masterSlaveModel, deviceName = windowTitle, deviceWidget = deviceName, areaTabWidget = areaTabWidget)
|
||||||
|
self.devicesManange.recalculateAddress()
|
||||||
else:
|
else:
|
||||||
self.accept() # 所有输入都是数字且不为空时接受对话框
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
111111111111111111111111
|
||||||
|
|
||||||
|
111111111111111111111111
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
class Area():
|
||||||
|
mainLayout = None
|
||||||
|
leftLayoutWidget = []
|
||||||
|
rightLayoutWidget = []
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Device():
|
||||||
|
deviceName = None
|
||||||
|
areaTabWidget = None
|
||||||
|
dockWidget = None
|
||||||
|
|
||||||
|
class DeviceWidgetManage():
|
||||||
|
|
||||||
|
def addDevice(self,deviceName, areaTabWidget, dockWidget):
|
||||||
|
Device.deviceName = deviceName
|
||||||
|
Device.areaTabWidget = areaTabWidget
|
||||||
|
Device.dockWidget = dockWidget
|
||||||
|
|
||||||
|
def getDeviceName(self):
|
||||||
|
return Device.deviceName
|
||||||
|
|
||||||
|
def addArea(self, mainLayout=None, leftLayoutWidget=None, rightLayoutWidget=None):
|
||||||
|
|
||||||
|
if mainLayout is not None:
|
||||||
|
Area.mainLayout = mainLayout
|
||||||
|
if leftLayoutWidget is not None:
|
||||||
|
Area.leftLayoutWidget = leftLayoutWidget
|
||||||
|
if rightLayoutWidget is not None:
|
||||||
|
Area.rightLayoutWidget = rightLayoutWidget
|
||||||
|
|
||||||
|
def getAreaTabWidget(self):
|
||||||
|
return Device.areaTabWidget
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
class Solution(object):
|
||||||
|
def twoSum(self, nums, target):
|
||||||
|
"""
|
||||||
|
:type nums: List[int]
|
||||||
|
:type target: int
|
||||||
|
:rtype: List[int]
|
||||||
|
"""
|
||||||
|
|
||||||
|
for i in range(0, len(nums)):
|
||||||
|
for j in range(1, len(nums)):
|
||||||
|
if nums[i] + nums[j] == target:
|
||||||
|
print([i,j])
|
||||||
|
|
||||||
|
solution = Solution()
|
||||||
|
solution.twoSum([2,7,11,15], 9)
|
||||||
Loading…
Reference in New Issue