diff options
author | Walter Bender <walter.bender@gmail.com> | 2011-12-09 14:50:35 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2011-12-09 14:50:35 (GMT) |
commit | 225f0ff32174c2093546824ced0ea9a80f912f6c (patch) | |
tree | 6b07b6e111d92425ec690a8d43a7c03e9deb98fb /TurtleArt | |
parent | e29f8189d18f8465fdcd35f322e9565ebd00bac2 (diff) |
clean up after saving images, html, logo code
Diffstat (limited to 'TurtleArt')
-rw-r--r-- | TurtleArt/taexporthtml.py | 20 | ||||
-rw-r--r-- | TurtleArt/tawindow.py | 7 |
2 files changed, 18 insertions, 9 deletions
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 """ |