""" Copyright (C) 2009 Mike Major This file is part of HopAround. HopAround is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. HopAround is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Foobar. If not, see . """ from data import LevelData from view import Views import gtk, locale, gobject from sugar.activity import activity import locale class HopaRoundActivity(activity.Activity): def __init__(self, handle): activity.Activity.__init__(self, handle) # make the toolbox toolbox = activity.ActivityToolbox(self) self.set_toolbox(toolbox) toolbox.show() self.data = LevelData() self.ui = Views() self.ui.clear(self.data) self.ui.slider_click.connect("clicked", self.submit_answer, self.ui.slider_tool) self.ui.mult_1.connect("clicked", self.submit_answer, self.ui.mult_1) self.ui.mult_2.connect("clicked", self.submit_answer, self.ui.mult_2) self.ui.mult_3.connect("clicked", self.submit_answer, self.ui.mult_3) self.ui.mult_4.connect("clicked", self.submit_answer, self.ui.mult_4) self.ui.entry_click.connect("clicked", self.submit_answer, self.ui.entry_tool) self.ui.entry_tool.connect("activate", self.submit_answer, self.ui.entry_tool) self.setup(self.data, self.ui) #sugar canvas self.set_canvas(self.ui.get_user_interaction()) self.show_all() self.ui.help.hide() def setup(self, data, ui): data.gen_random() ui.set_rounding_phrase(self.data) ui.set_choices(self.data.random_number, self.data.mult) ui.set_tab(self.data) def submit_answer(self, widget, answer): try: # for int answer because of entry field if answer.get_name() == "GtkHScale": num = int(answer.get_value()) elif answer.get_name() == "GtkButton": num = locale.atoi(answer.get_label()) elif answer.get_name() == "GtkEntry": num = locale.atoi(answer.get_text()) except: self.ui.answer_nan() else: if self.data.check_answer(num): self.ui.answer_correct(self.data) else: self.ui.answer_incorrect(self.data) gobject.timeout_add(2500, self.ui.clear, self.data) self.setup(self.data, self.ui)