From cbf23a55067bbe8864cca33873b1fbf30aa6cbce Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sat, 21 Jul 2012 12:57:48 +0000 Subject: Update labels on named boxes when running in debug mode --- (limited to 'TurtleArt') diff --git a/TurtleArt/tabasics.py b/TurtleArt/tabasics.py index 84363c4..59d482b 100644 --- a/TurtleArt/tabasics.py +++ b/TurtleArt/tabasics.py @@ -927,6 +927,7 @@ variable')) prim_name='box', default=_('my box'), logo_command='box', + value_block=True, help_string=_('named variable (numeric value)')) self.tw.lc.def_prim('box', 1, lambda self, x: primitive_dictionary['box'](x)) @@ -1087,10 +1088,11 @@ variable')) if int(float(x)) == x: x = int(x) self.tw.lc.boxes[name + str(x)] = val + self.tw.lc.update_label_value('box', val, label=x) return - - self.tw.lc.boxes[name] = val - self.tw.lc.update_label_value(name, val) + else: + self.tw.lc.boxes[name] = val + self.tw.lc.update_label_value(name, val) def _prim_stack(self, x): """ Process a named stack """ diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py index 932085e..dd19d68 100644 --- a/TurtleArt/tablock.py +++ b/TurtleArt/tablock.py @@ -244,7 +244,7 @@ class Block: return False if self.name in block_styles['box-style']: return False - if self.name in ['sandwichtop', 'sandwichtop_no_label']: + if self.name in ['box', 'sandwichtop', 'sandwichtop_no_label']: return False return True diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py index 25bf44c..143f584 100644 --- a/TurtleArt/talogo.py +++ b/TurtleArt/talogo.py @@ -608,8 +608,9 @@ class LogoCode: self.value_blocks_to_update[name] = \ self.tw.block_list.get_similar_blocks('block', name) - def update_label_value(self, name, value=None): + def update_label_value(self, name, value=None, label=None): """ Update the label of value blocks to reflect current value """ + # If it is a named box, we need to match the label to the box if not self.tw.interactive_mode: return if self.tw.hide: @@ -618,7 +619,16 @@ class LogoCode: if value is None: for block in self.value_blocks_to_update[name]: block.spr.set_label(block_names[name][0]) - block.resize() + if name == 'box': + argblk = block.connections[-2] + dx = block.dx + block.resize() + if argblk is not None: + # Move connections over... + dx = (block.dx - dx) * self.tw.block_scale + argblk.spr.move_relative((dx, 0)) + else: + block.resize() elif self.update_values: if type(value) == float: valstring = str(round_int(value)).replace('.', @@ -626,8 +636,21 @@ class LogoCode: else: valstring = str(value) for block in self.value_blocks_to_update[name]: - block.spr.set_label(block_names[name][0] + ' = ' + valstring) - block.resize() + if label is None: + block.spr.set_label( + block_names[name][0] + ' = ' + valstring) + block.resize() + else: + argblk = block.connections[-2] + # Only update if label matches + if argblk is not None and argblk.spr.labels[0] == label: + block.spr.set_label( + block_names[name][0] + ' = ' + valstring) + dx = block.dx + block.resize() + # Move connections over... + dx = (block.dx - dx) * self.tw.block_scale + argblk.spr.move_relative((dx, 0)) def push_file_data_to_heap(self, dsobject): """ push contents of a data store object (assuming json encoding) """ -- cgit v0.9.1