hytos / DTI_PID / DTI_PID / ItemDataExportDialog.py @ 87666643
이력 | 보기 | 이력해설 | 다운로드 (34.8 KB)
1 |
# coding: utf-8
|
---|---|
2 |
""" This is ItemDataExportDialog module """
|
3 |
|
4 |
import os |
5 |
import sys |
6 |
from PyQt5.QtCore import * |
7 |
from PyQt5.QtGui import * |
8 |
from PyQt5.QtWidgets import * |
9 |
from AppDocData import AppDocData, Config |
10 |
from openpyxl import * |
11 |
from openpyxl.styles import * |
12 |
import ItemDataExport_UI |
13 |
|
14 |
# all view, list order, table : 0 Line, 1 Equipment, 2 Valve, 3 Instrument, 4 Note
|
15 |
dbListOrderName = ['LINE_DATA_LIST_EXPORT_ORDER', 'EQUIPMENT_DATA_LIST_EXPORT_ORDER', 'VALVE_DATA_LIST_EXPORT_ORDER', |
16 |
'INSTRUMENT_DATA_LIST_EXPORT_ORDER', 'NOTE_DATA_LIST_EXPORT_ORDER'] |
17 |
|
18 |
|
19 |
class QItemDataExportDialog(QDialog): |
20 |
""" This is QItemDataExportDialog class """
|
21 |
|
22 |
DATA_LIST = ['LINE_DATA_LIST', 'EQUIPMENT_DATA_LIST', 'VALVE_DATA_LIST', 'INSTRUMENT_DATA_LIST', 'NOTE_DATA_LIST', |
23 |
'SPECIAL_ITEMS']
|
24 |
|
25 |
def __init__(self, parent): |
26 |
QDialog.__init__(self, parent)
|
27 |
self.setWindowFlag(Qt.WindowMinMaxButtonsHint)
|
28 |
|
29 |
try:
|
30 |
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
31 |
|
32 |
self.delimiter = '!-!' |
33 |
self.delimiterCombine = '!@!' |
34 |
self.emptyCol = 'Empty Column' |
35 |
self.initialTables = []
|
36 |
|
37 |
self.sceneLineData = {}
|
38 |
self.sceneEquipData = {}
|
39 |
self.scene_valve_data = {}
|
40 |
self.sceneInstData = {}
|
41 |
self.sceneNoteData = {}
|
42 |
|
43 |
self.lineColumnListAll = []
|
44 |
self.equipColumnListAll = []
|
45 |
self.valveColumnListAll = []
|
46 |
self.instColumnListAll = []
|
47 |
self.noteColumnListAll = []
|
48 |
self.columnListAll = \
|
49 |
{ |
50 |
QItemDataExportDialog.DATA_LIST[0]: self.lineColumnListAll, |
51 |
QItemDataExportDialog.DATA_LIST[1]: self.equipColumnListAll, |
52 |
QItemDataExportDialog.DATA_LIST[2]: self.valveColumnListAll, |
53 |
QItemDataExportDialog.DATA_LIST[3]: self.instColumnListAll, |
54 |
QItemDataExportDialog.DATA_LIST[4]: self.noteColumnListAll, |
55 |
QItemDataExportDialog.DATA_LIST[5]: []
|
56 |
} |
57 |
|
58 |
self.lineOrder = []
|
59 |
self.equipOrder = []
|
60 |
self.valveOrder = []
|
61 |
self.instOrder = []
|
62 |
self.noteOrder = []
|
63 |
self.columnOrder = \
|
64 |
{ |
65 |
QItemDataExportDialog.DATA_LIST[0]: self.lineOrder, |
66 |
QItemDataExportDialog.DATA_LIST[1]: self.equipOrder, |
67 |
QItemDataExportDialog.DATA_LIST[2]: self.valveOrder, |
68 |
QItemDataExportDialog.DATA_LIST[3]: self.instOrder, |
69 |
QItemDataExportDialog.DATA_LIST[4]: self.noteOrder, |
70 |
QItemDataExportDialog.DATA_LIST[5]: []
|
71 |
} |
72 |
|
73 |
self.parent = parent
|
74 |
self.ui = ItemDataExport_UI.Ui_ItemDataExportDialog()
|
75 |
self.ui.setupUi(self) |
76 |
header = self.ui.tableWidgetDrawing.horizontalHeader()
|
77 |
header.setSectionResizeMode(0, QHeaderView.ResizeToContents)
|
78 |
|
79 |
# line no table setting combobox column
|
80 |
self.nominalDiameterList = []
|
81 |
self.fluidCodeList = []
|
82 |
self.insulationPurposeList = []
|
83 |
self.pipingMaterialClassList = []
|
84 |
self.initLineNoAttrData()
|
85 |
self.lineNoTableComboBoxDic = {}
|
86 |
self.lineNoTableComboBoxDic[1] = self.nominalDiameterList |
87 |
self.lineNoTableComboBoxDic[2] = self.fluidCodeList |
88 |
self.lineNoTableComboBoxDic[4] = self.pipingMaterialClassList |
89 |
self.lineNoTableComboBoxDic[7] = self.fluidCodeList |
90 |
self.lineNoTableComboBoxDic[16] = self.insulationPurposeList |
91 |
|
92 |
try:
|
93 |
self.init_drawings()
|
94 |
self.viewTables = \
|
95 |
{ |
96 |
QItemDataExportDialog.DATA_LIST[0]: self.ui.tableWidgetLineDataList, |
97 |
QItemDataExportDialog.DATA_LIST[1]: self.ui.tableWidgetEquipmentDataList, |
98 |
QItemDataExportDialog.DATA_LIST[2]: self.ui.tableWidgetValveDataList, |
99 |
QItemDataExportDialog.DATA_LIST[3]: self.ui.tableWidgetInstrumentDataList, |
100 |
QItemDataExportDialog.DATA_LIST[4]: self.ui.tableWidgetNoteDataList, |
101 |
QItemDataExportDialog.DATA_LIST[5]: self.ui.tableWidgetSpecialItems |
102 |
} |
103 |
self.initTableWidget()
|
104 |
except Exception as ex: |
105 |
from App import App |
106 |
from AppDocData import MessageType |
107 |
|
108 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
109 |
sys.exc_info()[-1].tb_lineno)
|
110 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
111 |
return None |
112 |
|
113 |
# event connect
|
114 |
self.ui.pushButtonItemDataFormat.clicked.connect(self.show_item_data_format_dialog) |
115 |
self.ui.pushButtonQuery.clicked.connect(self.query_engineering_list) |
116 |
self.ui.pushButtonExport.clicked.connect(self.save_excel) |
117 |
self.ui.pushButtonClose.clicked.connect(self.pushButtonCloseClicked) |
118 |
self.ui.pushButtonSelectAll.clicked.connect(self.select_all) |
119 |
self.ui.pushButtonUnSelectAll.clicked.connect(self.unselect_all) |
120 |
finally:
|
121 |
QApplication.restoreOverrideCursor() |
122 |
|
123 |
@property
|
124 |
def checked_drawings(self): |
125 |
"""return checked drawings"""
|
126 |
|
127 |
res = [] |
128 |
for row in range(self.ui.tableWidgetDrawing.rowCount()): |
129 |
item = self.ui.tableWidgetDrawing.item(row, 0) |
130 |
if Qt.Checked == item.checkState():
|
131 |
res.append(item.text()) |
132 |
|
133 |
return res
|
134 |
|
135 |
'''
|
136 |
@brief dialog close
|
137 |
@author euisung
|
138 |
@date 2018.10.29
|
139 |
'''
|
140 |
|
141 |
def pushButtonCloseClicked(self): |
142 |
QDialog.reject(self)
|
143 |
|
144 |
'''
|
145 |
@brief setting commbobox Data
|
146 |
@author kyouho
|
147 |
@date 2018.08.16
|
148 |
'''
|
149 |
|
150 |
def initLineNoAttrData(self): |
151 |
docData = AppDocData.instance() |
152 |
lineProps = docData.getLineProperties() |
153 |
for prop in lineProps: |
154 |
if prop.AttributeType == 'Code Table': |
155 |
tableName = prop.Attribute.upper().replace(' ', '') |
156 |
if tableName == 'NOMINALDIAMETER': |
157 |
self.nominalDiameterList = docData.getCodeTable(tableName, True) |
158 |
elif tableName == 'FLUIDCODE': |
159 |
self.fluidCodeList = docData.getCodeTable(tableName, True) |
160 |
elif tableName == 'INSULATIONPURPOSE': |
161 |
self.insulationPurposeList = docData.getCodeTable(tableName, True) |
162 |
elif tableName == 'PIPINGMATERIALSCLASS': |
163 |
self.pipingMaterialClassList = docData.getCodeTable(tableName, True) |
164 |
|
165 |
def save_excel(self): |
166 |
"""save engineering list to excel"""
|
167 |
|
168 |
appDocData = AppDocData.instance() |
169 |
project = appDocData.getCurrentProject() |
170 |
options = QFileDialog.Options() |
171 |
options |= QFileDialog.DontUseNativeDialog |
172 |
fileName = QFileDialog.getSaveFileName(self, "Save xlsx file", project.path, "xlsx files(*.xlsx)", |
173 |
options=options) |
174 |
if fileName == ('', ''): |
175 |
return
|
176 |
|
177 |
QApplication.setOverrideCursor(Qt.WaitCursor) |
178 |
|
179 |
try:
|
180 |
wb = Workbook() |
181 |
wb.active.title = self.tr(self.ui.tabWidget.tabText(0)) |
182 |
for i in range(1, self.ui.tabWidget.count()): |
183 |
wb.create_sheet(self.tr(self.ui.tabWidget.tabText(i))) |
184 |
|
185 |
for index in range(self.ui.tabWidget.count()): |
186 |
self.qtable_to_sheet(self.viewTables[QItemDataExportDialog.DATA_LIST[index]], wb.worksheets[index], |
187 |
index) |
188 |
|
189 |
fileName, ext = os.path.splitext(fileName[0])
|
190 |
wb.save(fileName + ext if ext.upper() == '.XLSX' else fileName + '.xlsx') |
191 |
|
192 |
QMessageBox.about(self, self.tr("Information"), self.tr('Successfully saved.')) |
193 |
|
194 |
command = os.path.join(project.path, fileName + '.xlsx')
|
195 |
os.startfile(command) |
196 |
except Exception as ex: |
197 |
from App import App |
198 |
from AppDocData import MessageType |
199 |
|
200 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
201 |
sys.exc_info()[-1].tb_lineno)
|
202 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
203 |
finally:
|
204 |
QApplication.restoreOverrideCursor() |
205 |
|
206 |
'''
|
207 |
@brief save excel
|
208 |
@author kyouho
|
209 |
@date 2018.08.16
|
210 |
@history 2018.10.26 euisung export order apply
|
211 |
'''
|
212 |
|
213 |
def qtable_to_sheet(self, table, sheet, index): |
214 |
try:
|
215 |
key = QItemDataExportDialog.DATA_LIST[index] |
216 |
self.set_sheet_header(table, sheet, key)
|
217 |
self.set_sheet_data(table, sheet, key)
|
218 |
self.auto_resize_columns(sheet)
|
219 |
except Exception as ex: |
220 |
from App import App |
221 |
from AppDocData import MessageType |
222 |
|
223 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
224 |
sys.exc_info()[-1].tb_lineno)
|
225 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
226 |
|
227 |
def set_sheet_header(self, table, sheet, index): |
228 |
""" set list header """
|
229 |
try:
|
230 |
thin = Side(border_style='thin', color='000000') |
231 |
border = Border(left=thin, right=thin, top=thin, bottom=thin) |
232 |
_col = 1
|
233 |
for col in range(table.columnCount()): |
234 |
logical_index = table.horizontalHeader().logicalIndex(col) |
235 |
col_name = table.horizontalHeaderItem(logical_index).text() |
236 |
if table.isColumnHidden(logical_index): continue |
237 |
sheet.cell(1, _col, col_name)
|
238 |
sheet.cell(row=1, column=_col).alignment = Alignment(horizontal='center', vertical='center', |
239 |
wrapText=True)
|
240 |
sheet.cell(row=1, column=_col).fill = PatternFill(patternType='solid', fill_type='solid', |
241 |
fgColor=Color('8DB4E2'))
|
242 |
sheet.cell(row=1, column=_col).border = border
|
243 |
_col += 1
|
244 |
except Exception as ex: |
245 |
from App import App |
246 |
from AppDocData import MessageType |
247 |
|
248 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
249 |
sys.exc_info()[-1].tb_lineno)
|
250 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
251 |
|
252 |
def set_sheet_data(self, table, sheet, index): |
253 |
""" write list data to sheet """
|
254 |
try:
|
255 |
thin = Side(border_style='thin', color='000000') |
256 |
border = Border(left=thin, right=thin, top=thin, bottom=thin) |
257 |
|
258 |
for rowIndex in range(table.rowCount()): |
259 |
_col = 1
|
260 |
for col in range(table.columnCount()): |
261 |
logical_index = table.horizontalHeader().logicalIndex(col) |
262 |
if table.isColumnHidden(logical_index): continue |
263 |
|
264 |
widgetItem = table.cellWidget(rowIndex, logical_index) |
265 |
if widgetItem is None: |
266 |
data = table.item(rowIndex, logical_index).text() if table.item(rowIndex,
|
267 |
logical_index) is not None else '' |
268 |
else:
|
269 |
data = widgetItem.currentText() if widgetItem.currentIndex() >= 0 else '' |
270 |
|
271 |
sheet.cell(rowIndex + 2, _col, data)
|
272 |
sheet.cell(row=rowIndex + 2, column=_col).border = border
|
273 |
_col += 1
|
274 |
except Exception as ex: |
275 |
from App import App |
276 |
from AppDocData import MessageType |
277 |
|
278 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
279 |
sys.exc_info()[-1].tb_lineno)
|
280 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
281 |
|
282 |
def auto_resize_columns(self, sheet): |
283 |
""" auto resize columns with contents """
|
284 |
|
285 |
from openpyxl.utils import get_column_letter |
286 |
try:
|
287 |
for col in sheet.columns: |
288 |
max_length = 0
|
289 |
column = col[0].column # Get the column name |
290 |
for cell in col: |
291 |
try: # Necessary to avoid error on empty cells |
292 |
if len(str(cell.value)) > max_length: |
293 |
max_length = len(cell.value)
|
294 |
except:
|
295 |
pass
|
296 |
|
297 |
adjusted_width = (max_length + 2) * 1.2 |
298 |
sheet.column_dimensions[get_column_letter(column) if type(column) is int else column].width = adjusted_width |
299 |
except Exception as ex: |
300 |
from App import App |
301 |
from AppDocData import MessageType |
302 |
|
303 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
304 |
sys.exc_info()[-1].tb_lineno)
|
305 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
306 |
|
307 |
def init_drawings(self): |
308 |
"""initialize drawing list"""
|
309 |
app_doc_data = AppDocData.instance() |
310 |
|
311 |
documentNameList = [] |
312 |
documentNameData = app_doc_data.get_document_name_list() |
313 |
documentNameList.extend(documentNameData) |
314 |
|
315 |
self.ui.tableWidgetDrawing.setColumnCount(1) |
316 |
self.ui.tableWidgetDrawing.setRowCount(len(documentNameData)) |
317 |
|
318 |
index = 0
|
319 |
for name in documentNameData: |
320 |
item = QTableWidgetItem(name) |
321 |
item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) |
322 |
item.setCheckState(Qt.Unchecked) |
323 |
self.ui.tableWidgetDrawing.setItem(index, 0, item) |
324 |
index += 1
|
325 |
|
326 |
if not self.parent.graphicsView.hasImage(): |
327 |
return
|
328 |
|
329 |
'''
|
330 |
@brief init table widget
|
331 |
@author kyouho
|
332 |
@date 2018.08.13
|
333 |
@history Euisung 2018.10.23 add list export order in db
|
334 |
Euisung 2018.10.24 add list sorting process with export order in db
|
335 |
Euisung 2018.10.25 add initial list saving process
|
336 |
'''
|
337 |
|
338 |
def initTableWidget(self): |
339 |
from SpecialItemTypesDialog import SpecialItemTypes |
340 |
|
341 |
app_doc_data = AppDocData.instance() |
342 |
special_item_types = SpecialItemTypes.instance() |
343 |
self.lineColumnListAll = ['UID', 'Drawing Name'] |
344 |
self.lineColumnListAll.extend([prop.Attribute for prop in app_doc_data.getLineProperties()]) |
345 |
self.lineColumnListAll = self.add_hmb_header(self.lineColumnListAll) |
346 |
self.equipColumnListAll = ['UID', 'ITEM_NO'] |
347 |
self.equipColumnListAll.extend([prop.Attribute for prop in app_doc_data.get_equipment_attributes()]) |
348 |
self.equipColumnListAll.append('Drawing Name') |
349 |
self.valveColumnListAll = ['UID', 'ITEM_NO'] |
350 |
self.valveColumnListAll.extend([prop.Attribute for prop in app_doc_data.get_valve_attributes()]) |
351 |
self.valveColumnListAll.append('Drawing Name') |
352 |
self.instColumnListAll = ['UID', 'ITEM_NO'] |
353 |
self.instColumnListAll.extend([prop.Attribute for prop in app_doc_data.get_instrument_attributes()]) |
354 |
self.instColumnListAll = self.add_hmb_header(self.instColumnListAll) |
355 |
self.instColumnListAll.append('Drawing Name') |
356 |
self.noteColumnListAll = ['UID', 'ITEM_NO'] |
357 |
self.noteColumnListAll.extend([prop.Attribute for prop in app_doc_data.get_note_attributes()]) |
358 |
self.noteColumnListAll.append('Drawing Name') |
359 |
|
360 |
self.columnListAll.clear()
|
361 |
self.columnListAll[QItemDataExportDialog.DATA_LIST[0]] = self.lineColumnListAll |
362 |
self.columnListAll[QItemDataExportDialog.DATA_LIST[1]] = self.equipColumnListAll |
363 |
self.columnListAll[QItemDataExportDialog.DATA_LIST[2]] = self.valveColumnListAll |
364 |
self.columnListAll[QItemDataExportDialog.DATA_LIST[3]] = self.instColumnListAll |
365 |
self.columnListAll[QItemDataExportDialog.DATA_LIST[4]] = self.noteColumnListAll |
366 |
self.columnListAll[QItemDataExportDialog.DATA_LIST[5]] = ['UID', 'Line No'] + [code['Code'] for code in |
367 |
special_item_types.values] |
368 |
# 엑셀 추출시 사용할 리스트 오더를 db에서 읽거나 없으면 db에 추가
|
369 |
try:
|
370 |
configs = [] |
371 |
for data in QItemDataExportDialog.DATA_LIST: |
372 |
self.columnOrder[data] = app_doc_data.getConfigs('Order', data) |
373 |
if len(self.columnOrder[data]) is 0: # use column name if setting does not exit |
374 |
if data == 'LINE_DATA_LIST': |
375 |
value = ''
|
376 |
for prop in app_doc_data.getLineProperties(): |
377 |
value += (prop.Attribute + self.delimiterCombine + prop.Attribute + self.delimiter) |
378 |
value = value[:-len(self.delimiter)] |
379 |
config = Config('Order', data, value)
|
380 |
configs.append(config) |
381 |
self.columnOrder[data] = [config]
|
382 |
else:
|
383 |
value = ''
|
384 |
for col in self.columnListAll[data]: |
385 |
value += (col + self.delimiterCombine + col + self.delimiter) |
386 |
value = value[:-len(self.delimiter)] |
387 |
config = Config('Order', data, value)
|
388 |
configs.append(config) |
389 |
self.columnOrder[data] = [config]
|
390 |
|
391 |
app_doc_data.saveConfigs(configs) |
392 |
|
393 |
except Exception as ex: |
394 |
from App import App |
395 |
from AppDocData import MessageType |
396 |
|
397 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
398 |
sys.exc_info()[-1].tb_lineno)
|
399 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
400 |
return None |
401 |
|
402 |
try:
|
403 |
for key in self.viewTables.keys(): |
404 |
# set table column count
|
405 |
self.viewTables[key].setColumnCount(len(self.columnListAll[key])) |
406 |
# Table Header Label 설정
|
407 |
self.viewTables[key].setHorizontalHeaderLabels(self.columnListAll[key]) |
408 |
# Table Header 크기 설정
|
409 |
for col in range(len(self.columnListAll[key])): |
410 |
self.viewTables[key].horizontalHeaderItem(col).setSizeHint(QSize(25, 25)) |
411 |
self.viewTables[key].setColumnWidth(col, len(self.columnListAll[key][col]) * 8 + 10) |
412 |
# UID column hide
|
413 |
self.viewTables[key].hideColumn(0) |
414 |
self.viewTables[key].setSortingEnabled(True) |
415 |
|
416 |
self.sortListOrder()
|
417 |
except Exception as ex: |
418 |
from App import App |
419 |
from AppDocData import MessageType |
420 |
|
421 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
422 |
sys.exc_info()[-1].tb_lineno)
|
423 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
424 |
|
425 |
'''
|
426 |
@brief sort columns
|
427 |
@author humkyung
|
428 |
'''
|
429 |
def sortListOrder(self): |
430 |
try:
|
431 |
docData = AppDocData.instance() |
432 |
|
433 |
for key in self.viewTables.keys(): |
434 |
config = docData.getConfigs('Order', key)
|
435 |
if not config: |
436 |
continue
|
437 |
|
438 |
orders = docData.getConfigs('Order', key)[0].value.split(self.delimiter) |
439 |
headers = [] |
440 |
for col in range(len(orders)): |
441 |
header = orders[col].split(self.delimiterCombine)
|
442 |
headers.append(header) |
443 |
|
444 |
for header in headers: |
445 |
if header[0] == self.emptyCol: |
446 |
count = self.viewTables[key].columnCount()
|
447 |
self.viewTables[key].setColumnCount(count + 1) |
448 |
item = QTableWidgetItem(header[1])
|
449 |
self.viewTables[key].setHorizontalHeaderItem(count, item)
|
450 |
|
451 |
col = 0
|
452 |
for header in headers: |
453 |
if header[0] != self.emptyCol: |
454 |
matches = [index for index in range(self.viewTables[key].columnCount()) if |
455 |
header[0] == self.viewTables[key].horizontalHeaderItem(index).text()] |
456 |
else:
|
457 |
matches = [index for index in range(self.viewTables[key].columnCount()) if |
458 |
header[1] == self.viewTables[key].horizontalHeaderItem(index).text()] |
459 |
if matches:
|
460 |
item = self.viewTables[key].horizontalHeaderItem(matches[0]) |
461 |
item.setText(header[1]) # display user column name |
462 |
item.setData(Qt.UserRole, header[0])
|
463 |
_from = self.viewTables[key].horizontalHeader().visualIndex(matches[0]) |
464 |
self.viewTables[key].horizontalHeader().moveSection(_from, col)
|
465 |
|
466 |
col = col + 1
|
467 |
|
468 |
# hide unselected columns by user
|
469 |
for col in range(self.viewTables[key].columnCount()): |
470 |
matches = [col for header in headers if |
471 |
header[1] == self.viewTables[key].horizontalHeaderItem(col).text()] |
472 |
if not matches: |
473 |
self.viewTables[key].hideColumn(col)
|
474 |
|
475 |
except Exception as ex: |
476 |
from App import App |
477 |
from AppDocData import MessageType |
478 |
|
479 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
480 |
sys.exc_info()[-1].tb_lineno)
|
481 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
482 |
|
483 |
def add_hmb_header(self, header_list): |
484 |
''' add hmb data header '''
|
485 |
app_doc_data = AppDocData.instance() |
486 |
hmb_datas = app_doc_data.get_hmb_data(None)
|
487 |
names = ['PHASE']
|
488 |
if hmb_datas:
|
489 |
for data in hmb_datas[0].data: |
490 |
if data.name not in names: |
491 |
names.append(data.name) |
492 |
names.append(data.name + '_min')
|
493 |
names.append(data.name + '_max')
|
494 |
header_list.extend(names) |
495 |
|
496 |
return header_list
|
497 |
|
498 |
def add_hmb_data(self, hmb_datas, dataList): |
499 |
''' add hmb data dependon stream no '''
|
500 |
dataList_backup = dataList.copy() |
501 |
try:
|
502 |
names = [] |
503 |
if hmb_datas:
|
504 |
for data in hmb_datas[0].data: |
505 |
if data.name not in names: |
506 |
names.append(data.name) |
507 |
else:
|
508 |
return dataList
|
509 |
|
510 |
for data in dataList: |
511 |
matches = [key for key in data.keys() if key == 'Stream No'] |
512 |
if matches and data[matches[0]] != '' and data[matches[0]] != 'None': |
513 |
stream_no = data[matches[0]]
|
514 |
|
515 |
matches = [hmb_data for hmb_data in hmb_datas if hmb_data.stream_no == stream_no] |
516 |
if matches:
|
517 |
hmb_data = matches[0]
|
518 |
phase = hmb_data.phase |
519 |
|
520 |
if phase and phase == 'Two': |
521 |
phase = 'LIQUID'
|
522 |
elif not phase: |
523 |
continue
|
524 |
|
525 |
data['PHASE'] = phase
|
526 |
|
527 |
datas = hmb_data.data |
528 |
|
529 |
for name in names: |
530 |
matches = [data for data in datas if data.name == name and data.phase == phase] |
531 |
if matches:
|
532 |
value = matches[0].value
|
533 |
value_max = matches[0].value_max
|
534 |
value_min = matches[0].value_min
|
535 |
|
536 |
data[name] = value |
537 |
data[name + '_min'] = value_min
|
538 |
data[name + '_max'] = value_max
|
539 |
|
540 |
else:
|
541 |
matches = [data for data in datas if data.name == name] |
542 |
if matches:
|
543 |
value = matches[0].value
|
544 |
value_max = matches[0].value_max
|
545 |
value_min = matches[0].value_min
|
546 |
|
547 |
data[name] = value |
548 |
data[name + '_min'] = value_min
|
549 |
data[name + '_max'] = value_max
|
550 |
|
551 |
return dataList
|
552 |
|
553 |
except Exception as ex: |
554 |
from App import App |
555 |
from AppDocData import MessageType |
556 |
|
557 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
558 |
sys.exc_info()[-1].tb_lineno)
|
559 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
560 |
|
561 |
return dataList_backup
|
562 |
|
563 |
def set_line_list_data(self): |
564 |
pass
|
565 |
|
566 |
|
567 |
'''
|
568 |
@brief setting line data
|
569 |
@author kyouho
|
570 |
@date 2018.08.13
|
571 |
'''
|
572 |
def set_line_data(self): |
573 |
lineTable = self.ui.tableWidgetLineDataList
|
574 |
docData = AppDocData.instance() |
575 |
# 기존 저장된 데이터 불러옴
|
576 |
drawings = self.checked_drawings
|
577 |
|
578 |
dataList = docData.get_line_data_list(drawings if drawings else None) |
579 |
lineTable.setRowCount(len(dataList))
|
580 |
row = 0
|
581 |
for data in dataList: |
582 |
for col in range(self.ui.tableWidgetLineDataList.columnCount()): |
583 |
col_item = self.ui.tableWidgetLineDataList.horizontalHeaderItem(col)
|
584 |
matches = [value for value in data if value[0] == col_item.data(Qt.UserRole)] |
585 |
if matches:
|
586 |
item = QTableWidgetItem(matches[0][1] if matches[0][1] is not None else '') |
587 |
item.setFlags(Qt.ItemIsEnabled) |
588 |
lineTable.setItem(row, col, item) |
589 |
|
590 |
row += 1
|
591 |
|
592 |
def set_equipment_data(self): |
593 |
"""fill equipment data"""
|
594 |
try:
|
595 |
equipTable = self.ui.tableWidgetEquipmentDataList
|
596 |
app_doc_data = AppDocData.instance() |
597 |
|
598 |
# 기존 저장된 데이터 불러옴
|
599 |
drawings = self.checked_drawings
|
600 |
dataList = app_doc_data.get_equipment_data_list(drawings if drawings else None) |
601 |
equipTable.setRowCount(len(dataList))
|
602 |
row = 0
|
603 |
for data in dataList: |
604 |
for col in range(equipTable.columnCount()): |
605 |
col_item = equipTable.horizontalHeaderItem(col) |
606 |
matches = [value for value in data if value[0] == col_item.data(Qt.UserRole)] |
607 |
if matches:
|
608 |
item = QTableWidgetItem(matches[0][1] if matches[0][1] is not None else '') |
609 |
item.setFlags(Qt.ItemIsEnabled) |
610 |
equipTable.setItem(row, col, item) |
611 |
|
612 |
row += 1
|
613 |
except Exception as ex: |
614 |
from App import App |
615 |
from AppDocData import MessageType |
616 |
|
617 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
618 |
sys.exc_info()[-1].tb_lineno)
|
619 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
620 |
|
621 |
def set_valve_data(self): |
622 |
"""setting valve data"""
|
623 |
|
624 |
try:
|
625 |
valve_table = self.ui.tableWidgetValveDataList
|
626 |
docData = AppDocData.instance() |
627 |
|
628 |
# 기존 저장된 데이터 불러옴
|
629 |
drawings = self.checked_drawings
|
630 |
dataList = docData.get_valve_data_list(drawings if drawings else None) |
631 |
valve_table.setRowCount(len(dataList))
|
632 |
row = 0
|
633 |
for data in dataList: |
634 |
for col in range(self.ui.tableWidgetValveDataList.columnCount()): |
635 |
col_item = self.ui.tableWidgetValveDataList.horizontalHeaderItem(col)
|
636 |
matches = [key for key in data.keys() if key == col_item.data(Qt.UserRole)] |
637 |
if matches:
|
638 |
item = QTableWidgetItem(data[matches[0]])
|
639 |
item.setFlags(Qt.ItemIsEnabled) |
640 |
valve_table.setItem(row, col, item) |
641 |
row += 1
|
642 |
|
643 |
# set column headers
|
644 |
headers = [] |
645 |
for col in range(valve_table.columnCount()): |
646 |
headers.append(valve_table.horizontalHeaderItem(col).text()) |
647 |
except Exception as ex: |
648 |
from App import App |
649 |
from AppDocData import MessageType |
650 |
|
651 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
652 |
sys.exc_info()[-1].tb_lineno)
|
653 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
654 |
|
655 |
'''
|
656 |
@brief setting Inst data
|
657 |
@author kyouho
|
658 |
@date 2018.08.14
|
659 |
'''
|
660 |
|
661 |
def set_instrument_data(self, hmb_datas=None): |
662 |
inst_table = self.ui.tableWidgetInstrumentDataList
|
663 |
app_doc_data = AppDocData.instance() |
664 |
|
665 |
# 기존 저장된 데이터 불러옴
|
666 |
drawings = self.checked_drawings
|
667 |
dataList = app_doc_data.get_instrument_data_list(drawings if drawings else None) |
668 |
dataList = self.add_hmb_data(hmb_datas, dataList)
|
669 |
inst_table.setRowCount(len(dataList))
|
670 |
row = 0
|
671 |
for data in dataList: |
672 |
for col in range(self.ui.tableWidgetInstrumentDataList.columnCount()): |
673 |
col_item = self.ui.tableWidgetInstrumentDataList.horizontalHeaderItem(col)
|
674 |
matches = [key for key in data.keys() if key == col_item.data(Qt.UserRole)] |
675 |
if matches:
|
676 |
item = QTableWidgetItem(data[matches[0]])
|
677 |
item.setFlags(Qt.ItemIsEnabled) |
678 |
inst_table.setItem(row, col, item) |
679 |
row += 1
|
680 |
|
681 |
# set column headers
|
682 |
headers = [] |
683 |
for col in range(inst_table.columnCount()): |
684 |
headers.append(inst_table.horizontalHeaderItem(col).text()) |
685 |
|
686 |
def set_note_data(self): |
687 |
""" set note data """
|
688 |
note_table = self.ui.tableWidgetNoteDataList
|
689 |
app_doc_data = AppDocData.instance() |
690 |
|
691 |
# 기존 저장된 데이터 불러옴
|
692 |
drawings = self.checked_drawings
|
693 |
dataList = app_doc_data.get_note_data_list(drawings if drawings else None) |
694 |
note_table.setRowCount(len(dataList))
|
695 |
|
696 |
row = 0
|
697 |
for data in dataList: |
698 |
for col in range(note_table.columnCount()): |
699 |
col_item = note_table.horizontalHeaderItem(col) |
700 |
matches = [key for key in data.keys() if key == col_item.data(Qt.UserRole)] |
701 |
if matches:
|
702 |
item = QTableWidgetItem(data[matches[0]])
|
703 |
item.setFlags(Qt.ItemIsEnabled) |
704 |
note_table.setItem(row, col, item) |
705 |
row += 1
|
706 |
|
707 |
# set column headers
|
708 |
headers = [] |
709 |
for col in range(note_table.columnCount()): |
710 |
headers.append(note_table.horizontalHeaderItem(col).text()) |
711 |
|
712 |
def fill_special_items(self): |
713 |
""" fill table widget with special items """
|
714 |
|
715 |
try:
|
716 |
app_doc_data = AppDocData.instance() |
717 |
drawings = self.checked_drawings
|
718 |
special_items = app_doc_data.get_special_items(drawings if drawings else None) |
719 |
merged_special_items = [] |
720 |
for item in special_items: |
721 |
matches = [merged for merged in merged_special_items if merged['Line No'] == item[0]] |
722 |
if matches:
|
723 |
matches[0][item[1]] = 'O' |
724 |
else:
|
725 |
merged_special_items.append({'Line No': item[0], item[1]: 'O'}) |
726 |
|
727 |
self.ui.tableWidgetSpecialItems.setRowCount(len(merged_special_items)) |
728 |
|
729 |
row = 0
|
730 |
for item in merged_special_items: |
731 |
for col in range(self.ui.tableWidgetSpecialItems.columnCount()): |
732 |
if self.ui.tableWidgetSpecialItems.isColumnHidden(col): continue |
733 |
col_name = self.ui.tableWidgetSpecialItems.horizontalHeaderItem(col).text()
|
734 |
widget_item = QTableWidgetItem(item[col_name]) if col_name in item.keys() else QTableWidgetItem('X') |
735 |
widget_item.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter) |
736 |
widget_item.setFlags(Qt.ItemIsEnabled) |
737 |
self.ui.tableWidgetSpecialItems.setItem(row, col, widget_item)
|
738 |
row += 1
|
739 |
except Exception as ex: |
740 |
from App import App |
741 |
from AppDocData import MessageType |
742 |
|
743 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
744 |
sys.exc_info()[-1].tb_lineno)
|
745 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
746 |
|
747 |
def show_item_data_format_dialog(self): |
748 |
""" show item data format dialog """
|
749 |
|
750 |
from ItemDataFormatDialog import QItemDataFormatDialog |
751 |
|
752 |
dlg = QItemDataFormatDialog(self, self.columnListAll, self.columnOrder) |
753 |
if dlg.exec_():
|
754 |
self.initTableWidget()
|
755 |
|
756 |
def query_engineering_list(self, text): |
757 |
"""query engineering list"""
|
758 |
|
759 |
QApplication.setOverrideCursor(Qt.WaitCursor) |
760 |
try:
|
761 |
hmb_datas = AppDocData.instance().get_hmb_data(None)
|
762 |
configs = docData.getConfigs('Line List', 'Use Stream No') |
763 |
if configs and int(configs[0].value) == 1: |
764 |
self.set_line_list_data()
|
765 |
else:
|
766 |
self.set_line_data()
|
767 |
self.set_equipment_data()
|
768 |
self.set_valve_data()
|
769 |
self.set_instrument_data(hmb_datas)
|
770 |
self.set_note_data()
|
771 |
self.fill_special_items()
|
772 |
except Exception as ex: |
773 |
from App import App |
774 |
from AppDocData import MessageType |
775 |
|
776 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
777 |
sys.exc_info()[-1].tb_lineno)
|
778 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
779 |
finally:
|
780 |
QApplication.restoreOverrideCursor() |
781 |
|
782 |
def select_all(self): |
783 |
"""select all drawings"""
|
784 |
|
785 |
for row in range(self.ui.tableWidgetDrawing.rowCount()): |
786 |
item = self.ui.tableWidgetDrawing.item(row, 0) |
787 |
item.setCheckState(Qt.Checked) |
788 |
|
789 |
def unselect_all(self): |
790 |
"""unselect all drawings"""
|
791 |
|
792 |
for row in range(self.ui.tableWidgetDrawing.rowCount()): |
793 |
item = self.ui.tableWidgetDrawing.item(row, 0) |
794 |
item.setCheckState(~Qt.Checked) |