hytos / HYTOS / HYTOS / SymbolTreeWidget.py @ 506c5823
이력 | 보기 | 이력해설 | 다운로드 (6.27 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.initSymbolTreeWidget()
|
28 |
#self.itemDoubleClicked.connect(self.itemDoubleClickEvent)
|
29 |
|
30 |
|
31 |
'''
|
32 |
@history 2019.07.11 yeonjin 심벌 편집 시 png 파일이 아닌 svg 파일을 불러 오도록 수정
|
33 |
|
34 |
'''
|
35 |
def showSymbolEditorDialog(self, sym): |
36 |
try:
|
37 |
path = sym.getSvgFileFullPath() |
38 |
image = QImage(path, "SVG")
|
39 |
symbolEditorDialog = SymbolEditorDialog.QSymbolEditorDialog(self, image, AppDocData.instance().getCurrentProject(), sym)
|
40 |
(isAccepted, isImmediateInsert, offsetX, offsetY, newSym) = symbolEditorDialog.showDialog() |
41 |
self.initSymbolTreeWidget()
|
42 |
except Exception as ex: |
43 |
from App import App |
44 |
|
45 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
46 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
47 |
|
48 |
|
49 |
def getSymbolByItemUID(self, item): |
50 |
uid = item.text(1)
|
51 |
|
52 |
return AppDocData.instance().getSymbolByQuery("uid", uid) |
53 |
|
54 |
def itemDoubleClickEvent(self, item, columnNo): |
55 |
|
56 |
sym = self.getSymbolByItemUID(item)
|
57 |
if sym is not None: |
58 |
self.showSymbolEditorDialog(sym)
|
59 |
|
60 |
|
61 |
'''
|
62 |
@history 2018.05.02 Jeongwoo Change return value of QSymbolEditorDialog (Single variable → Tuple)
|
63 |
'''
|
64 |
def initSymbolTreeWidget(self): |
65 |
project = AppDocData.instance().getCurrentProject() |
66 |
if project is not None: |
67 |
self.clear()
|
68 |
self.makeChildDir()
|
69 |
self.loadSymbolInfo()
|
70 |
self.expandAll()
|
71 |
|
72 |
'''
|
73 |
@brief Load Symbol Info and add TreeItem with DB
|
74 |
@author Jeongwoo
|
75 |
@date 18.04.20
|
76 |
@history Jeongwoo 2018.05.03 Get Svg File Path by SymbolBase.getSvgFileFullPath()
|
77 |
humkyung 2018.07.30 sort child items
|
78 |
'''
|
79 |
def loadSymbolInfo(self): |
80 |
try:
|
81 |
symbolCategoryList = AppDocData.instance().getSymbolCategoryList() |
82 |
for symbolCategory in symbolCategoryList: |
83 |
if symbolCategory == 'Stream Line': |
84 |
continue
|
85 |
parent = QTreeWidgetItem(self, [symbolCategory])
|
86 |
parent.setData(0, self.TREE_DATA_ROLE, symbolCategory) |
87 |
|
88 |
symbolTypeList = AppDocData.instance().getSymbolTypeListByCategory(symbolCategory) |
89 |
for symbolType in symbolTypeList: |
90 |
category = QTreeWidgetItem(parent, [symbolType[2]])
|
91 |
category.setData(0, self.TREE_DATA_ROLE, symbolType) |
92 |
|
93 |
symbolList = AppDocData.instance().getSymbolListByUID(symbolType[0])
|
94 |
for symbol in symbolList: |
95 |
#symbolItem = QTreeWidgetItem(category, [symbol.getName()])
|
96 |
symbolItem = QTreeWidgetItem(category, [symbol.sName, symbol.uid]) |
97 |
symbolItem.setData(0, self.TREE_DATA_ROLE, symbol) |
98 |
svgPath = symbol.getSvgFileFullPath() |
99 |
icon = QIcon(svgPath) |
100 |
symbolItem.setIcon(0, icon)
|
101 |
symbolItem.svgFilePath = svgPath # save svg file path
|
102 |
|
103 |
parent.sortChildren(0, Qt.AscendingOrder)
|
104 |
except Exception as ex: |
105 |
from App import App |
106 |
|
107 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
108 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
109 |
|
110 |
'''
|
111 |
@brief Make Directory
|
112 |
@author Jeongwoo
|
113 |
@date 18.04.??
|
114 |
@history 18.04.12 Jeongwoo Add output, temp Directory
|
115 |
'''
|
116 |
def makeChildDir(self): |
117 |
project = AppDocData.instance().getCurrentProject() |
118 |
dbDir = project.getDbFilePath() |
119 |
if not os.path.exists(dbDir): |
120 |
os.makedirs(dbDir) |
121 |
imgDir = project.getImageFilePath() |
122 |
if not os.path.exists(imgDir): |
123 |
os.makedirs(imgDir) |
124 |
svgDir = project.getSvgFilePath() |
125 |
if not os.path.exists(svgDir): |
126 |
os.makedirs(svgDir) |
127 |
outputDir = project.getOutputPath() |
128 |
if not os.path.exists(outputDir): |
129 |
os.makedirs(outputDir) |
130 |
tempDir = project.getTempPath() |
131 |
if not os.path.exists(tempDir): |
132 |
os.makedirs(tempDir) |
133 |
|
134 |
'''
|
135 |
@brief start drag
|
136 |
@author humkyung
|
137 |
@date 2018.04.17
|
138 |
@history 18.04.20 Jeongwoo Change Path in QPixmap
|
139 |
18.06.21 Jeongwoo Casting string to float and int
|
140 |
'''
|
141 |
def startDrag(self, dropAction): |
142 |
try:
|
143 |
items = self.selectedItems()
|
144 |
if items and hasattr(items[0], 'svgFilePath'): |
145 |
symData = items[0].data(0, self.TREE_DATA_ROLE) |
146 |
pixmap = QPixmap(items[0].svgFilePath)
|
147 |
|
148 |
mime = QMimeData() |
149 |
#mime.setText(symData.getName())
|
150 |
mime.setText(symData.getUid()) |
151 |
|
152 |
drag = QDrag(self)
|
153 |
drag.setMimeData(mime) |
154 |
originalPoint = symData.getOriginalPoint() |
155 |
drag.setHotSpot(QPoint(int(float(originalPoint.split(",")[0])), int(float(originalPoint.split(",")[1])))) |
156 |
drag.setPixmap(pixmap) |
157 |
drag.exec(Qt.CopyAction) |
158 |
except Exception as ex: |
159 |
from App import App |
160 |
|
161 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
162 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |