From fbaaf7bd31a8fb5194afb5f42f76470fe3b684f4 Mon Sep 17 00:00:00 2001 From: Marion Date: Wed, 21 Aug 2013 15:44:34 +0000 Subject: use the global_objects dict to set the first argument of Primitives --- diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py index 5c44d63..48972ae 100644 --- a/TurtleArt/taprimitive.py +++ b/TurtleArt/taprimitive.py @@ -28,7 +28,7 @@ from taconstants import (Color, CONSTANTS) from talogo import LogoCode from taturtle import (Turtle, Turtles) from tautils import debug_output -from tawindow import TurtleArtWindow +from tawindow import (global_objects, TurtleArtWindow) class PyExportError(BaseException): @@ -264,20 +264,23 @@ class Primitive(object): on what this primitive wants as its first arg). This argument is also exempt from the slot wrappers. """ - # replace or remove the first argument if it is a LogoCode instance - first_arg = None + # remove the first argument if it is a LogoCode instance if runtime_args and isinstance(runtime_args[0], LogoCode): - (lc, runtime_args) = (runtime_args[0], runtime_args[1:]) - if self.wants_turtle(): - first_arg = lc.tw.turtles.get_active_turtle() - elif self.wants_turtles(): - first_arg = lc.tw.turtles - elif self.wants_canvas(): - first_arg = lc.tw.canvas - elif self.wants_logocode(): - first_arg = lc - elif self.wants_tawindow(): - first_arg = lc.tw + runtime_args = runtime_args[1:] + + # what does this primitive want as its first argument? + if self.wants_turtle(): + first_arg = global_objects["turtles"].get_active_turtle() + elif self.wants_turtles(): + first_arg = global_objects["turtles"] + elif self.wants_canvas(): + first_arg = global_objects["canvas"] + elif self.wants_logocode(): + first_arg = global_objects["logo"] + elif self.wants_tawindow(): + first_arg = global_objects["window"] + else: + first_arg = None # constant arguments (all_args, all_kwargs) = self._add_constant_args(runtime_args, -- cgit v0.9.1