개정판 85ba4667
issue #628: 자주 사용하는 심볼을 즐겨 찾기에 추가하여 도면에 입력할 수 있다
Change-Id: I5432f45bda162b61732eec026e6588abe1779441
DTI_PID/DTI_PID/AppDocData.py | ||
---|---|---|
618 | 618 |
|
619 | 619 |
return targetSymbolList |
620 | 620 |
|
621 |
def get_libraries(self): |
|
621 |
def get_favorite_libraries(self):
|
|
622 | 622 |
res = [] |
623 | 623 |
|
624 | 624 |
with self.project.database.connect() as conn: |
625 | 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()}'" |
|
626 |
sql = f"select UID,Symbol_UID from Libraries where User='{os.environ['COMPUTERNAME'].upper()}'" |
|
632 | 627 |
try: |
633 | 628 |
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) |
|
629 |
return cursor.fetchall() |
|
640 | 630 |
except Exception as ex: |
641 | 631 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
642 | 632 |
sys.exc_info()[-1].tb_lineno)) |
643 | 633 |
|
644 |
return res
|
|
634 |
return None
|
|
645 | 635 |
|
646 | 636 |
def buildAppDatabase(self): |
647 | 637 |
"""build application database""" |
DTI_PID/DTI_PID/LibraryItem.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 |
""" This is library module """ |
3 | 3 |
|
4 |
import sys |
|
4 | 5 |
from PyQt5.QtCore import * |
5 | 6 |
from PyQt5.QtGui import * |
6 | 7 |
from PyQt5.QtWidgets import * |
7 | 8 |
from PyQt5.QtSvg import * |
9 |
from AppDocData import AppDocData, MessageType |
|
8 | 10 |
|
9 | 11 |
|
10 | 12 |
class LibraryItemWidget(QWidget): |
11 | 13 |
COLUMN = 3 |
12 | 14 |
|
13 |
def __init__(self, parent=None): |
|
15 |
def __init__(self, symbol_tree_widget, parent=None):
|
|
14 | 16 |
super().__init__(parent) |
15 |
self.setAcceptDrops(True) |
|
17 |
try: |
|
18 |
self.setAcceptDrops(True) |
|
19 |
self._symbol_tree_widget = symbol_tree_widget |
|
16 | 20 |
|
17 |
self.layout = QGridLayout() |
|
18 |
self.setLayout(self.layout) |
|
21 |
self.layout = QGridLayout() |
|
22 |
self.setLayout(self.layout) |
|
23 |
|
|
24 |
app_doc_data = AppDocData.instance() |
|
25 |
self.favorites = app_doc_data.get_favorite_libraries() |
|
26 |
|
|
27 |
for idx, symbol in enumerate(self._symbol_tree_widget.symbols): |
|
28 |
matches = [favorite for favorite in self.favorites if symbol.getUid() == favorite['Symbol_UID']] |
|
29 |
if matches: |
|
30 |
self.layout.addWidget(LibraryItem(symbol), int(idx / LibraryItemWidget.COLUMN), |
|
31 |
idx % LibraryItemWidget.COLUMN) |
|
32 |
except Exception as ex: |
|
33 |
from App import App |
|
34 |
|
|
35 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
36 |
sys.exc_info()[-1].tb_lineno) |
|
37 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
19 | 38 |
|
20 | 39 |
def remove_library(self, item): |
40 |
"""remove library from widget and delete it from database""" |
|
21 | 41 |
matches = [idx for idx in range(self.layout.count()) if self.layout.itemAt(idx).widget() is item] |
22 | 42 |
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() |
|
43 |
app_doc_data = AppDocData.instance() |
|
44 |
with app_doc_data.project.database.connect() as conn: |
|
45 |
try: |
|
46 |
cursor = conn.cursor() |
|
47 |
sql = 'delete from Libraries where Symbol_UID=?' |
|
48 |
param = (str(item.symbol.getUid()), ) |
|
49 |
cursor.execute(sql, param) |
|
50 |
conn.commit() |
|
51 |
|
|
52 |
layout_item = self.layout.takeAt(matches[0]) |
|
53 |
self.layout.removeWidget(item) |
|
54 |
item.deleteLater() |
|
55 |
del item |
|
56 |
self.layout.removeItem(layout_item) |
|
57 |
del layout_item |
|
58 |
|
|
59 |
self.layout.update() |
|
60 |
except Exception as ex: |
|
61 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
62 |
sys.exc_info()[-1].tb_lineno)) |
|
63 |
|
|
64 |
def add_library(self, item): |
|
65 |
"""add library to widget and save it""" |
|
66 |
import os |
|
67 |
import uuid |
|
68 |
|
|
69 |
row = int((self.layout.count()) / LibraryItemWidget.COLUMN) |
|
70 |
col = (self.layout.count()) % LibraryItemWidget.COLUMN |
|
71 |
self.layout.addWidget(item, row, col) |
|
72 |
|
|
73 |
app_doc_data = AppDocData.instance() |
|
74 |
with app_doc_data.project.database.connect() as conn: |
|
75 |
try: |
|
76 |
cursor = conn.cursor() |
|
77 |
sql = 'insert into Libraries(UID,User,Symbol_UID) values(?,?,?)' |
|
78 |
param = (str(uuid.uuid4()), os.environ['COMPUTERNAME'].upper(), item.symbol.getUid()) |
|
79 |
cursor.execute(sql, param) |
|
80 |
conn.commit() |
|
81 |
except Exception as ex: |
|
82 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
83 |
sys.exc_info()[-1].tb_lineno)) |
|
31 | 84 |
|
32 | 85 |
def dragEnterEvent(self, event: QDragEnterEvent) -> None: |
33 | 86 |
if issubclass(type(event.source()), QTreeWidget) and event.mimeData().hasFormat('text/plain'): |
... | ... | |
47 | 100 |
def dropEvent(self, event: QDropEvent) -> None: |
48 | 101 |
if hasattr(event.mimeData(), 'tag'): |
49 | 102 |
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) |
|
103 |
self.add_library(item) |
|
53 | 104 |
|
54 | 105 |
event.acceptProposedAction() |
55 | 106 |
|
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
173 | 173 |
self.verticalLayoutSymbolTree.addWidget(self.symbolTreeWidget) |
174 | 174 |
|
175 | 175 |
from LibraryItem import LibraryItemWidget |
176 |
self.libraryWidget = LibraryItemWidget() |
|
176 |
self.libraryWidget = LibraryItemWidget(symbol_tree_widget=self.symbolTreeWidget)
|
|
177 | 177 |
self.verticalLayoutLibrary.addWidget(self.libraryWidget) |
178 | 178 |
# Add Custom Property TableWidget |
179 | 179 |
self.propertyTableWidget = SymbolPropertyTableWidget.QSymbolPropertyTableWidget() |
DTI_PID/DTI_PID/Scripts/ID2.sql | ||
---|---|---|
388 | 388 |
Description TEXT, |
389 | 389 |
Allowables TEXT |
390 | 390 |
); |
391 |
|
|
392 |
CREATE TABLE Libraries ( |
|
393 |
UID VARCHAR (37) PRIMARY KEY, |
|
394 |
User VARCHAR (256), |
|
395 |
Symbol_UID INTEGER REFERENCES Symbol (UID), |
|
396 |
UNIQUE ( |
|
397 |
User, |
|
398 |
Symbol_UID |
|
399 |
) |
|
400 |
); |
DTI_PID/DTI_PID/SymbolTreeWidget.py | ||
---|---|---|
23 | 23 |
class QSymbolTreeWidget(QTreeWidget): |
24 | 24 |
# Add signal |
25 | 25 |
singleClicked = pyqtSignal(SymbolBase.SymbolBase) |
26 |
symbols_loaded = pyqtSignal([SymbolBase.SymbolBase]) |
|
26 | 27 |
TREE_DATA_ROLE = Qt.UserRole |
27 | 28 |
|
28 | 29 |
def __init__(self): |
... | ... | |
37 | 38 |
self.customContextMenuRequested.connect(self.openContextMenu) |
38 | 39 |
self.currentItemChanged.connect(self.onCurrentItemChanged) |
39 | 40 |
|
41 |
@property |
|
42 |
def symbols(self): |
|
43 |
"""return symbols""" |
|
44 |
res = [] |
|
45 |
|
|
46 |
try: |
|
47 |
tree_item_stack = [self.invisibleRootItem()] |
|
48 |
while tree_item_stack: |
|
49 |
tree_item = tree_item_stack.pop(0) |
|
50 |
if tree_item and tree_item.childCount(): |
|
51 |
for idx in range(tree_item.childCount()): |
|
52 |
child = tree_item.child(idx) |
|
53 |
tree_item_stack.append(child) |
|
54 |
elif tree_item and tree_item.data(0, Qt.UserRole): |
|
55 |
if type(tree_item.data(0, Qt.UserRole)) is SymbolBase.SymbolBase: |
|
56 |
res.append(tree_item.data(0, Qt.UserRole)) |
|
57 |
except Exception as ex: |
|
58 |
from App import App |
|
59 |
|
|
60 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
61 |
sys.exc_info()[-1].tb_lineno) |
|
62 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
63 |
|
|
64 |
return res |
|
65 |
|
|
40 | 66 |
''' |
41 | 67 |
@brief Show Context Menu |
42 | 68 |
@author Jeongwoo |
... | ... | |
188 | 214 |
self.load_symbol_info() |
189 | 215 |
self.expandAll() |
190 | 216 |
|
191 |
''' |
|
192 |
@brief Load Symbol Info and add TreeItem with DB |
|
193 |
@author Jeongwoo |
|
194 |
@date 18.04.20 |
|
195 |
@history Jeongwoo 2018.05.03 Get Svg File Path by SymbolBase.getSvgFileFullPath() |
|
196 |
humkyung 2018.07.30 sort child items |
|
197 |
''' |
|
198 |
|
|
199 | 217 |
def load_symbol_info(self): |
218 |
"""Load Symbol Info and add TreeItem with DB""" |
|
200 | 219 |
try: |
201 | 220 |
app_doc_data = AppDocData.instance() |
202 | 221 |
|
... | ... | |
225 | 244 |
symbolItem.svgFilePath = svgPath # save svg file path |
226 | 245 |
|
227 | 246 |
parent.sortChildren(0, Qt.AscendingOrder) |
247 |
|
|
228 | 248 |
except Exception as ex: |
229 | 249 |
from App import App |
230 | 250 |
|
내보내기 Unified diff