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.py44
1 files changed, 34 insertions, 10 deletions
diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py
index a3f91c2..f258029 100644
--- a/TurtleArt/tablock.py
+++ b/TurtleArt/tablock.py
@@ -25,7 +25,7 @@ import cairo
from taconstants import (EXPANDABLE, EXPANDABLE_ARGS, OLD_NAMES, CONSTANTS,
STANDARD_STROKE_WIDTH, BLOCK_SCALE, BOX_COLORS,
GRADIENT_COLOR, EXPANDABLE_FLOW, Color,
- PREFIX_DICTIONARY)
+ MEDIA_BLOCK2TYPE)
from tapalette import (palette_blocks, block_colors, expandable_blocks,
content_blocks, block_names, block_primitives,
block_styles, special_block_colors)
@@ -37,6 +37,33 @@ from tautils import (debug_output, error_output)
media_blocks_dictionary = {} # new media blocks get added here
+class Media(object):
+ """ Media objects can be images, audio files, videos, Journal
+ descriptions, or camera snapshots. """
+
+ ALL_TYPES = ('media', 'audio', 'video', 'descr', 'camera', 'camera1')
+
+ def __init__(self, type_, value=None):
+ """
+ type_ --- a string that indicates the kind of media:
+ media --- image
+ audio --- audio file
+ video --- video
+ descr --- Journal description
+ camera, camera1 --- camera snapshot
+ value --- a file path or a reference to a Sugar datastore object """
+ if type_ not in Media.ALL_TYPES:
+ raise ValueError("Media.type must be one of " +
+ repr(Media.ALL_TYPES))
+ self.type = type_
+ self.value = value
+
+ def __str__(self):
+ return '%s_%s' % (self.type, str(self.value))
+
+ def __repr__(self):
+ return 'Media(type=%s, value=%s)' % (repr(self.type), repr(self.value))
+
class Blocks:
@@ -301,7 +328,6 @@ class Block:
if not self.is_value_block():
return None
- result = ''
if self.name == 'number':
try:
return float(self.values[0])
@@ -311,23 +337,21 @@ class Block:
self.name == 'title'): # deprecated block
if add_type_prefix:
result = '#s'
+ else:
+ result = ''
if isinstance(self.values[0], (float, int)):
if int(self.values[0]) == self.values[0]:
self.values[0] = int(self.values[0])
result += str(self.values[0])
else:
result += self.values[0]
- elif self.name in PREFIX_DICTIONARY:
- if add_type_prefix:
- result = PREFIX_DICTIONARY[self.name]
- result += str(self.values[0])
+ return result
+ elif self.name in MEDIA_BLOCK2TYPE:
+ return Media(MEDIA_BLOCK2TYPE[self.name], self.values[0])
elif self.name in media_blocks_dictionary:
- if add_type_prefix:
- result = '#smedia_'
- result += self.name.upper()
+ return Media('media', self.name.upper())
else:
return None
- return result
def highlight(self):
""" We may want to highlight a block... """