hytos / DTI_PID / DTI_PID / SymbolAttrEditorDialog.py @ 064816ac
이력 | 보기 | 이력해설 | 다운로드 (15.9 KB)
1 |
# coding: utf-8
|
---|---|
2 |
"""
|
3 |
This is SymbolAttrEditor module
|
4 |
"""
|
5 |
import os |
6 |
import sys |
7 |
import re |
8 |
from PyQt5.QtCore import * |
9 |
from PyQt5.QtGui import * |
10 |
from PyQt5.QtWidgets import * |
11 |
import sqlite3 |
12 |
from AppDocData import AppDocData |
13 |
from AppDocData import Config |
14 |
from TableWidgetEx import QTableWidgetEx |
15 |
from SymbolSvgItem import SymbolSvgItem |
16 |
|
17 |
import SymbolAttrEditor_UI |
18 |
|
19 |
class QSymbolAttrEditorDialog(QDialog): |
20 |
""" This is symbol attribute editor dialog class """
|
21 |
|
22 |
SYMBOL_ATTR_DATA_TYPES = {'Symbol Item':-1, 'Size Text Item':-1, 'Text Item':-1, 'Tag No':-1, 'Valve Oper Code':-1, 'Line Item':-1, 'Comp Item':-1, 'EQ Item':-1, 'Int':1, 'String':1} |
23 |
LINE_NO_ATTR_TYPES = ['Code Table', 'Int', 'String', 'Symbol'] |
24 |
|
25 |
def __init__(self, parent, symbolType = None): |
26 |
QDialog.__init__(self, parent)
|
27 |
|
28 |
self.ui = SymbolAttrEditor_UI.Ui_SymbolAttrEditorDialog()
|
29 |
self.ui.setupUi(self) |
30 |
|
31 |
self._symbolType = symbolType
|
32 |
if symbolType is not None: |
33 |
self.ui.labelLineNo.setVisible(False) |
34 |
self.currentTypeId = 0 |
35 |
# insert QTableWidgetEx
|
36 |
self.ui.tableWidgetAttr = QTableWidgetEx(self.ui.groupBox) |
37 |
self.ui.tableWidgetAttr.setColumnCount(8) |
38 |
self.ui.tableWidgetAttr.setObjectName("tableWidgetAttr") |
39 |
self.ui.tableWidgetAttr.setRowCount(0) |
40 |
self.ui.tableWidgetAttr.verticalHeader().setVisible(False) |
41 |
self.ui.horizontalLayout_2.addWidget(self.ui.tableWidgetAttr) |
42 |
# up to here
|
43 |
# combobox logic
|
44 |
self.settingComboBoxSymbolType(symbolType[2]) |
45 |
self.ui.comboBoxSymbolType.currentTextChanged.connect(self.changeSymbolType) |
46 |
self.ui.comboBoxSymbolType.setEnabled(False) |
47 |
# up to here
|
48 |
self.ui.pushButtonAddAttr.clicked.connect(self.onAddAttr) |
49 |
self.ui.pushButtonDelAttr.clicked.connect(self.onDelAttr) |
50 |
self.ui.tableWidgetAttr.setHorizontalHeaderLabels(['UID', 'Name', 'Display Name', 'Type', 'Attr At', |
51 |
'Expression', 'Target', 'Code Table']) |
52 |
self.ui.tableWidgetAttr.horizontalHeaderItem(1).setSizeHint(QSize(25, 25)) |
53 |
self.ui.tableWidgetAttr.setColumnWidth(3, 130) |
54 |
self.ui.tableWidgetAttr.hideColumn(0) |
55 |
|
56 |
self.ui.tableWidgetAttr.cellDoubleClicked.connect(self.cell_double_clicked) |
57 |
else:
|
58 |
self.ui.comboBoxSymbolType.setVisible(False) |
59 |
# insert QTableWidgetEx
|
60 |
self.ui.tableWidgetAttr = QTableWidgetEx(self.ui.groupBox) |
61 |
self.ui.tableWidgetAttr.setColumnCount(5) |
62 |
self.ui.tableWidgetAttr.setObjectName("tableWidgetAttr") |
63 |
self.ui.tableWidgetAttr.setRowCount(0) |
64 |
self.ui.tableWidgetAttr.verticalHeader().setVisible(False) |
65 |
self.ui.horizontalLayout_2.addWidget(self.ui.tableWidgetAttr) |
66 |
# up to here
|
67 |
self.ui.tableWidgetAttr.setHorizontalHeaderLabels(['UID', 'Name', 'Display Name', 'Type', 'Length', |
68 |
'Expression'])
|
69 |
self.ui.tableWidgetAttr.horizontalHeaderItem(1).setSizeHint(QSize(25, 25)) |
70 |
self.ui.tableWidgetAttr.hideColumn(0) |
71 |
|
72 |
self.settingLineNoAttributeTable()
|
73 |
|
74 |
self.ui.pushButtonAddAttr.clicked.connect(self.onAddLineNoAttr) |
75 |
self.ui.pushButtonDelAttr.clicked.connect(self.onDelLineNoAttr) |
76 |
|
77 |
def cell_double_clicked(self, row, column): |
78 |
if self._symbolType is None or not (column is 6 or column is 7): return |
79 |
if hasattr(self.ui.tableWidgetAttr.item(row, 0), 'tag') and self.ui.tableWidgetAttr.item(row, 0).tag.IsProp == 2: return |
80 |
|
81 |
from SymbolAttrTargetDialog import SymbolAttrTargetDialog |
82 |
from SymbolAttrCodeTableDialog import SymbolAttrCodeTableDialog |
83 |
from App import App |
84 |
|
85 |
try:
|
86 |
# code table setting
|
87 |
if column == 7: |
88 |
dialog = SymbolAttrCodeTableDialog(self, str(self.ui.tableWidgetAttr.item(row, 0).tag.UID), tableDatas=self.ui.tableWidgetAttr.item(row, 7).tag) |
89 |
(isAccept, code_data) = dialog.showDialog() |
90 |
|
91 |
if isAccept:
|
92 |
self.ui.tableWidgetAttr.item(row, 7).tag = code_data |
93 |
|
94 |
graphicsView = App.mainWnd().graphicsView |
95 |
if dialog.code_area:
|
96 |
if dialog.code_area.scene():
|
97 |
graphicsView.scene.removeItem(dialog.code_area) |
98 |
if dialog.desc_area:
|
99 |
if dialog.desc_area.scene():
|
100 |
graphicsView.scene.removeItem(dialog.desc_area) |
101 |
graphicsView.useDefaultCommand() |
102 |
# target setting
|
103 |
elif column == 6: |
104 |
symbolType = self.ui.comboBoxSymbolType.currentText()
|
105 |
|
106 |
dialog = SymbolAttrTargetDialog(self, symbolType, self.ui.tableWidgetAttr.item(row, 6).tag) |
107 |
(isAccept, target) = dialog.showDialog() |
108 |
|
109 |
if isAccept:
|
110 |
self.ui.tableWidgetAttr.item(row, 6).tag = target |
111 |
if target == 'ALL': |
112 |
self.ui.tableWidgetAttr.item(row, 6).setText('ALL') |
113 |
else:
|
114 |
self.ui.tableWidgetAttr.item(row, 6).setText('...') |
115 |
|
116 |
except Exception as ex: |
117 |
from App import App |
118 |
from AppDocData import MessageType |
119 |
|
120 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
121 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
122 |
|
123 |
'''
|
124 |
@brief setting combobox symbolType
|
125 |
@author kyouho
|
126 |
@date 2018.08.16
|
127 |
'''
|
128 |
def settingComboBoxSymbolType(self, selectedType): |
129 |
docData = AppDocData.instance() |
130 |
comboBox = self.ui.comboBoxSymbolType
|
131 |
|
132 |
symbolTypes = docData.getSymbolTypeList() |
133 |
for type in symbolTypes: |
134 |
comboBox.addItem(type[2]) |
135 |
|
136 |
result = comboBox.findText(selectedType) |
137 |
if result != -1: |
138 |
comboBox.setCurrentIndex(result) |
139 |
|
140 |
self.changeSymbolType()
|
141 |
|
142 |
'''
|
143 |
@brief combobox symbolType change logic
|
144 |
@author kyouho
|
145 |
@date 2018.08.16
|
146 |
'''
|
147 |
def changeSymbolType(self): |
148 |
self._symbolType = self.ui.comboBoxSymbolType.currentText() |
149 |
self.ui.tableWidgetAttr.setRowCount(0) |
150 |
self.loadData(self._symbolType) |
151 |
|
152 |
def loadData(self, symbolType): |
153 |
"""
|
154 |
@brief load data
|
155 |
@author humkyung
|
156 |
@date 2018.08.14
|
157 |
@history humkyung 2018.10.13 add expression
|
158 |
"""
|
159 |
|
160 |
appDocData = AppDocData.instance() |
161 |
|
162 |
self.currentTypeId = appDocData.getSymbolTypeId(symbolType)
|
163 |
|
164 |
attrs = appDocData.getSymbolAttribute(symbolType) |
165 |
self.ui.tableWidgetAttr.setRowCount(len(attrs)) |
166 |
|
167 |
row = 0
|
168 |
for attr in attrs: |
169 |
item = QTableWidgetItem(str(attr.UID)) # UID |
170 |
item.tag = attr |
171 |
self.ui.tableWidgetAttr.setItem(row, 0, item) |
172 |
item = QTableWidgetItem(attr.Attribute) # Name
|
173 |
if attr.IsProp >= 2: |
174 |
item.setFlags(Qt.ItemIsEnabled) |
175 |
item.setBackground(Qt.lightGray) |
176 |
self.ui.tableWidgetAttr.setItem(row, 1, item) |
177 |
item = QTableWidgetItem(attr.DisplayAttribute) # Display Name
|
178 |
self.ui.tableWidgetAttr.setItem(row, 2, item) |
179 |
|
180 |
attrTypeComboBox = QComboBox() |
181 |
for key,value in QSymbolAttrEditorDialog.SYMBOL_ATTR_DATA_TYPES.items(): |
182 |
attrTypeComboBox.addItem(key) |
183 |
|
184 |
if attr.IsProp >= 3: |
185 |
attrTypeComboBox.setEnabled(False)
|
186 |
if attr.AttributeType in [type for type , _ in QSymbolAttrEditorDialog.SYMBOL_ATTR_DATA_TYPES.items()]: |
187 |
self.ui.tableWidgetAttr.setCellWidget(row, 3, attrTypeComboBox) |
188 |
result = attrTypeComboBox.findText(attr.AttributeType) # Type
|
189 |
attrTypeComboBox.setCurrentIndex(result) |
190 |
else:
|
191 |
if attr.IsProp >= 3: |
192 |
item = QTableWidgetItem(attr.AttributeType) |
193 |
item.setFlags(Qt.ItemIsEnabled) |
194 |
self.ui.tableWidgetAttr.setItem(row, 3, item) |
195 |
|
196 |
item = QTableWidgetItem(str(attr.AttrAt)) # Attribute At |
197 |
if attr.IsProp >= 2: |
198 |
item.setFlags(Qt.ItemIsEnabled) |
199 |
self.ui.tableWidgetAttr.setItem(row, 4, item) |
200 |
|
201 |
item = QTableWidgetItem(attr.Expression) # Expression
|
202 |
if attr.IsProp >= 2: |
203 |
item.setFlags(Qt.ItemIsEnabled) |
204 |
self.ui.tableWidgetAttr.setItem(row, 5, item) |
205 |
|
206 |
item = QTableWidgetItem('ALL') if attr.Target == 'ALL' or attr.Target is None else QTableWidgetItem('...') |
207 |
item.tag = attr.Target |
208 |
item.setTextAlignment(Qt.AlignHCenter) |
209 |
item.setFlags(Qt.ItemIsEnabled) |
210 |
self.ui.tableWidgetAttr.setItem(row, 6, item) |
211 |
|
212 |
item = QTableWidgetItem('...')
|
213 |
item.tag = attr.Codes.values |
214 |
item.setTextAlignment(Qt.AlignHCenter) |
215 |
item.setFlags(Qt.ItemIsEnabled) |
216 |
self.ui.tableWidgetAttr.setItem(row, 7, item) |
217 |
|
218 |
row = row + 1
|
219 |
|
220 |
def saveData(self): |
221 |
"""save symbol attributes"""
|
222 |
|
223 |
appDocData = AppDocData.instance() |
224 |
|
225 |
attrs = [] |
226 |
table = self.ui.tableWidgetAttr
|
227 |
|
228 |
for index in range(table.rowCount()): |
229 |
attr = [] |
230 |
attr.append(table.item(index, 0).text() if table.item(index, 0) is not None else '') |
231 |
attr.append(table.item(index, 1).text() if table.item(index, 1) is not None else '') |
232 |
attr.append(table.item(index, 2).text() if table.item(index, 2) is not None else '') |
233 |
attr.append(table.cellWidget(index, 3).currentText() if table.cellWidget(index, 3) else table.item(index, 3).text())#attr.append(table.item(index, 1).text()) |
234 |
attr.append(table.item(index, 4).text() if table.item(index, 4) is not None else '') # Attribute At |
235 |
attr.append(table.item(index, 5).text() if table.item(index, 5) is not None else '') # Expression |
236 |
attr.append(table.item(index, 6).tag if table.item(index, 6).tag is not None else 'ALL') # Target |
237 |
attr.append(index) |
238 |
attr.append(table.item(index, 0).tag.IsProp) if hasattr(table.item(index, 0), 'tag') else attr.append(0) |
239 |
attr.append(table.item(index, 7).tag)
|
240 |
attrs.append(attr) |
241 |
|
242 |
appDocData.saveSymbolAttributes(self.currentTypeId, attrs, self._symbolType) |
243 |
|
244 |
'''
|
245 |
@brief add a attribute
|
246 |
@author humkyung
|
247 |
@date 2018.08.13
|
248 |
'''
|
249 |
def onAddAttr(self): |
250 |
import uuid |
251 |
from SymbolAttr import SymbolAttr |
252 |
|
253 |
rows = self.ui.tableWidgetAttr.rowCount()
|
254 |
self.ui.tableWidgetAttr.setRowCount(rows + 1) |
255 |
|
256 |
attrTypeComboBox = QComboBox() |
257 |
for key,value in QSymbolAttrEditorDialog.SYMBOL_ATTR_DATA_TYPES.items(): |
258 |
attrTypeComboBox.addItem(key) |
259 |
|
260 |
self.ui.tableWidgetAttr.setCellWidget(rows, 3, attrTypeComboBox) |
261 |
|
262 |
item = QTableWidgetItem('ALL')
|
263 |
item.tag = 'ALL'
|
264 |
item.setTextAlignment(Qt.AlignHCenter) |
265 |
item.setFlags(Qt.ItemIsEnabled) |
266 |
self.ui.tableWidgetAttr.setItem(rows, 6, item) |
267 |
|
268 |
item = QTableWidgetItem('...')
|
269 |
item.tag = [] |
270 |
item.setTextAlignment(Qt.AlignHCenter) |
271 |
item.setFlags(Qt.ItemIsEnabled) |
272 |
self.ui.tableWidgetAttr.setItem(rows, 7, item) |
273 |
|
274 |
attr = SymbolAttr() |
275 |
item = QTableWidgetItem(str(attr.UID))
|
276 |
item.tag = attr |
277 |
self.ui.tableWidgetAttr.setItem(rows, 0, item) |
278 |
|
279 |
'''
|
280 |
@brief delete selected attribute
|
281 |
@author humkyung
|
282 |
@date 2018.08.13
|
283 |
'''
|
284 |
def onDelAttr(self): |
285 |
model = self.ui.tableWidgetAttr.model()
|
286 |
row = self.ui.tableWidgetAttr.currentRow()
|
287 |
|
288 |
if row != -1 and not (hasattr(self.ui.tableWidgetAttr.item(row, 0), 'tag') and self.ui.tableWidgetAttr.item(row, 0).tag.IsProp == 2): |
289 |
model.removeRow(row) |
290 |
|
291 |
'''
|
292 |
@brief save attributes
|
293 |
@author humkyung
|
294 |
@date 2018.08.13
|
295 |
'''
|
296 |
def accept(self): |
297 |
if self._symbolType is not None: |
298 |
self.saveData()
|
299 |
else:
|
300 |
self.saveLineAttrData()
|
301 |
|
302 |
QDialog.accept(self)
|
303 |
|
304 |
'''
|
305 |
@brief setting attribute table line no
|
306 |
@author kyoyho
|
307 |
@date 2018.08.21
|
308 |
'''
|
309 |
def settingLineNoAttributeTable(self): |
310 |
table = self.ui.tableWidgetAttr
|
311 |
docData = AppDocData.instance() |
312 |
attrs = docData.getLineProperties() |
313 |
|
314 |
table.setRowCount(len(attrs))
|
315 |
|
316 |
row = 0
|
317 |
for attr in attrs: |
318 |
item = QTableWidgetItem(attr.UID if attr.UID is not None else '') |
319 |
self.ui.tableWidgetAttr.setItem(row, 0, item) |
320 |
item = QTableWidgetItem(attr.Attribute if attr.Attribute is not None else '') |
321 |
#item.setFlags(Qt.ItemIsEnabled)
|
322 |
self.ui.tableWidgetAttr.setItem(row, 1, item) |
323 |
item = QTableWidgetItem(attr.DisplayAttribute if attr.DisplayAttribute is not None else '') |
324 |
self.ui.tableWidgetAttr.setItem(row, 2, item) |
325 |
|
326 |
attrTypeComboBox = QComboBox() |
327 |
for _type in QSymbolAttrEditorDialog.LINE_NO_ATTR_TYPES: |
328 |
attrTypeComboBox.addItem(_type) |
329 |
self.ui.tableWidgetAttr.setCellWidget(row, 3, attrTypeComboBox) |
330 |
result = attrTypeComboBox.findText(attr.AttributeType if attr.DisplayAttribute is not None else '') |
331 |
attrTypeComboBox.setCurrentIndex(result) |
332 |
|
333 |
item = QTableWidgetItem(str(attr.Length) if attr.Length is not None else '') |
334 |
self.ui.tableWidgetAttr.setItem(row, 4, item) |
335 |
|
336 |
item = QTableWidgetItem(str(attr.Expression) if attr.Expression is not None else '') |
337 |
self.ui.tableWidgetAttr.setItem(row, 5, item) |
338 |
|
339 |
row = row + 1
|
340 |
|
341 |
'''
|
342 |
@brief add attribute
|
343 |
@author kyoyho
|
344 |
@date 2018.08.21
|
345 |
'''
|
346 |
def onAddLineNoAttr(self): |
347 |
rows = self.ui.tableWidgetAttr.rowCount()
|
348 |
self.ui.tableWidgetAttr.setRowCount(rows + 1) |
349 |
|
350 |
attrTypeComboBox = QComboBox() |
351 |
for _type in QSymbolAttrEditorDialog.LINE_NO_ATTR_TYPES: |
352 |
attrTypeComboBox.addItem(_type) |
353 |
self.ui.tableWidgetAttr.setCellWidget(rows, 3, attrTypeComboBox) |
354 |
|
355 |
import uuid |
356 |
self.ui.tableWidgetAttr.setItem(rows, 0, QTableWidgetItem(str(uuid.uuid4()))) |
357 |
|
358 |
'''
|
359 |
@brief delete selected attribute
|
360 |
@author kyoyho
|
361 |
@date 2018.08.21
|
362 |
'''
|
363 |
def onDelLineNoAttr(self): |
364 |
model = self.ui.tableWidgetAttr.model()
|
365 |
row = self.ui.tableWidgetAttr.currentRow()
|
366 |
|
367 |
if row != -1: |
368 |
model.removeRow(row) |
369 |
|
370 |
'''
|
371 |
@brief Check Number
|
372 |
@author kyouho
|
373 |
@date 2018.08.20
|
374 |
'''
|
375 |
def isNumber(self, num): |
376 |
p = re.compile('(^[0-9]+$)')
|
377 |
result = p.match(num) |
378 |
|
379 |
if result:
|
380 |
return True |
381 |
else:
|
382 |
return False |
383 |
|
384 |
'''
|
385 |
@brief save data
|
386 |
@author kyouho
|
387 |
@date 2018.08.21
|
388 |
'''
|
389 |
def saveLineAttrData(self): |
390 |
appDocData = AppDocData.instance() |
391 |
|
392 |
attrs = [] |
393 |
table = self.ui.tableWidgetAttr
|
394 |
|
395 |
for index in range(table.rowCount()): |
396 |
attr = [] |
397 |
attr.append(table.item(index, 0).text() if table.item(index, 0) is not None else '') |
398 |
attr.append(table.item(index, 1).text() if table.item(index, 1) is not None else '') |
399 |
attr.append(table.item(index, 2).text() if table.item(index, 2) is not None else '') |
400 |
attr.append(table.cellWidget(index, 3).currentText() if table.cellWidget(index, 3).currentIndex() >= 0 else '') |
401 |
attr.append(int(table.item(index, 4).text()) if table.item(index, 4) is not None and self.isNumber(table.item(index, 4).text()) else None) |
402 |
attr.append(index) |
403 |
attrs.append(attr) |
404 |
|
405 |
appDocData.saveLineAttributes(attrs) |