Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArt/tablock.py
diff options
context:
space:
mode:
Diffstat (limited to 'TurtleArt/tablock.py')
-rw-r--r--TurtleArt/tablock.py37
1 files changed, 36 insertions, 1 deletions
diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py
index 8d8ed4a..be1c718 100644
--- a/TurtleArt/tablock.py
+++ b/TurtleArt/tablock.py
@@ -24,7 +24,8 @@ import cairo
from taconstants import (EXPANDABLE, EXPANDABLE_ARGS, OLD_NAMES, CONSTANTS,
STANDARD_STROKE_WIDTH, BLOCK_SCALE, BOX_COLORS,
- GRADIENT_COLOR, EXPANDABLE_FLOW, COLORDICT)
+ GRADIENT_COLOR, EXPANDABLE_FLOW, COLORDICT,
+ PREFIX_DICTIONARY)
from tapalette import (palette_blocks, block_colors, expandable_blocks,
content_blocks, block_names, block_primitives,
block_styles, special_block_colors)
@@ -34,6 +35,9 @@ import sprites
from tautils import (debug_output, error_output)
+media_blocks_dictionary = {} # new media blocks get added here
+
+
class Blocks:
""" A class for the list of blocks and everything they share in common """
@@ -277,6 +281,37 @@ class Block:
return False
return True
+ def is_value_block(self):
+ """ Return True iff this block is a value block (numeric, string,
+ media, etc.) """
+ return self.primitive is None and self.values
+
+ def get_value(self):
+ """ Return the value stored in this value block """
+ # TODO what error to raise if this is not a value block?
+ if self.name == 'number':
+ try:
+ return float(self.values[0])
+ except ValueError:
+ return float(ord(self.values[0][0]))
+ elif (self.name == 'string' or
+ self.name == 'title'): # deprecated block
+ 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])
+ else:
+ return '#s' + self.values[0]
+ elif self.name in PREFIX_DICTIONARY:
+ if self.values[0] is not None:
+ return PREFIX_DICTIONARY[self.name] + str(self.values[0])
+ else:
+ return PREFIX_DICTIONARY[self.name] + 'None'
+ elif self.name in media_blocks_dictionary:
+ return '#smedia_' + self.name.upper()
+ else:
+ return None
+
def highlight(self):
""" We may want to highlight a block... """
if self.spr is not None and self.status is not 'collapsed':