프로젝트

일반

사용자정보

개정판 08955797

ID08955797c4d0044a457e5e3caa84dee05356a35c
상위 bc5020f7
하위 c8ef167e

김연진이(가) 약 5년 전에 추가함

issue #1048 : 화면/네뉴/툴바 개발

Change-Id: I1b89f30441c774d71581ea4125ce639240e419b6

차이점 보기:

HYTOS/HYTOS/Flowmeter.py
14 14
import math
15 15

  
16 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

  
17 32
def is_not_blank(s):
18 33
    return bool(s and s.strip())
19 34

  
20 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

  
21 52
class QFlowmeter(QDialog):
22 53
    def __init__(self):
23 54
        QDialog.__init__(self)
......
63 94
        matches = [connector.data for connector in self._item.connectors if connector.data]
64 95
        if matches:
65 96
            pressure_drop = matches[0].pressure_drop
66
            if pressure_drop:
67
                self.ui.lineEdit_Pressure_Drop.setText(str(pressure_drop))
97
            if pressure_drop is not None:
98
                self.ui.lineEdit_Pressure_Drop.setText(str(convert_to_fixed_point(pressure_drop)))
68 99

  
69 100
            elevation = matches[0].elevation
70
            if elevation:
71
                self.ui.lineEdit_Elevation.setText(str(elevation))
101
            if elevation is not None:
102
                self.ui.lineEdit_Elevation.setText(str(convert_to_fixed_point(elevation)))
72 103

  
73 104
    def accept(self):
74 105
        """ set tag no and nozzle data """
......
85 116
                if pressure_drop:
86 117
                    connector.data.pressure_drop = float(pressure_drop)
87 118
                else:
88
                    connector.data.pressure_drop = None
119
                    connector.data.pressure_drop = 0
89 120

  
90 121
                elevation = self.ui.lineEdit_Elevation.text()
91 122
                if elevation:
92 123
                    connector.data.elevation = float(elevation)
93 124
                else:
94
                    connector.data.elevation = None
125
                    connector.data.elevation = 0
95 126

  
96 127
            QDialog.accept(self)
97 128
        else:
98
            QMessageBox.warning(self, self.tr('Notice'), self.tr('Please Input [Tag No.]'))
129
            QMessageBox.information(self, self.tr('Information'), self.tr('Please Input [Tag No.]'))
99 130

  
100 131
    def reject(self):
101 132
        QDialog.reject(self)

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)