hytos / DTI_PID / DTI_PID / ReplaceSymbolDialog.py @ 298baf11
이력 | 보기 | 이력해설 | 다운로드 (8.02 KB)
1 |
# coding: utf-8
|
---|---|
2 |
""" This is text item edit dialog module """
|
3 | |
4 |
import os |
5 |
import sys, math |
6 |
from PyQt5.QtCore import * |
7 |
from PyQt5.QtGui import * |
8 |
from PyQt5.QtWidgets import * |
9 |
from AppDocData import AppDocData |
10 |
import ReplaceSymbol_UI |
11 |
from EngineeringTextItem import QEngineeringTextItem |
12 |
from SymbolSvgItem import SymbolSvgItem |
13 |
from EngineeringLineItem import QEngineeringLineItem |
14 |
from EngineeringVendorItem import QEngineeringVendorItem |
15 |
from QtImageViewer import QtImageViewer |
16 | |
17 | |
18 |
class QReplaceSymbolDialog(QDialog): |
19 |
""" This is symbol item replace and insert dialog class """
|
20 | |
21 |
#CONDITION_REPLACE = {'radioButtonHasCon':['item.has_connection'], 'radioButtonHasNoCon':['not item.has_connection'], 'radioButtonConLine':['False'], 'radioButtonAll':['True']}
|
22 |
#CONDITION_INSERT = {'radioButtonHasCon':['conn.connetionItem'], 'radioButtonHasNoCon':['not conn.connectedItem'], 'radioButtonConLine':['conn.connectedItem and type(conn.connectedItem) is QEngineeringLineItem', 'conn.connectedItem.is_piping(True)'], 'radioButtonAll':['True']}
|
23 | |
24 |
def __init__(self, parent): |
25 |
QDialog.__init__(self, parent)
|
26 | |
27 |
self.mainWindow = parent
|
28 |
self.view = self.mainWindow.graphicsView |
29 |
self.ui = ReplaceSymbol_UI.Ui_ReplaceSymbolDialog()
|
30 |
self.ui.setupUi(self) |
31 |
self.ui.buttonBox.button(QDialogButtonBox.Save).setIcon(QIcon(':/newPrefix/OK.svg')) |
32 |
self.ui.buttonBox.button(QDialogButtonBox.Close).setIcon(QIcon(':/newPrefix/Remove.svg')) |
33 | |
34 |
self.ui.pushButtonRun.clicked.connect(self.run) |
35 |
self.ui.buttonBox.rejected.connect(self.reject) |
36 |
self.ui.buttonBox.button(QDialogButtonBox.Save).clicked.connect(self.save_preset) |
37 |
self.ui.pushButtonPreset.clicked.connect(self.add_preset) |
38 | |
39 |
# hide custom condition
|
40 |
self.ui.radioButtonCustom.setHidden(True) |
41 |
self.ui.plainTextEdit.setHidden(True) |
42 | |
43 |
self.ui.tableWidgetPreset.horizontalHeader().setStretchLastSection(True) |
44 |
self.ui.tableWidgetPreset.setColumnCount(5) |
45 |
self.ui.tableWidgetPreset.setHorizontalHeaderLabels(['', 'Find', 'Target', 'Action', 'Condition']) |
46 | |
47 |
self.init_symbol_list()
|
48 |
self.init_preset()
|
49 | |
50 |
def init_preset(self): |
51 |
""" load pesets """
|
52 |
app_doc_data = AppDocData.instance() |
53 |
presets = app_doc_data.getSymbolPreset() |
54 | |
55 |
self.ui.tableWidgetPreset.setRowCount(len(presets)) |
56 | |
57 |
rowCount = 0
|
58 |
for preset in presets: |
59 |
item = QTableWidgetItem() |
60 |
item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsSelectable | Qt.ItemIsEnabled) |
61 |
item.setCheckState(Qt.Unchecked) |
62 |
self.ui.tableWidgetPreset.setItem(rowCount, 0, item) |
63 | |
64 |
item = QTableWidgetItem(preset[0])
|
65 |
item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) |
66 |
self.ui.tableWidgetPreset.setItem(rowCount, 1, item) |
67 | |
68 |
item = QTableWidgetItem(preset[1])
|
69 |
item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) |
70 |
self.ui.tableWidgetPreset.setItem(rowCount, 2, item) |
71 | |
72 |
item = QTableWidgetItem(preset[2])
|
73 |
item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) |
74 |
self.ui.tableWidgetPreset.setItem(rowCount, 3, item) |
75 |
|
76 |
item = QTableWidgetItem(preset[3])
|
77 |
item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) |
78 |
self.ui.tableWidgetPreset.setItem(rowCount, 4, item) |
79 | |
80 |
rowCount += 1
|
81 | |
82 |
def add_preset(self): |
83 |
""" save current action into preset """
|
84 |
find_symbol = self.ui.comboBoxFind.currentText()
|
85 |
replace_symbol = self.ui.comboBoxReplace.currentText()
|
86 | |
87 |
condition = self.ui.buttonGroup_2.checkedButton().objectName()
|
88 |
if condition == 'radioButtonCustom' or condition == 'radioButtonPreset': |
89 |
return False |
90 |
#conditions = [text for text in self.ui.plainTextEdit.toPlainText().split('\n')]
|
91 |
else:
|
92 |
pass
|
93 |
#conditions = QReplaceSymbolDialog.CONDITION_REPLACE[condition] if self.ui.radioButtonReplace.isChecked() else QReplaceSymbolDialog.CONDITION_INSERT[condition]
|
94 | |
95 |
rowCount = self.ui.tableWidgetPreset.rowCount()
|
96 |
self.ui.tableWidgetPreset.setRowCount(rowCount + 1) |
97 | |
98 |
item = QTableWidgetItem() |
99 |
item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsSelectable | Qt.ItemIsEnabled) |
100 |
item.setCheckState(Qt.Unchecked) |
101 |
self.ui.tableWidgetPreset.setItem(rowCount, 0, item) |
102 | |
103 |
item = QTableWidgetItem(find_symbol) |
104 |
item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) |
105 |
self.ui.tableWidgetPreset.setItem(rowCount, 1, item) |
106 | |
107 |
item = QTableWidgetItem(replace_symbol) |
108 |
item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) |
109 |
self.ui.tableWidgetPreset.setItem(rowCount, 2, item) |
110 | |
111 |
item = QTableWidgetItem('Replace' if self.ui.radioButtonReplace.isChecked() else 'Insert') |
112 |
item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) |
113 |
self.ui.tableWidgetPreset.setItem(rowCount, 3, item) |
114 |
|
115 |
item = QTableWidgetItem(condition.replace('radioButton', '')) |
116 |
item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) |
117 |
self.ui.tableWidgetPreset.setItem(rowCount, 4, item) |
118 | |
119 |
def init_symbol_list(self): |
120 |
app_doc_data = AppDocData.instance() |
121 |
symbol_list = app_doc_data.getTargetSymbolList(all=True)
|
122 | |
123 |
# for nozzle and equipment package
|
124 |
self.ui.comboBoxFind.addItem('Equipment Package') |
125 | |
126 |
for symbol in symbol_list: |
127 |
self.ui.comboBoxFind.addItem(symbol.getName())
|
128 |
self.ui.comboBoxReplace.addItem(symbol.getName())
|
129 | |
130 |
def keyPressEvent(self, event): |
131 |
try:
|
132 |
if event.key() == Qt.Key_Delete:
|
133 |
try:
|
134 |
row = self.ui.tableWidgetPreset.selectedIndexes()[0].row() |
135 |
self.ui.tableWidgetPreset.removeRow(row)
|
136 |
except Exception as ex: |
137 |
pass
|
138 | |
139 |
QDialog.keyPressEvent(self, event)
|
140 |
except Exception as ex: |
141 |
from App import App |
142 |
from AppDocData import MessageType |
143 | |
144 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
145 |
sys.exc_info()[-1].tb_lineno)
|
146 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
147 |
return None |
148 | |
149 |
def run(self): |
150 |
from ReplaceInsertCommand import ReplaceInsertCommand |
151 |
from App import App |
152 |
|
153 | |
154 |
scene = self.view.scene()
|
155 | |
156 |
find_symbol = self.ui.comboBoxFind.currentText()
|
157 |
replace_symbol = self.ui.comboBoxReplace.currentText()
|
158 | |
159 |
replace_action = 'Replace' if self.ui.radioButtonReplace.isChecked() else 'Insert' |
160 | |
161 |
condition = self.ui.buttonGroup_2.checkedButton().objectName().replace('radioButton', '') |
162 | |
163 |
if condition == 'Custom': |
164 |
custom = self.ui.plainTextEdit.toPlainText()
|
165 |
else:
|
166 |
custom = None
|
167 | |
168 |
if condition == 'Preset': |
169 |
table = self.ui.tableWidgetPreset
|
170 |
for index in range(table.rowCount()): |
171 |
if int(table.item(index, 0).checkState()) is int(Qt.Checked): |
172 |
find_symbol = table.item(index, 1).text()
|
173 |
replace_symbol = table.item(index, 2).text()
|
174 |
replace_action = table.item(index, 3).text()
|
175 |
condition = table.item(index, 4).text()
|
176 |
break
|
177 | |
178 |
cmd = ReplaceInsertCommand() |
179 |
cmd.display_message.connect(App.mainWnd().onAddMessage) |
180 |
cmd.execute(scene, find_symbol, replace_symbol, replace_action, condition, custom=custom) |
181 | |
182 |
def reject(self): |
183 |
"""close a dialog"""
|
184 |
QDialog.reject(self)
|
185 | |
186 |
def save_preset(self): |
187 |
""" save preset """
|
188 |
presets = [] |
189 |
table = self.ui.tableWidgetPreset
|
190 |
for index in range(table.rowCount()): |
191 |
preset = [table.item(index, 1).text(), table.item(index, 2).text(), table.item(index, 3).text(), table.item(index, 4).text()] |
192 |
presets.append(preset) |
193 | |
194 |
app_doc_data = AppDocData.instance() |
195 |
app_doc_data.saveSymbolPreset(presets) |
196 | |
197 |
QDialog.accept(self)
|