개정판 4a6bef3f
issue #538: 복사, 붙여넣기 개선
Change-Id: I3bea77929e7b5325e8591c1e86bf2ece68d8e12e
DTI_PID/DTI_PID/Commands/DefaultCommand.py | ||
---|---|---|
95 | 95 |
self.imageViewer.setRubberBandSelectionMode(Qt.ContainsItemShape) |
96 | 96 |
else: |
97 | 97 |
self.imageViewer.setRubberBandSelectionMode(Qt.IntersectsItemShape) |
98 |
elif 'keyPressEvent' == param[0] and (event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_C): |
|
99 |
selectedItems = self.imageViewer.scene().selectedItems() |
|
100 |
if len(selectedItems) == 1 and issubclass(type(selectedItems[0]), SymbolSvgItem): |
|
101 |
from xml.etree.ElementTree import tostring |
|
102 |
xmlStr = str(tostring(selectedItems[0].toXml())) |
|
103 |
xmlStr = xmlStr[xmlStr.find('<SYMBOL>'):xmlStr.find('</SYMBOL>') + 9] |
|
104 |
QApplication.clipboard().setText(xmlStr) |
|
105 |
elif len(selectedItems) > 0: |
|
106 |
import io, csv |
|
107 |
|
|
108 |
text_items = [item for item in selectedItems if issubclass(type(item), QEngineeringTextItem)] |
|
109 |
text_items = sorted(text_items, key=lambda param:param.loc[0]) |
|
110 |
table = [[text.text() for text in text_items]] |
|
111 |
stream = io.StringIO() |
|
112 |
csv.writer(stream, delimiter='\t').writerows(table) |
|
113 |
QApplication.clipboard().setText(stream.getvalue()) |
|
114 |
|
|
115 |
elif 'keyPressEvent' == param[0] and (event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_V): |
|
116 |
xmlStr = QApplication.clipboard().text() |
|
117 |
if xmlStr.find('<SYMBOL>') > -1 and xmlStr.find('</SYMBOL>') > -1: |
|
118 |
self.copySymbol(QApplication.clipboard().text()) |
|
119 | 98 |
self.isTreated = False |
120 | 99 |
elif self.isCopy and self.isSpecBreak: |
121 | 100 |
if 'mouseReleaseEvent' == param[0] and event.button() == Qt.LeftButton: |
... | ... | |
212 | 191 |
|
213 | 192 |
def redo(self): |
214 | 193 |
pass |
215 |
|
|
216 |
''' |
|
217 |
@brief xml to ElementTree and ElementTree to Symbol |
|
218 |
@author kyouho |
|
219 |
@date 18.07.31 |
|
220 |
''' |
|
221 |
def copySymbol(self, xmlStr): |
|
222 |
from xml.etree.ElementTree import Element, SubElement, dump, ElementTree, parse, fromstring |
|
223 |
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + '\\Shapes') |
|
224 |
from SymbolSvgItem import SymbolSvgItem |
|
225 |
import uuid |
|
226 |
|
|
227 |
try: |
|
228 |
# string to ElementTree |
|
229 |
et = fromstring(xmlStr) |
|
230 |
item = SymbolSvgItem.fromXml(et) |
|
231 |
self.symbol = item |
|
232 |
for connector in self.symbol.connectors: |
|
233 |
connector.connectedItem = None |
|
234 |
# uid 새로 할당 |
|
235 |
self.symbol.uid = uuid.uuid4() |
|
236 |
self.imageViewer.scene().addItem(self.symbol) |
|
237 |
self.imageViewer.scene().clearFocus() |
|
238 |
self.imageViewer.scene().setFocusItem(self.symbol) |
|
239 |
self.symbol.setSelected(True) |
|
240 |
self.isCopy = True |
|
241 |
|
|
242 |
QApplication.instance().setOverrideCursor(QCursor(Qt.DragCopyCursor)) |
|
243 |
except Exception as ex: |
|
244 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
245 |
|
DTI_PID/DTI_PID/Commands/SaveWorkCommand.py | ||
---|---|---|
78 | 78 |
|
79 | 79 |
app_doc_data = AppDocData.instance() |
80 | 80 |
path = os.path.join(app_doc_data.getCurrentProject().getTempPath(), app_doc_data.imgName + '.xml') |
81 |
result = xg.writeXmlOnScene(path, app_doc_data.activeDrawing.width, app_doc_data.activeDrawing.height,
|
|
81 |
xml, result = xg.write_to_xml(path, app_doc_data.activeDrawing.width, app_doc_data.activeDrawing.height,
|
|
82 | 82 |
app_doc_data.allItems, app_doc_data.tracerLineNos) |
83 |
if xml: |
|
84 |
from xml.etree import ElementTree |
|
85 |
ElementTree.ElementTree(xml).write(path) |
|
83 | 86 |
|
84 | 87 |
resultStr = '[저장 결과]' |
85 |
|
|
86 | 88 |
for item in result.items(): |
87 | 89 |
itemName = str(item[0]) |
88 | 90 |
itemSuccessCount = str(item[1][0]) |
DTI_PID/DTI_PID/QtImageViewerScene.py | ||
---|---|---|
47 | 47 |
|
48 | 48 |
def addItem(self, item): |
49 | 49 |
""" add given item to scene """ |
50 |
|
|
51 | 50 |
QGraphicsScene.addItem(self, item) |
52 | 51 |
self.contents_changed.emit() |
53 | 52 |
|
... | ... | |
89 | 88 |
|
90 | 89 |
event.accept() |
91 | 90 |
return |
91 |
elif event.key() == Qt.Key_C and event.modifiers() & Qt.ControlModifier: |
|
92 |
from xml.etree import ElementTree |
|
93 |
import XmlGenerator as xg |
|
94 |
from AppDocData import AppDocData |
|
95 |
|
|
96 |
app_doc_data = AppDocData.instance() |
|
97 |
xml, result = xg.write_to_xml(app_doc_data.activeDrawing.file_path, app_doc_data.activeDrawing.width, |
|
98 |
app_doc_data.activeDrawing.height, self.selectedItems(), []) |
|
99 |
if xml: |
|
100 |
QApplication.clipboard().setText(ElementTree.tostring(xml, encoding='unicode')) |
|
101 |
elif event.key() == Qt.Key_V and event.modifiers() & Qt.ControlModifier: |
|
102 |
from App import App |
|
103 |
import uuid |
|
104 |
|
|
105 |
clipboard = QApplication.clipboard() |
|
106 |
mime_data = clipboard.mimeData() |
|
107 |
if mime_data.hasText(): |
|
108 |
text = mime_data.text() |
|
109 |
if text.find('<DWG>') != -1 and text.find('</DWG>') != -1: |
|
110 |
from xml.etree import ElementTree |
|
111 |
from SymbolBase import SymbolBase |
|
112 |
|
|
113 |
origin = self.views()[0].mapFromGlobal(QCursor.pos()) |
|
114 |
origin = self.views()[0].mapToScene(origin) |
|
115 |
|
|
116 |
root = ElementTree.fromstring(text) |
|
117 |
for symbol in root.find('SYMBOLS').iter('SYMBOL'): |
|
118 |
item = SymbolSvgItem.fromXml(symbol) |
|
119 |
# uid 새로 할당 |
|
120 |
item.uid = uuid.uuid4() |
|
121 |
for connector in item.connectors: |
|
122 |
connector.connectedItem = None |
|
123 |
item.origin[0], item.origin[1] = origin.x(), origin.y() |
|
124 |
item.transfer.onRemoved.connect(App.mainWnd().itemRemoved) |
|
125 |
item.addSvgItemToScene(self, True) |
|
126 |
item.setVisible(True) |
|
92 | 127 |
elif event.key() == Qt.Key_Z and event.modifiers() & Qt.ControlModifier: |
93 | 128 |
self._undo_stack.undo() |
94 | 129 |
elif event.key() == Qt.Key_R and event.modifiers() & Qt.ControlModifier: |
DTI_PID/DTI_PID/XmlGenerator.py | ||
---|---|---|
404 | 404 |
''' |
405 | 405 |
|
406 | 406 |
|
407 |
def writeXmlOnScene(path, pidWidth, pidHeight, items, tracer_line_nos):
|
|
407 |
def write_to_xml(path, pidWidth, pidHeight, items, tracer_line_nos):
|
|
408 | 408 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
409 | 409 |
from EngineeringNoteItem import QEngineeringNoteItem |
410 | 410 |
from EngineeringTextItem import QEngineeringTextItem |
... | ... | |
495 | 495 |
xml.append(unknownListNode) |
496 | 496 |
xml.append(trimLineNoListNode) |
497 | 497 |
xml.append(vendorListNode) |
498 |
ElementTree(xml).write(path) |
|
498 |
#ElementTree(xml).write(path)
|
|
499 | 499 |
except Exception as ex: |
500 | 500 |
from App import App |
501 | 501 |
from AppDocData import MessageType |
... | ... | |
504 | 504 |
sys.exc_info()[-1].tb_lineno) |
505 | 505 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
506 | 506 |
|
507 |
return resultDic |
|
507 |
return xml, resultDic
|
|
508 | 508 |
|
509 | 509 |
|
510 | 510 |
def indent(elem, level=0): |
내보내기 Unified diff