diff options
author | Marion <marion.zepf@gmail.com> | 2013-07-18 09:16:01 (GMT) |
---|---|---|
committer | Marion <marion.zepf@gmail.com> | 2013-07-18 09:16:01 (GMT) |
commit | ccf1695b3ebb4c13ac4756e1f454d72b34df9aff (patch) | |
tree | dca6e7a0b3f630e4c9beae009c3d69c7bfc87107 /TurtleArt/taexportpython.py | |
parent | f08f71ea8efb9eb7de31fd3a84ac3d550ce39974 (diff) |
add menu item to GNOME version for exporting python code
Diffstat (limited to 'TurtleArt/taexportpython.py')
-rw-r--r-- | TurtleArt/taexportpython.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/TurtleArt/taexportpython.py b/TurtleArt/taexportpython.py index ac04512..85889bb 100644 --- a/TurtleArt/taexportpython.py +++ b/TurtleArt/taexportpython.py @@ -23,6 +23,8 @@ import re from os import linesep +from tautils import find_top_block + _SETUP_CODE_START = """\ @@ -64,6 +66,19 @@ PAT_IDENTIFIER_ILLEGAL_CHAR = re.compile("[^A-Za-z0-9_]") +def save_python(tw): + """ Find all the action stacks and turn each into python code """ + stacks_of_blocks = tw.just_blocks() + pythoncode = "" + for stack in stacks_of_blocks: + # TODO name of action stack? + top = find_top_block(stack) + if stack != top: + continue + pythoncode += action_stack_to_python(stack) + pythoncode += linesep + return pythoncode + def action_stack_to_python(blklist, name="start"): """ Turn a stack of blocks into python code name -- the name of the action stack (defaults to "start") """ |