Skip to content
Snippets Groups Projects
Commit 5af7abb7 authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Prefer sending data from the view over retrieving it from the controller.

parent 34339231
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,9 @@ class Classification(Enum):
class TriangleApp(App):
a = StringProperty('')
b = StringProperty('')
c = StringProperty('')
classification = StringProperty()
@staticmethod
......@@ -36,15 +39,23 @@ class TriangleApp(App):
return Classification.SCALENE
def update(self):
ids = self.root.ids
try:
self.classification = TriangleApp.classify(int(ids.a.text), int(ids.b.text), int(ids.c.text)).value
self.classification = TriangleApp.classify(int(self.a), int(self.b), int(self.c)).value
except ValueError:
self.classification = f'{Classification.INVALID.value} (non-integer sides)'
def on_start(self):
self.update()
def on_a(self, _, __):
self.update()
def on_b(self, _, __):
self.update()
def on_c(self, _, __):
self.update()
if __name__ == '__main__':
app = TriangleApp()
......
......@@ -13,12 +13,11 @@ BoxLayout:
Widget:
size_hint: (0.25, 1.0)
TextInput:
id: a
multiline: False
write_tab: False
text: ''
text: app.a
font_size: sp(24)
on_text: app.update()
on_text: app.a = self.text
Widget:
BoxLayout:
orientation: 'horizontal'
......@@ -31,12 +30,11 @@ BoxLayout:
Widget:
size_hint: (0.25, 1.0)
TextInput:
id: b
multiline: False
write_tab: False
text: ''
text: app.b
font_size: sp(24)
on_text: app.update()
on_text: app.b = self.text
Widget:
BoxLayout:
orientation: 'horizontal'
......@@ -49,12 +47,11 @@ BoxLayout:
Widget:
size_hint: (0.25, 1.0)
TextInput:
id: c
multiline: False
write_tab: False
text: ''
text: app.c
font_size: sp(24)
on_text: app.update()
on_text: app.c = self.text
Widget:
Widget:
BoxLayout:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment