diff options
author | Marion <marion.zepf@gmail.com> | 2013-09-09 23:05:44 (GMT) |
---|---|---|
committer | Marion <marion.zepf@gmail.com> | 2013-09-09 23:05:44 (GMT) |
commit | 3d3238126b293f2354b97d7d331fc502b70f198e (patch) | |
tree | e2b04d1b7065796d3d8ca74b2aafd9019be4868d | |
parent | 023c384f5cb05d172920e23aaa2bf7820186e5e1 (diff) |
add Primitive for the 'time' block
-rw-r--r-- | TurtleArt/taexportpython.py | 3 | ||||
-rw-r--r-- | TurtleArt/talogo.py | 3 | ||||
-rw-r--r-- | plugins/turtle_blocks_extras/turtle_blocks_extras.py | 17 |
3 files changed, 20 insertions, 3 deletions
diff --git a/TurtleArt/taexportpython.py b/TurtleArt/taexportpython.py index d41ec98..19cf48e 100644 --- a/TurtleArt/taexportpython.py +++ b/TurtleArt/taexportpython.py @@ -41,7 +41,7 @@ _SETUP_CODE_START = """\ from math import sqrt from random import uniform -from time import sleep +from time import (sleep, time) from pyexported.window_setup import * @@ -59,6 +59,7 @@ _SETUP_CODE_END = """\ if __name__ == '__main__': + tw.lc.start_time = time() tw.lc.icall(start) gobject.idle_add(tw.lc.doevalstep) gtk.main() diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py index ed40555..20a374d 100644 --- a/TurtleArt/talogo.py +++ b/TurtleArt/talogo.py @@ -680,6 +680,9 @@ class LogoCode: def reset_timer(self): self.start_time = time() + def get_start_time(self): + return self.start_time + def reset_internals(self): self.hidden_turtle = None if self.tw.running_turtleart: diff --git a/plugins/turtle_blocks_extras/turtle_blocks_extras.py b/plugins/turtle_blocks_extras/turtle_blocks_extras.py index f9c6b11..c75cbbd 100644 --- a/plugins/turtle_blocks_extras/turtle_blocks_extras.py +++ b/plugins/turtle_blocks_extras/turtle_blocks_extras.py @@ -441,7 +441,6 @@ to the stack')) self.tw.lc.def_prim('see', 0, lambda self: primitive_dictionary['see']()) - primitive_dictionary['time'] = self._prim_time palette.add_block('time', style='box-style', label=_('time'), @@ -450,7 +449,15 @@ to the stack')) help_string=_('elapsed time (in seconds) since \ program started')) self.tw.lc.def_prim('time', 0, - lambda self: primitive_dictionary['time']()) + Primitive(Primitive.identity, + return_type=TYPE_INT, + arg_descs=[ + ConstantArg(Primitive(int, arg_descs=[ + ConstantArg(Primitive(Primitive.minus, arg_descs=[ + ConstantArg(Primitive(time)), + ConstantArg(Primitive(self.tw.lc.get_start_time)) + ]))]))], + call_afterwards=self.after_time)) def _extras_palette(self): palette = make_palette('extras', @@ -1393,6 +1400,12 @@ Journal objects')) self.tw.lc.update_label_value('time', elapsed_time) return elapsed_time + def after_time(self, elapsed_time): + """ Update the label of the 'time' block after computing the new + value. """ + if self.tw.lc.update_values: + self.tw.lc.update_label_value('time', elapsed_time) + def _prim_hideblocks(self): """ hide blocks and show showblocks button """ self.tw.hideblocks() |