0529更新
parent
9a3dee6735
commit
409404e112
Binary file not shown.
Binary file not shown.
@ -0,0 +1,112 @@
|
|||||||
|
|
||||||
|
from PyQt5.QtWidgets import QPushButton,QStackedWidget, QLineEdit, QVBoxLayout, QHBoxLayout, QWidget, QLabel, QSplitter
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
from utils.DBModels.DeviceParModels import *
|
||||||
|
from UI.BlockParameterView import PressureTBlockView, AIFunctionBlockView, PhysicalBlockView
|
||||||
|
from UI.SearchAddressWidget import SearchAddressWidget
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class BlockParameterManageWidget(QWidget):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.initUI()
|
||||||
|
|
||||||
|
|
||||||
|
def initUI(self):
|
||||||
|
self.pressureTBlockView = PressureTBlockView()
|
||||||
|
self.aiFunctionBlockView = AIFunctionBlockView()
|
||||||
|
self.physicalBlockView = PhysicalBlockView()
|
||||||
|
|
||||||
|
self.mainlayout = QVBoxLayout()
|
||||||
|
self.parameStackWidget = QStackedWidget()
|
||||||
|
self.settingLayout = QHBoxLayout()
|
||||||
|
self.deviceAddressLabel = QLabel('从站地址')
|
||||||
|
self.deviceAddressEdit = QLineEdit()
|
||||||
|
|
||||||
|
self.confirmBtn = QPushButton('确定')
|
||||||
|
self.confirmBtn.clicked.connect(self.testUI)
|
||||||
|
|
||||||
|
self.deviceAddressSearchBtn = QPushButton('查找')
|
||||||
|
self.deviceAddressSearchBtn.clicked.connect(self.searchAddress)
|
||||||
|
|
||||||
|
self.pblockBtn = QPushButton('物理块')
|
||||||
|
# self.pblockBtn.setCheckable(True)
|
||||||
|
self.pblockBtn.clicked.connect(lambda: self.switchParameterWidget('pblockBtn'))
|
||||||
|
|
||||||
|
self.fblockBtn = QPushButton('功能块')
|
||||||
|
self.fblockBtn.clicked.connect(lambda: self.switchParameterWidget('fblockBtn'))
|
||||||
|
# self.pblockBtn.setCheckable(True)
|
||||||
|
|
||||||
|
self.tblockBtn = QPushButton('转换块')
|
||||||
|
self.tblockBtn.clicked.connect(lambda: self.switchParameterWidget('tblockBtn'))
|
||||||
|
# self.tblockBtn.setCheckable(True)
|
||||||
|
|
||||||
|
|
||||||
|
self.settingLayout.addWidget(self.deviceAddressLabel, 1)
|
||||||
|
self.settingLayout.addWidget(self.deviceAddressEdit, 1)
|
||||||
|
self.settingLayout.addWidget(self.confirmBtn, 1)
|
||||||
|
self.settingLayout.addWidget(self.deviceAddressSearchBtn, 1)
|
||||||
|
self.settingLayout.addWidget(self.pblockBtn, 1)
|
||||||
|
self.settingLayout.addWidget(self.fblockBtn, 1)
|
||||||
|
self.settingLayout.addWidget(self.tblockBtn, 1)
|
||||||
|
self.settingLayout.addWidget(QSplitter(), 18)
|
||||||
|
|
||||||
|
|
||||||
|
self.mainlayout.addLayout(self.settingLayout,1)
|
||||||
|
|
||||||
|
self.parameStackWidget.addWidget(self.physicalBlockView)
|
||||||
|
self.parameStackWidget.addWidget(self.aiFunctionBlockView)
|
||||||
|
self.parameStackWidget.addWidget(self.pressureTBlockView)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
self.mainlayout.addWidget(self.parameStackWidget, 20)
|
||||||
|
|
||||||
|
# self.proxy = QtCore.QSortFilterProxyModel(self)
|
||||||
|
# self.parameTableView.proxy = self.proxy
|
||||||
|
# self.proxy.setSourceModel(self.parameTableView.model)
|
||||||
|
|
||||||
|
# self.parameTableView.setModel(self.proxy)
|
||||||
|
|
||||||
|
# datas = PressureTranslationBlock.getallParame()
|
||||||
|
# for index, data in enumerate(datas):
|
||||||
|
# desc = data[2].replace('\r\n', '').replace('\n', '')
|
||||||
|
# lines = [desc[i:i+50] + "\r\n" for i in range(0, len(desc), 50)]
|
||||||
|
# # 合并列表为一个字符串,移除最后一个换行符
|
||||||
|
# result = "".join(lines).rstrip("\r\n")
|
||||||
|
# data[2] = result
|
||||||
|
# data = data + ['', '', '']
|
||||||
|
# self.parameTableView.model.append_data(data)
|
||||||
|
# self.parameTableView.setVerticalHeader(ParamsVHeader(self, self.parameTableView.model.datas))
|
||||||
|
|
||||||
|
self.setLayout(self.mainlayout)
|
||||||
|
|
||||||
|
def switchParameterWidget(self,blockType):
|
||||||
|
match blockType:
|
||||||
|
case "pblockBtn":
|
||||||
|
self.parameStackWidget.setCurrentIndex(0)
|
||||||
|
case "fblockBtn":
|
||||||
|
self.parameStackWidget.setCurrentIndex(1)
|
||||||
|
case "tblockBtn":
|
||||||
|
self.parameStackWidget.setCurrentIndex(2)
|
||||||
|
|
||||||
|
def testUI(self):
|
||||||
|
model = self.parameStackWidget.currentWidget().model
|
||||||
|
model.updateColumn(5, '查询中...')
|
||||||
|
|
||||||
|
def searchAddress(self):
|
||||||
|
self.searchAddressWidget = SearchAddressWidget(self.deviceAddressEdit)
|
||||||
|
self.searchAddressWidget.show()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,210 @@
|
|||||||
|
import typing
|
||||||
|
import re
|
||||||
|
import qtawesome
|
||||||
|
from PyQt5 import QtGui,QtCore,QtWidgets
|
||||||
|
from PyQt5.QtCore import QAbstractTableModel, QModelIndex, Qt, QVariant, QSize
|
||||||
|
from PyQt5.QtWidgets import QItemDelegate, QHBoxLayout, QWidget, QPushButton, QMessageBox, QLineEdit, QComboBox, QStyledItemDelegate
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class VarTableModel(QAbstractTableModel):
|
||||||
|
''' 变量表模型类'''
|
||||||
|
def __init__(self, header, data: list, table = None):
|
||||||
|
'''
|
||||||
|
header : 表头变量
|
||||||
|
data : 表格内容
|
||||||
|
table : 缺省参数
|
||||||
|
'''
|
||||||
|
QAbstractTableModel.__init__(self, parent=None)
|
||||||
|
self.header = header
|
||||||
|
self.datas = data
|
||||||
|
self.checkList = ['Unchecked'] * len(self.datas)
|
||||||
|
self.supportedDragActions()
|
||||||
|
self.table = table
|
||||||
|
self.editableList = [] # 表格中可编辑项
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def append_data(self, x):
|
||||||
|
|
||||||
|
self.datas.append(x)
|
||||||
|
self.checkList = ['Unchecked'] * len(self.datas)
|
||||||
|
self.table.proxy.invalidate()
|
||||||
|
# self.layoutChanged.emit()
|
||||||
|
|
||||||
|
def insert_data(self, x, index):
|
||||||
|
self.datas.insert(index, x)
|
||||||
|
self.checkList = ['Unchecked'] * len(self.datas)
|
||||||
|
self.table.proxy.invalidate()
|
||||||
|
|
||||||
|
def updateColumn(self, column, value):
|
||||||
|
if column < 0 or column >= self.columnCount():
|
||||||
|
print("列索引超出范围")
|
||||||
|
return
|
||||||
|
for row in range(self.rowCount()):
|
||||||
|
self.datas[row][column] = value
|
||||||
|
self.table.proxy.invalidate()
|
||||||
|
# self.layoutChanged.emit() # 通知视图数据已更改
|
||||||
|
# self.dataChanged.emit()
|
||||||
|
|
||||||
|
def remove_row(self, row):
|
||||||
|
self.datas.pop(row)
|
||||||
|
self.checkList = ['UnChecked'] * len(self.datas)
|
||||||
|
self.table.proxy.invalidate()
|
||||||
|
|
||||||
|
def rowCount(self, parent: QModelIndex = ...) -> int:
|
||||||
|
if len(self.datas) > 0:
|
||||||
|
return len(self.datas)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def columnCount(self, parent: QModelIndex = ...) -> int:
|
||||||
|
return len(self.header)
|
||||||
|
|
||||||
|
def data(self, QModelIndex, role=None):
|
||||||
|
# print(Qt.__dict__.items())
|
||||||
|
if role == Qt.TextAlignmentRole:
|
||||||
|
return Qt.AlignCenter
|
||||||
|
if not QModelIndex.isValid():
|
||||||
|
print("行或者列有问题")
|
||||||
|
return QVariant()
|
||||||
|
|
||||||
|
if role == Qt.TextColorRole:
|
||||||
|
return QtGui.QColor('#1A1A1A')
|
||||||
|
|
||||||
|
if role == Qt.DisplayRole or role == Qt.EditRole:
|
||||||
|
if QModelIndex.row() in self.editableList or 'w' in self.datas[QModelIndex.row()][4]:
|
||||||
|
return self.datas[QModelIndex.row()][QModelIndex.column()]
|
||||||
|
if role != Qt.DisplayRole:
|
||||||
|
return QVariant()
|
||||||
|
|
||||||
|
|
||||||
|
return self.datas[QModelIndex.row()][QModelIndex.column()]
|
||||||
|
|
||||||
|
def headerData(self, section: int, orientation: Qt.Orientation, role: int = ...) -> typing.Any: # 表头
|
||||||
|
if role != Qt.DisplayRole:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if role == Qt.SizeHintRole:
|
||||||
|
# print(self.datas[QModelIndex.row()][QModelIndex.column()].find('\r\n'))
|
||||||
|
return QSize(500, 500)
|
||||||
|
|
||||||
|
if orientation == Qt.Horizontal:
|
||||||
|
return self.header[section]
|
||||||
|
|
||||||
|
# if orientation == Qt.Vertical:
|
||||||
|
# return str(section + 1)
|
||||||
|
|
||||||
|
def setData(self, index, value, role):
|
||||||
|
row = index.row()
|
||||||
|
col = index.column()
|
||||||
|
if role == Qt.EditRole:
|
||||||
|
self.datas[row][col] = value
|
||||||
|
return True
|
||||||
|
return True
|
||||||
|
|
||||||
|
def flags(self, index):
|
||||||
|
# if index.column() == 0:
|
||||||
|
# return Qt.ItemIsEnabled | Qt.ItemIsUserCheckable
|
||||||
|
if index.row() in self.editableList and index.column() or index.column() == 6:
|
||||||
|
return Qt.ItemIsEnabled | Qt.ItemIsUserCheckable | Qt.ItemIsEditable
|
||||||
|
|
||||||
|
|
||||||
|
if 'w' in self.datas[index.row()][4] and index.column() == 5:
|
||||||
|
return Qt.ItemIsEnabled | Qt.ItemIsEditable
|
||||||
|
|
||||||
|
return Qt.ItemIsEnabled
|
||||||
|
|
||||||
|
def dragMoveEvent(self, event):
|
||||||
|
event.setDropAction(QtCore.Qt.MoveAction)
|
||||||
|
event.accept()
|
||||||
|
|
||||||
|
def moveRow(self, sourceParent: QModelIndex, sourceRow: int, destinationParent: QModelIndex,
|
||||||
|
destinationChild: int) -> bool:
|
||||||
|
if self.datas[destinationChild] == self.datas[sourceRow]:
|
||||||
|
return
|
||||||
|
self.datas[sourceRow], self.datas[destinationChild] = self.datas[destinationChild], self.datas[sourceRow]
|
||||||
|
self.table.proxy.invalidate()
|
||||||
|
|
||||||
|
|
||||||
|
class VarButtonDelegate(QItemDelegate):
|
||||||
|
"""该类用于向单元格中添加按钮 任务表格"""
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super(VarButtonDelegate, self).__init__(parent)
|
||||||
|
|
||||||
|
def paint(self, painter, option, index):
|
||||||
|
if not self.parent().indexWidget(index):
|
||||||
|
button1 = QPushButton(
|
||||||
|
qtawesome.icon('fa.play', color='#1fbb6f'),
|
||||||
|
"",
|
||||||
|
self.parent()
|
||||||
|
)
|
||||||
|
|
||||||
|
if 'w' not in self.parent().model.datas[index.row()][4]:
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
button1.index = [index.row(), index.column()]
|
||||||
|
|
||||||
|
parameEditline = QLineEdit()
|
||||||
|
|
||||||
|
boxLayout = QHBoxLayout()
|
||||||
|
boxLayout.addWidget(parameEditline)
|
||||||
|
boxLayout.addWidget(button1)
|
||||||
|
|
||||||
|
button1.clicked.connect(lambda: self.startAction(parameEditline))
|
||||||
|
|
||||||
|
boxLayout.setContentsMargins(2, 0, 0, 2)
|
||||||
|
boxLayout.setAlignment(Qt.AlignCenter)
|
||||||
|
widget = QWidget()
|
||||||
|
widget.setLayout(boxLayout)
|
||||||
|
self.parent().setIndexWidget(
|
||||||
|
index,
|
||||||
|
widget
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def startAction(self, parameEditline):
|
||||||
|
sender = self.sender()
|
||||||
|
model = self.parent().model
|
||||||
|
# value = model.datas[sender.index[0]][sender.index[1]]
|
||||||
|
value = parameEditline.text()
|
||||||
|
pattern = re.compile(r'[^0-9\.-]+')
|
||||||
|
if not value or re.findall(pattern, str(value)):
|
||||||
|
reply = QMessageBox.question(self.parent(),
|
||||||
|
'警告',
|
||||||
|
"请输入强制值或数字",
|
||||||
|
QMessageBox.Yes)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
class ComboBoxDelegate(QStyledItemDelegate):
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super(ComboBoxDelegate, self).__init__(parent)
|
||||||
|
|
||||||
|
def createEditor(self, parent, option, index):
|
||||||
|
# 仅在第二列第二行创建编辑器
|
||||||
|
if index.row() == 5 and index.column() == 5:
|
||||||
|
comboBox = QComboBox(parent)
|
||||||
|
comboBox.addItems(["非服务", "手动初始化", "本地超驰", '手动', '自动', '级联', '远程级联', '远程输出'])
|
||||||
|
return comboBox
|
||||||
|
else:
|
||||||
|
return super().createEditor(parent, option, index)
|
||||||
|
|
||||||
|
def setEditorData(self, editor, index):
|
||||||
|
if index.row() == 5 and index.column() == 5:
|
||||||
|
# value = index.model().data(index, Qt.EditRole)
|
||||||
|
value = "非服务"
|
||||||
|
if value:
|
||||||
|
editor.setCurrentText(value)
|
||||||
|
else:
|
||||||
|
super().setEditorData(editor, index)
|
||||||
|
|
||||||
|
def setModelData(self, editor, model, index):
|
||||||
|
if index.row() == 5 and index.column() == 5:
|
||||||
|
model.setData(index, editor.currentText(), Qt.EditRole)
|
||||||
|
else:
|
||||||
|
super().setModelData(editor, model, index)
|
||||||
|
|
||||||
|
def updateEditorGeometry(self, editor, option, index):
|
||||||
|
editor.setGeometry(option.rect)
|
||||||
@ -0,0 +1,112 @@
|
|||||||
|
from PyQt5 import QtCore
|
||||||
|
from PyQt5.QtGui import QTextDocument
|
||||||
|
from PyQt5.QtCore import Qt
|
||||||
|
from PyQt5.QtWidgets import QHeaderView, QAbstractItemView, QTableView, QWidget, QDesktopWidget
|
||||||
|
from UI.BlockParameterModel import VarTableModel, VarButtonDelegate, ComboBoxDelegate
|
||||||
|
|
||||||
|
from utils.DBModels.DeviceParModels import *
|
||||||
|
|
||||||
|
class ParamsVHeader(QHeaderView):
|
||||||
|
def __init__(self, parent, datas):
|
||||||
|
super().__init__(Qt.Vertical, parent)
|
||||||
|
self.datas = datas
|
||||||
|
|
||||||
|
def resizeEvent(self, event):
|
||||||
|
"""Resize table as a whole, need this to enable resizing"""
|
||||||
|
super(QHeaderView, self).resizeEvent(event)
|
||||||
|
|
||||||
|
for index, content in enumerate(self.datas):
|
||||||
|
self.setSectionResizeMode(index, QHeaderView.Fixed)
|
||||||
|
self.resizeSection(index, 50 * (content[2].count('\r\n') + 1))
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
class VarTableView(QTableView):
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super(VarTableView, self).__init__(parent)
|
||||||
|
self.parent = parent
|
||||||
|
self.setHeader()
|
||||||
|
self.setupUi()
|
||||||
|
|
||||||
|
def setHeader(self):
|
||||||
|
self.setItemDelegateForColumn(6, VarButtonDelegate(self))
|
||||||
|
self.setItemDelegateForColumn(5, ComboBoxDelegate(self))
|
||||||
|
|
||||||
|
self.model = VarTableModel(['相对索引', '参数名', '描述', '数据类型', '访问', '当前值', '输入值'], [], table = self)
|
||||||
|
|
||||||
|
def setupUi(self):
|
||||||
|
self.setShowGrid(True)
|
||||||
|
self.setAlternatingRowColors(True)
|
||||||
|
self.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||||
|
|
||||||
|
|
||||||
|
#设置单元格宽度比例
|
||||||
|
self.header = self.horizontalHeader()
|
||||||
|
self.header.setSectionResizeMode(QHeaderView.Interactive)
|
||||||
|
self.header.setStretchLastSection(True)
|
||||||
|
|
||||||
|
self.proxy = QtCore.QSortFilterProxyModel(self)
|
||||||
|
# # self.parameTableView.proxy = self.proxy
|
||||||
|
self.proxy.setSourceModel(self.model)
|
||||||
|
|
||||||
|
self.setModel(self.proxy)
|
||||||
|
self.setCustomColumnWidths([1, 3, 9, 2, 2, 2, 2])
|
||||||
|
|
||||||
|
|
||||||
|
# self.header.checkClicked.connect(self.model.headerClick)
|
||||||
|
# self.setHorizontalHeader(self.header)
|
||||||
|
# self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
||||||
|
|
||||||
|
# self.header.setSectionResizeMode(0, QHeaderView.Fixed)
|
||||||
|
# self.header.resizeSection(0, 70)
|
||||||
|
def setCustomColumnWidths(self, ratios):
|
||||||
|
# 计算总比例
|
||||||
|
totalRatio = sum(ratios)
|
||||||
|
# 获取窗口宽度
|
||||||
|
screen = QDesktopWidget().screenGeometry()
|
||||||
|
width = screen.width() - 80
|
||||||
|
|
||||||
|
# 根据比例设置每列的宽度
|
||||||
|
for i, ratio in enumerate(ratios):
|
||||||
|
columnWidth = int(width * (ratio / totalRatio))
|
||||||
|
self.setColumnWidth(i, columnWidth)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class PressureTBlockView(VarTableView):
|
||||||
|
def __init__(self, datas = None):
|
||||||
|
super().__init__()
|
||||||
|
self.datas = datas
|
||||||
|
self.initUI()
|
||||||
|
|
||||||
|
|
||||||
|
def initUI(self):
|
||||||
|
if not self.datas:
|
||||||
|
self.datas = PressureTranslationBlock.getallParame()
|
||||||
|
for index, data in enumerate(self.datas):
|
||||||
|
desc = data[2].replace('\r\n', '').replace('\n', '')
|
||||||
|
lines = [desc[i:i+50] + "\r\n" for i in range(0, len(desc), 50)]
|
||||||
|
# 合并列表为一个字符串,移除最后一个换行符
|
||||||
|
result = "".join(lines).rstrip("\r\n")
|
||||||
|
data[2] = result
|
||||||
|
data = data + ['', '', '']
|
||||||
|
self.model.append_data(data)
|
||||||
|
self.setVerticalHeader(ParamsVHeader(self, self.model.datas))
|
||||||
|
|
||||||
|
class AIFunctionBlockView(PressureTBlockView):
|
||||||
|
def __init__(self):
|
||||||
|
self.datas = AIFunctionBlock.getallParame()
|
||||||
|
super().__init__(self.datas)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class PhysicalBlockView(PressureTBlockView):
|
||||||
|
def __init__(self):
|
||||||
|
self.datas = PhysicalBlock.getallParame()
|
||||||
|
super().__init__(self.datas)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,80 @@
|
|||||||
|
from UI.DeviceDialogWidget import DeviceDialog
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
import random
|
||||||
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||||
|
from PyQt5.QtCore import Qt, QTimer
|
||||||
|
from PyQt5.Qt import *
|
||||||
|
|
||||||
|
from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout, \
|
||||||
|
QApplication, QLineEdit, QWidget, QTableWidget, QSplitter,QVBoxLayout,QPushButton, QProgressBar, QTableWidgetItem, QMessageBox
|
||||||
|
from PyQt5.QtWidgets import QDialog
|
||||||
|
|
||||||
|
class SearchAddressWidget(QWidget):
|
||||||
|
def __init__(self, deviceAddressEdit):
|
||||||
|
super().__init__()
|
||||||
|
self.selected_value = None
|
||||||
|
self.deviceAddressEdit = deviceAddressEdit
|
||||||
|
self.initUI()
|
||||||
|
|
||||||
|
def initUI(self):
|
||||||
|
self.resize(800, 500)
|
||||||
|
self.setObjectName('deviceDialog')
|
||||||
|
self.addressTabWidget = QTableWidget()
|
||||||
|
self.addressTabWidget.setRowCount(10)
|
||||||
|
self.addressTabWidget.setColumnCount(1)
|
||||||
|
|
||||||
|
self.addressTabWidget.setShowGrid(False) #隐藏网格线
|
||||||
|
self.addressTabWidget.horizontalHeader().setVisible(False) # 隐藏水平表头
|
||||||
|
self.addressTabWidget.verticalHeader().setVisible(False) # 隐藏垂直表头
|
||||||
|
self.header = self.addressTabWidget.horizontalHeader()
|
||||||
|
self.header.setStretchLastSection(True) #设置最后一列顶格
|
||||||
|
self.addressTabWidget.setFocusPolicy(Qt.NoFocus) #取消选中焦点,去掉虚线框
|
||||||
|
self.addressTabWidget.setEditTriggers(QTableWidget.NoEditTriggers)
|
||||||
|
self.addressTabWidget.cellClicked.connect(self.onCellClicked)
|
||||||
|
self.addressTabWidget.cellDoubleClicked.connect(lambda row, column: self.onCellClicked(row, column, True))
|
||||||
|
|
||||||
|
self.item = QTableWidgetItem('16')
|
||||||
|
self.addressTabWidget.setItem(0, 0, self.item)
|
||||||
|
|
||||||
|
self.mainlayout = QVBoxLayout()
|
||||||
|
self.progressBar = QProgressBar(self)
|
||||||
|
self.bottomLayout = QHBoxLayout()
|
||||||
|
|
||||||
|
self.confirmBtn = QPushButton('确定')
|
||||||
|
self.confirmBtn.clicked.connect(self.onConfirm)
|
||||||
|
|
||||||
|
self.cancelBtn = QPushButton('取消')
|
||||||
|
|
||||||
|
self.bottomLayout.addWidget(self.confirmBtn)
|
||||||
|
self.bottomLayout.addWidget(QSplitter())
|
||||||
|
self.bottomLayout.addWidget(self.cancelBtn)
|
||||||
|
|
||||||
|
self.mainlayout.addWidget(self.progressBar)
|
||||||
|
self.mainlayout.addWidget(self.addressTabWidget)
|
||||||
|
self.mainlayout.addLayout(self.bottomLayout)
|
||||||
|
|
||||||
|
self.setLayout(self.mainlayout)
|
||||||
|
self.setWindowTitle('从站地址查找')
|
||||||
|
|
||||||
|
self.timer = QTimer()
|
||||||
|
self.timer.timeout.connect(self.updateProgress)
|
||||||
|
self.timer.start(500)
|
||||||
|
|
||||||
|
def updateProgress(self):
|
||||||
|
# 模拟一个任务,逐步更新进度条
|
||||||
|
self.progressBar.setValue(int(125 * (100/125)))
|
||||||
|
# QApplication.processEvents() # 确保UI及时更新
|
||||||
|
# QTimer.singleShot(100, lambda: None) # 暂停一小段时间,模拟任务执行时间
|
||||||
|
|
||||||
|
def onCellClicked(self, row, column, double = False):
|
||||||
|
item = self.addressTabWidget.item(row, column)
|
||||||
|
if item:
|
||||||
|
self.address = item.text()
|
||||||
|
if double:
|
||||||
|
self.onConfirm()
|
||||||
|
|
||||||
|
def onConfirm(self):
|
||||||
|
self.deviceAddressEdit.setText(self.address)
|
||||||
|
self.close()
|
||||||
|
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
|
from peewee import *
|
||||||
|
import json
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
from utils.DBModels.BaseModel import BaseModel
|
||||||
|
|
||||||
|
sys.path.append('../')
|
||||||
|
sys.path.append('../../../')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class PressureTranslationBlock(BaseModel):
|
||||||
|
index = CharField()
|
||||||
|
paramName = CharField()
|
||||||
|
objectType = CharField()
|
||||||
|
dataType = CharField()
|
||||||
|
saveType = CharField()
|
||||||
|
dataSize = CharField()
|
||||||
|
accessType = CharField()
|
||||||
|
transferType = CharField()
|
||||||
|
description = CharField()
|
||||||
|
createTime = CharField()
|
||||||
|
|
||||||
|
# 查询设备是否存在
|
||||||
|
@classmethod
|
||||||
|
def getallParame(cls):
|
||||||
|
devices = cls.get_all()
|
||||||
|
if devices is 'error':
|
||||||
|
return
|
||||||
|
l = []
|
||||||
|
for x in devices:
|
||||||
|
l.append([x.index, x.paramName, x.description, x.dataType, x.accessType])
|
||||||
|
return l
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def getByName(cls, paramName):
|
||||||
|
try:
|
||||||
|
return cls.get(cls.paramName == str(paramName))
|
||||||
|
except Exception as e:
|
||||||
|
return
|
||||||
|
|
||||||
|
def addParame(self, index, paramName, objectType, dataType, saveType, dataSize, accessType, transferType, description):
|
||||||
|
self.index = index
|
||||||
|
self.paramName = paramName
|
||||||
|
self.objectType = objectType
|
||||||
|
self.dataType = dataType
|
||||||
|
self.saveType = saveType
|
||||||
|
self.dataSize = dataSize
|
||||||
|
self.accessType = accessType
|
||||||
|
self.transferType = transferType
|
||||||
|
self.description = description
|
||||||
|
self.createTime = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S')
|
||||||
|
# print(self.createTime)
|
||||||
|
self.save()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class PhysicalBlock(PressureTranslationBlock):
|
||||||
|
index = CharField()
|
||||||
|
paramName = CharField()
|
||||||
|
objectType = CharField()
|
||||||
|
dataType = CharField()
|
||||||
|
saveType = CharField()
|
||||||
|
dataSize = CharField()
|
||||||
|
accessType = CharField()
|
||||||
|
transferType = CharField()
|
||||||
|
description = CharField()
|
||||||
|
createTime = CharField()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class AIFunctionBlock(PressureTranslationBlock):
|
||||||
|
index = CharField()
|
||||||
|
paramName = CharField()
|
||||||
|
objectType = CharField()
|
||||||
|
dataType = CharField()
|
||||||
|
saveType = CharField()
|
||||||
|
dataSize = CharField()
|
||||||
|
accessType = CharField()
|
||||||
|
transferType = CharField()
|
||||||
|
description = CharField()
|
||||||
|
createTime = CharField()
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
from utils.DBModels.DeviceParModels import *
|
||||||
|
|
||||||
|
|
||||||
|
class InitParameterDB():
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self.writeParameter()
|
||||||
|
|
||||||
|
def writeParameter(self) -> None:
|
||||||
|
blockNames = pd.ExcelFile('static/PA块信息表.xlsx').sheet_names
|
||||||
|
for blockName in blockNames:
|
||||||
|
parameters = pd.read_excel('static/PA块信息表.xlsx', sheet_name=str(blockName))
|
||||||
|
|
||||||
|
for index, row in parameters.iterrows():
|
||||||
|
parameter = row.values
|
||||||
|
clsblockName = globals()[blockName]() #通过excel的sheet名字获取对应的数据库函数
|
||||||
|
if not clsblockName.getByName(parameter[1]):
|
||||||
|
clsblockName.addParame(index = parameter[0], paramName = parameter[1], objectType = parameter[2], dataType = parameter[3],
|
||||||
|
saveType = parameter[4], dataSize = parameter[5], accessType = parameter[6], transferType = parameter[7], description = parameter[8])
|
||||||
|
|
||||||
Loading…
Reference in New Issue