def _printPost(self): name = os.path.basename(self.fileName) outputFile = name.replace(".py",".ngc") form = cgi.FieldStorage() if form['generation'].value == 'interactive': print "Content-Type: text/html" print html_header = self.postHead # add the tree control javascript stuff #html_header += HtmlTree.html_header_text utils.printHead('Hugomatic gcode', ('banner','nav','interactive','footer'), extraText=html_header) utils.printBanner() utils.printPostNavBar(self.fileName) print "<h1>" + outputFile + "</h1><Pre>" #print '<h2>Source code: <a href="sourceView.py?src=' + name + '">' + name+'</a></h2>' old_out = sys.stdout sys.stdout = RedirectStdOut(old_out, True) # add hook to end program with a copyright notice atexit.register(printPostFooter) else: print 'Content-Type: text/plain' print "Content-Disposition: attachment; filename=\"" + outputFile + "\"" print print "( " + self.title + " )" print "( " + self.desc + " )" print callingFrame = inspect.currentframe().f_back.f_back for p in self.params: name = p['name'] desc = p['desc'] value = p['obj'] newVal = None if type(value) == bool: if form.__contains__(name): newVal = True else: newVal = False else: if form.__contains__(name): newVal = None if type(value) == float: newVal = float(form[name].value) elif type(value) == int: newVal = int(form[name].value) if form[name].filename: newVal = self._uploadFile(form[name]) if newVal == None: # if the value has not changed, set newVal to the old one newVal = form[name].value # assign the new value callingFrame.f_globals[name] = newVal strV = name + " = " + str(newVal) + ", "+ desc+ " default: "+ str(value) s2 = "( " + gcodeCommentEscape(strV) + ")" print s2
def main(): print "Content-Type: text/html" print printHead('Hugomatic under construction', ('banner','footer'),path='') printBanner(path='') print """ <br> <h1>Under construction ;-(</h1> <br> <br> <br>If all knowledge, all culture, all art, all useful information, can be costlessly given to everyone at the same price that it is given to anyone... free access to information is essential because the alternative is unethical and unacceptable. """ printFooter() print " </body>"
def _interactive_post(self, name, output_file, form): print "Content-Type: text/html" print html_header = self.postHead # add the tree control javascript stuff #html_header += HtmlTree.html_header_text utils.printHead('Hugomatic gcode', ('banner','nav','interactive','footer'), extraText=html_header) utils.printBanner() utils.printPostNavBar(self.fileName) print "<h1>" + output_file + "</h1><Pre>" #print '<h2>Source code: <a href="sourceView.py?src=' + name + '">' + name+'</a></h2>' old_out = sys.stdout sys.stdout = RedirectStdOut(old_out, True) # add hook to end program with a copyright notice if googleAppEngine == False: atexit.register(print_interactive_post_footer)
def main(sourceFile): print "Content-Type: text/html" print oldwd = os.getcwd() filedir = oldwd.replace("/hugomatic/web","") # os.chdir(curdir) # cwd = os.getcwd() printHead('Hugomatic source explorer', ('banner','nav','footer'), path='' ) printBanner(path='') printSourceViewNavBar(sourceFile) head, tail = os.path.split(sourceFile) print "<h1>" + tail+"</h1>" filePath = filedir + "/" + sourceFile # print "<h4><pre>" # print "sourceFile: " + sourceFile # print "head: " + head # print "tail: " + tail # print "oldwd: " + oldwd # print "cwd: " + cwd # print "filePath: " + filePath # print "</pre></h4>" PyToHTML(filePath, sys.stdout) print print print "<hr>" print '<table>' printPyFileSrcLinks(".") print '</table>' printFooter() print "</body>"
def _printForm(self): """ Generates a web page that contains a FORM with inputs for every parameter published via addArgument in the self.params list """ def openGroup(group): print "<fieldset><legend>" + group + "</legend>" def closeGroup(group): print "</fieldset>" def printInputField(name, desc, value, choices, isFilePath): def printSelect(name, value, choices, desc): print "<select name=\"%s\">" % name for option in choices: s = '>' if option == value: s = ' selected>' print ' <option value ="' + option + '"' + s + option + "</option>" print "</select> " + desc + " ( " + value + " )<br>" size = 10 t = type(value) if t == bool: if value == True: #text on the right print """<input type="checkbox" name=\""""+ name+ "\"value=\"", value, "\"CHECKED/>", desc, "(", value,")<br>" else: print """<input type="checkbox" name=\""""+ name+ "\"value=\"", value, "\"/>", desc, "(", value,")<br>" #text on the left #print "<br>"+ desc +"""<input type="checkbox" name=\""""+ name+ "\"value=\"", value, "\">", "(", value,")" else: if isFilePath: print "<input type=\"file\" name=\""+name+ "\" size=\"", size * 2 , "\" value=\"", value ,"\"/>", desc, "(", value,")<br>" else: if choices: printSelect(name, value, choices, desc) else: print "<input type=\"text\" name=\""+name+ "\" size=\"", 10, "\" value=\"", value ,"\"/>", desc, "(", value,")<br>" print "Content-Type: text/html" print utils.printHead('Hugomatic gcode generator', ('banner','getform','nav','footer'), extraText=self.getHead) utils.printBanner() utils.printGetNavBar(self.fileName) print "<h1>", self.title, "</h1>" if self.picture_file != None: print """ <div id="form-content"> <div id="form-image"> <IMG SRC=\"""" + self.picture_file + """"\"> </div>""" print """ <div id="form-elements"> <form name="GcodeForm" enctype="multipart/form-data" method="post">""" legend = self.desc print "<strong>" + legend + "</strong>" print "<fieldset>" # <legend>" + legend + "</legend>" currentGroup = None for p in self.params: name = p['name'] desc = p['desc'] value = p['obj'] filePath = p['filePath'] choices = p['choices'] group = p['group'] if group != currentGroup: if currentGroup != None: closeGroup(currentGroup) currentGroup = group if currentGroup != None: openGroup(group) if group == None: print "<br>" # reopening the top group.. add a spacer printInputField(name, desc, value, choices, filePath) if currentGroup != None: closeGroup(currentGroup) print """ <input type="hidden" name="generation" value="none" /> <br><INPUT type="button" value="Generate with UI" name=button1 onclick="return OnButtonPreview();"> <INPUT type="button" value="Generate & download" name=button2 onclick="return OnButtonDownload();"> <input value="RESET" type="reset"> </fieldset> </form> </div> </div> """ print """ <p><i>A computer in every workshop!</i></p> """ utils.printFooter()
# # You can contact me at the following email address: # [email protected] # try: from utils import printHead, printBanner, printFooter, printContactNavBar except: # google app engine from hugomatic.web.utils import printHead, printBanner, printFooter, printContactNavBar print "Content-Type: text/html" print printHead('Contact Hugomatic',('nav','banner','footer'), path="") printBanner( path='') printContactNavBar() print "<h1>Contact us</h1>" print '<div id="contact">' print '<img src="stylesheets/img/phone.jpg">' print '<br>Hugomatic is a Montreal based company' print '<br>email: [email protected]' print '<br><br><br>' print '</div>'