Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/taexporthtml.py
diff options
context:
space:
mode:
authorWalter Bender <walter@walter-laptop.(none)>2009-02-28 22:19:20 (GMT)
committer Walter Bender <walter@walter-laptop.(none)>2009-02-28 22:19:20 (GMT)
commit3d195dff75c3f99a647d7e0d995e91648fd85db3 (patch)
treef3328b00ae59de8ee5102953b383b5f7c588607b /taexporthtml.py
parentd7e2efe1163c5390a1b51ecf3de42ecf05242d0b (diff)
reorg of SVGs
Diffstat (limited to 'taexporthtml.py')
-rw-r--r--taexporthtml.py82
1 files changed, 51 insertions, 31 deletions
diff --git a/taexporthtml.py b/taexporthtml.py
index 8474404..f3f7fbb 100644
--- a/taexporthtml.py
+++ b/taexporthtml.py
@@ -23,7 +23,7 @@ import talogo
from sugar.activity import activity
from sugar.datastore import datastore
import os.path
-import os
+import subprocess
from talogo import get_pixbuf_from_journal
from gettext import gettext as _
@@ -36,13 +36,16 @@ def save_html(self, tw, embed_flag=True):
datapath = \
"/home/olpc/.sugar/default/org.laptop.TurtleArtActivity/instance"
- # this dictionary is used to define the html wrappers around template elements
+ # dictionary defines the html wrappers around template elements
# start of block, end of block
html_glue = {
- 'doctype': ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n", ""),
+ 'doctype': ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 \
+Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n", ""),
'html': ("<http>\n", "</http>\n"),
- 'head': ("<head>\n<!-- Created by Turtle Art Portfolio -->\n", "</head>\n"),
- 'meta': ("<meta http-equiv=\"content-type\" content=\"text/html;charset=UTF-8\">\n", ""),
+ 'head': ("<head>\n<!-- Created by Turtle Art Portfolio -->\n", \
+ "</head>\n"),
+ 'meta': ("<meta http-equiv=\"content-type\" content=\"text/html; \
+charset=UTF-8\">\n", ""),
'title': ("<title>", "</title>\n"),
'style': ("<style type=\"text/css\">\n<!--\n","-->\n</style>\n"),
'body': ("<body>\n", "\n</body>\n"),
@@ -51,13 +54,16 @@ def save_html(self, tw, embed_flag=True):
'h1': ("<h1>", "</h1>\n"),
'table': ("<table cellpadding=\"10\">\n", "</table>\n"),
'tr': ("<tr>\n", "</tr>\n"),
- 'td': ("<td valign=\"top\" width=\"400\" height=\"300\">\n", "\n</td>\n"),
- 'img': ("<img width=\"400\" height=\"300\" alt=\"Image\" src=\"image", ".png\" />\n"),
+ 'td': ("<td valign=\"top\" width=\"400\" height=\"300\">\n", \
+ "\n</td>\n"),
+ 'img': ("<img width=\"400\" height=\"300\" alt=\"Image\" src=\"image",\
+ ".png\" />\n"),
'ul': ("<ul>\n", "</ul>\n"),
'li': ("<li>", "</li>\n") }
if embed_flag == True:
- html_glue['img'] = ("<img width=\"400\" height=\"300\" alt=\"Image\" src=\"data:image/png;base64,\n", " \"/>\n")
+ html_glue['img'] = ("<img width=\"400\" height=\"300\" alt=\"Image\" \
+src=\"data:image/png;base64,\n", " \"/>\n")
bs = tawindow.blocks(tw)
code = ""
imagecount = 0
@@ -87,7 +93,10 @@ def save_html(self, tw, embed_flag=True):
sevenbullets = 8
elif sevenbullets > 0:
if sevenbullets == 8:
- tmp = html_glue['slide'][0] + str(slidecount) + html_glue['slide'][1] + html_glue['div'][0] + html_glue['h1'][0] + d[2:] + html_glue['h1'][1] + html_glue['ul'][0]
+ tmp = html_glue['slide'][0] + str(slidecount) +\
+ html_glue['slide'][1] + \
+ html_glue['div'][0] + html_glue['h1'][0] + \
+ d[2:] + html_glue['h1'][1] + html_glue['ul'][0]
elif d[2:] != "":
tmp = html_glue['li'][0] + d[2:] + html_glue['li'][1]
this_stack += tmp
@@ -96,7 +105,8 @@ def save_html(self, tw, embed_flag=True):
if sevenbullets == 0:
this_stack += html_glue['ul'][1]
elif onepic == 1 or twopic == 1 or fourpic == 1:
- tmp = html_glue['slide'][0] + str(slidecount) + html_glue['slide'][1] + \
+ tmp = html_glue['slide'][0] + str(slidecount) + \
+ html_glue['slide'][1] + \
html_glue['div'][0] + html_glue['h1'][0] + d[2:] + \
html_glue['h1'][1] + html_glue['table'][0]
this_stack += tmp
@@ -105,8 +115,8 @@ def save_html(self, tw, embed_flag=True):
elif fourpic > 0: fourpic += 1
slidecount += 1
elif onepic > 1 or twopic > 1 or fourpic > 1:
- # We need to get filename and copy it into instance directory
- # if it is not an image, save the preview to a file instead
+ # Need filename to copy it into instance directory
+ # if it is not an image, save the preview
# save the description too.
print str(onepic) + " " + str(twopic) + " " + str(fourpic)
if d[8:] != None:
@@ -116,60 +126,70 @@ def save_html(self, tw, embed_flag=True):
except:
pixbuf = None
if pixbuf != None:
- filename = os.path.join(datapath, 'image' + str(imagecount) \
- + ".png")
+ filename = os.path.join(datapath, 'image' + \
+ str(imagecount) + ".png")
pixbuf.save(filename, "png")
- # if the embed flag is True, embed base64 directly into the html
+ # if the embed flag is True
+ # embed base64 into the html
if embed_flag == True:
base64 = os.path.join(datapath, 'base64tmp')
- os.system( "base64 <" + filename + " >" + base64)
+ cmd = "base64 <" + filename + " >" + base64
+ subprocess.check_call(cmd, shell=True)
f = open( base64, 'r')
imgdata = f.read()
f.close()
- if onepic == 2 or twopic == 2 or twopic == 4 or fourpic == 2 or \
- fourpic == 4:
+ if onepic == 2 or twopic == 2 or twopic == 4 or\
+ fourpic == 2 or fourpic == 4:
tmp = html_glue['tr'][0]
else:
tmp = ""
if pixbuf != None:
- tmp = tmp + html_glue['td'][0] + html_glue['img'][0]
+ tmp = tmp + html_glue['td'][0] + \
+ html_glue['img'][0]
if embed_flag == True:
tmp = tmp + imgdata
else:
tmp = tmp + str(imagecount)
- tmp = tmp + html_glue['img'][1] + html_glue['td'][1]
+ tmp = tmp + html_glue['img'][1] + \
+ html_glue['td'][1]
if fourpic == 0:
try:
description = dsobject.metadata['description']
except:
description = ""
- tmp = tmp + html_glue['td'][0] + description + html_glue['td'][1]
- if onepic == 2 or twopic == 3 or fourpic == 3 or fourpic == 5:
+ tmp = tmp + html_glue['td'][0] + description + \
+ html_glue['td'][1]
+ if onepic == 2 or twopic == 3 or fourpic == 3 or \
+ fourpic == 5:
tmp = tmp + html_glue['tr'][1]
imagecount += 1
this_stack += tmp
if onepic > 1:
- this_stack += html_glue['table'][1] + html_glue['div'][1]
+ this_stack += html_glue['table'][1] + \
+ html_glue['div'][1]
onepic = 0
elif twopic > 1:
if twopic == 3:
- this_stack += html_glue['table'][1] + html_glue['div'][1]
+ this_stack += html_glue['table'][1] + \
+ html_glue['div'][1]
twopic = 0
else: twopic += 1
elif fourpic > 1:
if fourpic == 5:
- this_stack += html_glue['table'][1] + html_glue['div'][1]
+ this_stack += html_glue['table'][1] + \
+ html_glue['div'][1]
fourpic = 0
else: fourpic += 1
this_stack += " "
if len(data) > 0:
code += this_stack
- code = html_glue['doctype'][0] + html_glue['html'][0] + html_glue['head'][0] + \
- html_glue['meta'][0] + html_glue['title'][0] + _("Turtle Art Portfolio") + \
- html_glue['title'][1] + html_glue['style'][0] + html_glue['style'][1] + \
- html_glue['head'][1] + html_glue['body'][0] + code + html_glue['body'][1] + \
- html_glue['html'][1]
-# print code
+ code = html_glue['doctype'][0] + html_glue['html'][0] + \
+ html_glue['head'][0] + \
+ html_glue['meta'][0] + html_glue['title'][0] + _("Turtle Art") + \
+ html_glue['title'][1] + html_glue['style'][0] + \
+ html_glue['style'][1] + \
+ html_glue['head'][1] + html_glue['body'][0] + code + \
+ html_glue['body'][1] + html_glue['html'][1]
return code
def walk_stack(self, tw, spr):