hytos / HYTOS / HYTOS / Strainer_Y.py @ 08955797
이력 | 보기 | 이력해설 | 다운로드 (3.98 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
|
3 |
# Form implementation generated from reading ui file 'ProjectDialog.ui'
|
4 |
#
|
5 |
# Created by: PyQt5 UI code generator 5.6
|
6 |
#
|
7 |
# WARNING! All changes made in this file will be lost!
|
8 |
|
9 |
from PyQt5 import QtCore, QtGui, QtWidgets |
10 |
from PyQt5.QtWidgets import * |
11 |
import os |
12 |
from AppDocData import AppDocData |
13 |
import Strainer_Y_UI |
14 |
import math |
15 |
|
16 |
|
17 |
def is_float(s): |
18 |
try:
|
19 |
if s:
|
20 |
float(s)
|
21 |
return True |
22 |
else:
|
23 |
return False |
24 |
except ValueError: |
25 |
return False |
26 |
|
27 |
|
28 |
def is_blank(s): |
29 |
return not (s and s.strip()) |
30 |
|
31 |
|
32 |
def is_not_blank(s): |
33 |
return bool(s and s.strip()) |
34 |
|
35 |
|
36 |
def convert_to_fixed_point(value): |
37 |
if is_float(str(value)): |
38 |
tokens = f"{float(value):.10f}".split('.') |
39 |
if len(tokens) == 2: |
40 |
# 소수점 아래가 있을 경우 소수점 아래의 trailing zero를 제거한다.
|
41 |
if is_blank(tokens[1].rstrip('0')): |
42 |
return tokens[0] |
43 |
else:
|
44 |
tokens[1] = tokens[1].rstrip('0') |
45 |
return '.'.join(tokens) |
46 |
else:
|
47 |
return tokens[0] |
48 |
else:
|
49 |
return value
|
50 |
|
51 |
|
52 |
class QStrainer_Y(QDialog): |
53 |
def __init__(self): |
54 |
QDialog.__init__(self)
|
55 |
|
56 |
self.ui = Strainer_Y_UI.Ui_Strainer_Y_Dialog()
|
57 |
self.ui.setupUi(self) |
58 |
self._item = None |
59 |
|
60 |
self.ui.lineEdit_Pressure_Drop.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Pressure_Drop)) |
61 |
self.ui.lineEdit_Elevation.setValidator(QtGui.QDoubleValidator(self.ui.lineEdit_Elevation)) |
62 |
self.initialize()
|
63 |
|
64 |
def show_dialog(self, item): |
65 |
self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint) |
66 |
self._item = item
|
67 |
|
68 |
self.ui.lineEdit_TagNo.setFocus()
|
69 |
self.set_controls()
|
70 |
self.load_data()
|
71 |
|
72 |
return self.exec_() |
73 |
|
74 |
def initialize(self): |
75 |
self.ui.label_Img.setVisible(False) |
76 |
|
77 |
def set_controls(self): |
78 |
self.ui.label_Img.setVisible(True) |
79 |
|
80 |
def load_data(self): |
81 |
""" load tag no and nozzle data """
|
82 |
tag_no = self._item.tag_no
|
83 |
if tag_no != 'None' and is_not_blank(tag_no): |
84 |
self.ui.lineEdit_TagNo.setText(tag_no)
|
85 |
|
86 |
app_doc_data = AppDocData.instance() |
87 |
drawing = app_doc_data.activeDrawing |
88 |
if drawing:
|
89 |
for attr in drawing.attrs: |
90 |
if attr[0] == 'Units': |
91 |
self.ui.label_PressureUnit.setText(attr[1]['Pressure']) |
92 |
self.ui.label_ElevationUnit.setText(attr[1]['Length']) |
93 |
|
94 |
matches = [connector.data for connector in self._item.connectors if connector.data] |
95 |
if matches:
|
96 |
pressure_drop = matches[0].pressure_drop
|
97 |
if pressure_drop is not None: |
98 |
self.ui.lineEdit_Pressure_Drop.setText(str(convert_to_fixed_point(pressure_drop))) |
99 |
|
100 |
elevation = matches[0].elevation
|
101 |
if elevation is not None: |
102 |
self.ui.lineEdit_Elevation.setText(str(convert_to_fixed_point(elevation))) |
103 |
|
104 |
def accept(self): |
105 |
""" set tag no and nozzle data """
|
106 |
from EngineeringConnectorItem import NozzleData |
107 |
tag_no = self.ui.lineEdit_TagNo.text()
|
108 |
|
109 |
if is_not_blank(tag_no):
|
110 |
self._item.tag_no = tag_no
|
111 |
for connector in self._item.connectors: |
112 |
if not connector.data: |
113 |
connector.data = NozzleData() |
114 |
|
115 |
pressure_drop = self.ui.lineEdit_Pressure_Drop.text()
|
116 |
if pressure_drop:
|
117 |
connector.data.pressure_drop = float(pressure_drop)
|
118 |
else:
|
119 |
connector.data.pressure_drop = 0
|
120 |
|
121 |
elevation = self.ui.lineEdit_Elevation.text()
|
122 |
if elevation:
|
123 |
connector.data.elevation = float(elevation)
|
124 |
else:
|
125 |
connector.data.elevation = 0
|
126 |
|
127 |
QDialog.accept(self)
|
128 |
else:
|
129 |
QMessageBox.information(self, self.tr('Information'), self.tr('Please Input [Tag No.]')) |
130 |
|
131 |
def reject(self): |
132 |
QDialog.reject(self)
|