Public » Miscellaneous » Twenty
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

add a little GUI app

Changeset a2d21db4ebee

Parent e6822d100bdf

by Profile picture of Benjamin PollackBenjamin Pollack

Changes to one file · Browse files at a2d21db4ebee Showing diff from parent e6822d100bdf Diff from another changeset...

Change 1 of 1 Show Entire File twivy.py Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@@ -0,0 +1,51 @@
+from kivy.app import App +from kivy.uix.label import Label +from kivy.uix.button import Button +from kivy.uix.gridlayout import GridLayout + +from brain import load, Thing + +BRAIN_DB = 'brain.db' + +class TwivyApp(App): + + def yes(self, e): + if isinstance(self.question, Thing): + self.questioner.mark_succeeded() + self.question_label.text = 'YAAAAAAAAAAY!!!' + else: + self.questioner.advance_yes() + self.ask() + + def no(self, e): + if isinstance(self.question, Thing): + self.questioner.mark_failed() + self.question_label.text = 'BOOOOO I FAILED' + else: + self.questioner.advance_no() + self.ask() + + def build(self): + maingrid = GridLayout(cols=1) + self.question_label = Label(text='No question yet') + maingrid.add_widget(self.question_label) + subgrid = GridLayout(cols=2) + yesbutton = Button(text='Yes') + yesbutton.bind(on_release=self.yes) + nobutton = Button(text='No') + nobutton.bind(on_release=self.no) + subgrid.add_widget(yesbutton) + subgrid.add_widget(nobutton) + maingrid.add_widget(subgrid) + return maingrid + + def ask(self): + self.question = self.questioner.next_question() + self.question_label.text = self.question.question() + + def on_start(self): + self.questioner = load(BRAIN_DB) + self.questioner.start() + self.ask() + +TwivyApp().run()