개정판 98901dd9
issue #621: add text copy to clipboard as csv
Change-Id: I5052afdf34a6130b932dfeb18c126fe02b61eae7
DTI_PID/DTI_PID/Commands/DefaultCommand.py | ||
---|---|---|
47 | 47 |
def execute(self, param): |
48 | 48 |
from SymbolSvgItem import SymbolSvgItem |
49 | 49 |
from EngineeringLineNoTextItem import QEngineeringLineNoTextItem |
50 |
from EngineeringTextItem import QEngineeringTextItem |
|
50 | 51 |
|
51 | 52 |
event = param[1] |
52 | 53 |
scenePos = param[2] |
... | ... | |
100 | 101 |
xmlStr = str(tostring(selectedItems[0].toXml())) |
101 | 102 |
xmlStr = xmlStr[xmlStr.find('<SYMBOL>'):xmlStr.find('</SYMBOL>') + 9] |
102 | 103 |
QApplication.clipboard().setText(xmlStr) |
104 |
elif len(selectedItems) > 0: |
|
105 |
import io, csv |
|
106 |
|
|
107 |
text_items = [item for item in selectedItems if issubclass(type(item), QEngineeringTextItem)] |
|
108 |
text_items = sorted(text_items, key=lambda param:param.loc[0]) |
|
109 |
table = [[text.text() for text in text_items]] |
|
110 |
stream = io.StringIO() |
|
111 |
csv.writer(stream, delimiter='\t').writerows(table) |
|
112 |
QApplication.clipboard().setText(stream.getvalue()) |
|
113 |
|
|
103 | 114 |
elif 'keyPressEvent' == param[0] and (event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_V): |
104 | 115 |
xmlStr = QApplication.clipboard().text() |
105 | 116 |
if xmlStr.find('<SYMBOL>') > -1 and xmlStr.find('</SYMBOL>') > -1: |
내보내기 Unified diff