개정판 a1723c66
issue #628: 자주 사용하는 심볼을 즐겨 찾기에 추가하여 도면에 입력할 수 있다
Change-Id: I76f3ff8aaa698693c4b79c9173b6fd4012cc8380
DTI_PID/DTI_PID/AppDocData.py | ||
---|---|---|
618 | 618 |
|
619 | 619 |
return targetSymbolList |
620 | 620 |
|
621 |
def get_libraries(self): |
|
622 |
res = [] |
|
623 |
|
|
624 |
with self.project.database.connect() as conn: |
|
625 |
cursor = conn.cursor() |
|
626 |
sql = f"SELECT a.UID,a.Name,b.Type,a.Threshold,a.MinMatchPoint,a.IsDetectOrigin,a.RotationCount," \ |
|
627 |
f"a.OCROption,a.IsContainChild,a.OriginalPoint,a.ConnectionPoint,a.BaseSymbol,a.AdditionalSymbol," \ |
|
628 |
f"a.IsExceptDetect,a.HasInstrumentLabel,a.flip,a.TextArea,b.UID FROM Symbol a inner join " \ |
|
629 |
f"SymbolType b on a.SymbolType_UID=b.UID " \ |
|
630 |
f"inner join Libraries C on a.UID=C.Symbol_UID WHERE " \ |
|
631 |
f"C.User='{os.environ['COMPUTERNAME'].upper()}'" |
|
632 |
try: |
|
633 |
cursor.execute(sql) |
|
634 |
rows = cursor.fetchall() |
|
635 |
for row in rows: |
|
636 |
sym = symbol.SymbolBase(row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], |
|
637 |
row[10], row[11], row[12], row[13], row[14], row[0], iType=row[17], |
|
638 |
detectFlip=row[15], text_area=row[16]) # uid is last item |
|
639 |
res.append(sym) |
|
640 |
except Exception as ex: |
|
641 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
642 |
sys.exc_info()[-1].tb_lineno)) |
|
643 |
|
|
644 |
return res |
|
645 |
|
|
621 | 646 |
def buildAppDatabase(self): |
622 | 647 |
"""build application database""" |
623 | 648 |
path = os.path.join(os.getenv('ALLUSERSPROFILE'), 'Digital PID') |
DTI_PID/DTI_PID/LibraryItem.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
""" This is library module """ |
|
3 |
|
|
4 |
from PyQt5.QtCore import * |
|
5 |
from PyQt5.QtGui import * |
|
6 |
from PyQt5.QtWidgets import * |
|
7 |
from PyQt5.QtSvg import * |
|
8 |
|
|
9 |
|
|
10 |
class LibraryItemWidget(QWidget): |
|
11 |
COLUMN = 3 |
|
12 |
|
|
13 |
def __init__(self, parent=None): |
|
14 |
super().__init__(parent) |
|
15 |
self.setAcceptDrops(True) |
|
16 |
|
|
17 |
self.layout = QGridLayout() |
|
18 |
self.setLayout(self.layout) |
|
19 |
|
|
20 |
def remove_library(self, item): |
|
21 |
matches = [idx for idx in range(self.layout.count()) if self.layout.itemAt(idx).widget() is item] |
|
22 |
if matches: |
|
23 |
layout_item = self.layout.takeAt(matches[0]) |
|
24 |
self.layout.removeWidget(item) |
|
25 |
item.deleteLater() |
|
26 |
del item |
|
27 |
self.layout.removeItem(layout_item) |
|
28 |
del layout_item |
|
29 |
|
|
30 |
self.layout.update() |
|
31 |
|
|
32 |
def dragEnterEvent(self, event: QDragEnterEvent) -> None: |
|
33 |
if issubclass(type(event.source()), QTreeWidget) and event.mimeData().hasFormat('text/plain'): |
|
34 |
|
|
35 |
# check if symbol is already registered |
|
36 |
for idx in range(self.layout.count()): |
|
37 |
widget = self.layout.itemAt(idx).widget() |
|
38 |
id = f"{event.mimeData().tag.getType()}.{event.mimeData().tag.getName()}" |
|
39 |
if widget.id == id: |
|
40 |
event.ignore() |
|
41 |
return |
|
42 |
# up to here |
|
43 |
event.accept() |
|
44 |
else: |
|
45 |
event.ignore() |
|
46 |
|
|
47 |
def dropEvent(self, event: QDropEvent) -> None: |
|
48 |
if hasattr(event.mimeData(), 'tag'): |
|
49 |
item = LibraryItem(event.mimeData().tag) |
|
50 |
row = int((self.layout.count()) / LibraryItemWidget.COLUMN) |
|
51 |
col = (self.layout.count()) % LibraryItemWidget.COLUMN |
|
52 |
self.layout.addWidget(item, row, col) |
|
53 |
|
|
54 |
event.acceptProposedAction() |
|
55 |
|
|
56 |
|
|
57 |
class LibraryItem(QFrame): |
|
58 |
def __init__(self, symbol): |
|
59 |
QFrame.__init__(self) |
|
60 |
self.id = f"{symbol.getType()}.{symbol.getName()}" |
|
61 |
self._symbol = symbol |
|
62 |
# An Icon and a label below |
|
63 |
icon = QLabel() |
|
64 |
icon.resize(symbol.pixmap.width(), symbol.pixmap.height()) |
|
65 |
icon.setPixmap(symbol.pixmap) |
|
66 |
layout = QGridLayout() |
|
67 |
layout.addWidget(icon, 0, 0, Qt.AlignHCenter) |
|
68 |
title = QLabel(symbol.getName()) |
|
69 |
font = title.font() |
|
70 |
font.setPixelSize(10) |
|
71 |
title.setFont(font) |
|
72 |
layout.addWidget(title, 1, 0, Qt.AlignTop | Qt.AlignHCenter) |
|
73 |
self.setLayout(layout) |
|
74 |
self.setMaximumSize(64, 64) |
|
75 |
|
|
76 |
@property |
|
77 |
def symbol(self): |
|
78 |
return self._symbol |
|
79 |
|
|
80 |
def keyPressEvent(self, event: QKeyEvent) -> None: |
|
81 |
if event.key() == Qt.Key_Delete: |
|
82 |
self.parentWidget().remove_library(self) |
|
83 |
return |
|
84 |
|
|
85 |
super(LibraryItem, self).keyPressEvent(event) |
|
86 |
|
|
87 |
""" |
|
88 |
Drag and drop management |
|
89 |
""" |
|
90 |
|
|
91 |
def enterEvent(self, event): |
|
92 |
self.setFrameStyle(QFrame.Panel | QFrame.Sunken) |
|
93 |
self.setCursor(Qt.OpenHandCursor) |
|
94 |
self.setFocus() |
|
95 |
|
|
96 |
def leaveEvent(self, event): |
|
97 |
self.setFrameStyle(QFrame.NoFrame) |
|
98 |
self.setCursor(Qt.ArrowCursor) |
|
99 |
|
|
100 |
def mousePressEvent(self, mouseEvent): |
|
101 |
self.setCursor(Qt.ClosedHandCursor) |
|
102 |
|
|
103 |
def mouseReleaseEvent(self, mouseEvent): |
|
104 |
self.setCursor(Qt.OpenHandCursor) |
|
105 |
|
|
106 |
def mouseMoveEvent(self, event): |
|
107 |
"""Drag-n-Drop on left click""" |
|
108 |
if event.buttons() != Qt.LeftButton: |
|
109 |
return |
|
110 |
|
|
111 |
mime = QMimeData() |
|
112 |
mime.setText(self._symbol.getName()) |
|
113 |
|
|
114 |
drag = QDrag(self) |
|
115 |
drag.setMimeData(mime) |
|
116 |
originalPoint = self._symbol.getOriginalPoint() |
|
117 |
drag.setHotSpot(QPoint(int(float(originalPoint.split(",")[0])), int(float(originalPoint.split(",")[1])))) |
|
118 |
drag.setPixmap(self._symbol.pixmap) |
|
119 |
drag.exec(Qt.CopyAction) |
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
172 | 172 |
self.symbolTreeWidget.header().hide() |
173 | 173 |
self.symbolTabVerticalLayout.addWidget(self.symbolTreeWidget) |
174 | 174 |
|
175 |
from LibraryItem import LibraryItemWidget |
|
176 |
self.propertyTableWidget = LibraryItemWidget() |
|
177 |
self.symbolTabVerticalLayout.addWidget(self.propertyTableWidget) |
|
178 |
""" |
|
175 | 179 |
# Add Custom Property TableWidget |
176 | 180 |
self.propertyTableWidget = SymbolPropertyTableWidget.QSymbolPropertyTableWidget() |
177 | 181 |
self.symbolTabVerticalLayout.addWidget(self.propertyTableWidget) |
178 | 182 |
self.symbolTreeWidget.singleClicked.connect(self.propertyTableWidget.getClickedSymbol) |
183 |
""" |
|
179 | 184 |
# add splitter widget |
180 | 185 |
splitter = QSplitter(Qt.Vertical) |
181 | 186 |
splitter.addWidget(self.symbolTreeWidget) |
DTI_PID/DTI_PID/RecognitionDialog.py | ||
---|---|---|
825 | 825 |
global targetSymbolList |
826 | 826 |
|
827 | 827 |
targetSymbolList.clear() |
828 |
appDocData = AppDocData.instance()
|
|
829 |
symbolList = appDocData.getTargetSymbolList()
|
|
830 |
equipments = [item for item in symbolList if appDocData.getSymbolCategoryByType(item.getType()) == 'Equipment']
|
|
828 |
app_doc_data = AppDocData.instance()
|
|
829 |
symbolList = app_doc_data.getTargetSymbolList()
|
|
830 |
equipments = [item for item in symbolList if app_doc_data.getSymbolCategoryByType(item.getType()) == 'Equipment']
|
|
831 | 831 |
nozzles = [item for item in symbolList if item.getType() == 'Nozzles'] |
832 | 832 |
# [[equipments],[nozzles],[symbols]] |
833 | 833 |
targetSymbolList.append(equipments) |
DTI_PID/DTI_PID/SymbolBase.py | ||
---|---|---|
41 | 41 |
else: |
42 | 42 |
self.text_area = text_area |
43 | 43 |
|
44 |
self._pixmap = None |
|
45 |
|
|
46 |
@property |
|
47 |
def pixmap(self): |
|
48 |
return self._pixmap |
|
49 |
|
|
50 |
@pixmap.setter |
|
51 |
def pixmap(self, value): |
|
52 |
self._pixmap = value |
|
53 |
|
|
44 | 54 |
def setUid(self, uid): |
45 | 55 |
self.uid = uid |
46 | 56 |
|
DTI_PID/DTI_PID/SymbolTreeWidget.py | ||
---|---|---|
212 | 212 |
|
213 | 213 |
_, svg = app_doc_data.read_symbol_shape(symbol.sName) |
214 | 214 |
if svg: |
215 |
pixmap = QPixmap(QSize(32, 32)) |
|
216 |
pixmap.loadFromData(svg if isinstance(svg, bytes) else svg.encode()) |
|
217 |
icon = QIcon(pixmap) |
|
215 |
symbol.pixmap = QPixmap(QSize(32, 32))
|
|
216 |
symbol.pixmap.loadFromData(svg if isinstance(svg, bytes) else svg.encode())
|
|
217 |
icon = QIcon(symbol.pixmap)
|
|
218 | 218 |
symbolItem.setIcon(0, icon) |
219 | 219 |
symbolItem.svgFilePath = None # save svg file path |
220 | 220 |
else: |
221 | 221 |
svgPath = symbol.getSvgFileFullPath() |
222 | 222 |
icon = QIcon(svgPath) |
223 |
symbol.pixmap = icon.pixmap(QSize(32, 32)) |
|
223 | 224 |
symbolItem.setIcon(0, icon) |
224 | 225 |
symbolItem.svgFilePath = svgPath # save svg file path |
225 | 226 |
|
... | ... | |
359 | 360 |
|
360 | 361 |
mime = QMimeData() |
361 | 362 |
mime.setText(symData.getName()) |
363 |
mime.tag = symData |
|
362 | 364 |
|
363 | 365 |
drag = QDrag(self) |
364 | 366 |
drag.setMimeData(mime) |
내보내기 Unified diff