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.
PROFIBUS/UI/DelAreaWidget.py

98 lines
3.3 KiB
Python

2 years ago
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
2 years ago
from UI.AreaSettingWidget import AreaSettingWidget
2 years ago
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap, QIcon
import sys
2 years ago
from model.ProjectModel.DeviceManage import Device
2 years ago
class DelAreaWidget(QDialog):
2 years ago
def __init__(self, deviceName):
2 years ago
super().__init__()
self.checkbox_data ={}
self.deviceName = deviceName
self.delAreaRowAndColunm = []
self.initUI()
def initUI(self):
vorlayout = QVBoxLayout() #主布局
2 years ago
# 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
2 years ago
checkbox = QCheckBox(text)
2 years ago
vorlayout.addWidget(checkbox)
2 years ago
checkbox.stateChanged.connect(self.checkbox_state_changed)
2 years ago
self.checkbox_data[checkbox] = row
row += 1
# for i in self.areaLabel:
# if self.deviceName in i:
# widget = i[2]
# row = i[3]
# text = widget.text()
# column = i[4]
# checkbox = QCheckBox(text)
#
# if column > 0:
# vorlayout.addWidget(checkbox)
#
# else:
# vorlayout.addWidget(checkbox)
# self.checkbox_data[checkbox] = [row, column]
2 years ago
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
2 years ago
ok_button = button_box.button(QDialogButtonBox.Ok)
ok_button.setText("确定") # 设置Ok按钮的文本
cancel_button = button_box.button(QDialogButtonBox.Cancel)
cancel_button.setText("取消") # 设置Cancel按钮的文本
2 years ago
button_box.accepted.connect(self.getDelAreaRowAndColunm)
button_box.rejected.connect(self.reject)
vorlayout.addWidget(button_box)
2 years ago
self.setWindowIcon(QIcon('Static/zhjt.ico'))
2 years ago
self.setWindowTitle("删除通道")
self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint)#去掉标题栏的问号
self.setLayout(vorlayout)
2 years ago
2 years ago
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):
2 years ago
self.accept()
2 years ago
return self.delAreaRowAndColunm
if __name__ == '__main__':
app = QApplication(sys.argv)
# Client.initDB()
window = DelAreaWidget()
window.show()
sys.exit(app.exec_())