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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
import gtk, random
import locale
class Views():
def __init__(self):
locale.setlocale(locale.LC_ALL,"")
self.user_interaction = gtk.Notebook()
self.quiz_tab = gtk.HBox()
self.user_interaction.append_page(self.quiz_tab)
self.user_input = gtk.VBox()
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
self.tabber = gtk.Notebook()
self.tabber.set_show_tabs(False)
self.user_input.pack_start(self.tabber, False, False, 10)
#create the slider tab
self.slider_tab = gtk.VButtonBox()
self.slider_instruction = gtk.Label()
self.slider_instruction.set_markup("<big>Move the slider to choose the correct answer</big>")
self.slider_tab.pack_start(self.slider_instruction, False, False, 10)
self.slider_adjustment = gtk.Adjustment()
self.slider_tool = gtk.HScale(self.slider_adjustment)
self.slider_tool.set_digits(0)
self.slider_tab.pack_start(self.slider_tool, False, False, 10)
self.slider_click = gtk.Button("OK")
self.slider_tab.pack_start(self.slider_click, False, False, 10)
self.tabber.append_page(self.slider_tab)
#create the multiple choice tab
self.mult_tab = gtk.VBox()
self.mult_instruction = gtk.Label()
self.mult_instruction.set_markup("<big>Choose one of the answers below</big>")
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)
self.mult_2 = gtk.Button()
self.mult_tab.pack_start(self.mult_2, False, False, 10)
self.mult_3 = gtk.Button()
self.mult_tab.pack_start(self.mult_3, False, False, 10)
self.mult_4 = gtk.Button()
self.mult_tab.pack_start(self.mult_4, False, False, 10)
self.tabber.append_page(self.mult_tab)
#create the entry tab
self.entry_tab = gtk.VButtonBox()
self.entry_instruction = gtk.Label()
self.entry_instruction.set_markup("<big>Type your answer below and click 'OK'</big>")
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)
self.entry_click = gtk.Button("OK")
self.entry_tab.pack_start(self.entry_click, False, False, 10)
self.tabber.append_page(self.entry_tab)
#create the output
self.user_output = gtk.VBox()
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)
self.image_output = gtk.Image()
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("<big>Let's round numbers with Hoppy the Grasshopper</big>")
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 = "<big>Round the number <b>"
text += self.locl(data.random_number)
text += "</b> to the nearest <b>"
text += self.locl(data.answer_decade) + "</b></big>"
self.rounding_phrase.set_markup(text)
def set_choices(self, number, choices):
self.slider_adjustment.set_all(number, choices[0], choices[1], 1)
# shuffle around the possibilities
random.shuffle(choices)
self.mult_1.set_label(self.locl(choices[0]))
self.mult_2.set_label(self.locl(choices[1]))
self.mult_3.set_label(self.locl(choices[2]))
self.mult_4.set_label(self.locl(choices[3]))
self.entry_tool.set_text("")
def answer_correct(self, data):
text = "<big><span foreground=\"dark green\"><b>That's Right!!! =8-) </b></span> \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\n<span foreground=\"dark green\"><b>You made it to the next level! =8^P</b></span>"
text += "</big>"
self.output.set_markup(text)
self.image_output.set_from_pixbuf(self.image_correct_answer)
def answer_incorrect(self, data):
text = "<big><span foreground=\"red\"><b>Sorry Charlie >:( </b></span> \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\n<span foreground=\"red\"><b>You dropped a level. Concentrate! >8^|</b></span>"
text += "</big>"
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 = "<big><span foreground=\"blue\"><b>Please enter only numbers.</b></span> \n\n</big>"
self.output.set_markup(text)
def set_tab(self, data):
if data.question_count > data.thresh_entry:
self.tabber.set_current_page(2)
self.entry_tool.grab_focus()
elif data.question_count > data.thresh_mult:
self.tabber.set_current_page(1)
elif data.question_count > data.thresh_slider:
self.tabber.set_current_page(0)
self.slider_tool.grab_focus()
def locl(self, characters):
return str(locale.format("%d", characters, True))
|