Select Git revision
example2.py
Forked from
SOFT Core / SOFT 161 and 162 / Testability Examples
Source project has a limited visibility.
example2.py 1.24 KiB
from math import inf
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import NumericProperty, StringProperty
class Field(BoxLayout):
label_text = StringProperty()
class Example2App(App):
smallest_positive = NumericProperty(inf)
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.values = []
def add_field(self):
container = self.root.ids.fields
container.add_widget(Field(label_text=f'Field #{len(container.children)}: '))
def remove_field(self):
container = self.root.ids.fields
if len(container.children) > 0:
container.remove_widget(container.children[0])
def _find_smallest_positive(self):
result = inf
for value in self.values:
if 0 < value < result:
result = value
return result
def update(self):
container = self.root.ids.fields
self.values = []
for field in container.children:
try:
self.values.append(float(field.ids.input.text))
except ValueError:
pass
self.smallest_positive = self._find_smallest_positive()
if __name__ == '__main__':
app = Example2App()
app.run()