diff options
author | Pootle daemon <pootle@pootle.sugarlabs.org> | 2013-11-01 04:30:35 (GMT) |
---|---|---|
committer | Pootle daemon <pootle@pootle.sugarlabs.org> | 2013-11-01 04:30:35 (GMT) |
commit | 76622c8b3d82bb8ea8833fe4956644294e4b80ba (patch) | |
tree | bf46e7830d749fcd10764ed6005274bea03f82fb /TurtleArt | |
parent | 4ed97f79ceb34d615fb9406ad4e724fe75b17f8f (diff) | |
parent | d0b3ef4fe54c58efae577f96fc3c799a649fec2b (diff) |
Merge branch 'master' of git.sugarlabs.org:turtleart/mainline
Diffstat (limited to 'TurtleArt')
-rw-r--r-- | TurtleArt/taconstants.py | 42 | ||||
-rw-r--r-- | TurtleArt/taexportpython.py | 23 | ||||
-rw-r--r-- | TurtleArt/talogo.py | 11 | ||||
-rw-r--r-- | TurtleArt/taprimitive.py | 25 | ||||
-rw-r--r-- | TurtleArt/tawindow.py | 9 |
5 files changed, 73 insertions, 37 deletions
diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py index 43ae9bc..1cedaa3 100644 --- a/TurtleArt/taconstants.py +++ b/TurtleArt/taconstants.py @@ -344,7 +344,7 @@ MACROS = { [5, ['number', '0.1'], 0, 0, [4, None]], [6, 'kbinput', 0, 0, [4, None]]], 'picturelist': - [[0, 'sandwichtop_no_label', 0, 0, [None, 1]], + [[0, ['sandwichclamp', 252], 0, 0, [None, 1, None]], [1, 'penup', 0, 0, [0, 2]], [2, 'setxy2', 0, 0, [1, 3, 4, 5]], [3, 'titlex', 0, 0, [2, None]], @@ -361,12 +361,11 @@ MACROS = { [14, 'pendown', 0, 0, [11, 15]], [15, 'setscale', 0, 0, [14, 16, 17]], [16, ['number', '67'], 0, 0, [15, None]], - [17, 'list', 0, 0, [15, 18, 19, 20]], + [17, 'list', 0, 0, [15, 18, 19, None]], [18, ['string', '∙ '], 0, 0, [17, None]], - [19, ['string', '∙ '], 0, 0, [17, None]], - [20, 'sandwichbottom', 0, 0, [17, None]]], + [19, ['string', '∙ '], 0, 0, [17, None]]], 'picture1x1a': - [[0, 'sandwichtop_no_label', 0, 0, [None, 1]], + [[0, ['sandwichclamp', 231], 0, 0, [None, 1, None]], [1, 'penup', 0, 0, [0, 2]], [2, 'setxy2', 0, 0, [1, 3, 4, 5]], [3, 'titlex', 0, 0, [2, None]], @@ -383,11 +382,10 @@ MACROS = { [14, 'pendown', 0, 0, [11, 15]], [15, 'setscale', 0, 0, [14, 16, 17]], [16, ['number', '90'], 0, 0, [15, None]], - [17, 'showaligned', 0, 0, [15, 18, 19]], - [18, 'journal', 0, 0, [17, None]], - [19, 'sandwichbottom', 0, 0, [17, None]]], + [17, 'showaligned', 0, 0, [15, 18, None]], + [18, 'journal', 0, 0, [17, None]]], 'picture2x2': - [[0, 'sandwichtop_no_label', 0, 0, [None, 1]], + [[0, ['sandwichclamp', 546], 0, 0, [None, 1, None]], [1, 'penup', 0, 0, [0, 2]], [2, 'setxy2', 0, 0, [1, 3, 4, 5]], [3, 'titlex', 0, 0, [2, None]], @@ -425,11 +423,10 @@ MACROS = { [35, 'rightx', 0, 0, [34, None]], [36, 'bottomy', 0, 0, [34, None]], [37, 'pendown', 0, 0, [34, 38]], - [38, 'showaligned', 0, 0, [37, 39, 40]], - [39, 'journal', 0, 0, [38, None]], - [40, 'sandwichbottom', 0, 0, [38, None]]], + [38, 'showaligned', 0, 0, [37, 39, None]], + [39, 'journal', 0, 0, [38, None]]], 'picture1x2': - [[0, 'sandwichtop_no_label', 0, 0, [None, 1]], + [[0, ['sandwichclamp', 546], 0, 0, [None, 1, None]], [1, 'penup', 0, 0, [0, 2]], [2, 'setxy2', 0, 0, [1, 3, 4, 5]], [3, 'titlex', 0, 0, [2, None]], @@ -467,11 +464,10 @@ MACROS = { [35, 'rightx', 0, 0, [34, None]], [36, 'bottomy', 0, 0, [34, None]], [37, 'pendown', 0, 0, [34, 38]], - [38, 'showaligned', 0, 0, [37, 39, 40]], - [39, 'description', 0, 0, [38, None]], - [40, 'sandwichbottom', 0, 0, [38, None]]], + [38, 'showaligned', 0, 0, [37, 39, None]], + [39, 'description', 0, 0, [38, None]]], 'picture2x1': - [[0, 'sandwichtop_no_label', 0, 0, [None, 1]], + [[0, ['sandwichclamp', 546], 0, 0, [None, 1, None]], [1, 'penup', 0, 0, [0, 2]], [2, 'setxy2', 0, 0, [1, 3, 4, 5]], [3, 'titlex', 0, 0, [2, None]], @@ -509,11 +505,10 @@ MACROS = { [35, 'rightx', 0, 0, [34, None]], [36, 'bottomy', 0, 0, [34, None]], [37, 'pendown', 0, 0, [34, 38]], - [38, 'showaligned', 0, 0, [37, 39, 40]], - [39, 'description', 0, 0, [38, None]], - [40, 'sandwichbottom', 0, 0, [38, None]]], + [38, 'showaligned', 0, 0, [37, 39, None]], + [39, 'description', 0, 0, [38, None]]], 'picture1x1': - [[0, 'sandwichtop_no_label', 0, 0, [None, 1]], + [[0, ['sandwichclamp', 336], 0, 0, [None, 1, None]], [1, 'penup', 0, 0, [0, 2]], [2, 'setxy2', 0, 0, [1, 3, 4, 5]], [3, 'titlex', 0, 0, [2, None]], @@ -537,9 +532,8 @@ MACROS = { [21, 'rightx', 0, 0, [20, None]], [22, 'topy', 0, 0, [20, None]], [23, 'pendown', 0, 0, [20, 24]], - [24, 'showaligned', 0, 0, [23, 25, 26]], - [25, 'description', 0, 0, [24, None]], - [26, 'sandwichbottom', 0, 0, [24, None]]], + [24, 'showaligned', 0, 0, [23, 25, None]], + [25, 'description', 0, 0, [24, None]]], 'reskin': [[0, 'skin', 0, 0, [None, 1, None]], [1, 'journal', 0, 0, [0, None]]]} diff --git a/TurtleArt/taexportpython.py b/TurtleArt/taexportpython.py index 76087ad..49bde06 100644 --- a/TurtleArt/taexportpython.py +++ b/TurtleArt/taexportpython.py @@ -33,7 +33,7 @@ from talogo import LogoCode from taprimitive import (ast_yield_true, Primitive, PyExportError, value_to_ast) from tautils import (debug_output, find_group, find_top_block, get_stack_name) - +from tawindow import global_objects _SETUP_CODE_START = """\ @@ -66,10 +66,11 @@ def %s(): """ _START_STACK_START_ADD = """\ tw.start_plugins() + global_objects = tw.get_global_objects() """ _ACTION_STACK_PREAMBLE = """\ - turtle = tw.turtles.get_active_turtle() turtles = tw.turtles + turtle = turtles.get_active_turtle() canvas = tw.canvas logo = tw.lc @@ -83,7 +84,7 @@ 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 """ + """ Find all the action stacks and turn each into Python code """ all_blocks = tw.just_blocks() blocks_covered = set() tops_of_stacks = [] @@ -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"): - """ Turn a stack of blocks into python code +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) @@ -126,6 +128,11 @@ def _action_stack_to_python(block, lc, name="start"): name_id = _make_identifier(name) if name == 'start': pre_preamble = _START_STACK_START_ADD + # TODO: only add the objects we are using + for k in global_objects.keys(): + if k not in ['window', 'canvas', 'logo', 'turtles']: + pre_preamble += " %s = global_objects['%s']\n" % ( + k.lower(), k) else: pre_preamble = '' generated_code = _indent(generated_code, 1) @@ -255,5 +262,3 @@ def _indent(code, num_levels=1): for line in line_list: new_line_list.append(indentation + line) return linesep.join(new_line_list) - - diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py index 2b297ef..1ee11f2 100644 --- a/TurtleArt/talogo.py +++ b/TurtleArt/talogo.py @@ -1054,6 +1054,17 @@ class LogoCode: gobject.idle_add(self.tw.send_event, event) os.remove(tmp_file) + def showlist(self, objects): + """ Display list of media objects """ + x = (self.tw.turtles.get_active_turtle().get_xy()[0] / + self.tw.coord_scale) + y = (self.tw.turtles.get_active_turtle().get_xy()[1] / + self.tw.coord_scale) + for obj in objects: + self.tw.turtles.get_active_turtle().set_xy(x, y, pendown=False) + self.show(obj) + y -= int(self.tw.canvas.textsize * self.tw.lead) + def show(self, obj, center=False): """ Show is the general-purpose media-rendering block. """ # media diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py index 112540a..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 @@ -138,6 +138,14 @@ class Primitive(object): func_name = "logo.heap." elif self.wants_tawindow(): func_name = "tw." + else: + results, plugin = self.wants_plugin() + if results: + for k in global_objects.keys(): + if k == plugin: + func_name = k.lower() + '.' + break + # get the name of the function directly from the function itself func_name += self.func.__name__ return func_name @@ -290,6 +298,10 @@ class Primitive(object): first_arg = global_objects["logo"].heap elif new_prim.wants_tawindow(): first_arg = global_objects["window"] + else: + result, plugin = new_prim.wants_plugin() + if result: + first_arg = plugin # execute the actual function if first_arg is None: @@ -556,6 +568,14 @@ class Primitive(object): as its first argument? """ return self._wants(TurtleArtWindow) + def wants_plugin(self): + """Does this Primitive want to get a plugin instance as its first + argument? """ + for obj in global_objects.keys(): + if self._wants(global_objects[obj].__class__): + return True, obj + return False, None + def wants_nothing(self): """ Does this Primitive want nothing as its first argument? I.e. does it want to be passed all the arguments of the block and nothing @@ -727,7 +747,8 @@ class Primitive(object): @staticmethod def comment(text): - """ In 'snail' execution mode, display the comment. Else, do nothing. """ + """In 'snail' execution mode, display the comment. Else, do + nothing.""" tw = global_objects["window"] if not tw.hide and tw.step_time != 0: tw.showlabel('print', text) diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py index 5d8f715..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() @@ -388,10 +392,11 @@ class TurtleArtWindow(): # Add the icon dir to the icon_theme search path self._add_plugin_icon_dir(os.path.join(self._get_plugin_home(), plugin_dir)) + # Add the plugin to the list of global objects + global_objects[plugin_class] = self.turtleart_plugins[-1] except Exception as e: debug_output('Failed to load %s: %s' % (plugin_class, str(e)), self.running_sugar) - def _add_plugin_icon_dir(self, dirname): ''' If there is an icon subdir, add it to the search path. ''' |