You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.9 KiB
Python
74 lines
2.9 KiB
Python
import re
|
|
from PyQt5.QtWidgets import QDialog, QFormLayout, QLineEdit, QDialogButtonBox, QMessageBox
|
|
from PyQt5.QtGui import QIcon
|
|
from PyQt5.QtCore import Qt
|
|
from utils.DBModels.DeviceModels import DeviceDB
|
|
|
|
class DeviceDialog(QDialog):
|
|
def __init__(self,dataTypeAndModel,parent=None):
|
|
super().__init__(parent)
|
|
self.dataTypeAndModel = dataTypeAndModel
|
|
self.initUI()
|
|
|
|
def initUI(self):
|
|
layout = QFormLayout()
|
|
|
|
deviceName = QLineEdit()
|
|
deviceName.setObjectName('deviceName')
|
|
|
|
pvUpperLimit = QLineEdit()
|
|
pvUpperLimit.setObjectName('pvUpperLimit')
|
|
|
|
pvLowerLimit = QLineEdit()
|
|
pvLowerLimit.setObjectName('pvLowerLimit')
|
|
|
|
pvUnit = QLineEdit()
|
|
pvUnit.setObjectName('pvUnit')
|
|
|
|
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):
|
|
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, pvUpperLimit, pvLowerLimit, pvUnit
|
|
|
|
def check_input(self):
|
|
titleName, pvUpperLimit, pvLowerLimit, pvUnit = self.getParameters()
|
|
deviceName = titleName + self.dataTypeAndModel
|
|
if not pvUpperLimit or not pvLowerLimit or not pvUnit or not deviceName:
|
|
QMessageBox.warning(self, '警告', '有值未输入。')
|
|
return
|
|
elif DeviceDB.getByName(deviceName):
|
|
print(DeviceDB.getByName(deviceName),2343)
|
|
QMessageBox.warning(self, '警告', '设备名重复')
|
|
return
|
|
elif not re.match(r'^[-+]?\d*\.?\d*$', pvUpperLimit) or not re.match(r'^[-+]?\d*\.?\d*$', pvLowerLimit):
|
|
QMessageBox.warning(self, '警告', '请输入数字。')
|
|
return
|
|
elif pvUpperLimit < pvLowerLimit:
|
|
QMessageBox.warning(self, '警告', '量程输入有误。')
|
|
return
|
|
else:
|
|
self.accept() # 所有输入都是数字且不为空时接受对话框 |