示例#1
0
from __future__ import division
import math
import pythonsvg

# ========================================================================================
# Main Code
# ========================================================================================

if __name__ == '__main__':
	a = pythonsvg.mySvgCanvas("svg1", 600, 600)

	ascii_string= ""
	while True:
		try:
			new_line = raw_input()
			ascii_string += new_line + "\n"
		except:
			break	

	a.process_ascii_multi_line(ascii_string)
	xml = a.generate_string()

	print xml

# ========================================================================================


i = 1
count_error = 0
count_success = 0

for dirpath, dirnames, filenames in os.walk(path):
    for filename in [f for f in filenames if f.endswith(".ascsvg")]:
        
			# Read ASCIISVG files
			g = open(os.path.join(dirpath, filename),'r')
			ascii_text = g.read()
			g.close()

			print str(i) + " " + filename.split(".")[0]

			# SVG (xml script)
			my_svg = pythonsvg.mySvgCanvas(filename.split(".")[0], 400, 400) # default size of SVG
			my_svg.process_ascii_multi_line(ascii_text)
			xml = my_svg.generate_string()

			# XML object
			svg_object = etree.fromstring(xml)

			# PNG Image	
			pythonsvg.create_png("png_images/" + filename.split(".")[0], int(float(svg_object.attrib['width'])), int(float(svg_object.attrib['height'])), xml) 

			# Append contents to the HTML page
			if ("ERROR" in xml): contents += "<tr bgcolor='#cd7879'><td>"; count_error += 1
			else: contents += "<tr bgcolor='#86cd78'><td>";  count_success += 1
			contents += "Folder: /" + dirpath.split("/")[-1] + "/<br>"
			if ("ERROR" in xml): contents += "Error: #" + str(count_error) + "<br>"
			else: contents += "Correct: #" + str(count_success) + "<br>"