MCPcopy Index your code
hub / github.com/pyfa-org/Pyfa / FloatBox

Class FloatBox

gui/utils/inputs.py:58–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56
57
58class FloatBox(wx.TextCtrl):
59
60 def __init__(self, parent, value, id=wx.ID_ANY, style=0, validator=None, **kwargs):
61 # Workaround for #2591
62 if 'wxMac' in wx.PlatformInfo and 'size' not in kwargs:
63 kwargs['size'] = wx.Size(97, 26)
64 super().__init__(parent=parent, id=id, style=style, **kwargs)
65 self.Bind(wx.EVT_TEXT, self.OnText)
66 self._storedValue = ''
67 self._validator = validator
68 self.ChangeValue(valToStr(value))
69
70 def ChangeValue(self, value):
71 self._storedValue = value
72 super().ChangeValue(value)
73 self.updateColor()
74
75 def ChangeValueFloat(self, value):
76 self.ChangeValue(valToStr(value))
77
78 def updateColor(self):
79 if self.isValid():
80 self.SetForegroundColour(wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT))
81 else:
82 self.SetForegroundColour(wx.RED)
83
84 def isValid(self):
85 if self._validator is None:
86 return True
87 return self._validator.validate(self.GetValue())
88
89 def getInvalidationReason(self):
90 if self._validator is None:
91 return None
92 return self._validator.getReason(self.GetValue())
93
94 def OnText(self, event):
95 currentValue = self.GetValue()
96 if currentValue == self._storedValue:
97 event.Skip()
98 return
99 if currentValue == '' or re.match(r'^\d*\.?\d*$', currentValue):
100 self._storedValue = currentValue
101 self.updateColor()
102 event.Skip()
103 else:
104 self.ChangeValue(self._storedValue)
105
106 def GetValueFloat(self):
107 return strToFloat(self.GetValue())
108
109
110class FloatRangeBox(wx.TextCtrl):

Callers 3

__addInputFieldMethod · 0.90
__init__Method · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected