Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarion <marion.zepf@gmail.com>2013-09-06 10:01:10 (GMT)
committer Marion <marion.zepf@gmail.com>2013-09-06 10:01:10 (GMT)
commit440b2fd29dd1bce06678e9f2d774ee5e443cad96 (patch)
treeca6c31df57f6ffbf7d90ed95ff5a80f0f0e4c3bf
parent20e59359edae3d88b65c08523607050401e38693 (diff)
add Primitive and special export handling for the 'wait' block
-rw-r--r--TurtleArt/tabasics.py16
-rw-r--r--TurtleArt/taexportpython.py1
-rw-r--r--TurtleArt/talogo.py11
-rw-r--r--TurtleArt/taprimitive.py5
4 files changed, 20 insertions, 13 deletions
diff --git a/TurtleArt/tabasics.py b/TurtleArt/tabasics.py
index 2943100..df17cfa 100644
--- a/TurtleArt/tabasics.py
+++ b/TurtleArt/tabasics.py
@@ -828,7 +828,6 @@ operators'))
colors=["#FFC000", "#A08000"],
help_string=_('Palette of flow operators'))
- primitive_dictionary['wait'] = self._prim_wait
palette.add_block('wait',
style='basic-style-1arg',
label=_('wait'),
@@ -837,7 +836,9 @@ operators'))
logo_command='wait',
help_string=_('pauses program execution a specified \
number of seconds'))
- self.tw.lc.def_prim('wait', 1, primitive_dictionary['wait'], True)
+ self.tw.lc.def_prim('wait', 1,
+ Primitive(self.tw.lc.prim_wait, arg_descs=[ArgSlot(TYPE_NUMBER)]),
+ True)
primitive_dictionary['forever'] = self._prim_forever
palette.add_block('forever',
@@ -1277,17 +1278,6 @@ variable'))
self.tw.lc.ireturn()
yield True
- def _prim_wait(self, wait_time):
- ''' Show the turtle while we wait '''
- self.tw.turtles.get_active_turtle().show()
- endtime = _millisecond() + wait_time * 1000.
- while _millisecond() < endtime:
- sleep(wait_time / 10.)
- yield True
- self.tw.turtles.get_active_turtle().hide()
- self.tw.lc.ireturn()
- yield True
-
# Math primitives
def _prim_careful_divide(self, x, y):
diff --git a/TurtleArt/taexportpython.py b/TurtleArt/taexportpython.py
index 0d1e27a..db00add 100644
--- a/TurtleArt/taexportpython.py
+++ b/TurtleArt/taexportpython.py
@@ -41,6 +41,7 @@ _SETUP_CODE_START = """\
from math import sqrt
from random import uniform
+from time import sleep
from pyexported.window_setup import *
diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py
index 13d40bc..f1d5b91 100644
--- a/TurtleArt/talogo.py
+++ b/TurtleArt/talogo.py
@@ -702,6 +702,17 @@ class LogoCode:
""" Stop execution of a stack """
self.procstop = True
+ def prim_wait(self, wait_time):
+ """ Show the turtle while we wait """
+ self.tw.turtles.get_active_turtle().show()
+ endtime = _millisecond() + wait_time * 1000.
+ while _millisecond() < endtime:
+ sleep(wait_time / 10.)
+ yield True
+ self.tw.turtles.get_active_turtle().hide()
+ self.ireturn()
+ yield True
+
def prim_if(self, boolean, blklist):
""" If bool, do list """
if boolean:
diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py
index 47317b1..dc06ef3 100644
--- a/TurtleArt/taprimitive.py
+++ b/TurtleArt/taprimitive.py
@@ -388,9 +388,14 @@ class Primitive(object):
call_ast = get_call_ast('logo.icall', [stack_func])
return [call_ast, ast_yield_true()]
+ # stop stack
elif self == LogoCode.prim_stop_stack:
return ast.Return()
+ # sleep/ wait
+ elif self == LogoCode.prim_wait:
+ return get_call_ast('sleep', new_arg_asts)
+
# standard operators
elif self.func.__name__ in Primitive.STANDARD_OPERATORS:
op = Primitive.STANDARD_OPERATORS[self.func.__name__]