From 83e8e566fbc8f9e9ed5b13e632951a523ce9fec9 Mon Sep 17 00:00:00 2001 From: Mike Major Date: Sat, 29 Aug 2009 12:35:02 +0000 Subject: Added timer to change the user outputs. Started with tabs for the introduction to rounding. --- diff --git a/data.py b/data.py index dd45592..f62468b 100644 --- a/data.py +++ b/data.py @@ -72,7 +72,7 @@ class LevelData(): self.mult.append(int(math.floor(self.random_number/(self.answer_decade*factor)) * self.answer_decade * factor)) self.mult.append(int(math.ceil(self.random_number/(self.answer_decade*factor)) * self.answer_decade * factor)) - def show_game_data(self): + def get_game_data(self): temp = "\nLevel: " + str(self.current_level) #temp += "\nRandom Number: " + str(self.random_number) #temp += "\nDecade: " + str(self.answer_decade) diff --git a/hoparound.py b/hoparound.py index 9d98c5e..a267452 100644 --- a/hoparound.py +++ b/hoparound.py @@ -1,6 +1,6 @@ from data import LevelData from view import Views -import gtk, locale +import gtk, locale, gobject from sugar.activity import activity import locale @@ -43,8 +43,9 @@ class HopaRoundActivity(activity.Activity): self.ui.answer_nan() else: if self.data.check_answer(num): - self.ui.answer_correct(self.data) + self.ui.answer_correct(self.data) else: self.ui.answer_incorrect(self.data) + gobject.timeout_add(2000, self.ui.clear, self.data) self.setup(self.data, self.ui) diff --git a/view.py b/view.py index 7b8bdbb..01777e7 100644 --- a/view.py +++ b/view.py @@ -4,9 +4,11 @@ import locale class Views(): def __init__(self): locale.setlocale(locale.LC_ALL,"") - self.user_interaction = gtk.HBox() + self.user_interaction = gtk.Notebook() + self.quiz_tab = gtk.HBox() + self.user_interaction.append_page(self.quiz_tab) self.user_input = gtk.VBox() - self.user_interaction.pack_start(self.user_input, False, False, 10) + self.quiz_tab.pack_start(self.user_input, False, False, 10) self.rounding_phrase = gtk.Label("rounding phrase") self.user_input.pack_start(self.rounding_phrase, False, False, 10) #create the notebook @@ -15,7 +17,8 @@ class Views(): self.user_input.pack_start(self.tabber, False, False, 10) #create the slider tab self.slider_tab = gtk.VButtonBox() - self.slider_instruction = gtk.Label("Move the slider to choose the correct answer") + self.slider_instruction = gtk.Label() + self.slider_instruction.set_markup("Move the slider to choose the correct answer") self.slider_tab.pack_start(self.slider_instruction, False, False, 10) self.slider_adjustment = gtk.Adjustment() self.slider_tool = gtk.HScale(self.slider_adjustment) @@ -26,7 +29,8 @@ class Views(): self.tabber.append_page(self.slider_tab) #create the multiple choice tab self.mult_tab = gtk.VBox() - self.mult_instruction = gtk.Label("Choose one of the answers below") + self.mult_instruction = gtk.Label() + self.mult_instruction.set_markup("Choose one of the answers below") self.mult_tab.pack_start(self.mult_instruction, False, False, 10) self.mult_1 = gtk.Button() self.mult_tab.pack_start(self.mult_1, False, False, 10) @@ -39,7 +43,8 @@ class Views(): self.tabber.append_page(self.mult_tab) #create the entry tab self.entry_tab = gtk.VButtonBox() - self.entry_instruction = gtk.Label("Type your answer below and click 'OK'") + self.entry_instruction = gtk.Label() + self.entry_instruction.set_markup("Type your answer below and click 'OK'") self.entry_tab.pack_start(self.entry_instruction, False, False, 10) self.entry_tool = gtk.Entry() self.entry_tab.pack_start(self.entry_tool, False, False, 10) @@ -48,7 +53,7 @@ class Views(): self.tabber.append_page(self.entry_tab) #create the output self.user_output = gtk.VBox() - self.user_interaction.pack_start(self.user_output, False, False, 10) + self.quiz_tab.pack_start(self.user_output, False, False, 10) self.output = gtk.Label("") self.output.set_alignment(0.1, 0.5) self.user_output.pack_start(self.output, False, False, 10) @@ -56,15 +61,23 @@ class Views(): self.user_output.pack_start(self.image_output, False, False, 10) self.image_correct_answer = gtk.gdk.pixbuf_new_from_file("hoppy-right.svg") self.image_incorrect_answer = gtk.gdk.pixbuf_new_from_file("hoppy-wrong.svg") + # intro tab + self.intro_tab = gtk.VBox() + self.intro_text = gtk.Label() + self.intro_text.set_markup("Let's round numbers with Hoppy the Grasshopper") + self.intro_tab.pack_start(self.intro_text, False, False, 10) + self.introduction = gtk.Notebook() + self.intro_tab.pack_start(self.introduction, False, False, 10) + self.user_interaction.append_page(self.intro_tab) def get_user_interaction(self): return self.user_interaction def set_rounding_phrase(self, data): - text = "Round the number " + text = "Round the number " text += self.locl(data.random_number) text += " to the nearest " - text += self.locl(data.answer_decade) + "" + text += self.locl(data.answer_decade) + "" self.rounding_phrase.set_markup(text) def set_choices(self, number, choices): @@ -78,27 +91,33 @@ class Views(): self.entry_tool.set_text("") def answer_correct(self, data): - text = "That's Right!!! =8-) \n\n" + text = "That's Right!!! =8-) \n\n" text += self.locl(data.random_number) + " rounded to the nearest " text += self.locl(data.answer_decade) + " is " + self.locl(data.correct_answer) if data.level_change: text += "\n\nYou made it to the next level! =8^P" - text += "\n" #+ data.show_game_data() + text += "" self.output.set_markup(text) self.image_output.set_from_pixbuf(self.image_correct_answer) def answer_incorrect(self, data): - text = "Sorry Charlie >:( \n\n" + text = "Sorry Charlie >:( \n\n" text += self.locl(data.random_number) + " rounded to the nearest " text += self.locl(data.answer_decade) + " is " + self.locl(data.correct_answer) if data.level_change: text += "\n\nYou dropped a level. Concentrate! >8^|" - text += "\n" #+ data.show_game_data() + text += "" self.output.set_markup(text) self.image_output.set_from_pixbuf(self.image_incorrect_answer) + self.output.queue_draw() + + def clear(self, data): + self.output.set_markup(data.get_game_data()) + self.image_output.clear() + return False def answer_nan(self): - text = "Please enter only numbers. \n\n" + text = "Please enter only numbers. \n\n" self.output.set_markup(text) def set_tab(self, data): -- cgit v0.9.1