From 1263d238bba635f0a5900f2f69933d3bf8b27c51 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Wed, 20 Oct 2010 00:53:23 +0000 Subject: show box values on box label --- diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py index 865e8e9..5f61b5e 100644 --- a/TurtleArt/tablock.py +++ b/TurtleArt/tablock.py @@ -119,6 +119,13 @@ class Blocks: return block return None + def get_all_blocks_of_same_type_and_name(self, type, name): + block_list = [] + for block in self.list: + if block.type == type and block.name == name: + block_list.append(block) + return block_list + class Block: """ A class for the individual blocks """ diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py index 0d467ac..cbd839b 100644 --- a/TurtleArt/talogo.py +++ b/TurtleArt/talogo.py @@ -34,7 +34,7 @@ except: pass from taconstants import PALETTES, PALETTE_NAMES, TAB_LAYER, BLACK, WHITE, \ - DEFAULT_SCALE, ICON_SIZE + DEFAULT_SCALE, ICON_SIZE, BLOCK_NAMES from tagplay import play_audio, play_movie_from_file, stop_media from tajail import myfunc, myfunc_import from tautils import get_pixbuf_from_journal, movie_media_type, convert, \ @@ -270,6 +270,24 @@ def millis(): return int(clock() * 1000) +def update_label_value(tw, name, value=None): + """ Update the label of value blocks to reflect current value """ + if tw.hide or not tw.interactive_mode: + return + list = tw.block_list.get_all_blocks_of_same_type_and_name( + 'block', name) + if value is None: + for block in list: + block.spr.set_label(BLOCK_NAMES[name][0]) + else: + if type(value) == float: + valstring = str(round_int(value)).replace('.', tw.decimal_point) + else: + valstring = str(value) + for block in list: + block.spr.set_label(BLOCK_NAMES[name][0] + ' = ' + valstring) + + class LogoCode: """ A class for parsing Logo code """ @@ -822,6 +840,8 @@ class LogoCode: self.tw.set_polar(False) self.tw.set_cartesian(False) self.hidden_turtle = None + for name in ['box1', 'box2']: + update_label_value(self.tw, name) def prim_start(self): """ Start block: recenter """ @@ -1057,13 +1077,15 @@ class LogoCode: def prim_setbox(self, name, x, val): """ Define value of named box """ - if x is None: - self.boxes[name] = val - else: + if x is not None: if type(convert(x, float, False)) == float: if int(float(x)) == x: x = int(x) self.boxes[name + str(x)] = val + return + + self.boxes[name] = val + update_label_value(self.tw, name, val) def prim_push(self, val): """ Push value onto FILO """ -- cgit v0.9.1