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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
"""
Copyright (C) 2009 Mike Major <ossfm@yahoo.com>
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 <http://www.gnu.org/licenses/>.
"""
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()
|