hytos / HYTOS / HYTOS / Export_To_PAP.py @ 339ba307
이력 | 보기 | 이력해설 | 다운로드 (8.23 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
"""This is Equipment module"""
|
3 |
import sys |
4 |
from PyQt5 import QtCore, QtGui, QtWidgets |
5 |
from PyQt5.QtWidgets import * |
6 |
from PyQt5.QtGui import QMovie |
7 |
from PyQt5.QtCore import * |
8 |
from SymbolSvgItem import SymbolSvgItem |
9 |
import os |
10 |
import asyncio |
11 |
import aiohttp |
12 |
from App import App |
13 |
import Export_To_PAP_UI |
14 |
import math |
15 |
import requests |
16 |
import json |
17 |
from AppDocData import AppDocData |
18 |
def is_float(s): |
19 |
try:
|
20 |
if s:
|
21 |
float(s)
|
22 |
return True |
23 |
else:
|
24 |
return False |
25 |
except ValueError: |
26 |
return False |
27 |
|
28 |
def strToBool(s): |
29 |
return s.upper() == "TRUE" |
30 |
|
31 |
def is_blank(s): |
32 |
return not (s and s.strip()) |
33 |
|
34 |
|
35 |
def is_not_blank(s): |
36 |
return bool(s and s.strip()) |
37 |
|
38 |
|
39 |
def convert_to_fixed_point(value): |
40 |
if is_float(str(value)): |
41 |
tokens = f"{float(value):.10f}".split('.') |
42 |
if len(tokens) == 2: |
43 |
# 소수점 아래가 있을 경우 소수점 아래의 trailing zero를 제거한다.
|
44 |
if is_blank(tokens[1].rstrip('0')): |
45 |
return tokens[0] |
46 |
else:
|
47 |
tokens[1] = tokens[1].rstrip('0') |
48 |
return '.'.join(tokens) |
49 |
else:
|
50 |
return tokens[0] |
51 |
else:
|
52 |
return value
|
53 |
|
54 |
|
55 |
class MappingsDelegate(QStyledItemDelegate): |
56 |
def __init__(self, parent=None): |
57 |
QStyledItemDelegate.__init__(self, parent)
|
58 |
|
59 |
|
60 |
def createEditor(self, parent, option, index): |
61 |
editor = None
|
62 |
item = parent.parent().model().itemFromIndex(parent.parent().model().index(index.row(), 0))
|
63 |
|
64 |
if index.column() == 2: |
65 |
datacase = [] |
66 |
editor = QComboBox(parent) |
67 |
if item.text() == "Pump": |
68 |
datacase = ["Rated Flow Case", "Maximum Flow Case","N/A"] |
69 |
elif item.text() == "Compressor": |
70 |
datacase = ["Design Case", "N/A"] |
71 |
editor.setEditable(True)
|
72 |
elif item.text() == "Valve": |
73 |
datacase = ["Maximum Flowrate Case", "Normal Flowrate Case", "Minimum Flowrate Case","N/A"] |
74 |
else:
|
75 |
pass
|
76 |
editor.addItems([str(datacase[_index]) for _index in range(len(datacase))]) |
77 |
|
78 |
return editor if editor else super(MappingsDelegate, self).createEditor(parent, option, index) |
79 |
|
80 |
class QExport_To_PAP(QDialog): |
81 |
def __init__(self): |
82 |
QDialog.__init__(self)
|
83 |
self.ui = Export_To_PAP_UI.Ui_Dialog()
|
84 |
self.ui.setupUi(self) |
85 |
self.ui.buttonBox.button(QDialogButtonBox.Ok).setIcon(QtGui.QIcon(':/images/OK.svg')) |
86 |
self.ui.buttonBox.button(QDialogButtonBox.Cancel).setIcon(QtGui.QIcon(':/images/Cancel.svg')) |
87 |
self.load_movie = QMovie(":/images/loader.gif") |
88 |
self.close_movie = QMovie(":/images/close.png") |
89 |
self.done_movie = QMovie(":/images/done.png") |
90 |
self.ui.comboBox_select_PAP_Project.currentIndexChanged.connect(self.connect_api) |
91 |
self.send_api(end_point = "/api/Projects", method= "GET") |
92 |
self.data_load()
|
93 |
#self.ui.tableView_upload_item_list.resizeColumnsToContents()
|
94 |
#self.ui.tableView_upload_item_list.horizontalHeader().setSectionResizeMode(
|
95 |
# self.ui.tableView_upload_item_list.horizontalHeader().count() - 1, QtWidgets.QHeaderView.Stretch)
|
96 |
#self.ui.tableView_upload_item_list.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents);
|
97 |
self.ui.tableView_upload_item_list.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
98 |
|
99 |
def data_load(self): |
100 |
self.calculation_calse = ["Maximum Flowrate Case", "Normal Flowrate Case", "Minimum Flowrate Case"] |
101 |
self.ui.comboBox_Calculation_Case.addItems(self.calculation_calse) |
102 |
self.graphicsView = App.mainWnd().graphicsView
|
103 |
items = [item for item in self.graphicsView.scene.items() if type(item) is SymbolSvgItem] |
104 |
if items:
|
105 |
self.data_frame_to_ui_configuration(items)
|
106 |
|
107 |
def data_frame_to_ui_configuration(self, items): |
108 |
headerColumn = ["Item Type.", "Item Tag No." ,"Data Case"] |
109 |
# for the table model
|
110 |
value_model = QtGui.QStandardItemModel() |
111 |
# set table headers
|
112 |
value_model.setColumnCount(len(headerColumn))
|
113 |
value_model.setHorizontalHeaderLabels(headerColumn) |
114 |
|
115 |
# fill table model data
|
116 |
for row_idx in range(0, len(items)): # len(data_frame.values) |
117 |
row = list()
|
118 |
for col_idx in range(len(headerColumn)): |
119 |
if headerColumn[col_idx] == headerColumn[0] : |
120 |
value = items[row_idx].type |
121 |
if headerColumn[col_idx] == headerColumn[1] : |
122 |
value = items[row_idx].tag_no |
123 |
val = QtGui.QStandardItem(value) |
124 |
val.setEditable(True)
|
125 |
row.append(val) |
126 |
value_model.appendRow(row) |
127 |
|
128 |
# Sort Filter Proxy Set Model
|
129 |
self.ui.tableView_upload_item_list.setModel(value_model)
|
130 |
self.model = value_model
|
131 |
# Sort Filter Proxy Set Model
|
132 |
# Set Selection Model
|
133 |
self.selection_model = self.ui.tableView_upload_item_list.selectionModel() |
134 |
# Set Selection Model
|
135 |
self.ui.tableView_upload_item_list.setSortingEnabled(True) |
136 |
self.ui.tableView_upload_item_list.setItemDelegate(MappingsDelegate(self.ui.tableView_upload_item_list)) |
137 |
|
138 |
def startAnimation(self): |
139 |
self.close_movie.stop()
|
140 |
self.done_movie.stop()
|
141 |
self.ui.label_loading.setMovie(self.load_movie) |
142 |
self.load_movie.start()
|
143 |
# Stop Animation(According to need)
|
144 |
|
145 |
def doneAnimation(self): |
146 |
self.load_movie.stop()
|
147 |
self.close_movie.stop()
|
148 |
self.ui.label_loading.setMovie(self.done_movie) |
149 |
self.done_movie.start()
|
150 |
|
151 |
def closeAnimation(self): |
152 |
self.load_movie.stop()
|
153 |
self.done_movie.stop()
|
154 |
self.ui.label_loading.setMovie(self.close_movie) |
155 |
self.close_movie.start()
|
156 |
|
157 |
def send_api(self, end_point, method): |
158 |
app_doc_data = AppDocData.instance() |
159 |
url = app_doc_data.API_HOST + end_point |
160 |
headers = {'Content-Type': 'application/json', 'charset': 'UTF-8', 'Accept': '*/*'} |
161 |
try:
|
162 |
if method == 'GET': |
163 |
response = requests.get(url, headers=headers) |
164 |
if response.status_code == 200: |
165 |
json_objects = json.loads(response.text) |
166 |
for json_object in json_objects: |
167 |
self.ui.comboBox_select_PAP_Project.addItem(json_object['Name']) |
168 |
except Exception as ex: |
169 |
from App import App |
170 |
from AppDocData import MessageType |
171 |
|
172 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
173 |
sys.exc_info()[-1].tb_lineno)
|
174 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
175 |
|
176 |
def connect_api(self, index): |
177 |
#self.ui.comboBox_select_PAP_Project.setEnabled(False)
|
178 |
self.startAnimation()
|
179 |
QTimer.singleShot(500, self.connections) |
180 |
|
181 |
def connections(self): |
182 |
result = "false"
|
183 |
projectNo = self.ui.comboBox_select_PAP_Project.currentText()
|
184 |
try:
|
185 |
asyncio.run(self.run_connection(projectNo))
|
186 |
except Exception as ex: |
187 |
from App import App |
188 |
from AppDocData import MessageType |
189 |
|
190 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
191 |
sys.exc_info()[-1].tb_lineno)
|
192 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
193 |
|
194 |
|
195 |
async def run_connection(self, projectNo): |
196 |
task = asyncio.create_task(self.connection(projectNo))
|
197 |
result = await task |
198 |
self.ui.comboBox_select_PAP_Project.setEnabled(True) |
199 |
if strToBool(str(result)): |
200 |
QTimer.singleShot(500, self.doneAnimation) |
201 |
else:
|
202 |
QTimer.singleShot(500, self.closeAnimation) |
203 |
|
204 |
@asyncio.coroutine
|
205 |
async def connection(self,projectNo): |
206 |
app_doc_data = AppDocData.instance() |
207 |
end_point = f"{app_doc_data.API_HOST}/api/Projects/Connection?ProjectName={projectNo}"
|
208 |
async with aiohttp.ClientSession() as session: |
209 |
async with session.get(f'{end_point}') as resp: |
210 |
return await resp.json()
|
211 |
|
212 |
def accept(self): |
213 |
QDialog.accept(self)
|
214 |
|
215 |
def reject(self): |
216 |
QDialog.reject(self)
|