Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter 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)
commit225f0ff32174c2093546824ced0ea9a80f912f6c (patch)
tree6b07b6e111d92425ec690a8d43a7c03e9deb98fb
parente29f8189d18f8465fdcd35f322e9565ebd00bac2 (diff)
clean up after saving images, html, logo code
-rw-r--r--TurtleArt/taexporthtml.py20
-rw-r--r--TurtleArt/tawindow.py7
-rw-r--r--TurtleArtActivity.py7
3 files changed, 24 insertions, 10 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 """
diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py
index daba8f9..a50300e 100644
--- a/TurtleArtActivity.py
+++ b/TurtleArtActivity.py
@@ -114,7 +114,7 @@ class TurtleArtActivity(activity.Activity):
save_type = '.html'
if len(self.tw.saved_pictures) > 0:
- if self.tw.saved_pictures[0].endswith(('.svg')):
+ if self.tw.saved_pictures[0][1]: # svg=True
save_type = '.xml'
html_file = os.path.join(datapath, 'portfolio' + save_type)
@@ -155,6 +155,10 @@ class TurtleArtActivity(activity.Activity):
gobject.timeout_add(250, self.save_as_html.set_icon, 'htmloff')
self.tw.saved_pictures = [] # Clear queue of pictures we have viewed.
+ if embed_flag:
+ os.remove(html_file)
+ else:
+ os.remove(tar_file)
return
def do_save_as_logo_cb(self, button):
@@ -172,6 +176,7 @@ class TurtleArtActivity(activity.Activity):
datastore.write(dsobject)
dsobject.destroy()
+ os.remove(logo_code_path)
gobject.timeout_add(250, self.save_as_logo.set_icon, 'logo-saveoff')
return