hytos / HYTOS / HYTOS / SymbolTreeWidget.py @ aff7c828
이력 | 보기 | 이력해설 | 다운로드 (6.02 KB)
1 |
try:
|
---|---|
2 |
from PyQt5.QtCore import * |
3 |
from PyQt5.QtGui import * |
4 |
from PyQt5.QtWidgets import * |
5 |
except ImportError: |
6 |
try:
|
7 |
from PyQt4.QtCore import * |
8 |
from PyQt4.QtGui import * |
9 |
except ImportError: |
10 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
11 |
from AppDocData import * |
12 |
import os |
13 |
import sys |
14 |
import SymbolBase |
15 |
import symbol |
16 |
import SymbolEditorDialog |
17 |
import QSymbolDisplayDialog |
18 |
|
19 |
class QSymbolTreeWidget(QTreeWidget): |
20 |
# Add signal
|
21 |
singleClicked = pyqtSignal(SymbolBase.SymbolBase) |
22 |
TREE_DATA_ROLE = Qt.UserRole |
23 |
|
24 |
def __init__(self): |
25 |
QTreeWidget.__init__(self)
|
26 |
self.setDragEnabled(True) # enable drag |
27 |
self.setIconSize(QSize(32, 32)) |
28 |
|
29 |
'''
|
30 |
@history 2019.07.11 yeonjin 심벌 편집 시 png 파일이 아닌 svg 파일을 불러 오도록 수정
|
31 |
|
32 |
'''
|
33 |
def showSymbolEditorDialog(self, sym): |
34 |
try:
|
35 |
path = sym.getSvgFileFullPath() |
36 |
image = QImage(path, "SVG")
|
37 |
symbolEditorDialog = SymbolEditorDialog.QSymbolEditorDialog(self, image, AppDocData.instance().getCurrentProject(), sym)
|
38 |
(isAccepted, isImmediateInsert, offsetX, offsetY, newSym) = symbolEditorDialog.showDialog() |
39 |
self.initSymbolTreeWidget()
|
40 |
except Exception as ex: |
41 |
from App import App |
42 |
|
43 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
44 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
45 |
|
46 |
|
47 |
def getSymbolByItemUID(self, item): |
48 |
uid = item.text(1)
|
49 |
|
50 |
return AppDocData.instance().getSymbolByQuery("uid", uid) |
51 |
|
52 |
def itemDoubleClickEvent(self, item, columnNo): |
53 |
|
54 |
sym = self.getSymbolByItemUID(item)
|
55 |
if sym is not None: |
56 |
self.showSymbolEditorDialog(sym)
|
57 |
|
58 |
|
59 |
'''
|
60 |
@history 2018.05.02 Jeongwoo Change return value of QSymbolEditorDialog (Single variable → Tuple)
|
61 |
'''
|
62 |
def initSymbolTreeWidget(self): |
63 |
self.clear()
|
64 |
self.loadSymbolInfo()
|
65 |
self.expandAll()
|
66 |
|
67 |
'''
|
68 |
@brief Load Symbol Info and add TreeItem with DB
|
69 |
@author Jeongwoo
|
70 |
@date 18.04.20
|
71 |
@history Jeongwoo 2018.05.03 Get Svg File Path by SymbolBase.getSvgFileFullPath()
|
72 |
humkyung 2018.07.30 sort child items
|
73 |
'''
|
74 |
def loadSymbolInfo(self): |
75 |
from PyQt5.QtSvg import QSvgRenderer |
76 |
|
77 |
try:
|
78 |
app_doc_data = AppDocData.instance() |
79 |
symbolCategoryList = app_doc_data.getSymbolCategoryList() |
80 |
for symbolCategory in symbolCategoryList: |
81 |
if symbolCategory == 'Stream Line': |
82 |
continue
|
83 |
parent = QTreeWidgetItem(self, [symbolCategory])
|
84 |
parent.setData(0, self.TREE_DATA_ROLE, symbolCategory) |
85 |
|
86 |
symbolTypeList = app_doc_data.getSymbolTypeListByCategory(symbolCategory) |
87 |
for symbolType in symbolTypeList: |
88 |
category = QTreeWidgetItem(parent, [symbolType[2]])
|
89 |
category.setData(0, self.TREE_DATA_ROLE, symbolType) |
90 |
|
91 |
symbolList = app_doc_data.getSymbolListByUID(symbolType[0])
|
92 |
for symbol in symbolList: |
93 |
symbolItem = QTreeWidgetItem(category, [symbol.sName, symbol.uid]) |
94 |
symbolItem.setData(0, self.TREE_DATA_ROLE, symbol) |
95 |
|
96 |
shape = app_doc_data.read_symbol_shape(app_doc_data.activeDrawing.path, symbol.uid) |
97 |
if shape:
|
98 |
pixmap = QPixmap(QSize(32, 32)) |
99 |
pixmap.loadFromData(shape) |
100 |
icon = QIcon(pixmap) |
101 |
symbolItem.setIcon(0, icon)
|
102 |
symbolItem.svgFilePath = None # reset svg file path |
103 |
else:
|
104 |
svgPath = symbol.getSvgFileFullPath() |
105 |
icon = QIcon(svgPath) |
106 |
symbolItem.setIcon(0, icon)
|
107 |
symbolItem.svgFilePath = svgPath # save svg file path
|
108 |
|
109 |
parent.sortChildren(0, Qt.AscendingOrder)
|
110 |
except Exception as ex: |
111 |
from App import App |
112 |
|
113 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
114 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
115 |
|
116 |
'''
|
117 |
@brief start drag
|
118 |
@author humkyung
|
119 |
@date 2018.04.17
|
120 |
@history 18.04.20 Jeongwoo Change Path in QPixmap
|
121 |
18.06.21 Jeongwoo Casting string to float and int
|
122 |
'''
|
123 |
def startDrag(self, dropAction): |
124 |
try:
|
125 |
items = self.selectedItems()
|
126 |
if items and hasattr(items[0], 'svgFilePath'): |
127 |
symData = items[0].data(0, self.TREE_DATA_ROLE) |
128 |
if items[0].svgFilePath: |
129 |
pixmap = QPixmap(items[0].svgFilePath)
|
130 |
else:
|
131 |
app_doc_data = AppDocData.instance() |
132 |
shape = app_doc_data.read_symbol_shape(app_doc_data.activeDrawing.path, symData.uid) |
133 |
if shape:
|
134 |
pixmap = QPixmap() |
135 |
pixmap.loadFromData(shape) |
136 |
|
137 |
mime = QMimeData() |
138 |
mime.setText(symData.getUid()) |
139 |
|
140 |
drag = QDrag(self)
|
141 |
drag.setMimeData(mime) |
142 |
originalPoint = symData.getOriginalPoint() |
143 |
drag.setHotSpot(QPoint(int(float(originalPoint.split(",")[0])), int(float(originalPoint.split(",")[1])))) |
144 |
drag.setPixmap(pixmap) |
145 |
drag.exec(Qt.CopyAction) |
146 |
except Exception as ex: |
147 |
from App import App |
148 |
|
149 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
150 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |