0205更新
parent
5a18962b20
commit
9df90d56a6
@ -1,9 +1,109 @@
|
||||
|
||||
QMdiSubWindow {
|
||||
|
||||
font-size: 18px;
|
||||
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
|
||||
from PyQt5.QtGui import QPixmap, QIcon
|
||||
from PyQt5.QtCore import Qt
|
||||
import sys
|
||||
import re
|
||||
class DeviceDialog(QDialog):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.initUI()
|
||||
import json
|
||||
|
||||
from PyQt5.QtWidgets import QMainWindow, QDialog, QTabWidget, QPushButton, QSpacerItem, QSizePolicy,QMessageBox, QHBoxLayout, QWidget
|
||||
from PyQt5.QtGui import QIcon
|
||||
|
||||
from UI.DeviceDialogWidget import DeviceDialog
|
||||
|
||||
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()
|
||||
|
||||
|
||||
def initUI(self):
|
||||
layout = QFormLayout()
|
||||
proType = QComboBox()
|
||||
proType.addItems(['DP', 'PA'])
|
||||
proType.setObjectName('ProtocolType')
|
||||
masterSlaveModel = QComboBox()
|
||||
masterSlaveModel.addItems(['主站', '从站'])
|
||||
masterSlaveModel.setObjectName('masterSlaveModel')
|
||||
|
||||
deviceName = QLineEdit()
|
||||
deviceName.setObjectName('deviceName')
|
||||
|
||||
pvUpperLimit = QLineEdit()
|
||||
pvUpperLimit.setObjectName('pvUpperLimit')
|
||||
|
||||
pvLowerLimit = QLineEdit()
|
||||
pvLowerLimit.setObjectName('pvLowerLimit')
|
||||
|
||||
pvUnit = QLineEdit()
|
||||
pvUnit.setObjectName('pvUnit')
|
||||
|
||||
layout.addRow('协议类型', proType)
|
||||
layout.addRow('主从模式', masterSlaveModel)
|
||||
layout.addRow("设备名:", deviceName)
|
||||
layout.addRow("量程上限:", pvUpperLimit)
|
||||
layout.addRow("量程下限:", pvLowerLimit)
|
||||
layout.addRow("单位:", pvUnit)
|
||||
|
||||
|
||||
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):
|
||||
proType = self.findChild(QComboBox, "ProtocolType").currentText()
|
||||
masterSlaveModel = self.findChild(QComboBox, "masterSlaveModel").currentText()
|
||||
deviceName = self.findChild(QLineEdit, "deviceName").text()
|
||||
pvUpperLimit = self.findChild(QLineEdit, "pvUpperLimit").text()
|
||||
pvLowerLimit = self.findChild(QLineEdit, "pvLowerLimit").text()
|
||||
pvUnit = self.findChild(QLineEdit, "pvUnit").text()
|
||||
return deviceName, proType, masterSlaveModel, pvUpperLimit, pvLowerLimit, pvUnit
|
||||
|
||||
def check_input(self):
|
||||
deviceName, proType, masterSlaveModel, pvUpperLimit, pvLowerLimit, pvUnit = self.getParameters()
|
||||
|
||||
if not pvUpperLimit or not pvLowerLimit or not pvUnit or not deviceName:
|
||||
QMessageBox.warning(self, '警告', '有值未输入。')
|
||||
elif not re.match(r'^[-+]?\d*\.?\d*$', pvUpperLimit) or not re.match(r'^[-+]?\d*\.?\d*$', pvLowerLimit):
|
||||
QMessageBox.warning(self, '警告', '请输入数字。')
|
||||
elif pvUpperLimit < pvLowerLimit:
|
||||
QMessageBox.warning(self, '警告', '量程输入有误。')
|
||||
#获取DP、PA协议和主从模式
|
||||
|
||||
self.proType = self.dockWidget.windowTitle()[0:2]
|
||||
self.masterSlaveModel = self.dockWidget.windowTitle()[2:4]
|
||||
|
||||
# self.deviceWidgetManage = DeviceWidgetManage()
|
||||
self.deviceTabWidget = QTabWidget(self)
|
||||
self.deviceTabWidget.setObjectName('deviceTabWidget')
|
||||
|
||||
|
||||
self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
|
||||
self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
|
||||
|
||||
self.addDeviceButton = QPushButton('添加设备 ')
|
||||
self.addDeviceButton.setObjectName('deviceAddButton')
|
||||
self.addDeviceButton.setIcon(QIcon('Static/add.png'))
|
||||
self.addDeviceButton.setFlat(True)
|
||||
self.addDeviceButton.clicked.connect(self.addDeviceWidget)
|
||||
|
||||
self.deviceTabWidget.setCornerWidget(self.addDeviceButton)
|
||||
self.deviceTabWidget.setTabsClosable(True)
|
||||
self.deviceTabWidget.tabCloseRequested.connect(self.closeTab)
|
||||
|
||||
self.initWidget()
|
||||
|
||||
# 设置主窗口的中心部分为 QTabWidget
|
||||
self.setCentralWidget(self.deviceTabWidget)
|
||||
|
||||
def closeTab(self, index):
|
||||
reply = QMessageBox.question(self, 'Confirmation', '确定删掉此设备吗?',
|
||||
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
|
||||
if reply == QMessageBox.Yes:
|
||||
if index != -1:
|
||||
self.deviceTabWidget.removeTab(index)
|
||||
DeviceDB.deleteDevice(deviceName = self.deviceName)
|
||||
else:
|
||||
return
|
||||
if self.deviceTabWidget.count() == 0:
|
||||
self.initWidget()
|
||||
|
||||
|
||||
|
||||
def addDeviceWidget(self,init = False,deviceName = None):
|
||||
if deviceName is None:
|
||||
dialog = DeviceDialog()
|
||||
if dialog.exec_() == QDialog.Accepted:
|
||||
self.titleName = dialog.getParameters()
|
||||
self.deviceName = self.titleName + self.dockWidget.windowTitle()
|
||||
DeviceDB().addDevice(deviceName = self.deviceName, proType = self.proType , masterSlaveModel = self.masterSlaveModel)
|
||||
areaTabWidget = AreaTabWidget(self)
|
||||
if init:
|
||||
self.deviceTabWidget.removeTab(0)
|
||||
tabIndex = self.deviceTabWidget.count()
|
||||
self.deviceTabWidget.tabBar().setHidden(False)
|
||||
self.deviceTabWidget.addTab(areaTabWidget,str(self.titleName))
|
||||
self.deviceTabWidget.setCurrentIndex(tabIndex)
|
||||
# self.deviceWidgetManage.addDevice(deviceName = self.deviceName, areaTabWidget=areaTabWidget, dockWidget=self.dockWidget)
|
||||
else:
|
||||
return
|
||||
else:
|
||||
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:
|
||||
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