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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
# Copyright 2008 by Peter Moxhay and Wade Brainerd.
# This file is part of Math.
#
# Math 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.
#
# Math 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 Math. If not, see <http://www.gnu.org/licenses/>.
from objectarea import Object
from vector import Vector
import gtk
from droptargetobject import DropTargetObject
from symbolobject import SymbolObject
from symbolmovableobject import SymbolMovableObject
class SignsDropTarget(DropTargetObject):
"""Rectangular area into which other objects can be dropped."""
def __init__(self, pos, container):
DropTargetObject.__init__(self, pos, Vector(100, 100), container)
self.draggable = False
self.selectable = False
self.hilite = False
self.contents = None
self.drop_origin = None
self.drop_targets = None
self.full = False
self.shape1 = None
self.shape2 = None
self.answer = 'equal'
def draw(self, cr):
cr.rectangle(self.pos.x, self.pos.y, self.size.x, self.size.y)
cr.set_source_rgb(0, 0, 0)
cr.set_line_width(4.0)
if self.hilite:
cr.set_dash((10, 10), 0)
cr.stroke()
def get_bounds(self):
return self.pos - Vector (2, 2), self.pos + self.size
def contains(self, other_bounds):
self_bounds_mn, self_bounds_mx = self.get_bounds()
other_bounds_mn, other_bounds_mx = other_bounds
if other_bounds_mn.x > self_bounds_mn.x \
and other_bounds_mx.x < self_bounds_mx.x \
and other_bounds_mn.y > self_bounds_mn.y \
and other_bounds_mx.y < self_bounds_mx.y :
return True
else:
return False
def processDrop(self, draggable_object):
if not isinstance(draggable_object, SymbolObject) and not isinstance(draggable_object, SymbolMovableObject):
return False
if self.full:
self.drop_origin.reset()
return False
#last_selected = self.drop_origin.ltsymbol
#
#if self.drop_origin.ltsymbol.selected == True:
# last_selected = self.drop_origin.ltsymbol
#elif self.drop_origin.eqsymbol.selected == True:
# last_selected = self.drop_origin.eqsymbol
#elif self.drop_origin.gtsymbol.selected == True:
# last_selected = self.drop_origin.gtsymbol
if isinstance(draggable_object, SymbolMovableObject):
movable_object = SymbolMovableObject(self.pos + Vector(50, 50), draggable_object.symbol, self.drop_targets, self.container, size=80)
draggable_object.move(Vector(10000, 10000))
draggable_object.dragged = False
draggable_object.selected = False
draggable_object.draggable = False
draggable_object.selectable = False
draggable_object.drag_type = None
# Get rid of the incoming MovableObject.
self.remove_object(draggable_object)
movable_object.dragged = False
movable_object.selected = False
movable_object.draggable = True
movable_object.selectable = True
movable_object.drop_targets = self.drop_targets
movable_object.drop_origin = self.drop_origin
self.container.add_object(movable_object)
self.contents = movable_object
self.full = True
self.hilite = False
self.queue_draw()
if self.drop_origin:
self.container.select_object(self.drop_origin.ltsymbol)
else:
movable_object = SymbolMovableObject(self.pos + Vector(50, 50), draggable_object.symbol, self.drop_targets, self.container, size=80)
draggable_object.move(Vector(10000, 10000))
draggable_object.dragged = False
draggable_object.selected = False
draggable_object.draggable = False
draggable_object.selectable = False
draggable_object.drag_type = None
movable_object.dragged = False
movable_object.selected = False
movable_object.draggable = True
movable_object.selectable = True
movable_object.drop_targets = self.drop_targets
movable_object.drop_origin = self.drop_origin
if self.container:
self.container.add_object(movable_object)
self.contents = movable_object
self.full = True
self.hilite = False
self.queue_draw()
if self.drop_origin:
if self.container:
self.container.select_object(self.drop_origin.ltsymbol)
if not self.answer_correct() and self.all_drop_targets_full():
self.container.show_hint()
self.reset_all_drop_targets()
self.container.register_error()
elif self.answer_correct():
self.container.selected_object = None
self.freeze_drop_targets()
if self.answer == 'greater':
self.container.increment_n_greater_than_problems_correct()
elif self.answer == 'equal':
self.container.increment_n_equals_problems_correct()
elif self.answer == 'less':
self.container.increment_n_less_than_problems_correct()
self.container.finish_problem_stage3()
if self.drop_origin:
self.drop_origin.reset()
return True
def freeze_drop_targets(self):
for o in self.drop_targets:
o.contents.selectable = False
o.contents.draggable = False
o.full = False
def reset_all_drop_targets(self):
for o in self.drop_targets:
o.reset()
o.full = False
def reset(self):
self.remove_object(self.contents)
def all_drop_targets_full(self):
b = True
for o in self.drop_targets:
if not o.full:
b = False
break
return b
def answer_correct(self):
b = False
if self.full:
if self.answer == 'greater' \
and self.contents.symbol == '>':
b = True
elif self.answer == 'equal' \
and self.contents.symbol == '=':
b = True
elif self.answer == 'less' \
and self.contents.symbol == '<':
b = True
return b
|