Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPootle daemon <pootle@pootle.sugarlabs.org>2013-11-09 05:30:38 (GMT)
committer Pootle daemon <pootle@pootle.sugarlabs.org>2013-11-09 05:30:38 (GMT)
commitd1baec9324c4663abb5dc396da338ea35426a740 (patch)
treedaecec5fbaf3512f42312fbc5852f7ff31674b41
parentd0bd918104e7f4c916906609d3c850bb2821d6cf (diff)
parent08340db0f3dbcbd1d2fb796f3c2166af0c53e198 (diff)
Merge branch 'master' of git.sugarlabs.org:turtleart/mainline
-rw-r--r--NEWS2
-rw-r--r--TurtleArt/taexportpython.py28
-rw-r--r--TurtleArt/talogo.py5
-rw-r--r--TurtleArt/taprimitive.py6
-rw-r--r--TurtleArt/taturtle.py35
-rw-r--r--TurtleArtActivity.py6
-rw-r--r--plugins/audio_sensors/audio_sensors.py6
-rw-r--r--plugins/turtle_blocks_extras/turtle_blocks_extras.py2
-rw-r--r--samples/card-18.tb (renamed from samples/graphics-bumps.tb)0
-rw-r--r--samples/thumbnails/card-18.png (renamed from samples/thumbnails/graphics-bumps.png)bin15893 -> 15893 bytes
-rwxr-xr-xturtleblocks.py4
-rw-r--r--util/ast_extensions.py17
-rw-r--r--util/codegen.py6
13 files changed, 49 insertions, 68 deletions
diff --git a/NEWS b/NEWS
index 7dc9ee9..85daa56 100644
--- a/NEWS
+++ b/NEWS
@@ -3,7 +3,9 @@
ENHANCEMENTS:
* Merged Marian Zepf's export Python branch (This is really fun. Give it a try.)
* Added busy cursor while project is loading from store
+* Added tabbing through palette proto-blocks
* New sample program from Cynthia Solomon
+* Logging errors in project metadata for making learning visible
* New translations
BUG FIX:
diff --git a/TurtleArt/taexportpython.py b/TurtleArt/taexportpython.py
index c3c8e84..1ed1ac5 100644
--- a/TurtleArt/taexportpython.py
+++ b/TurtleArt/taexportpython.py
@@ -123,13 +123,6 @@ def _action_stack_to_python(block, tw, name="start"):
# serialize the ASTs into python code
generated_code = codegen.to_source(action_stack_ast)
- # FIXME: there must be a better way to do this using the AST
- # patch code to include missing get_active_turtle() calls
- if generated_code.count('turtles.set_turtle') > 0:
- generated_code = _insert_extra_code(
- generated_code, 'turtles.set_turtle',
- 'turtle = turtles.get_active_turtle()\n')
-
# wrap the action stack setup code around everything
name_id = _make_identifier(name)
if name == 'start':
@@ -152,27 +145,6 @@ def _action_stack_to_python(block, tw, name="start"):
return "".join(snippets)
-def _insert_extra_code(generated_code, target, insert):
- """ Add extra code when needed """
- tmp_code = ''
- while target in generated_code:
- i = generated_code.index(target)
- if i == 0:
- indent = 0
- else:
- indent = 0
- while generated_code[i - 1 - indent] == ' ':
- indent += 1
- while generated_code[i] != '\n':
- i += 1
- i += 1 # include the newline
- tmp_code += generated_code[0:i]
- for j in range(indent):
- tmp_code += ' '
- tmp_code += insert
- generated_code = generated_code[i:]
- return tmp_code + generated_code
-
def _walk_action_stack(top_block, lc, convert_me=True):
""" Turn a stack of blocks into a list of ASTs
convert_me -- convert values and Primitives to ASTs or return them
diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py
index f4511df..775af0f 100644
--- a/TurtleArt/talogo.py
+++ b/TurtleArt/talogo.py
@@ -735,6 +735,9 @@ class LogoCode:
""" Stop execution of a stack """
self.procstop = True
+ def prim_turtle(self, name):
+ self.tw.turtles.set_turtle(name)
+
def prim_wait(self, wait_time):
""" Show the turtle while we wait """
self.tw.turtles.get_active_turtle().show()
@@ -1357,7 +1360,7 @@ class LogoCode:
first_label_blk = HiddenBlock('string', value=action_flow_name)
# Assign new connections and build the docks
- if inflow is not None:
+ if inflow is not None and b in inflow.connections:
i = inflow.connections.index(b)
if until_blk and whileflow is not None:
inflow.connections[i] = action_first
diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py
index 7f9d76c..b689de5 100644
--- a/TurtleArt/taprimitive.py
+++ b/TurtleArt/taprimitive.py
@@ -488,6 +488,12 @@ class Primitive(object):
ast_list.append(new_ast)
return ast_list
+ # set turtle
+ elif self == LogoCode.prim_turtle:
+ text = 'turtle = turtles.get_active_turtle()'
+ return [get_call_ast('logo.prim_turtle', new_arg_asts),
+ ast_extensions.ExtraCode(text)]
+
# comment
elif self == Primitive.comment:
if isinstance(new_arg_asts[0], ast.Str):
diff --git a/TurtleArt/taturtle.py b/TurtleArt/taturtle.py
index beed99d..c35125b 100644
--- a/TurtleArt/taturtle.py
+++ b/TurtleArt/taturtle.py
@@ -347,12 +347,7 @@ class Turtle:
def set_heading(self, heading, share=True):
''' Set the turtle heading (one shape per 360/SHAPES degrees) '''
- try:
- self._heading = heading
- except (TypeError, ValueError):
- debug_output('bad value sent to %s' % (__name__),
- self._turtles.turtle_window.running_sugar)
- return
+ self._heading = heading
self._heading %= 360
self._update_sprite_heading()
@@ -384,12 +379,7 @@ class Turtle:
else:
color = self._pen_color
- try:
- self._pen_color = color
- except (TypeError, ValueError):
- debug_output('bad value sent to %s' % (__name__),
- self._turtles.turtle_window.running_sugar)
- return
+ self._pen_color = color
self._turtles.turtle_window.canvas.set_fgcolor(shade=self._pen_shade,
gray=self._pen_gray,
@@ -403,12 +393,7 @@ class Turtle:
def set_gray(self, gray=None, share=True):
''' Set the pen gray level for this turtle. '''
if gray is not None:
- try:
- self._pen_gray = gray
- except (TypeError, ValueError):
- debug_output('bad value sent to %s' % (__name__),
- self._turtles.turtle_window.running_sugar)
- return
+ self._pen_gray = gray
if self._pen_gray < 0:
self._pen_gray = 0
@@ -427,12 +412,7 @@ class Turtle:
def set_shade(self, shade=None, share=True):
''' Set the pen shade for this turtle. '''
if shade is not None:
- try:
- self._pen_shade = shade
- except (TypeError, ValueError):
- debug_output('bad value sent to %s' % (__name__),
- self._turtles.turtle_window.running_sugar)
- return
+ self._pen_shade = shade
self._turtles.turtle_window.canvas.set_fgcolor(shade=self._pen_shade,
gray=self._pen_gray,
@@ -446,12 +426,7 @@ class Turtle:
def set_pen_size(self, pen_size=None, share=True):
''' Set the pen size for this turtle. '''
if pen_size is not None:
- try:
- self._pen_size = max(0, pen_size)
- except (TypeError, ValueError):
- debug_output('bad value sent to %s' % (__name__),
- self._turtles.turtle_window.running_sugar)
- return
+ self._pen_size = max(0, pen_size)
self._turtles.turtle_window.canvas.set_pen_size(
self._pen_size * self._turtles.turtle_window.coord_scale)
diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py
index 14bebed..d103b15 100644
--- a/TurtleArtActivity.py
+++ b/TurtleArtActivity.py
@@ -1273,10 +1273,10 @@ class TurtleArtActivity(activity.Activity):
self.metadata['public'] = data_to_string(['activity count',
'turtle blocks'])
if len(self.error_list) > 0:
+ errors = []
if 'error_list' in self.metadata:
- errors = data_from_string(self.metadata['error_list'])
- else:
- errors = []
+ for error in data_from_string(self.metadata['error_list']):
+ errors.append(error)
for error in self.error_list:
errors.append(error)
self.metadata['error_list'] = data_to_string(errors)
diff --git a/plugins/audio_sensors/audio_sensors.py b/plugins/audio_sensors/audio_sensors.py
index f520330..eec73bb 100644
--- a/plugins/audio_sensors/audio_sensors.py
+++ b/plugins/audio_sensors/audio_sensors.py
@@ -331,9 +331,9 @@ class Audio_sensors(Plugin):
def prim_sound(self, channel=0):
if not self._status:
return 0
+ self._prim_sound(0)
# Return average of both channels if sampling in stereo
if self._channels == 2:
- self._prim_sound(0)
self._prim_sound(1)
return (self._sound[0] + self._sound[1]) / 2.0
else:
@@ -354,9 +354,9 @@ class Audio_sensors(Plugin):
def prim_volume(self, channel=0):
if not self._status:
return 0
+ self._prim_volume(0)
# Return average of both channels if sampling in stereo
if self._channels == 2:
- self._prim_volume(0)
self._prim_volume(1)
return (self._volume[0] + self._volume[1]) / 2.0
else:
@@ -377,9 +377,9 @@ class Audio_sensors(Plugin):
def prim_pitch(self, channel=0):
if not self._status:
return 0
+ self._prim_pitch(0)
# Return average of both channels if sampling in stereo
if self._channels == 2:
- self._prim_pitch(0)
self._prim_pitch(1)
return (self._pitch[0] + self._pitch[1]) / 2.0
else:
diff --git a/plugins/turtle_blocks_extras/turtle_blocks_extras.py b/plugins/turtle_blocks_extras/turtle_blocks_extras.py
index 8d5ab91..e6f2989 100644
--- a/plugins/turtle_blocks_extras/turtle_blocks_extras.py
+++ b/plugins/turtle_blocks_extras/turtle_blocks_extras.py
@@ -787,7 +787,7 @@ module found in the Journal'))
string_or_number=True,
help_string=_('chooses which turtle to command'))
self.tw.lc.def_prim('addturtle', 1,
- Primitive(self.tw.turtles.set_turtle,
+ Primitive(self.tw.lc.prim_turtle,
arg_descs=[ArgSlot(TYPE_STRING)]))
palette.add_block('turtlex',
diff --git a/samples/graphics-bumps.tb b/samples/card-18.tb
index 951a3fb..951a3fb 100644
--- a/samples/graphics-bumps.tb
+++ b/samples/card-18.tb
diff --git a/samples/thumbnails/graphics-bumps.png b/samples/thumbnails/card-18.png
index 9d32c25..9d32c25 100644
--- a/samples/thumbnails/graphics-bumps.png
+++ b/samples/thumbnails/card-18.png
Binary files differ
diff --git a/turtleblocks.py b/turtleblocks.py
index df25eea..604d609 100755
--- a/turtleblocks.py
+++ b/turtleblocks.py
@@ -551,6 +551,7 @@ Would you like to save before quitting?'))
if len(logocode) == 0:
return
save_type = '.lg'
+ self.tw.load_save_folder = self._get_execution_dir()
filename, self.tw.load_save_folder = get_save_name(
save_type, self.tw.load_save_folder, 'logosession')
if isinstance(filename, unicode):
@@ -580,7 +581,8 @@ Would you like to save before quitting?'))
elif default_name.endswith(".ta") or default_name.endswith(".tb"):
default_name = default_name[:-3]
save_type = '.py'
- (filename, self.tw.load_save_folder) = get_save_name(
+ self.tw.load_save_folder = self._get_execution_dir()
+ filename, self.tw.load_save_folder = get_save_name(
save_type, self.tw.load_save_folder, default_name)
if isinstance(filename, unicode):
filename = filename.encode('utf-8')
diff --git a/util/ast_extensions.py b/util/ast_extensions.py
index 3335afb..d46bdb0 100644
--- a/util/ast_extensions.py
+++ b/util/ast_extensions.py
@@ -24,6 +24,23 @@
import ast
+class ExtraCode(ast.stmt):
+ """Adds extra content to a primitive needed in Python code, e.g.,
+ changes to the turtle (e.g., prim_turtle) require the addition of
+ turtle = turtles.get_active_turtle()
+ Extends the Python abstract grammar by the following: stmt
+ = ExtraContent(string text) | ... """
+
+ _fields = ('text')
+
+ def __init__(self, text="", lineno=1, col_offset=0):
+ """ text -- the textual content of the comment, i.e. everything
+ directly following the hashtag until the next newline """
+ self.text = text
+ self.lineno = lineno
+ self.col_offset = col_offset
+
+
class Comment(ast.stmt):
""" An inline comment, starting with a hashtag (#).
Extends the Python abstract grammar by the following:
diff --git a/util/codegen.py b/util/codegen.py
index 3785085..46184e7 100644
--- a/util/codegen.py
+++ b/util/codegen.py
@@ -35,7 +35,7 @@
Modified by Marion Zepf.
"""
from ast import *
-from ast_extensions import Comment
+from ast_extensions import Comment, ExtraCode
def to_source(node, indent_with=' ' * 4, add_line_information=False):
@@ -362,6 +362,10 @@ class SourceGenerator(NodeVisitor):
self.newline(node)
self.write('#' + str(node.text))
+ def visit_ExtraCode(self, node):
+ self.newline(node)
+ self.write(str(node.text))
+
# Expressions
def visit_Attribute(self, node):