Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2013-12-11 23:00:22 (GMT)
committer Walter Bender <walter@sugarlabs.org>2013-12-11 23:00:22 (GMT)
commitf7a43a4ad3b63859e4a534b3e8648100590cc3c3 (patch)
tree39053ce0c67a1500c979cc30d5334e4d52b5de40
parent324fb287d7b540bbb09a58350e2614507ed5c530 (diff)
add tracing; minor bug fixes
-rw-r--r--activity.py5
-rw-r--r--physics.py18
-rw-r--r--tools.py34
3 files changed, 47 insertions, 10 deletions
diff --git a/activity.py b/activity.py
index 4bf6a49..79e32bd 100644
--- a/activity.py
+++ b/activity.py
@@ -41,6 +41,7 @@ from sugar.graphics.alert import ConfirmationAlert
from sugar.graphics.toolbarbox import ToolbarBox
from sugar.graphics.toolbarbox import ToolbarButton
from sugar.graphics.style import GRID_CELL_SIZE
+from sugar.datastore import datastore
import tools
import physics
@@ -239,7 +240,7 @@ class PhysicsActivity(activity.Activity):
clear_all_alert = ConfirmationAlert()
clear_all_alert.props.title = _('Are You Sure?')
clear_all_alert.props.msg = \
- _('All you work will be discarded. This cannot be undone!')
+ _('All your work will be discarded. This cannot be undone!')
clear_all_alert.connect('response', clear_all_alert_cb)
self.add_alert(clear_all_alert)
@@ -275,7 +276,7 @@ class PhysicsActivity(activity.Activity):
jsonfile.write(json.dumps(data))
jsonfile.close()
- jobject.set_file_path(os.path.abspath(csvfile.name))
+ jobject.set_file_path(os.path.abspath(jsonfile.name))
datastore.write(jobject)
def _export_csv_cb(self, button):
diff --git a/physics.py b/physics.py
index 20502bd..b0cad5e 100644
--- a/physics.py
+++ b/physics.py
@@ -70,6 +70,7 @@ class PhysicsGame:
self.full_pos_list = []
self.tracked_bodies = []
+ self.body_colors = []
def switch_off_fake_pygame_cursor_cb(self, panel, event):
self.show_fake_cursor = False
@@ -138,14 +139,25 @@ class PhysicsGame:
if type(body.userData) == type({}):
if body.userData.has_key('track_index'):
trackdex = body.userData['track_index']
- tupled_pos = tuple_to_int(
- (body.position.x, body.position.y))
+
+ def to_screen(pos):
+ px = self.world.meter_to_screen(
+ pos[0])
+ py = self.world.meter_to_screen(
+ pos[1])
+ py = self.world.renderer.get_surface() \
+ .get_height() - py
+ return (px, py)
+
+ x = body.position.x
+ y = body.position.y
+ tupled_pos = to_screen((x, y))
posx = tupled_pos[0]
posy = tupled_pos[1]
try:
self.full_pos_list[trackdex].append(posx)
self.full_pos_list[trackdex].append(posy)
- except:
+ except IndexError:
self.full_pos_list.append([posx, posy])
if body.userData.has_key('rollMotor'):
diff --git a/tools.py b/tools.py
index 6465b18..af515b8 100644
--- a/tools.py
+++ b/tools.py
@@ -60,6 +60,9 @@ class Tool(object):
# Add ground, because we destroyed it before
self.game.world.add.ground()
+ # Also clear the points recorded in pens.
+ self.game.full_pos_list = \
+ [[] for _ in self.game.full_pos_list]
elif event.action == "focus_in":
self.game.in_focus = True
elif event.action == "focus_out":
@@ -77,12 +80,22 @@ class Tool(object):
return self.handleToolEvent(event)
def handleToolEvent(self, event):
- # Overload to handel events for Tool subclasses
+ # Overload to handle events for Tool subclasses
pass
def draw(self):
- # Default drawing method is don't draw anything
- pass
+ # Default drawing method is draw the pen points.
+ full_pos_list = self.game.full_pos_list
+ surface = self.game.world.renderer.get_surface()
+ for i, pos_list in enumerate(full_pos_list):
+ if len(self.game.body_colors) > i:
+ color = self.game.body_colors[i]
+ else:
+ color = 0
+ for i in range(0, len(pos_list), 2):
+ posx = int(pos_list[i])
+ posy = int(pos_list[i+1])
+ pygame.draw.circle(surface, color, (posx, posy), 2)
def cancel(self):
# Default cancel doesn't do anything
@@ -114,6 +127,7 @@ class CircleTool(Tool):
self.pt1 = None
def draw(self):
+ Tool.draw(self)
# Draw a circle from pt1 to mouse
if self.pt1 != None:
delta = distance(self.pt1,
@@ -165,6 +179,7 @@ class BoxTool(Tool):
self.pt1 = None
def draw(self):
+ Tool.draw(self)
# Draw a box from pt1 to mouse
if self.pt1 != None:
mouse_x_y = tuple_to_int(pygame.mouse.get_pos())
@@ -233,6 +248,7 @@ class TriangleTool(Tool):
self.vertices = None
def draw(self):
+ Tool.draw(self)
# Draw a triangle from pt1 to mouse
if self.pt1 != None:
mouse_x_y = tuple_to_int(pygame.mouse.get_pos())
@@ -310,6 +326,7 @@ class PolygonTool(Tool):
self.safe = True
def draw(self):
+ Tool.draw(self)
# Draw the poly being created
if self.vertices:
for i in range(len(self.vertices) - 1):
@@ -365,6 +382,7 @@ class MagicPenTool(Tool):
self.safe = True
def draw(self):
+ Tool.draw(self)
# Draw the poly being created
if self.vertices:
if len(self.vertices) > 1:
@@ -470,6 +488,7 @@ class JointTool(Tool):
self.jb1 = self.jb2 = self.jb1pos = self.jb2pos = None
def draw(self):
+ Tool.draw(self)
if self.jb1:
pygame.draw.line(self.game.screen, (100, 180, 255), self.jb1pos,
tuple_to_int(pygame.mouse.get_pos()), 3)
@@ -588,6 +607,7 @@ class DestroyTool(Tool):
self.cancel()
def draw(self):
+ Tool.draw(self)
# Draw the trail
if self.vertices:
if len(self.vertices) > 1:
@@ -597,6 +617,7 @@ class DestroyTool(Tool):
def cancel(self):
self.vertices = None
+
class EraseAllTool(Tool):
name = 'Erase All'
icon = 'destroy-all'
@@ -614,7 +635,7 @@ class EraseAllTool(Tool):
# Add alert for confirm the delete all action.
alert = ConfirmationAlert()
alert.props.title = _("Delete all shapes?")
- alert.props.msg = _("¡This can't be undone!")
+ alert.props.msg = _("This can't be undone!")
alert.connect('response', self.alert_info, event)
self.activity.add_alert(alert)
return
@@ -661,8 +682,10 @@ class TrackTool(Tool):
if pygame.mouse.get_pressed()[0]:
current_body = self.game.world.get_bodies_at_pos(
- tuple_to_int(event.pos))[0]
+ tuple_to_int(event.pos))
if current_body:
+ current_body = current_body[0]
+ color = current_body.userData['color']
point_pos = tuple_to_int(event.pos)
track_circle = self.game.world.add.ball(
point_pos, self.radius, dynamic=True, density=0.001,
@@ -673,6 +696,7 @@ class TrackTool(Tool):
self.game.world.add.joint(
track_circle, current_body, point_pos, point_pos, False)
self.game.tracked_bodies.append(track_circle)
+ self.game.body_colors.append(color)
def getAllTools():