""" Copyright (C) 2009 Mike Major This file is part of Hop-A-Round. Hop-A-Round 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 this program. If not, see . """ from sugar.activity import activity import view import data import gtk import locale import gobject class HopARoundActivity(activity.Activity): def __init__(self, handle): activity.Activity.__init__(self, handle) self.data = data.LevelData() self.ui = view.Views() # make the toolbox toolbox = activity.ActivityToolbox(self) self.set_toolbox(toolbox) toolbox.show() # make the settings toolbar self.settings_toolbar = view.SettingsToolbar(self.data) self.settings_toolbar.question_count_spin.connect("value-changed", self.tool_item_question_count_cb) toolbox.add_toolbar("Settings", self.settings_toolbar) self.settings_toolbar.show() self.ui.clear(self.data) self.ui.slider_click.connect_object("clicked", self.submit_answer, self.ui.slider_tool) self.ui.mult_1.connect("clicked", self.submit_answer) self.ui.mult_2.connect("clicked", self.submit_answer) self.ui.mult_3.connect("clicked", self.submit_answer) self.ui.mult_4.connect("clicked", self.submit_answer) self.ui.entry_click.connect_object("clicked", self.submit_answer, self.ui.entry_tool) self.ui.entry_tool.connect("activate", self.submit_answer) self.setup() self.set_canvas(self.ui.get_user_interaction()) self.show_all() self.ui.help.hide() def setup(self): self.data.gen_random() self.ui.set_rounding_phrase(self.data) self.ui.set_choices(self.data.random_number, self.data.mult) self.ui.set_tab(self.data) def submit_answer(self, widget): try: # for int answer because of entry field if widget.get_name() == "GtkHScale": num = int(widget.get_value()) elif widget.get_name() == "GtkButton": num = locale.atoi(widget.get_label()) elif widget.get_name() == "GtkEntry": num = locale.atoi(widget.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() def tool_item_question_count_cb(self, widget): self.data.set_question_count(widget.get_value_as_int()) self.ui.clear(self.data) self.setup()