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