diff --git a/main.py b/main.py index 66205d93bd0014ea773d11fcb85c98f17bcc2c25..66ca1e3d07a48087fa15d3143c722f9e196582fc 100644 --- a/main.py +++ b/main.py @@ -67,6 +67,10 @@ PAUSE_TIME = 0.75 # seconds class QuizzerApp(App): DEFAULT_QUESTION = ('What is your favourite color?', ('Blue', 'Blue', 'Blue', 'Blue'), 'Blue') + include_gui_topic = BooleanProperty(True) + include_color_topic = BooleanProperty(False) + include_tree_topic = BooleanProperty(False) + questions = ListProperty([]) paused = BooleanProperty(False) correct = BooleanProperty(False) @@ -74,20 +78,32 @@ class QuizzerApp(App): def build(self): inspector.create_inspector(Window, self) - def on_start(self): - self.reshuffle() - def reshuffle(self): - questions = [] - if self.root.ids.gui.active: + questions = [] # Use a plain list, not a list property, for the computations. + if self.include_gui_topic: questions += GUI_QUESTIONS - elif self.root.ids.color.active: + elif self.include_color_topic: questions += COLOR_QUESTIONS - elif self.root.ids.tree.active: + elif self.include_tree_topic: questions += TREE_QUESTIONS shuffle(questions) self.questions = questions + def on_start(self): + self.reshuffle() + + def toggle_gui_topic(self, include_gui_topic): + self.include_gui_topic = include_gui_topic + self.reshuffle() + + def toggle_color_topic(self, include_color_topic): + self.include_color_topic = include_color_topic + self.reshuffle() + + def toggle_tree_topic(self, include_tree_topic): + self.include_tree_topic = include_tree_topic + self.reshuffle() + def answer(self, answer): question = self.questions[-1] if len(self.questions) > 0 else self.DEFAULT_QUESTION self.paused = True diff --git a/quizzer.kv b/quizzer.kv index b022abd170cea7aedda653f8d9902fac95e46e96..b3ab475b32330ee4e821c76f3cc9ec988d65cb67 100644 --- a/quizzer.kv +++ b/quizzer.kv @@ -12,10 +12,10 @@ ScreenManager: CheckBox: id: gui group: 'categories' - active: True + active: app.include_gui_topic size_hint: (None, None) size: (sp(32), gui_label.height) - on_active: app.reshuffle() + on_active: app.toggle_gui_topic(self.active) Label: id: gui_label text: 'Graphical User Interfaces' @@ -28,10 +28,10 @@ ScreenManager: CheckBox: id: color group: 'categories' - active: False + active: app.include_color_topic size_hint: (None, None) size: (sp(32), color_label.height) - on_active: app.reshuffle() + on_active: app.toggle_color_topic(self.active) Label: id: color_label text: 'RGBA Quadruples' @@ -44,10 +44,10 @@ ScreenManager: CheckBox: id: tree group: 'categories' - active: False + active: app.include_tree_topic size_hint: (None, None) size: (sp(32), tree_label.height) - on_active: app.reshuffle() + on_active: app.toggle_tree_topic(self.active) Label: id: tree_label text: 'Containment Hierarchies'