From 8913f29678d54cc3cbf6cbcb612712c805dd9f35 Mon Sep 17 00:00:00 2001 From: Marion Date: Sun, 11 Aug 2013 21:56:47 +0000 Subject: avoid adding a type prefix to the value of value blocks when exporting them --- diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py index f44e3dc..4c0f207 100644 --- a/TurtleArt/tablock.py +++ b/TurtleArt/tablock.py @@ -286,9 +286,12 @@ class Block: media, etc.) """ return self.primitive is None and self.values - def get_value(self): - """ Return the value stored in this value block """ + def get_value(self, add_type_prefix=True): + """ Return the value stored in this value block + add_type_prefix -- prepend a prefix to indicate the type of the + 'raw' value """ # TODO what error to raise if this is not a value block? + result = '' if self.name == 'number': try: return float(self.values[0]) @@ -296,21 +299,28 @@ class Block: return float(ord(self.values[0][0])) elif (self.name == 'string' or self.name == 'title'): # deprecated block + if add_type_prefix: + result = '#s' if isinstance(self.values[0], (float, int)): if int(self.values[0]) == self.values[0]: self.values[0] = int(self.values[0]) - return '#s' + str(self.values[0]) + result += str(self.values[0]) else: - return '#s' + self.values[0] + result += self.values[0] elif self.name in PREFIX_DICTIONARY: + if add_type_prefix: + result = PREFIX_DICTIONARY[self.name] if self.values[0] is not None: - return PREFIX_DICTIONARY[self.name] + str(self.values[0]) + result += str(self.values[0]) else: - return PREFIX_DICTIONARY[self.name] + 'None' + result += 'None' elif self.name in media_blocks_dictionary: - return '#smedia_' + self.name.upper() + if add_type_prefix: + result = '#smedia_' + result += self.name.upper() else: return None + return result def highlight(self): """ We may want to highlight a block... """ diff --git a/TurtleArt/taexportpython.py b/TurtleArt/taexportpython.py index 8be59bf..0816d9f 100644 --- a/TurtleArt/taexportpython.py +++ b/TurtleArt/taexportpython.py @@ -128,7 +128,7 @@ def _walk_action_stack(top_block, lc): # value blocks don't have a primitive if block.is_value_block(): - raw_value = block.get_value() + raw_value = block.get_value(add_type_prefix=False) value_ast = value_to_ast(raw_value) if value_ast is not None: return [value_ast] -- cgit v0.9.1