diff options
Diffstat (limited to 'TurtleArt/talogo.py')
-rw-r--r-- | TurtleArt/talogo.py | 129 |
1 files changed, 64 insertions, 65 deletions
diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py index d3410a6..fff1d4b 100644 --- a/TurtleArt/talogo.py +++ b/TurtleArt/talogo.py @@ -36,7 +36,7 @@ except ImportError: import traceback -from tablock import (Block, media_blocks_dictionary) +from tablock import (Block, Media, media_blocks_dictionary) from taconstants import (TAB_LAYER, DEFAULT_SCALE) from tapalette import (block_names, value_blocks) from tatype import TATypeError @@ -346,7 +346,9 @@ class LogoCode: bindex = None if isinstance(token, tuple): (token, bindex) = token - if isNumberType(token): + if isinstance(token, Media): + res.append(token) + elif isNumberType(token): res.append(token) elif token.isdigit(): res.append(float(token)) @@ -892,74 +894,71 @@ class LogoCode: for blk in drag_group: blk.spr.move_relative((dx, 0)) - def show(self, string, center=False): + def show(self, obj, center=False): """ Show is the general-purpose media-rendering block. """ - if type(string) == str or type(string) == unicode: - if string in ['media_', 'descr_', 'audio_', 'video_', - 'media_None', 'descr_None', 'audio_None', - 'video_None']: - pass - elif string[0:6] in ['media_', 'descr_', 'audio_', 'video_']: - self.filepath = None - self.pixbuf = None # Camera writes directly to pixbuf - self.dsobject = None - if string[6:].lower() in media_blocks_dictionary: - media_blocks_dictionary[string[6:].lower()]() - elif os_path_exists(string[6:]): # is it a path? - self.filepath = string[6:] - elif self.tw.running_sugar: # is it a datastore object? - from sugar.datastore import datastore - try: - self.dsobject = datastore.get(string[6:]) - except: - debug_output("Couldn't find dsobject %s" % - (string[6:]), self.tw.running_sugar) - if self.dsobject is not None: - self.filepath = self.dsobject.file_path - if self.pixbuf is not None: - self.insert_image(center=center, pixbuf=True) - elif self.filepath is None: - if self.dsobject is not None: - self.tw.showlabel( - 'nojournal', - self.dsobject.metadata['title']) - else: - self.tw.showlabel('nojournal', string[6:]) - debug_output("Couldn't open %s" % (string[6:]), - self.tw.running_sugar) - elif string[0:6] == 'media_': - self.insert_image(center=center) - elif string[0:6] == 'descr_': - mimetype = None - if self.dsobject is not None and \ - 'mime_type' in self.dsobject.metadata: - mimetype = self.dsobject.metadata['mime_type'] - description = None - if self.dsobject is not None and \ - 'description' in self.dsobject.metadata: - description = self.dsobject.metadata[ - 'description'] - self.insert_desc(mimetype, description) - elif string[0:6] == 'audio_': - self.play_sound() - elif string[0:6] == 'video_': - self.play_video() + # media + if isinstance(obj, Media) and obj.value: + self.filepath = None + self.pixbuf = None # Camera writes directly to pixbuf + self.dsobject = None + + # camera snapshot + if obj.value.lower() in media_blocks_dictionary: + media_blocks_dictionary[obj.value.lower()]() + # file path + elif os_path_exists(obj.value): + self.filepath = obj.value + # datastore object + elif self.tw.running_sugar: + from sugar.datastore import datastore + try: + self.dsobject = datastore.get(obj.value) + except: + debug_output("Couldn't find dsobject %s" % + (obj.value), self.tw.running_sugar) if self.dsobject is not None: - self.dsobject.destroy() - else: # assume it is text to display - x, y = self.x2tx(), self.y2ty() - if center: - y -= self.tw.canvas.textsize - self.tw.turtles.get_active_turtle().draw_text(string, x, y, - int(self.tw.canvas.textsize * - self.scale / 100.), - self.tw.canvas.width - x) - elif type(string) == float or type(string) == int: - string = round_int(string) + self.filepath = self.dsobject.file_path + + if self.pixbuf is not None: + self.insert_image(center=center, pixbuf=True) + elif self.filepath is None: + if self.dsobject is not None: + self.tw.showlabel( + 'nojournal', + self.dsobject.metadata['title']) + else: + self.tw.showlabel('nojournal', obj.value) + debug_output("Couldn't open %s" % (obj.value), + self.tw.running_sugar) + elif obj.type == 'media': + self.insert_image(center=center) + elif obj.type == 'descr': + mimetype = None + if self.dsobject is not None and \ + 'mime_type' in self.dsobject.metadata: + mimetype = self.dsobject.metadata['mime_type'] + description = None + if self.dsobject is not None and \ + 'description' in self.dsobject.metadata: + description = self.dsobject.metadata[ + 'description'] + self.insert_desc(mimetype, description) + elif obj.type == 'audio': + self.play_sound() + elif obj.type == 'video': + self.play_video() + + if self.dsobject is not None: + self.dsobject.destroy() + + # text or number + elif isinstance(obj, (basestring, float, int)): + if isinstance(obj, (float, int)): + obj = round_int(obj) x, y = self.x2tx(), self.y2ty() if center: y -= self.tw.canvas.textsize - self.tw.turtles.get_active_turtle().draw_text(string, x, y, + self.tw.turtles.get_active_turtle().draw_text(obj, x, y, int(self.tw.canvas.textsize * self.scale / 100.), self.tw.canvas.width - x) |