From 0e78d5d868e85746a641804dade4c757f2122581 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Tue, 15 Feb 2011 21:54:03 +0000 Subject: added elapsed time block --- diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py index 55a9b34..1fd6dfd 100644 --- a/TurtleArt/taconstants.py +++ b/TurtleArt/taconstants.py @@ -136,7 +136,7 @@ PALETTES = [['clean', 'forward', 'back', 'show', 'left', 'right', 'myfunc1arg', 'userdefined', 'cartesian', 'width', 'height', 'polar', 'addturtle', 'reskin', 'sandwichtop_no_label', 'sandwichbottom'], - ['kbinput', 'keyboard', 'readpixel', 'see', + ['kbinput', 'keyboard', 'readpixel', 'see', 'time', 'sound', 'volume', 'pitch'], ['journal', 'audio', 'video', 'description', 'hideblocks', 'showblocks', 'fullscreen', 'savepix', 'savesvg', 'mediawait', @@ -224,7 +224,7 @@ BOX_STYLE = ['number', 'xcor', 'ycor', 'heading', 'pensize', 'color', 'shade', 'red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'purple', 'white', 'black', 'titlex', 'titley', 'leftx', 'topy', 'rightx', 'bottomy', 'sound', 'volume', 'pitch', 'voltage', 'resistance', 'gray', 'see', 'rfid', - 'luminance'] + 'luminance', 'time'] BOX_STYLE_MEDIA = ['description', 'audio', 'journal', 'video', 'camera'] NUMBER_STYLE = ['plus2', 'product2', 'myfunc'] NUMBER_STYLE_VAR_ARG = ['myfunc1arg', 'myfunc2arg', 'myfunc3arg'] @@ -448,6 +448,7 @@ BLOCK_NAMES = { 'template2x2': [' '], 'templatelist': [' '], 'textsize': [_('text size')], + 'time': [_('time')], 'titlex': [_('title x')], 'titley': [_('title y')], 'toppos': [_('top')], @@ -599,6 +600,7 @@ PRIMITIVES = { 'template2x2': 't2x2', 'templatelist': 'bullet', 'textsize': 'textsize', + 'time': 'time', 'titlex': 'titlex', 'titley': 'titley', 'toppos': 'tpos', @@ -932,6 +934,7 @@ HELP_STRINGS = { 'templatelist': _("presentation template: list of bullets"), 'textcolor': _("holds current text color (can be used in place of a number block)"), 'textsize': _("holds current text size (can be used in place of a number block)"), + 'time': _("elapsed time (in seconds) since program started"), 'toppos': _("ycor of top of screen"), 'trash': _("Trashcan"), 'turtle': _("Palette of turtle commands"), diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py index f107323..2821826 100644 --- a/TurtleArt/talogo.py +++ b/TurtleArt/talogo.py @@ -465,6 +465,7 @@ class LogoCode: x, y, z, a, b)], 'textcolor': [0, lambda self: self.tw.canvas.textcolor], 'textsize': [0, lambda self: self.tw.textsize], + 'time': [0, lambda self: self._elapsed_time()], 'titlex': [0, lambda self: CONSTANTS['titlex']], 'titley': [0, lambda self: CONSTANTS['titley']], 'topy': [0, lambda self: CONSTANTS['topy']], @@ -518,6 +519,7 @@ class LogoCode: self.ag = None self.filepath = None self.dsobject = None + self._start_time = None # Scale factors for depreciated portfolio blocks self.title_height = int((self.tw.canvas.height / 20) * self.tw.scale) @@ -595,6 +597,7 @@ class LogoCode: code = self._blocks_to_code(blk) if run_flag: _logger.debug("running code: %s" % (code)) + self._start_time = time() self._setup_cmd(code) if not self.tw.hide: self.tw.display_coordinates() @@ -900,6 +903,7 @@ class LogoCode: self.tw.set_polar(False) self.tw.set_cartesian(False) self.hidden_turtle = None + self._start_time = time() for name in VALUE_BLOCKS: self.update_label_value(name) @@ -1472,6 +1476,11 @@ class LogoCode: play_movie_from_file(self, self.filepath, self._x(), self._y(), self._w(), self._h()) + def _elapsed_time(self): + """ Number of seconds since program execution has started or + clean (prim_clear) block encountered """ + return int(time() - self._start_time) + def see(self): """ Read r, g, b from the canvas and return a corresponding palette color """ -- cgit v0.9.1