0311更新
parent
0e55c20ff2
commit
f603f2816f
@ -1,76 +0,0 @@
|
|||||||
from PyQt5.QtWidgets import QDialog, QFormLayout, QLineEdit, QComboBox, QDialogButtonBox, QApplication, QMessageBox
|
|
||||||
from PyQt5.QtGui import QPixmap, QIcon
|
|
||||||
from PyQt5.QtCore import Qt
|
|
||||||
import sys
|
|
||||||
import re
|
|
||||||
class AreaSettingWidget(QDialog):
|
|
||||||
def __init__(self, parent=None):
|
|
||||||
super().__init__(parent)
|
|
||||||
self.initUI()
|
|
||||||
|
|
||||||
def initUI(self):
|
|
||||||
layout = QFormLayout()
|
|
||||||
varType = QComboBox()
|
|
||||||
varType.addItems(['AI', 'AO', 'DI', 'DO'])
|
|
||||||
varType.setObjectName('varType')
|
|
||||||
|
|
||||||
channelNums = QLineEdit()
|
|
||||||
channelNums.setObjectName('channelNums')
|
|
||||||
|
|
||||||
channelBytes = QLineEdit()
|
|
||||||
channelBytes.setObjectName('channelBytes')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
layout.addRow('协议类型:', varType)
|
|
||||||
layout.addRow('通道数:', channelNums)
|
|
||||||
layout.addRow("字节长度:", channelBytes)
|
|
||||||
|
|
||||||
|
|
||||||
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):
|
|
||||||
varType = self.findChild(QComboBox, "varType").currentText()
|
|
||||||
channelNums = self.findChild(QLineEdit, "channelNums").text()
|
|
||||||
channelBytes = self.findChild(QLineEdit, "channelBytes").text()
|
|
||||||
|
|
||||||
return varType, channelNums, channelBytes
|
|
||||||
|
|
||||||
def check_input(self):
|
|
||||||
varType, channelNums, channelBytes = self.getParameters()
|
|
||||||
|
|
||||||
if not channelNums or not channelBytes:
|
|
||||||
QMessageBox.warning(self, '警告', '有值未输入。')
|
|
||||||
elif not re.match(r'^[-+]?\d*\.?\d*$', channelNums) or not re.match(r'^[-+]?\d*\.?\d*$', channelBytes):
|
|
||||||
QMessageBox.warning(self, '警告', '请输入数字。')
|
|
||||||
else:
|
|
||||||
self.accept() # 所有输入都是数字且不为空时接受对话框
|
|
||||||
|
|
||||||
def dataTypeTranslate(self, order):
|
|
||||||
self.dataTypeDict = {'不转换': 'ABCD', '字节转换': 'DCBA', '字转换': 'CDAB', '字转换': 'BADC'}
|
|
||||||
return self.dataTypeDict[order]
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
app = QApplication(sys.argv)
|
|
||||||
window = AreaSettingWidget()
|
|
||||||
window.show()
|
|
||||||
sys.exit(app.exec_())
|
|
@ -1,61 +0,0 @@
|
|||||||
from PyQt5.QtWidgets import QApplication, QMainWindow, QToolBar, QMdiArea, QAction, QInputDialog, QDialog, QFormLayout, QLineEdit, \
|
|
||||||
QMdiSubWindow, QDialogButtonBox, QWidget, QComboBox, QTabBar, QTabWidget, QGridLayout, QLabel, QPushButton, QSpacerItem,QSizePolicy
|
|
||||||
from AreaSettingWidget import AreaSettingWidget
|
|
||||||
|
|
||||||
import sys
|
|
||||||
|
|
||||||
class AreaWidget(QWidget):
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
self.initUI()
|
|
||||||
|
|
||||||
def initUI(self):
|
|
||||||
|
|
||||||
self.sub_window = QMdiSubWindow() # 创建一个子窗口
|
|
||||||
self.layoutAI = QGridLayout()
|
|
||||||
|
|
||||||
self.widget = QWidget()
|
|
||||||
self.widget.setLayout(self.layoutAI)
|
|
||||||
|
|
||||||
self.newbtn = QPushButton('New')
|
|
||||||
self.delbtn = QPushButton('Del')
|
|
||||||
self.layoutAI.addWidget(self.newbtn, 0, 0)
|
|
||||||
self.layoutAI.addWidget(self.delbtn, 0, 1)
|
|
||||||
self.newbtn.clicked.connect(lambda: self.newArea)
|
|
||||||
self.delbtn.clicked.connect(self.delArea)
|
|
||||||
|
|
||||||
|
|
||||||
self.layoutAI.addWidget(self.newbtn, 0, 0, 1, 1)
|
|
||||||
|
|
||||||
|
|
||||||
self.layoutAI.addWidget(self.delbtn, 0, 2, 1, 1)
|
|
||||||
|
|
||||||
self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
|
|
||||||
|
|
||||||
self.layoutAI.addItem(self.horizontalSpacer, 0, 1, 1, 1)
|
|
||||||
|
|
||||||
self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
|
|
||||||
|
|
||||||
self.layoutAI.addItem(self.verticalSpacer, 1, 0, 1, 1)
|
|
||||||
|
|
||||||
# self.sub_window.setGeometry(100, 100, 400, 300)
|
|
||||||
self.sub_window.setWidget(self.widget)
|
|
||||||
|
|
||||||
def newArea(self):
|
|
||||||
# print(1)
|
|
||||||
areaSettingWidget = AreaSettingWidget()
|
|
||||||
if areaSettingWidget.exec_() == QDialog.Accepted:
|
|
||||||
deviceName, proType, varType = areaSettingWidget.getParameters()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def delArea(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
app = QApplication(sys.argv)
|
|
||||||
window = AreaWidget()
|
|
||||||
window.show()
|
|
||||||
sys.exit(app.exec_())
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
|||||||
from PyQt5.QtWidgets import QApplication, QMainWindow, QToolBar, QMdiArea, QAction, QInputDialog, QDialog, QFormLayout, QLineEdit, \
|
|
||||||
QMdiSubWindow, QDialogButtonBox, QWidget, QComboBox, QTabBar, QTabWidget, QGridLayout, QLabel, QPushButton, QSpacerItem,QSizePolicy, QCheckBox, QVBoxLayout
|
|
||||||
from UI.AreaSettingWidget import AreaSettingWidget
|
|
||||||
from PyQt5.QtCore import Qt
|
|
||||||
from PyQt5.QtGui import QPixmap, QIcon
|
|
||||||
import sys
|
|
||||||
|
|
||||||
from model.ProjectModel.DeviceManage import Device
|
|
||||||
|
|
||||||
|
|
||||||
class DelAreaWidget(QDialog):
|
|
||||||
def __init__(self, deviceName):
|
|
||||||
super().__init__()
|
|
||||||
self.checkbox_data ={}
|
|
||||||
self.deviceName = deviceName
|
|
||||||
self.delAreaRowAndColunm = []
|
|
||||||
self.initUI()
|
|
||||||
|
|
||||||
self.intType = 0
|
|
||||||
self.foloatType = 1
|
|
||||||
def initUI(self):
|
|
||||||
vorlayout = QVBoxLayout() #主布局
|
|
||||||
# layout = QGridLayout()
|
|
||||||
jsonCons = Device.getAreaJson(self.deviceName)
|
|
||||||
|
|
||||||
row = 1
|
|
||||||
if jsonCons is None:
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
for jsoncon in jsonCons:
|
|
||||||
varType = jsoncon["type"]
|
|
||||||
channelNums = jsoncon["nums"]
|
|
||||||
channelBytes = jsoncon["bytes"]
|
|
||||||
text = varType + ": " + channelBytes + 'Byte' + '数量:'+ channelNums
|
|
||||||
checkbox = QCheckBox(text)
|
|
||||||
vorlayout.addWidget(checkbox)
|
|
||||||
checkbox.stateChanged.connect(self.checkbox_state_changed)
|
|
||||||
self.checkbox_data[checkbox] = row
|
|
||||||
row += 1
|
|
||||||
|
|
||||||
|
|
||||||
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.getDelAreaRowAndColunm)
|
|
||||||
button_box.rejected.connect(self.reject)
|
|
||||||
vorlayout.addWidget(button_box)
|
|
||||||
|
|
||||||
self.setWindowIcon(QIcon('Static/zhjt.ico'))
|
|
||||||
self.setWindowTitle("删除通道")
|
|
||||||
self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint)#去掉标题栏的问号
|
|
||||||
self.setLayout(vorlayout)
|
|
||||||
|
|
||||||
|
|
||||||
def checkbox_state_changed(self, state):
|
|
||||||
sender = self.sender() # 获取触发信号的对象
|
|
||||||
if isinstance(sender, QCheckBox):
|
|
||||||
if state == 2: # 选中状态
|
|
||||||
self.delAreaRowAndColunm.append(self.checkbox_data[sender]) # 从字典中获取行列信息
|
|
||||||
|
|
||||||
elif state == 0: # 取消选中状态
|
|
||||||
self.delAreaRowAndColunm.remove(self.checkbox_data[sender])
|
|
||||||
|
|
||||||
def getDelAreaRowAndColunm(self):
|
|
||||||
self.accept()
|
|
||||||
return self.delAreaRowAndColunm
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
app = QApplication(sys.argv)
|
|
||||||
# Client.initDB()
|
|
||||||
window = DelAreaWidget()
|
|
||||||
|
|
||||||
window.show()
|
|
||||||
sys.exit(app.exec_())
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
|||||||
|
|
||||||
111111111111111111111111
|
|
||||||
|
|
||||||
111111111111111111111111
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue