From 225f0ff32174c2093546824ced0ea9a80f912f6c Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Fri, 09 Dec 2011 14:50:35 +0000 Subject: clean up after saving images, html, logo code --- (limited to 'TurtleArt') diff --git a/TurtleArt/taexporthtml.py b/TurtleArt/taexporthtml.py index 90dcc4d..75da112 100644 --- a/TurtleArt/taexporthtml.py +++ b/TurtleArt/taexporthtml.py @@ -78,25 +78,33 @@ def save_html(self, tw, embed_flag=True): """ htmlcode = '' if len(tw.saved_pictures) > 0: - for i, image_file in enumerate(tw.saved_pictures): + # saved_picture list is a collection of tuples of either the + # image_file or the containing dsobject and an SVG flag + for i, (image, svg_flag) in enumerate(tw.saved_pictures): htmlcode += HTML_GLUE['slide'][0] + str(i) htmlcode += HTML_GLUE['slide'][1] + \ HTML_GLUE['div'][0] + \ HTML_GLUE['h1'][0] + if tw.running_sugar: + from sugar.datastore import datastore + dobject = datastore.get(image) # dsobject.object_id + image_file = dobject.file_path + else: + image_file = image if embed_flag: f = open(image_file, 'r') imgdata = f.read() f.close() - if image_file.endswith(('.svg')): + if svg_flag: tmp = imgdata else: - imgdata = image_to_base64(image_file, - get_path(tw.activity, 'instance')) + imgdata = image_to_base64( + image_file, get_path(tw.activity, 'instance')) tmp = HTML_GLUE['img2'][0] tmp += imgdata tmp += HTML_GLUE['img2'][1] else: - if image_file.endswith(('.svg')): + if svg_flag: f = open(image_file, 'r') imgdata = f.read() f.close() @@ -135,7 +143,7 @@ def save_html(self, tw, embed_flag=True): style = HTML_GLUE['style'][0] + \ HTML_GLUE['style'][1] if len(tw.saved_pictures) > 0: - if tw.saved_pictures[0].endswith(('.svg')): + if tw.saved_pictures[0][1]: header = HTML_GLUE['html_svg'][0] style = COMMENT diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py index e890be2..8a294ba 100644 --- a/TurtleArt/tawindow.py +++ b/TurtleArt/tawindow.py @@ -3008,9 +3008,6 @@ class TurtleArtWindow(): else: save_picture(self.canvas, file_path) - # keep a log of the saved pictures for export to HTML - self.saved_pictures.append(file_path) - if self.running_sugar: from sugar.datastore import datastore from sugar import profile @@ -3029,6 +3026,10 @@ class TurtleArtWindow(): dsobject.set_file_path(file_path) datastore.write(dsobject) dsobject.destroy() + self.saved_pictures.append((dsobject.object_id, svg)) + os.remove(file_path) + else: + self.saved_pictures.append((file_path, svg)) def just_blocks(self): """ Filter out 'proto', 'trash', and 'deleted' blocks """ -- cgit v0.9.1