Thu, 06 Apr 2017 19:00:07 +0200
ht is not PVC....
#!/usr/bin/env python # -*- coding: UTF-8 -*- """ Web CGI script for 3D View """ import cgi, data, json, config from cylindertransport import CylinderSpacerCalculator import base64 import cStringIO # enable debugging #import sys #sys.stderr = sys.stdout import cgitb cgitb.enable() def do_action(args): """ process some actions (like JSON requests) """ if args["action"].value == "calculate": cylinders = args.getlist("cylinders[]") calc = CylinderSpacerCalculator(cylinders) # Bug... Calculate gets called by render_image, producing double circles list #calc.calculate() image = calc.render_image() buffer = cStringIO.StringIO() image.save(buffer, format="PNG") img_str = base64.b64encode(buffer.getvalue()) print json.dumps({ "objects": calc.circles, "offset": (calc.width - (2 * calc.margin)) / 2, "scale3d": config.SCALE3D, "image": img_str }) else: print "unknown Action %s" % args["action"].value def run(): """ Main program, without action displays the html content """ print "Content-Type: text/html;charset=utf-8" print "" args = cgi.FieldStorage() if "action" in args: do_action(args) else: # display the html content content = open("stlviewer.html", "r").read() cyls = "" for cyl in sorted(data.CYLINDER.keys()): cyls += "<li key=\"%s\" weight=\"%s\">%s</li>" % ( cyl, data.CYLINDER[cyl][3], data.CYLINDER[cyl][4]) content = content.replace("<!-- PLACEHOLDER CYLINDERS -->", cyls) print content if __name__ == "__main__": run()