Thu, 06 Apr 2017 15:41:04 +0200
added text info box
#!/usr/bin/env python # -*- coding: UTF-8 -*- """ Web CGI script for 3D View """ import cgi, data, json, config from cylindertransport import CylinderSpacerCalculator # 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) calc.calculate() print json.dumps({ "objects": calc.circles, "scale3d": config.SCALE3D }) 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()