From d0b3ef4fe54c58efae577f96fc3c799a649fec2b Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Fri, 01 Nov 2013 00:11:13 +0000 Subject: need a way to get global_objects --- diff --git a/TurtleArt/taexportpython.py b/TurtleArt/taexportpython.py index 99084f0..49bde06 100644 --- a/TurtleArt/taexportpython.py +++ b/TurtleArt/taexportpython.py @@ -66,6 +66,7 @@ def %s(): """ _START_STACK_START_ADD = """\ tw.start_plugins() + global_objects = tw.get_global_objects() """ _ACTION_STACK_PREAMBLE = """\ turtles = tw.turtles @@ -98,22 +99,23 @@ def save_python(tw): for block in tops_of_stacks: stack_name = get_stack_name(block) if stack_name: - pythoncode = _action_stack_to_python(block, tw.lc, name=stack_name) + pythoncode = _action_stack_to_python(block, tw, name=stack_name) snippets.append(pythoncode) snippets.append(linesep) snippets.append(_SETUP_CODE_END) return "".join(snippets) -def _action_stack_to_python(block, lc, name="start"): +def _action_stack_to_python(block, tw, name="start"): """ Turn a stack of blocks into Python code name -- the name of the action stack (defaults to "start") """ + if isinstance(name, int): name = float(name) if not isinstance(name, basestring): name = str(name) # traverse the block stack and get the AST for every block - ast_list = _walk_action_stack(block, lc) + ast_list = _walk_action_stack(block, tw.lc) if not isinstance(ast_list[-1], ast.Yield): ast_list.append(ast_yield_true()) action_stack_ast = ast.Module(body=ast_list) diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py index f842f93..3f922b4 100644 --- a/TurtleArt/taprimitive.py +++ b/TurtleArt/taprimitive.py @@ -33,7 +33,7 @@ from talogo import (LogoCode, logoerror, NegativeRootError) from taturtle import (Turtle, Turtles) from tatype import * from tautils import debug_output -from tawindow import (global_objects, TurtleArtWindow) +from tawindow import TurtleArtWindow, global_objects from util import ast_extensions diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py index c3e6336..448dbf3 100644 --- a/TurtleArt/tawindow.py +++ b/TurtleArt/tawindow.py @@ -96,7 +96,8 @@ _UNFULLSCREEN_VISIBILITY_TIMEOUT = 2 _PLUGIN_SUBPATH = 'plugins' _MACROS_SUBPATH = 'macros' -global_objects = {} # the global instances of single-instance classes +# the global instances of single-instance classes +global_objects = {} class TurtleArtWindow(): @@ -315,6 +316,9 @@ class TurtleArtWindow(): self._init_plugins() self._setup_plugins() + def get_global_objects(self): + return global_objects + def _lazy_init(self): self._init_plugins() self._setup_plugins() -- cgit v0.9.1