From 2e03dfac8d21d34fdee14aa72a5f350d1ec7dd5e Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sat, 21 Dec 2013 14:05:10 +0000 Subject: pep8 cleanup; svineet patch to save tracked bodies --- diff --git a/NEWS b/NEWS index fdc96b5..58852d1 100644 --- a/NEWS +++ b/NEWS @@ -1,9 +1,13 @@ 12 -* Removed cjson dependency for elements +ENHANCEMENTS: * Added option to joints to set collideConnected = False * Added clear_all (svineet) * Added tracking (svineet) * Added tracing (svineet) * Added erase traces (svineet) * Added save/restore of pens and traces (svineet) + +BUG FIXES: +* Removed cjson dependency for elements +* pep8 cleanup (svineet) diff --git a/activity.py b/activity.py index 856be1c..129974b 100644 --- a/activity.py +++ b/activity.py @@ -87,13 +87,13 @@ class PhysicsActivity(activity.Activity): self.game.write_file(file_path) def get_preview(self): - """ Custom preview code to get image from pygame. """ + ''' Custom preview code to get image from pygame. ''' if self.preview: return self.preview surface = pygame.display.get_surface() width, height = surface.get_width(), surface.get_height() pixbuf = gtk.gdk.pixbuf_new_from_data(pygame.image.tostring(surface, - "RGB"), + 'RGB'), gtk.gdk.COLORSPACE_RGB, 0, 8, width, height, 3 * width) @@ -129,10 +129,10 @@ class PhysicsActivity(activity.Activity): toolbar_box.toolbar.insert(separator, -1) separator.show() - clear_trace = ToolButton("clear-trace") - clear_trace.set_tooltip(_("Clear Trace Marks")) - clear_trace.set_accelerator(_("x")) - clear_trace.connect("clicked", self.clear_trace_cb) + clear_trace = ToolButton('clear-trace') + clear_trace.set_tooltip(_('Clear Trace Marks')) + clear_trace.set_accelerator(_('x')) + clear_trace.connect('clicked', self.clear_trace_cb) clear_trace.set_sensitive(False) toolbar_box.toolbar.insert(clear_trace, -1) clear_trace.show() @@ -155,14 +155,14 @@ class PhysicsActivity(activity.Activity): activity_button.props.page.insert(separator, -1) separator.show() - export_json = ToolButton("save-as-json") - export_json.set_tooltip(_("Export tracked objects to journal")) + export_json = ToolButton('save-as-json') + export_json.set_tooltip(_('Export tracked objects to journal')) export_json.connect('clicked', self._export_json_cb) activity_button.props.page.insert(export_json, -1) export_json.show() - export_csv = ToolButton("save-as-csv") - export_csv.set_tooltip(_("Export tracked objects to journal")) + export_csv = ToolButton('save-as-csv') + export_csv.set_tooltip(_('Export tracked objects to journal')) export_csv.connect('clicked', self._export_csv_cb) activity_button.props.page.insert(export_csv, -1) export_csv.show() @@ -180,7 +180,7 @@ class PhysicsActivity(activity.Activity): def _insert_stop_play_button(self, toolbar): self.stop_play_state = True self.stop_play = ToolButton('media-playback-stop') - self.stop_play.set_tooltip(_("Stop")) + self.stop_play.set_tooltip(_('Stop')) self.stop_play.set_accelerator(_('space')) self.stop_play.connect('clicked', self.stop_play_cb) toolbar.insert(self.stop_play, -1) @@ -188,7 +188,7 @@ class PhysicsActivity(activity.Activity): def _insert_clear_all_button(self, toolbar): self.clear_all = ToolButton('clear_all') - self.clear_all.set_tooltip(_("Erase All")) + self.clear_all.set_tooltip(_('Erase All')) self.clear_all.set_accelerator(_('a')) self.clear_all.connect('clicked', self.clear_all_cb) toolbar.insert(self.clear_all, -1) @@ -243,27 +243,27 @@ class PhysicsActivity(activity.Activity): def stop_play_cb(self, button): pygame.event.post(pygame.event.Event(pygame.USEREVENT, - action="stop_start_toggle")) + action='stop_start_toggle')) self.stop_play_state = not self.stop_play_state if self.stop_play_state: self.stop_play.set_icon('media-playback-stop') - self.stop_play.set_tooltip(_("Stop")) + self.stop_play.set_tooltip(_('Stop')) else: self.stop_play.set_icon('media-playback-start') - self.stop_play.set_tooltip(_("Start")) + self.stop_play.set_tooltip(_('Start')) def clear_all_cb(self, button): def clear_all_alert_cb(alert, response_id): self.remove_alert(alert) if response_id is gtk.RESPONSE_OK: pygame.event.post(pygame.event.Event(pygame.USEREVENT, - action="clear_all")) + action='clear_all')) clear_all_alert = ConfirmationAlert() clear_all_alert.props.title = _('Are You Sure?') clear_all_alert.props.msg = \ - _('All your 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) @@ -272,30 +272,30 @@ class PhysicsActivity(activity.Activity): action=self.radioList[button])) def _focus_event(self, event, data=None): - """ Send focus events to pygame to allow it to idle when in - background. """ + ''' Send focus events to pygame to allow it to idle when in + background. ''' if not self.game.pygame_started: logging.debug('focus_event: pygame not yet initialized') return if data.state == gtk.gdk.VISIBILITY_FULLY_OBSCURED: pygame.event.post(pygame.event.Event(pygame.USEREVENT, - action="focus_out")) + action='focus_out')) else: self.game.show_fake_cursor = True pygame.event.post(pygame.event.Event(pygame.USEREVENT, - action="focus_in")) + action='focus_in')) def _export_json_cb(self, button): jobject = datastore.create() - jobject.metadata['title'] = _("Physics export") - jobject.metadata['mime_type'] = "text/plain" + jobject.metadata['title'] = _('Physics export') + jobject.metadata['mime_type'] = 'text/plain' tmp_dir = os.path.join(self.get_activity_root(), 'instance') fd, file_path = tempfile.mkstemp(dir=tmp_dir) os.close(fd) data = self.game.full_pos_list - jsonfile = open(file_path, "wb") + jsonfile = open(file_path, 'wb') jsonfile.write(json.dumps(data)) jsonfile.close() @@ -304,15 +304,15 @@ class PhysicsActivity(activity.Activity): def _export_csv_cb(self, button): jobject = datastore.create() - jobject.metadata['title'] = _("Physics export") - jobject.metadata['mime_type'] = "text/csv" + jobject.metadata['title'] = _('Physics export') + jobject.metadata['mime_type'] = 'text/csv' tmp_dir = os.path.join(self.get_activity_root(), 'instance') fd, file_path = tempfile.mkstemp(dir=tmp_dir) os.close(fd) data = self.game.full_pos_list - csvfile = open(file_path, "wb") + csvfile = open(file_path, 'wb') writer = csv.writer(csvfile) writer.writerows(data) csvfile.close() @@ -321,8 +321,8 @@ class PhysicsActivity(activity.Activity): datastore.write(jobject) def _window_event(self, window, event): - """ Send focus out event to pygame when switching to a desktop - view. """ + ''' Send focus out event to pygame when switching to a desktop + view. ''' if event.changed_mask & gtk.gdk.WINDOW_STATE_ICONIFIED: pygame.event.post(pygame.event.Event(pygame.USEREVENT, - action="focus_out")) + action='focus_out')) diff --git a/helpers.py b/helpers.py index 1d0d2fe..08c5da0 100644 --- a/helpers.py +++ b/helpers.py @@ -1,51 +1,48 @@ -""" - Physics, a 2D Physics Playground for Kids - Copyright (C) 2008 Alex Levenson and Brian Jordan - - This program 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. - - This program 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 . - -""" -#================================================================== -# Physics.activity -# Helper classes and functions -# By Alex Levenson -#================================================================== +# Physics, a 2D Physics Playground for Kids + +# Copyright (C) 2008 Alex Levenson and Brian Jordan +# Copyright (C) 2013 Walter Bender + +# This program 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. + +# This program 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 . + import math + def distance(pt1, pt2): - """Distance calculator, pt1 and pt2 are ordred pairs. - """ + '''Distance calculator, pt1 and pt2 are ordred pairs.''' return math.sqrt((pt1[0] - pt2[0]) ** 2 + (pt1[1] - pt2[1]) ** 2) + def getAngle(pt1, pt2): - """Returns angle between line segment pt1 -> pt2 and x axis, from -pi to pi. - """ + '''Returns angle between line segment pt1 -> pt2 and x axis, + from -pi to pi.''' xcomp = pt2[0] - pt1[0] ycomp = pt1[1] - pt2[1] return math.atan2(ycomp, xcomp) + def constructTriangleFromLine(p1, p2): - """Returns list of ordered pairs describing equilteral triangle around segment pt1 --> pt2. - """ + '''Returns list of ordered pairs describing equilteral triangle around + segment pt1 --> pt2.''' halfHeightVector = (0.57735 * (p2[1] - p1[1]), 0.57735 * (p2[0] - p1[0])) p3 = (p1[0] + halfHeightVector[0], p1[1] - halfHeightVector[1]) p4 = (p1[0] - halfHeightVector[0], p1[1] + halfHeightVector[1]) return [p2, p3, p4] + def polyArea(vertices): - """Returns the area of a polygon. - """ + '''Returns the area of a polygon.''' n = len(vertices) A = 0 p = n - 1 @@ -56,12 +53,10 @@ def polyArea(vertices): q += 1 return A / 2.0 - + def insideTriangle(pt, triangle): - """Returns true if pt is in triangle. - - Some polygon magic, thanks to John W. Ratcliff on www.flipcode.com - """ + '''Returns true if pt is in triangle. + Some polygon magic, thanks to John W. Ratcliff on www.flipcode.com''' ax = triangle[2][0] - triangle[1][0] ay = triangle[2][1] - triangle[1][1] bx = triangle[0][0] - triangle[2][0] @@ -77,9 +72,10 @@ def insideTriangle(pt, triangle): aCROSSbp = ax * bpy - ay * bpx cCROSSap = cx * apy - cy * apx - bCROSScp = bx * cpy - by * cpx + bCROSScp = bx * cpy - by * cpx return aCROSSbp >= 0.0 and bCROSScp >= 0.0 and cCROSSap >= 0.0 + def polySnip(vertices, u, v, w, n): EPSILON = 0.0000000001 @@ -107,12 +103,12 @@ def polySnip(vertices, u, v, w, n): def decomposePoly(vertices): - """Decomposes a polygon into its triangles. - """ + '''Decomposes a polygon into its triangles.''' vertices = list(vertices) n = len(vertices) result = [] - if(n < 3): return [] # not a poly! + if(n < 3): + return [] # not a poly! # Force counter-clockwise polygon if 0 >= polyArea(vertices): @@ -120,20 +116,23 @@ def decomposePoly(vertices): # Remove nv-2 vertices, creating 1 triangle every time nv = n - count = 2 * nv # error detection + count = 2 * nv # error detection v = nv - 1 while nv > 2: count -= 1 if 0 >= count: - return [] # Error -- probably bad polygon + return [] # Error -- probably bad polygon # Three consecutive vertices - u = v - if nv <= u: u = 0 # previous + u = v + if nv <= u: + u = 0 # previous v = u + 1 - if nv <= v: v = 0 # new v + if nv <= v: + v = 0 # new v w = v + 1 - if nv <= w: w = 0 # next + if nv <= w: + w = 0 # next if(polySnip(vertices, u, v, w, nv)): @@ -147,7 +146,8 @@ def decomposePoly(vertices): count = 2 * nv return result + def tuple_to_int(tuple_input): - """Cast tuple values to ints to avoid gtk+ and pygame's dislike of floats. - """ + '''Cast tuple values to ints to avoid gtk+ and pygame's dislike of + floats.''' return [int(i) for i in tuple_input] diff --git a/physics.py b/physics.py index e89e12a..b1894ad 100644 --- a/physics.py +++ b/physics.py @@ -1,29 +1,29 @@ #!/usr/bin/python -""" - Physics, a 2D Physics Playground for Kids - Copyright (C) 2008 Alex Levenson and Brian Jordan +# Physics, a 2D Physics Playground for Kids - This program 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. +# Copyright (C) 2008 Alex Levenson and Brian Jordan +# Copyright (C) 2012 Daniel Francis +# Copyright (C) 2012-13 Walter Bender +# Copyright (C) 2013 Sai Vineet +# Copyright (C) 2012-13 Sugar Labs - This program 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. +# This program 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. - You should have received a copy of the GNU General Public License - along with this program. If not, see . +# This program 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 . -Elements is Copyright (C) 2008, The Elements Team, +# Elements is Copyright (C) 2008, The Elements Team, -Wiki: http://wiki.sugarlabs.org/go/Activities/Physics -Code: git://git.sugarlabs.org/physics/mainline.git - -""" +# Wiki: http://wiki.sugarlabs.org/go/Activities/Physics +# Code: git://git.sugarlabs.org/physics/mainline.git import os import sys @@ -33,10 +33,10 @@ import pygame from pygame.locals import * from pygame.color import * -sys.path.append("lib/") +sys.path.append('lib/') # If your architecture is different, comment these lines and install # the modules in your system. -sys.path.append("lib/Box2D-2.0.2b1-py2.5-linux-i686.egg") +sys.path.append('lib/Box2D-2.0.2b1-py2.5-linux-i686.egg') import Box2D as box2d import elements @@ -80,8 +80,9 @@ class PhysicsGame: #Saving to journal self.world.add.remove_mouseJoint() additional_data = { - "trackinfo": self.trackinfo, - "full_pos_list": self.full_pos_list + 'trackinfo': self.trackinfo, + 'full_pos_list': self.full_pos_list, + 'tracked_bodies': self.tracked_bodies } self.world.json_save(path, additional_data, serialize=True) @@ -103,9 +104,9 @@ class PhysicsGame: (0, 0, 0, 0, 0, 0, 0, 0)) self.cursor_picture = pygame.image.load('standardcursor.png') self.cursor_picture.convert_alpha() - self.canvas.connect("enter_notify_event", + self.canvas.connect('enter_notify_event', self.switch_on_fake_pygame_cursor_cb) - self.canvas.connect("leave_notify_event", + self.canvas.connect('leave_notify_event', self.switch_off_fake_pygame_cursor_cb) self.canvas.add_events(gtk.gdk.ENTER_NOTIFY_MASK | gtk.gdk.LEAVE_NOTIFY_MASK) @@ -123,6 +124,9 @@ class PhysicsGame: self.world.additional_vars['full_pos_list'] if 'trackinfo' in self.world.additional_vars: self.trackinfo = self.world.additional_vars['trackinfo'] + if 'tracked_bodies' in self.world.additional_vars: + self.tracked_bodies = \ + self.world.additional_vars['tracked_bodies'] while self.loop: while gtk.events_pending(): @@ -186,16 +190,16 @@ class PhysicsGame: self.full_pos_list[trackdex].append(posy) except IndexError: self.full_pos_list.append([posx, posy]) - + ''' for body in self.world.world.GetBodyList(): if isinstance(body.userData, dict): - if body.userData.has_key('rollMotor'): - diff = body.userData['rollMotor'] \ - ['targetVelocity'] \ - - body.GetAngularVelocity() - body.ApplyTorque(body.userData['rollMotor'] \ - ['strength'] * diff \ - * body.getMassData().I) + if 'rollMotor' in body.userData: + rollmotor = body.userData['rollMotor'] + diff = rollmotor['targetVelocity'] - \ + body.GetAngularVelocity() + body.ApplyTorque(rollmotor['strength'] * \ + diff * body.getMassData().I) + ''' # Update & Draw World self.world.update() diff --git a/tools.py b/tools.py index d9c107b..0c925a4 100644 --- a/tools.py +++ b/tools.py @@ -1,27 +1,25 @@ # -*- coding: utf-8 -*- -""" - Physics, a 2D Physics Playground for Kids - Copyright (C) 2008 Alex Levenson and Brian Jordan - - This program 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. - - This program 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 . - -""" -#================================================================== -# Physics.activity -# Tool Classes -# By Alex Levenson -#================================================================== +# Physics, a 2D Physics Playground for Kids + +# Copyright (C) 2008 Alex Levenson and Brian Jordan +# Copyright (C) 2012 Daniel Francis +# Copyright (C) 2012-13 Walter Bender +# Copyright (C) 2013 Sai Vineet +# Copyright (C) 2012-13 Sugar Labs + +# This program 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. + +# This program 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 . + import pygame from pygame.locals import * from helpers import * @@ -34,7 +32,7 @@ import gtk class Tool(object): name = 'Tool' icon = 'icon' - toolTip = "Tool Tip" + toolTip = 'Tool Tip' toolAccelerator = None def __init__(self, gameInstance): @@ -45,12 +43,12 @@ class Tool(object): handled = True # Default event handling if event.type == USEREVENT: - if hasattr(event, "action"): - if event.action == "stop_start_toggle": + if hasattr(event, 'action'): + if event.action == 'stop_start_toggle': # Stop/start simulation toggle = self.game.world.run_physics self.game.world.run_physics = not toggle - elif event.action == "clear_all": + elif event.action == 'clear_all': if len(self.game.world.world.GetBodyList()) > 1: # Get bodies and destroy them too for body in self.game.world.world.GetBodyList(): @@ -61,11 +59,11 @@ class Tool(object): # Also clear the points recorded in pens. self.game.full_pos_list = \ [[] for _ in self.game.full_pos_list] - elif event.action == "focus_in": + elif event.action == 'focus_in': self.game.in_focus = True - elif event.action == "focus_out": + elif event.action == 'focus_out': self.game.in_focus = False - elif self.game.toolList.has_key(event.action): + elif event.action in self.game.toolList: self.game.setTool(event.action) elif event.type == MOUSEBUTTONDOWN and event.button == 1: self.game.canvas.grab_focus() @@ -105,8 +103,8 @@ class Tool(object): class CircleTool(Tool): name = 'Circle' icon = 'circle' - toolTip = _("Circle") - toolAccelerator = _("c") + toolTip = _('Circle') + toolAccelerator = _('c') def __init__(self, gameInstance): Tool.__init__(self, gameInstance) @@ -146,8 +144,8 @@ class CircleTool(Tool): class BoxTool(Tool): name = 'Box' icon = 'box' - toolTip = _("Box") - toolAccelerator = _("b") + toolTip = _('Box') + toolAccelerator = _('b') def __init__(self, gameInstance): Tool.__init__(self, gameInstance) @@ -199,8 +197,8 @@ class BoxTool(Tool): class TriangleTool(Tool): name = 'Triangle' icon = 'triangle' - toolTip = _("Triangle") - toolAccelerator = _("t") + toolTip = _('Triangle') + toolAccelerator = _('t') def __init__(self, gameInstance): Tool.__init__(self, gameInstance) @@ -269,8 +267,8 @@ class TriangleTool(Tool): class PolygonTool(Tool): name = 'Polygon' icon = 'polygon' - toolTip = _("Polygon") - toolAccelerator = _("p") + toolTip = _('Polygon') + toolAccelerator = _('p') def __init__(self, gameInstance): Tool.__init__(self, gameInstance) @@ -295,12 +293,14 @@ class PolygonTool(Tool): self.vertices = [[i[0] - delta_x, i[1] - delta_y] for i in self.previous_vertices] self.safe = True - self.game.world.add.complexPoly(self.vertices, dynamic=True, + self.game.world.add.complexPoly(self.vertices, + dynamic=True, density=1.0, restitution=0.16, friction=0.5) self.vertices = None - elif (event.type == MOUSEBUTTONUP or event.type == MOUSEBUTTONDOWN): + elif (event.type == MOUSEBUTTONUP or + event.type == MOUSEBUTTONDOWN): if self.vertices is None or (tuple_to_int(event.pos)[0] == self.vertices[-1][0] and tuple_to_int(event.pos)[1] @@ -321,7 +321,8 @@ class PolygonTool(Tool): self.vertices = None else: self.vertices.append(tuple_to_int(event.pos)) - if distance(tuple_to_int(event.pos), self.vertices[0]) > 54: + if distance(tuple_to_int(event.pos), + self.vertices[0]) > 54: self.safe = True def draw(self): @@ -345,8 +346,8 @@ class PolygonTool(Tool): class MagicPenTool(Tool): name = 'Magicpen' icon = 'magicpen' - toolTip = _("Draw") - toolAccelerator = _("d") + toolTip = _('Draw') + toolAccelerator = _('d') def __init__(self, gameInstance): Tool.__init__(self, gameInstance) @@ -402,8 +403,8 @@ class MagicPenTool(Tool): class GrabTool(Tool): name = 'Grab' icon = 'grab' - toolTip = _("Grab") - toolAccelerator = _("g") + toolTip = _('Grab') + toolAccelerator = _('g') def __init__(self, gameInstance): Tool.__init__(self, gameInstance) @@ -411,7 +412,7 @@ class GrabTool(Tool): def handleToolEvent(self, event): Tool.handleToolEvent(self, event) - # We handle two types of "grab" depending on simulation running or not + # We handle two types of 'grab' depending on simulation running or not if event.type == MOUSEBUTTONDOWN: if event.button == 1: # Grab the first object at the mouse pointer @@ -452,8 +453,8 @@ class GrabTool(Tool): class JointTool(Tool): name = 'Joint' icon = 'joint' - toolTip = _("Joint") - toolAccelerator = "j" + toolTip = _('Joint') + toolAccelerator = 'j' def __init__(self, gameInstance): Tool.__init__(self, gameInstance) @@ -500,8 +501,8 @@ class JointTool(Tool): class PinTool(Tool): name = 'Pin' icon = 'pin' - toolTip = _("Pin") - toolAccelerator = _("o") + toolTip = _('Pin') + toolAccelerator = _('o') def __init__(self, gameInstance): Tool.__init__(self, gameInstance) @@ -525,8 +526,8 @@ class PinTool(Tool): class MotorTool(Tool): name = 'Motor' icon = 'motor' - toolTip = _("Motor") - toolAccelerator = _("m") + toolTip = _('Motor') + toolAccelerator = _('m') def __init__(self, gameInstance): Tool.__init__(self, gameInstance) @@ -551,8 +552,8 @@ class MotorTool(Tool): class RollTool(Tool): name = 'Roll' icon = 'roll' - toolTip = _("Roll") - toolAccelerator = _("r") + toolTip = _('Roll') + toolAccelerator = _('r') def __init__(self, gameInstance): Tool.__init__(self, gameInstance) @@ -564,7 +565,7 @@ class RollTool(Tool): if event.button == 1: self.jb1pos = tuple_to_int(event.pos) self.jb1 = self.game.world.get_bodies_at_pos(self.jb1pos) - if self.jb1 and type(self.jb1[0].userData) == type({}): + if self.jb1 and isinstance(self.jb1[0].userData, dict): self.jb1[0].userData['rollMotor'] = {} self.jb1[0].userData['rollMotor']['targetVelocity'] = -10 self.jb1[0].userData['rollMotor']['strength'] = 40 @@ -578,8 +579,8 @@ class RollTool(Tool): class DestroyTool(Tool): name = 'Destroy' icon = 'destroy' - toolTip = _("Erase") - toolAccelerator = _("e") + toolTip = _('Erase') + toolAccelerator = _('e') def __init__(self, gameInstance): Tool.__init__(self, gameInstance) @@ -601,8 +602,9 @@ class DestroyTool(Tool): destroyed_body = False for key, info in tracklist: trackdex = info[4] - if trackdex in tokill[0].userData['track_indices'] and \ - info[3] is False: + if 'track_indices' in tokill[0].userData and \ + trackdex in tokill[0].userData['track_indices'] and \ + info[3] is False: self.game.world.world.DestroyBody(info[1]) self.game.trackinfo[key][3] = True destroyed_body = True @@ -632,7 +634,7 @@ class DestroyTool(Tool): class EraseAllTool(Tool): name = 'Erase All' icon = 'destroy-all' - toolTip = _("Erase all") + toolTip = _('Erase all') def __init__(self, gameInstance, activity=None): super(EraseAllTool, self).__init__(gameInstance) @@ -645,8 +647,8 @@ class EraseAllTool(Tool): if not action: # 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.title = _('Delete all shapes?') + alert.props.msg = _('This cannot be undone!') alert.connect('response', self.alert_info, event) self.activity.add_alert(alert) return @@ -682,7 +684,7 @@ class TrackTool(Tool): name = 'Track' icon = 'track' toolTip = _('Track Object') - toolAccelerator = _("r") + toolAccelerator = _('r') def __init__(self, game): Tool.__init__(self, game) @@ -703,7 +705,7 @@ class TrackTool(Tool): restitution=0.16, friction=0.1) trackdex = self.game.tracked_bodies track_circle.userData['track_index'] = trackdex - dictkey = "pen{0}".format(trackdex) + dictkey = 'pen{0}'.format(trackdex) self.game.world.add.joint( track_circle, current_body, point_pos, point_pos, False) -- cgit v0.9.1