hytos / DTI_PID / DTI_PID / ItemPropertyTableWidget.py @ 2b1f447d
이력 | 보기 | 이력해설 | 다운로드 (33.5 KB)
1 |
# coding: utf-8
|
---|---|
2 |
|
3 |
try:
|
4 |
from PyQt5.QtCore import * |
5 |
from PyQt5.QtGui import * |
6 |
from PyQt5.QtWidgets import * |
7 |
except ImportError: |
8 |
try:
|
9 |
from PyQt4.QtCore import * |
10 |
from PyQt4.QtGui import * |
11 |
except ImportError: |
12 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
13 |
|
14 |
import os |
15 |
import sys |
16 |
import math |
17 |
import re |
18 |
import SelectAttributeCommand |
19 |
|
20 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
21 |
from SymbolSvgItem import SymbolSvgItem |
22 |
from EngineeringLineNoTextItem import QEngineeringLineNoTextItem |
23 |
from EngineeringLineItem import QEngineeringLineItem |
24 |
from EngineeringNoteItem import QEngineeringNoteItem |
25 |
from EngineeringTextItem import QEngineeringTextItem |
26 |
from UserInputAttribute import UserInputAttribute |
27 |
from EngineeringSpecBreakItem import QEngineeringSpecBreakItem |
28 |
from EngineeringErrorItem import QEngineeringErrorItem |
29 |
from AppDocData import * |
30 |
from Drawing import Drawing |
31 |
from enum import Enum |
32 |
|
33 |
'''
|
34 |
@brief ItemType
|
35 |
@author Jeongwoo
|
36 |
@date 2018.04.27
|
37 |
@history 2018.05.10 Jeongwoo Add LINE_NO
|
38 |
'''
|
39 |
class ItemType(Enum): |
40 |
SYMBOL = 1
|
41 |
NOTE = 2
|
42 |
LINE_NO = 3
|
43 |
|
44 |
class QItemPropertyTableWidget(QTableWidget): |
45 |
def __init__(self, mainWindow): |
46 |
QTableWidget.__init__(self)
|
47 |
self._item = None |
48 |
self.initResultPropertyTableWidget()
|
49 |
self.mainWindow = mainWindow
|
50 |
|
51 |
self.cellChanged.connect(self.cellChangedEvent) |
52 |
self.cellDoubleClicked.connect(self.cellDoubleClickedEvent) |
53 |
|
54 |
'''
|
55 |
@brief show item's property
|
56 |
@author humkyung
|
57 |
@date 2018.07.03
|
58 |
@history euisung 2019.01.15 add icon image to line item
|
59 |
'''
|
60 |
def show_item_property(self, item): |
61 |
try:
|
62 |
from PyQt5 import QtGui |
63 |
from SymbolAttr import SymbolAttr |
64 |
|
65 |
self._item = item
|
66 |
|
67 |
self.blockSignals(True) |
68 |
|
69 |
if type(item) is QEngineeringLineItem: |
70 |
self.initTitleCell(item)
|
71 |
self.setItem(0, 1, QTableWidgetItem(str(item.uid))) |
72 |
owner_item = QTableWidgetItem('{}'.format('None' if item.owner is None else item.owner.uid)) |
73 |
icon = QtGui.QIcon() |
74 |
icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
75 |
owner_item.setIcon(icon) |
76 |
attr = SymbolAttr() |
77 |
attr.AttributeType = "OWNER"
|
78 |
owner_item.setData(Qt.UserRole, attr) |
79 |
|
80 |
self.setItem(1, 1, owner_item) |
81 |
|
82 |
pt = item.startPoint() |
83 |
key_item = QTableWidgetItem("시작점")
|
84 |
key_item.setBackground(Qt.lightGray) |
85 |
self.setItem(3, 0, key_item) |
86 |
self.setItem(3, 1, QTableWidgetItem('({},{})'.format(pt[0], pt[1]))) |
87 |
pt = item.endPoint() |
88 |
key_item = QTableWidgetItem("끝점")
|
89 |
key_item.setBackground(Qt.lightGray) |
90 |
self.setItem(4, 0, key_item) |
91 |
self.setItem(4, 1, QTableWidgetItem('({},{})'.format(pt[0], pt[1]))) |
92 |
self.show_item_connectors(item)
|
93 |
elif issubclass(type(item), SymbolSvgItem): |
94 |
self.onSymbolClicked(item)
|
95 |
elif type(item) is QEngineeringLineNoTextItem: |
96 |
self.onLineNoClicked(item)
|
97 |
elif type(item) is QEngineeringNoteItem: |
98 |
noteContentsList = item.findNoteContents(item.text()) |
99 |
self.onNoteClicked(item.text(), noteContentsList)
|
100 |
elif item is None: |
101 |
self.setRowCount(0) |
102 |
except Exception as ex: |
103 |
from App import App |
104 |
|
105 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
106 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
107 |
finally:
|
108 |
self.blockSignals(False) |
109 |
|
110 |
'''
|
111 |
@brief Initialize TableWidget
|
112 |
@author Jeongwoo
|
113 |
@date 18.04.13
|
114 |
@history humkyung 2018.07.08 show column header
|
115 |
'''
|
116 |
def initResultPropertyTableWidget(self): |
117 |
self.setColumnCount(2) |
118 |
self.setHorizontalHeaderLabels(['Name', 'Value']) |
119 |
self.horizontalHeaderItem(0).setSizeHint(QSize(25, 25)) |
120 |
self.setRowCount(13) |
121 |
self.verticalHeader().hide()
|
122 |
self.horizontalHeader().setStretchLastSection(True) |
123 |
|
124 |
'''
|
125 |
@brief Slot to accept item click event
|
126 |
@author Jeongwoo
|
127 |
@date 18.04.13
|
128 |
@history humkyung 2018.04.17 check if given symbol type is SymbolSvgItem
|
129 |
'''
|
130 |
@pyqtSlot(SymbolSvgItem)
|
131 |
def onSymbolClicked(self, symbol): |
132 |
if issubclass(type(symbol), SymbolSvgItem): |
133 |
self._item = symbol
|
134 |
self.symbolChanged(symbol)
|
135 |
elif type(symbol) is QEngineeringLineNoTextItem: |
136 |
self.lineNoChanged(symbol)
|
137 |
|
138 |
'''
|
139 |
@brief show drawing' attributes
|
140 |
@author humkyung
|
141 |
@date 2018.07.07
|
142 |
'''
|
143 |
@pyqtSlot(Drawing)
|
144 |
def onDrawingClicked(self, drawing): |
145 |
self.setRowCount(len(drawing.attrs)) |
146 |
|
147 |
row = 0
|
148 |
for attr in drawing.attrs: |
149 |
name = attr[0]
|
150 |
item = QTableWidgetItem(name) |
151 |
item.setFlags(Qt.ItemIsEnabled) |
152 |
item.setBackground(Qt.lightGray) |
153 |
self.setItem(row, 0, item) |
154 |
|
155 |
value = attr[1]
|
156 |
item = QTableWidgetItem(value) |
157 |
item.setFlags(Qt.ItemIsEnabled) |
158 |
self.setItem(row, 1, item) |
159 |
|
160 |
row = row + 1
|
161 |
|
162 |
'''
|
163 |
@brief Slot to accept Note item click event
|
164 |
@author Jeongwoo
|
165 |
@date 18.04.27
|
166 |
@history humkyung 2018.07.08 change method name to onNoteClicked
|
167 |
'''
|
168 |
@pyqtSlot(str, dict) |
169 |
def onNoteClicked(self, noteNoStr, noteContentsList): |
170 |
self.noteChanged(noteNoStr, noteContentsList)
|
171 |
|
172 |
'''
|
173 |
@brief Slot to accept Line No Item Click event
|
174 |
@author Jeongwoo
|
175 |
@date 18.05.10
|
176 |
@hisotry humkyung 2018.07.08 change method name to onLineNoClicked
|
177 |
'''
|
178 |
@pyqtSlot(QEngineeringAbstractItem)
|
179 |
def onLineNoClicked(self, item): |
180 |
self.lineNoChanged(item)
|
181 |
|
182 |
'''
|
183 |
@brief Reset table with new SymbolSvgItem
|
184 |
@author Jeongwoo
|
185 |
@date 18.04.13
|
186 |
@history .
|
187 |
'''
|
188 |
def symbolChanged(self, item): |
189 |
self.initTitleCell(item)
|
190 |
self.initContentsCell()
|
191 |
|
192 |
'''
|
193 |
@brief Reset table with note info
|
194 |
@author Jeongwoo
|
195 |
@date 18.04.27
|
196 |
'''
|
197 |
def noteChanged(self, noteNoStr, noteContentsList): |
198 |
self.initNoteCell(noteNoStr, noteContentsList)
|
199 |
|
200 |
'''
|
201 |
@brief Reset table with line no item
|
202 |
@author Jeongwoo
|
203 |
@date 18.05.10
|
204 |
'''
|
205 |
def lineNoChanged(self, item): |
206 |
from EngineeringRunItem import QEngineeringRunItem |
207 |
|
208 |
if type(item) is QEngineeringLineNoTextItem: |
209 |
self.initTitleCell(item)
|
210 |
self.initLineNoCell(item)
|
211 |
elif type(item) is QEngineeringRunItem: |
212 |
self.initLineRunCell(item)
|
213 |
|
214 |
""" show tooltip """
|
215 |
for index in range(self.rowCount()): |
216 |
item = self.item(index, 1) |
217 |
if item is not None: |
218 |
item.setToolTip(item.text()) |
219 |
|
220 |
'''
|
221 |
@brief Initialize Title Cell
|
222 |
@author Jeongwoos
|
223 |
@date 18.04.13
|
224 |
@history Jeongwoo 2018.04.27 Add if-statement by ItemType
|
225 |
Jeongwoo 2018.05.10 Add if-statement LINE_NO ItemType
|
226 |
humkyung 2018.08.15 add combobox for line type
|
227 |
'''
|
228 |
def initTitleCell(self, item): |
229 |
try:
|
230 |
self.clear()
|
231 |
self.setHorizontalHeaderLabels(['Name', 'Value']) |
232 |
self.horizontalHeaderItem(0).setSizeHint(QSize(25, 25)) |
233 |
if type(item) is QEngineeringSpecBreakItem: |
234 |
self.setRowCount(7) |
235 |
self.setItem(0, 0, QTableWidgetItem("UID")) |
236 |
self.setItem(1, 0, QTableWidgetItem("심볼명")) |
237 |
self.setItem(2, 0, QTableWidgetItem("타입")) |
238 |
self.setItem(3, 0, QTableWidgetItem("각도")) |
239 |
self.setItem(4, 0, QTableWidgetItem("원점")) |
240 |
self.setItem(5, 0, QTableWidgetItem("OWNER")) |
241 |
self.setItem(6, 0, QTableWidgetItem("Set Specs")) |
242 |
elif type(item) is QEngineeringErrorItem: |
243 |
self.setRowCount(7) |
244 |
self.setItem(0, 0, QTableWidgetItem("UID")) |
245 |
self.setItem(1, 0, QTableWidgetItem("심볼명")) |
246 |
self.setItem(2, 0, QTableWidgetItem("타입")) |
247 |
self.setItem(3, 0, QTableWidgetItem("각도")) |
248 |
self.setItem(4, 0, QTableWidgetItem("원점")) |
249 |
self.setItem(5, 0, QTableWidgetItem("OWNER")) |
250 |
self.setItem(6, 0, QTableWidgetItem("Message")) |
251 |
elif issubclass(type(item), SymbolSvgItem): |
252 |
self.setRowCount(6) |
253 |
self.setItem(0, 0, QTableWidgetItem("UID")) |
254 |
self.setItem(1, 0, QTableWidgetItem("심볼명")) |
255 |
self.setItem(2, 0, QTableWidgetItem("타입")) |
256 |
self.setItem(3, 0, QTableWidgetItem("각도")) |
257 |
self.setItem(4, 0, QTableWidgetItem("원점")) |
258 |
self.setItem(5, 0, QTableWidgetItem("OWNER")) |
259 |
elif type(item) is QEngineeringNoteItem: |
260 |
self.setRowCount(2) |
261 |
self.setItem(0, 0, QTableWidgetItem("노트번호")) |
262 |
self.setItem(1, 0, QTableWidgetItem("설명")) |
263 |
elif type(item) is QEngineeringLineNoTextItem: |
264 |
self.setRowCount(1) |
265 |
self.setItem(0, 0, QTableWidgetItem("UID")) |
266 |
elif type(item) is QEngineeringLineItem: |
267 |
self.setRowCount(5) |
268 |
self.setItem(0, 0, QTableWidgetItem('UID')) |
269 |
self.setItem(1, 0, QTableWidgetItem('OWNER')) |
270 |
widgetItem = QTableWidgetItem("타입")
|
271 |
widgetItem.setData(Qt.UserRole, item) |
272 |
self.setItem(2, 0, widgetItem) |
273 |
self._lineTypeComboBox = QComboBox(self) |
274 |
self._lineTypeComboBox.tag = widgetItem
|
275 |
appDocData = AppDocData.instance() |
276 |
lineTypes = appDocData.getLineTypes() |
277 |
for lineType in lineTypes: |
278 |
self._lineTypeComboBox.addItem(lineType)
|
279 |
self.setCellWidget(2, 1, self._lineTypeComboBox) |
280 |
self._lineTypeComboBox.setCurrentText(item.lineType)
|
281 |
self._lineTypeComboBox.currentIndexChanged.connect(self.onLineTypeChanged) |
282 |
|
283 |
for index in range(self.rowCount()): |
284 |
item = self.item(index, 0) |
285 |
if item is not None: |
286 |
item.setFlags(Qt.ItemIsEnabled) |
287 |
item.setBackground(Qt.lightGray) |
288 |
except Exception as ex: |
289 |
from App import App |
290 |
|
291 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
292 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
293 |
|
294 |
'''
|
295 |
@brief change selected lines' type by selected line type
|
296 |
@author humkyung
|
297 |
@date 2018.08.15
|
298 |
'''
|
299 |
def onLineTypeChanged(self, param): |
300 |
lineType = self._lineTypeComboBox.itemText(param)
|
301 |
data = self._lineTypeComboBox.tag.data(Qt.UserRole)
|
302 |
if type(data) is QEngineeringLineItem: |
303 |
data.lineType = lineType |
304 |
|
305 |
def show_item_properties(self, item): |
306 |
""" show item properties on grid """
|
307 |
from PyQt5 import QtGui |
308 |
|
309 |
row = self.rowCount()
|
310 |
if hasattr(item, '_properties'): |
311 |
self.setRowCount(row + len(item.properties)) |
312 |
|
313 |
for prop,value in item.properties.items(): |
314 |
""" show property name """
|
315 |
key_item = QTableWidgetItem(prop.DisplayAttribute if prop.DisplayAttribute else prop.Attribute) |
316 |
key_item.setFlags(Qt.ItemIsEnabled) |
317 |
key_item.setBackground(Qt.lightGray) |
318 |
key_item.setData(Qt.UserRole, prop) |
319 |
self.setItem(row, 0, key_item) |
320 |
|
321 |
""" show property value """
|
322 |
if prop.is_selectable:
|
323 |
if prop.Expression:
|
324 |
item = value # assume item is instance
|
325 |
value_item = QTableWidgetItem(eval(prop.Expression))
|
326 |
else:
|
327 |
value_item = QTableWidgetItem(str(value.uid) if value else '') |
328 |
icon = QtGui.QIcon() |
329 |
icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
330 |
value_item.setIcon(icon) |
331 |
value_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable) |
332 |
self.setItem(row, 1, value_item) |
333 |
else:
|
334 |
value_item = QTableWidgetItem(value if value else '') |
335 |
if prop.AttributeType == "String": |
336 |
icon = QtGui.QIcon() |
337 |
icon.addPixmap(QtGui.QPixmap(":/newPrefix/type.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
338 |
value_item.setIcon(icon) |
339 |
value_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable|Qt.ItemIsEditable) |
340 |
self.setItem(row, 1, value_item) |
341 |
row = row + 1
|
342 |
|
343 |
def show_item_attributes(self, item): |
344 |
""" show item's attributes on grid """
|
345 |
from PyQt5 import QtGui |
346 |
|
347 |
row = self.rowCount()
|
348 |
attrs = item.getAttributes() |
349 |
|
350 |
# display attributes of symbol
|
351 |
if attrs is not None: |
352 |
self.setRowCount(row + len(attrs)) |
353 |
|
354 |
for key,value in attrs.items(): |
355 |
key_item = QTableWidgetItem(key.DisplayAttribute if key.DisplayAttribute else key.Attribute) |
356 |
key_item.setBackground(Qt.lightGray) |
357 |
key_item.setData(Qt.UserRole, key) |
358 |
self.setItem(row, 0, key_item) |
359 |
|
360 |
value_item = QTableWidgetItem(str(value))
|
361 |
if key.is_selectable:
|
362 |
icon = QtGui.QIcon() |
363 |
icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
364 |
value_item.setIcon(icon) |
365 |
else:
|
366 |
value_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable|Qt.ItemIsEditable) |
367 |
|
368 |
if type(item) is QEngineeringSpecBreakItem: |
369 |
'''
|
370 |
comboBox = QComboBox()
|
371 |
comboBox.addItem('')
|
372 |
|
373 |
itemList = self.mainWindow.findOverlapConnector(self._item.connectors[0])
|
374 |
for item in itemList:
|
375 |
comboBox.addItem(str(item.uid))
|
376 |
|
377 |
if key == 'Up Stream':
|
378 |
comboBox.currentTextChanged.connect(self.upStreamChanged)
|
379 |
else:
|
380 |
comboBox.currentTextChanged.connect(self.downStreamChanged)
|
381 |
|
382 |
tempIndex = comboBox.findText(value) if comboBox.findText(value) != -1 else 0
|
383 |
comboBox.setCurrentIndex(tempIndex)
|
384 |
|
385 |
self.setCellWidget(row, 1, comboBox)
|
386 |
'''
|
387 |
if key.Attribute == 'UpStream' or key.Attribute == 'DownStream': |
388 |
UpDownItem = QTableWidgetItem('{}'.format('None' if value is None else value)) |
389 |
icon = QtGui.QIcon() |
390 |
icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
391 |
UpDownItem.setIcon(icon) |
392 |
self.setItem(row, 1, UpDownItem) |
393 |
elif key.AttributeType == 'Spec': |
394 |
self.setItem(row, 1, QTableWidgetItem(key.Attribute)) |
395 |
else:
|
396 |
self.setItem(row, 1, value_item) |
397 |
|
398 |
row = row + 1
|
399 |
|
400 |
def show_item_connectors(self, item): |
401 |
""" show items' connectors on grid """
|
402 |
from PyQt5 import QtGui |
403 |
from SymbolAttr import SymbolAttr |
404 |
|
405 |
row = self.rowCount()
|
406 |
self.setRowCount(row + len(item.connectors)) |
407 |
|
408 |
count = 1
|
409 |
for connector in item.connectors: |
410 |
connector_item = QTableWidgetItem('CONN{}'.format(count))
|
411 |
connector_item.setFlags(Qt.ItemIsEnabled) |
412 |
connector_item.setBackground(Qt.lightGray) |
413 |
self.setItem(row, 0, connector_item) |
414 |
|
415 |
attr = SymbolAttr() |
416 |
attr.AttributeType = "CONN"
|
417 |
attr.AttrAt = count |
418 |
connector_item.setData(Qt.UserRole, attr) |
419 |
|
420 |
connector_item = QTableWidgetItem('{}'.format('None' if connector.connectedItem is None else str(connector.connectedItem.uid))) |
421 |
icon = QtGui.QIcon() |
422 |
icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
423 |
connector_item.setIcon(icon) |
424 |
connector_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable) |
425 |
self.setItem(row, 1, connector_item) |
426 |
|
427 |
row = row + 1
|
428 |
count = count + 1
|
429 |
|
430 |
'''
|
431 |
@brief Initialize Contents Cell
|
432 |
@author Jeongwoo
|
433 |
@date 18.04.13
|
434 |
@history humkyung 2018.06.14 display symbol attributes
|
435 |
humkyung 2018.07.05 display connectivity
|
436 |
euisung 2019.01.15 edit specbreak
|
437 |
'''
|
438 |
def initContentsCell(self): |
439 |
from PyQt5 import QtGui |
440 |
from SymbolAttr import SymbolAttr |
441 |
|
442 |
try:
|
443 |
if self._item is not None: |
444 |
docData = AppDocData.instance() |
445 |
|
446 |
self.setItem(0, 1, QTableWidgetItem(str(self._item.uid))) |
447 |
self.setItem(1, 1, QTableWidgetItem(self._item.name)) |
448 |
self.setItem(2, 1, QTableWidgetItem(self._item.type)) |
449 |
self.setItem(3, 1, QTableWidgetItem(str(round(math.degrees(self._item.angle))))) |
450 |
self.setItem(4, 1, QTableWidgetItem(str(self._item.origin))) |
451 |
owner_item = QTableWidgetItem('{}'.format('None' if self._item.owner is None else self._item.owner.uid)) |
452 |
icon = QtGui.QIcon() |
453 |
icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
454 |
owner_item.setIcon(icon) |
455 |
attr = SymbolAttr() |
456 |
attr.AttributeType = "OWNER"
|
457 |
owner_item.setData(Qt.UserRole, attr) |
458 |
self.setItem(5, 1, owner_item) |
459 |
|
460 |
if type(self._item) is not QEngineeringSpecBreakItem and type(self._item) is not QEngineeringErrorItem: |
461 |
self.show_item_properties(self._item) |
462 |
|
463 |
if type(self._item) is QEngineeringSpecBreakItem: |
464 |
row = self.rowCount()
|
465 |
setSpecsItem = QTableWidgetItem('Open')
|
466 |
icon = QtGui.QIcon() |
467 |
icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
468 |
setSpecsItem.setIcon(icon) |
469 |
self.setItem(row - 1, 1, setSpecsItem) |
470 |
|
471 |
if type(self._item) is QEngineeringErrorItem: |
472 |
errType = 'None'
|
473 |
if type(self._item.parent) is QEngineeringLineItem: |
474 |
errType = 'line'
|
475 |
elif issubclass(type(self._item.parent), SymbolSvgItem): |
476 |
errType = 'symbol'
|
477 |
self.setItem(2, 1, QTableWidgetItem(errType)) |
478 |
self.setItem(5, 1, QTableWidgetItem(self._item.parent.uid)) |
479 |
self.setItem(6, 1, QTableWidgetItem(self._item.msg)) |
480 |
|
481 |
self.show_item_attributes(self._item) |
482 |
self.show_item_connectors(self._item) |
483 |
|
484 |
for index in range(self.rowCount()): |
485 |
item = self.item(index, 1) |
486 |
if item is not None: item.setToolTip(item.text()) |
487 |
#item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
|
488 |
else:
|
489 |
self.setRowCount(0) |
490 |
except Exception as ex: |
491 |
from App import App |
492 |
|
493 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
494 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
495 |
|
496 |
'''
|
497 |
@brief combobox change event
|
498 |
@author kyouho
|
499 |
@date 2018.08.28
|
500 |
'''
|
501 |
def upStreamChanged(self, text): |
502 |
if self._item is not None: |
503 |
find = False
|
504 |
for index in range(len(self._item.attrs)): |
505 |
if type(self._item.attrs[index]) is tuple and self._item.attrs[index][0] == 'Up Stream': |
506 |
self._item.attrs[index] = (self._item.attrs[index][0], text) |
507 |
find = True
|
508 |
break
|
509 |
|
510 |
if not find: |
511 |
self._item.attrs.append(('Up Stream', text)) |
512 |
|
513 |
'''
|
514 |
@brief combobox change event
|
515 |
@author kyouho
|
516 |
@date 2018.08.28
|
517 |
'''
|
518 |
def downStreamChanged(self, text): |
519 |
if self._item is not None: |
520 |
find = False
|
521 |
for index in range(len(self._item.attrs)): |
522 |
if type(self._item.attrs[index]) is tuple and self._item.attrs[index][0] == 'Down Stream': |
523 |
self._item.attrs[index] = (self._item.attrs[index][0], text) |
524 |
find = True
|
525 |
break
|
526 |
|
527 |
if not find: |
528 |
self._item.attrs.append(('Down Stream', text)) |
529 |
|
530 |
'''
|
531 |
@brief find text item using uid
|
532 |
@author kyouho
|
533 |
@date ?
|
534 |
'''
|
535 |
def findTextItemFromUID(self, uid): |
536 |
items = [item for item in self.mainWindow.graphicsView.scene.items() if issubclass(type(item), QEngineeringTextItem)] |
537 |
for item in items: |
538 |
if item.uid == uid:
|
539 |
return item
|
540 |
return None |
541 |
|
542 |
'''
|
543 |
@brief Initialize Note Contents Cell
|
544 |
@author Jeongwoo
|
545 |
@date 18.04.27
|
546 |
'''
|
547 |
def initNoteCell(self, noteNoStr, noteContentsList): |
548 |
self.setRowCount(0) |
549 |
|
550 |
for key in noteContentsList: |
551 |
row = self.rowCount()
|
552 |
self.setRowCount(row + len(noteContentsList[key])) |
553 |
item = QTableWidgetItem(key) |
554 |
self.setItem(row, 0, item) |
555 |
|
556 |
for index in range(len(noteContentsList[key])): |
557 |
self.setItem(row, 1, QTableWidgetItem(noteContentsList[key][index])) |
558 |
row = row + 1
|
559 |
|
560 |
for index in range(self.rowCount()): |
561 |
item = self.item(index, 0) |
562 |
if item is not None: |
563 |
item.setFlags(Qt.ItemIsEnabled) |
564 |
item.setBackground(Qt.lightGray) |
565 |
|
566 |
'''
|
567 |
@brief Initialize Line No Contents Cell
|
568 |
@author Jeongwoo
|
569 |
@date 18.05.10
|
570 |
@history humkyung 2018.07.20 display combobox when key is 'Stream No'
|
571 |
'''
|
572 |
def initLineNoCell(self, lineNoItem): |
573 |
appDocData = AppDocData.instance() |
574 |
configs = appDocData.getConfigs('Line No', 'Configuration') |
575 |
configs = configs[0].value.split('"-"') |
576 |
|
577 |
item = QTableWidgetItem(str(lineNoItem.uid))
|
578 |
item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable) |
579 |
self.setItem(0, 1, item) |
580 |
|
581 |
self.show_item_properties(lineNoItem)
|
582 |
|
583 |
row = self.rowCount()
|
584 |
attrs = lineNoItem.getAttributes() |
585 |
self.setRowCount(row + len(attrs)) |
586 |
if attrs is not None: |
587 |
for key in attrs.keys(): |
588 |
item = QTableWidgetItem(key.DisplayAttribute if key.DisplayAttribute else key.Attribute) |
589 |
item.setFlags(Qt.ItemIsEnabled) |
590 |
item.setBackground(Qt.lightGray) |
591 |
item.tag = key |
592 |
self.setItem(row, 0, item) |
593 |
|
594 |
# value cell
|
595 |
value = attrs[key] |
596 |
valueCell = QTableWidgetItem(value) |
597 |
|
598 |
# UID로 확인
|
599 |
keyStr = appDocData.getLinePropertiesByUID(key.UID) |
600 |
if keyStr:
|
601 |
# editable value cell
|
602 |
if keyStr[0].AttributeType == 'String': |
603 |
pass
|
604 |
#self.attrValueList.append((valueCell, key.Attribute))
|
605 |
#self.stringCell.append(valueCell)
|
606 |
if keyStr[0].UID in configs: valueCell.setFlags(Qt.ItemIsEnabled) |
607 |
else:
|
608 |
valueCell.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable) |
609 |
|
610 |
if key.Attribute.upper() == 'STREAM_NO': |
611 |
self.streamNoComboBox = QComboBox()
|
612 |
self.streamNoComboBox.tag = key
|
613 |
self.streamNoComboBox.currentIndexChanged.connect(self.onStreamNoChanged) |
614 |
|
615 |
streamNos = sorted(list(appDocData.hmbTable.streamNos())) |
616 |
for streamNo in streamNos: |
617 |
self.streamNoComboBox.addItem(streamNo)
|
618 |
self.setCellWidget(row, 1, self.streamNoComboBox) |
619 |
self.streamNoComboBox.setCurrentText(value)
|
620 |
else:
|
621 |
## 만약 Key 값이 CONN이면
|
622 |
if key.Attribute == 'CONN': |
623 |
from PyQt5 import QtGui |
624 |
icon = QtGui.QIcon() |
625 |
icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
626 |
valueCell.setIcon(icon) |
627 |
|
628 |
self.setItem(row, 1, valueCell) |
629 |
|
630 |
row = row + 1
|
631 |
|
632 |
'''
|
633 |
@brief change selected lines' stream no by selected stream no
|
634 |
@author humkyung
|
635 |
@date 2018.07.20
|
636 |
'''
|
637 |
def onStreamNoChanged(self, param): |
638 |
items = self.mainWindow.graphicsView.scene.selectedItems()
|
639 |
if items is not None and len(items) == 1: |
640 |
if type(items[0]) is QEngineeringLineNoTextItem: |
641 |
stream_no = self.streamNoComboBox.itemText(param)
|
642 |
items[0].setAttribute(self.streamNoComboBox.tag, stream_no) |
643 |
return
|
644 |
|
645 |
'''
|
646 |
@brief Initialize Run Contents Cell
|
647 |
@author humkyung
|
648 |
@date 2018.05.27
|
649 |
'''
|
650 |
def initLineRunCell(self, item): |
651 |
self.setRowCount(1) |
652 |
|
653 |
lineTypeItem = QTableWidgetItem("라인 타입")
|
654 |
lineTypeItem.setBackground(Qt.lightGray) |
655 |
lineTypeItem.setFlags(Qt.ItemIsEnabled) |
656 |
self.setItem(0, 0, lineTypeItem) |
657 |
|
658 |
'''
|
659 |
@brief Key Press Event
|
660 |
@author kyouho
|
661 |
@date 2018.07.19
|
662 |
'''
|
663 |
def keyPressEvent(self, event): |
664 |
if event.key() == Qt.Key_Delete:
|
665 |
items = self.mainWindow.graphicsView.scene.selectedItems()
|
666 |
selectedIndexes = self.selectedIndexes()
|
667 |
if len(items) == 1 and len(selectedIndexes) == 1 and type(items[0]) is not QEngineeringLineItem and type(items[0]) is not QEngineeringSpecBreakItem and self.item(selectedIndexes[0].row(), 0).text().find('CONN') is not 0: |
668 |
if selectedIndexes[0].column() == 1: |
669 |
attributeStr = self.item(selectedIndexes[0].row(), 0).text() |
670 |
items[0].removeSelfAttr(attributeStr)
|
671 |
self.mainWindow.refreshResultPropertyTableWidget()
|
672 |
elif len(items) == 1 and len(selectedIndexes) == 1 and (type(items[0]) is QEngineeringLineItem or issubclass(type(items[0]), SymbolSvgItem)): |
673 |
keyCell = self.item(selectedIndexes[0].row(), 0) |
674 |
if selectedIndexes[0].column() == 1 and keyCell.text().find('CONN') is 0: |
675 |
selectedUID = self.item(selectedIndexes[0].row(), 1).text() |
676 |
connNum = int(keyCell.text().replace('CONN', '')) |
677 |
items[0].connectors[connNum - 1].connectedItem = None |
678 |
self.show_item_property(items[0]) |
679 |
|
680 |
for sceneItem in self.mainWindow.graphicsView.scene.items(): |
681 |
if hasattr(sceneItem, 'uid') and str(sceneItem.uid) == selectedUID and hasattr(sceneItem, 'connectors'): |
682 |
for sceneConnector in sceneItem.connectors: |
683 |
if sceneConnector.connectedItem is not None and items[0].uid == sceneConnector.connectedItem.uid: |
684 |
sceneConnector.connectedItem = None
|
685 |
elif len(items) == 1 and len(selectedIndexes) == 1 and type(items[0]) is QEngineeringSpecBreakItem: |
686 |
keyCell = self.item(selectedIndexes[0].row(), 0) |
687 |
if selectedIndexes[0].column() == 1 and (keyCell.text() == 'UpStream' or keyCell.text() == 'DownStream'): |
688 |
for attr in items[0].attrs.keys(): |
689 |
if attr.Attribute == keyCell.text():
|
690 |
items[0].attrs[attr] = None |
691 |
self.show_item_property(items[0]) |
692 |
|
693 |
'''
|
694 |
@brief int cell check
|
695 |
@author kyouho
|
696 |
@date 2018.08.20
|
697 |
'''
|
698 |
def cellChangedEvent(self, row, column): |
699 |
try:
|
700 |
cell = self.item(row, 0) |
701 |
if cell is not None: |
702 |
data = cell.data(Qt.UserRole) |
703 |
if data is not None and not data.is_selectable: |
704 |
if self._item: self._item.properties[data] = self.item(row, column).text() |
705 |
except Exception as ex: |
706 |
from App import App |
707 |
from AppDocData import MessageType |
708 |
|
709 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
710 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
711 |
|
712 |
"""
|
713 |
key = self.item(row, 0).tag
|
714 |
cell = self.item(row, column)
|
715 |
|
716 |
items = self.mainWindow.graphicsView.scene.selectedItems()
|
717 |
if items is not None and len(items) == 1:
|
718 |
if type(items[0]) is QEngineeringLineNoTextItem:
|
719 |
items[0].setAttribute(key, cell.text())
|
720 |
elif issubclass(type(items[0]), SymbolSvgItem) and type(items[0]) is not QEngineeringSpecBreakItem:
|
721 |
items[0].setAttribute(key, cell.text())
|
722 |
else:
|
723 |
return
|
724 |
"""
|
725 |
|
726 |
'''
|
727 |
@brief Check Number
|
728 |
@author kyouho
|
729 |
@date 2018.08.20
|
730 |
'''
|
731 |
def isNumber(self, num): |
732 |
p = re.compile('(^[0-9]+$)')
|
733 |
result = p.match(num) |
734 |
|
735 |
if result:
|
736 |
return True |
737 |
else:
|
738 |
return False |
739 |
|
740 |
'''
|
741 |
@brief resultPropertyTableWidget Cell Double Click Event
|
742 |
@author kyouho
|
743 |
@date 2018.07.19
|
744 |
@history euisung 2019.01.15 edit specbreak
|
745 |
'''
|
746 |
def cellDoubleClickedEvent(self, row, column): |
747 |
from SymbolAttr import SymbolProp |
748 |
|
749 |
if column == 1: |
750 |
items = self.mainWindow.graphicsView.scene.selectedItems()
|
751 |
keyCell = self.item(row, 0) |
752 |
attr = keyCell.data(Qt.UserRole) |
753 |
if hasattr(keyCell, 'tag') and type(items[0]) is not QEngineeringSpecBreakItem: |
754 |
attr = keyCell.tag |
755 |
if attr.is_selectable:
|
756 |
cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView) |
757 |
cmd.onSuccess.connect(self.onSuccessSelectAttribute)
|
758 |
self.mainWindow.graphicsView.command = cmd
|
759 |
elif self.item(row, column).flags() != Qt.ItemIsEnabled: |
760 |
self.editItem(self.item(row, column)) |
761 |
elif keyCell.text() == 'CONN' and type(items[0]) is QEngineeringLineNoTextItem: |
762 |
from SymbolAttr import SymbolAttr |
763 |
attr = SymbolAttr() |
764 |
attr.AttributeType = "Line Item"
|
765 |
cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView) |
766 |
cmd.onSuccess.connect(self.onSuccessSelectAttribute)
|
767 |
self.mainWindow.graphicsView.command = cmd
|
768 |
elif keyCell.text() == 'OWNER' and ((type(items[0]) is QEngineeringLineItem) or (issubclass(type(items[0]), SymbolSvgItem))): |
769 |
attr = keyCell.data(Qt.UserRole) |
770 |
cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView) |
771 |
cmd.onSuccess.connect(self.onSuccessSelectAttribute)
|
772 |
self.mainWindow.graphicsView.command = cmd
|
773 |
elif type(items[0]) is QEngineeringSpecBreakItem: |
774 |
if keyCell.text() == 'UpStream' or keyCell.text() == 'DownStream': |
775 |
attr = keyCell.data(Qt.UserRole) |
776 |
cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView) |
777 |
cmd.onSuccess.connect(self.onSuccessSelectAttribute)
|
778 |
self.mainWindow.graphicsView.command = cmd
|
779 |
|
780 |
elif keyCell.text() == 'Set Specs': |
781 |
from SpecBreakDialog import QSpecBreakDialog |
782 |
|
783 |
try:
|
784 |
dialog = QSpecBreakDialog(self, items[0]) |
785 |
dialog.exec_() |
786 |
self.show_item_property(items[0]) |
787 |
except Exception as ex: |
788 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
789 |
elif issubclass(type(attr), SymbolProp): |
790 |
attr = keyCell.data(Qt.UserRole) |
791 |
cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView) |
792 |
cmd.onSuccess.connect(self.onSuccessSelectAttribute)
|
793 |
self.mainWindow.graphicsView.command = cmd
|
794 |
|
795 |
'''
|
796 |
@brief success select attribute
|
797 |
@author kyouho
|
798 |
@date 2018.10.23
|
799 |
'''
|
800 |
def onSuccessSelectAttribute(self, connItem = None): |
801 |
""" update item's properties after selecting """
|
802 |
self.show_item_property(self._item) |