def image_generate(title, image_file, author, email): img = (xhtml.div(title, {"class" : "title"}) + xhtml.image({"src" : image_file}) + xhtml.div(xhtml.span(author, {"class": "author"}) # + xhtml.span(xhtml.mailto(email), {"class" : "email"}) )) img = (xhtml.table(xhtml.table.row(xhtml.table.cell(xhtml.div(title, {"class" : "title"}), {"colspan": 2})) + xhtml.table.row(xhtml.table.cell(xhtml.image({"src" : image_file}), {"colspan" : 2})) + xhtml.table.row(xhtml.table.cell(xhtml.span(author, {"class" : "author"}), {"class" : "author"})) # + xhtml.table.row(xhtml.table.cell(xhtml.span(email, {"class" : "email"}), {"class" : "email"})) , {"class" : "splash-thumb"})) return (img)
def _ashtml(self, which="image"): return (xhtml.span(self["title"], {"class" : "title"}) + (xhtml.image({"src" : self[which]})) + (xhtml.span(self["author"] + " ", {"class": "author"}) #+ xhtml.span(" ") # + xhtml.span(" " + xhtml.character_reference(self["email"]), {"class" : "email"}) ))
def as_news_item(self): # As a line in the blotter iso_date = time.strftime(config.datetime_format, time.gmtime(calendar.timegm(email.Utils.parsedate(xhtml.unescape(self["date"]))))) s = str(xhtml.comment("$Id$")) + str(xhtml.span(xhtml.quote(self["subject"]), {"class" : "newstitle"}) + xhtml.span(xhtml.quote(iso_date), {"class" : "newsdate"})) s = xhtml.h1(s + " ", {"class" : "newsheading"}) img = "" if icon_by_name(self["image"]) != "": img = xhtml.image({"src" : config.icon_dir + icon_by_name(self["image"])}) pass s += str(xhtml.div(img + as_para(self["body"]), {"class" : "news"})) return (s)
def ashtml(self, which="image"): return (xhtml.table(xhtml.table.row(xhtml.table.cell(xhtml.div(self["title"], {"class" : "title"}), {"colspan": 2})) + xhtml.table.row(xhtml.table.cell(xhtml.image({"src" : self[which]}), {"colspan" : 2})) + xhtml.table.row(xhtml.table.cell(xhtml.span(self["author"], {"class" : "author"}), {"class" : "author"})) # + xhtml.table.row(xhtml.table.cell(xhtml.span(self["email"], {"class" : "email"}), {"class" : "email"})) , {"class" : "splash-thumb"}))
def make_html(root, converge_plot, te_plot, tr_plot, spec_tot_plot, spec_plot, complete_message=['test'], errors=['test', 'test2']): ''' Make an html file that collates all the results ''' string = xhtml.begin( 'Evaluation of how well the python run of %s succeeded' % root) string += xhtml.paragraph( 'Provide an overview of whether the run of %s has succeeded' % root) string += xhtml.add_list(complete_message) string += xhtml.hline() string += xhtml.h2('Did the run converge?') # print(xhtml.image('file:./diag_%s/convergence.png' % root)) string += xhtml.image('file:./diag_%s/convergence.png' % root) string += xhtml.paragraph(convergence_message) string += xhtml.paragraph(convergence2) # print('Test ',converge_plot) string += xhtml.image('file:%s' % (converge_plot)) string += xhtml.hline() string += xhtml.h2('What do the temperatures look like?') string += xhtml.image('file:%s' % (te_plot)) string += xhtml.image('file:%s' % (tr_plot)) # string+=xhtml.image('file:./diag_%s/%s_t_e.png' % (root,root)) # string+=xhtml.image('file:./diag_%s/%s_t_r.png' % (root,root)) string += xhtml.hline() string += xhtml.h2( 'What do the total spectra look like (somewhat smoothed)?') string += xhtml.image('file:%s' % (spec_tot_plot)) string += xhtml.hline() string += xhtml.h2( 'What do the final spectra look like (somewhat smoothed)?') string += xhtml.image('file:%s' % (spec_plot)) string += xhtml.hline() string += xhtml.h2('Errors and Warnings') string += xhtml.paragraph(error_description) string += xhtml.preformat(errors) string += xhtml.hline() # Now add the parameter file so we can see what we have string += xhtml.h2('The parameter file used:') x = open(root + '.pf') lines = x.readlines() string += xhtml.add_list(lines) string += xhtml.hline() string += xhtml.end() # print(string) g = open(root + '.html', 'w') g.write(string)
def display_slideshow(form): names = get_gallery_names() if len(names) == 0: wgo_contest.folio_init() wgo_contest.folio_fini() return name = os.path.basename(form.getvalue("image", names[0])) refresh = int(form.getvalue("refresh", "5")) fullscreen = form.getvalue("fullscreen", "") style = form.getvalue("style", "") if refresh < 2: refresh = 2 entry = wgo_contest.gallery_image(name) image_file = wgo_contest.gallery_file(entry["name"], ".png") next_name = name[0] for i in range(0, len(names)): if names[i] == name: next_name = names[(i + 1) % len(names)] break pass url = "gallery.cgi?display=slideshow&image=%s" % (next_name) if (fullscreen == "true"): fullscreen_attr = "&fullscreen=true" refresh_attr = "&refresh=%d" % (refresh) if style != "": style_attr = "&style=" + style else: style_attr = "" wgo.http_preamble(["Content-Type: text/html", "Refresh: " + str(refresh) + ";url=" + url + refresh_attr + fullscreen_attr + style_attr]) print xhtml.html.init() print xhtml.head() print xhtml.body.init({"style" : "background: black; color: white;"}) if style == "": fill_window = xhtml.hyperlink({"style" : "color: gray;", "href" : url + refresh_attr + fullscreen_attr + "&style=width:100%;"}, "[fill window]") else: fill_window = xhtml.hyperlink({"style" : "color: gray;", "href" : url + refresh_attr + fullscreen_attr}, "[normal size]") print xhtml.span({"style" : "font-size: small; margin-top: 10ex; margin-bottom: 5ex;"}, xhtml.hyperlink({"style" : "color: gray;", "href" : url + fullscreen_attr + style_attr + "&refresh=%s" % (5)}, "5s") + " " + xhtml.hyperlink({"style" : "color: gray;", "href" : url + fullscreen_attr + style_attr + "&refresh=%s" % (10)}, "10s") + " " + xhtml.hyperlink({"style" : "color: gray;", "href" : url + fullscreen_attr + style_attr + "&refresh=%s" % (15)}, "15s") + " " + xhtml.hyperlink({"style" : "color: gray;", "href" : url + fullscreen_attr + style_attr + "&refresh=%s" % (20)}, "20s") + " " + fill_window ) print xhtml.table.init({"style" : "text-align: center; vertical-align: middle; width: 100%;"}) print xhtml.table.row( xhtml.table.cell(xhtml.image({"style" : "%s" % (style), "src" : image_file})) + xhtml.table.cell({"style" : "font-size: xx-large; text-align: right; padding-right: 5%;" }, "<i>" + entry["title"] + "</i><br /> " + entry["author"]) ) print xhtml.table.fini() print xhtml.body.fini() print xhtml.html.fini() pass else: url = "gallery.cgi?display=slideshow&image=%s&refresh=%d" % (next_name, refresh) wgo.http_preamble(["Content-Type: text/html", "Refresh: %s;url=%s" % (refresh, url)]) wgo.header("page", "GIMP Splash Image Slideshow", [{"rel" : "stylesheet", "href" : wgo_contest.config.contest_dir + "wgo-contest.css", "type" : "text/css"}]) print xhtml.span({"style" : "font-size: small; margin-bottom: 5ex;"}, xhtml.hyperlink({"href" : "gallery.cgi?display=slideshow&image=%s&refresh=%s" % (next_name, 5)}, "[5s]") + " " + xhtml.hyperlink({"href" : "gallery.cgi?display=slideshow&image=%s&refresh=%s" % (next_name, 10)}, "[10s]") + " " + xhtml.hyperlink({"href" : "gallery.cgi?display=slideshow&image=%s&refresh=%s" % (next_name, 15)}, "[15s]") + " " + xhtml.hyperlink({"href" : "gallery.cgi?display=slideshow&image=%s&refresh=%s" % (next_name, 20)}, "[20s]") + " " + xhtml.hyperlink({"href" : "gallery.cgi?display=slideshow&image=%s&refresh=%s&fullscreen=true" % (next_name, refresh)}, "[full window]") ) print xhtml.table.init({"class" : "splash-slideshow"}) print xhtml.table.row( xhtml.table.cell(xhtml.image({"src" : image_file})) + xhtml.table.cell("<i>" + entry["title"] + "</i><br /> " + entry["author"]) ) print xhtml.table.fini() wgo_contest.folio_fini() pass return
def make_html(logfile='test_sum.log', outfile=''): ''' Create an html file using information in the log file History 150901 ksl fixed so that the htmlfile could be specified 151112 ksl Modified so that number of saturating stars could be printed out and so that only some of the columns in the table created by actor.actor_main were included in the html table that is part of the output. ''' xsize = 800 ysize = 400 try: root = logfile[0:logfile.rindex('_sum')] except ValueError: root = logfile[0:logfile.rindex('.')] hstring = html.begin('Summary for %s' % root) x = open(logfile, 'r') x = x.readlines() expcount = 0 for line in x: xline = line.strip() words = xline.split() if len(words) > 0: if words[0] == 'Header': expcount += 1 xline = "<a name=\"EXP%04d\">%s</a>" % ( expcount, xline.replace('Header', '')) hstring = hstring + html.h2(xline) elif words[0] == 'Table': xxx = read_table(words[1]) # Drop some columns, and reorder sligthly xxx = xxx['Visit', 'ExpNo', 'Target', 'RA', 'Dec', 'Config', 'Aper', 'Filter', 'SAMP-SEQ', 'NSAMP', 'Exptime', 'Repeats', 'ScanRate', 'Comment'] ### make links from exposure number links = [] for i in range(len(xxx)): link = '<a href=#EXP%04d>%d</a>' % (i + 1, xxx['ExpNo'][i]) links.append(link) xxx.add_column(Column(data=links, name='Exp'), 1) xxx.remove_column('ExpNo') # Note: ksl. I had troble getting the column names to form a # sincle record. This is what worked in the end my_table = [xxx.colnames[:]] for one in xxx: my_table.append(one) hstring = hstring + html.table(my_table) elif words[0] == 'Image': ximage = words[1] hstring = hstring + html.image(ximage, 'Bright stars image', xsize, ysize) else: if xline.startswith('Saturated'): print(xline) data = xline.split()[-5::2] colors = ['green', 'blue', 'red'] for i in range(3): if int(data[i]) == 0: data[ i] = "<span style=\"color:grey\">%s</span>" % ( data[i]) else: data[ i] = "<span style=\"color:%s; font-weight:bold;\">%s</span>" % ( colors[i], data[i]) hstring += html.paragraph( 'Saturated pixels in image:') + html.table( [xline.split()[-6::2], data], width="200px") elif xline.startswith('Number saturated'): data = xline.split()[-5::2] colors = ['green', 'blue', 'red'] for i in range(3): if int(data[i]) == 0: data[ i] = "<span style=\"color:grey\">%s</span>" % ( data[i]) else: data[ i] = "<span style=\"color:%s; font-weight:bold;\">%s</span>" % ( colors[i], data[i]) hstring += html.paragraph( 'Saturated stars in field:') + html.table( [xline.split()[-6::2], data], width="200px") else: hstring = hstring + html.paragraph(xline) hstring = hstring + html.end() # Create the html file if outfile == '': html_file = root + '.html' elif outfile.count('html') == 0: html_file = outfile + '.html' else: html_file = outfile print('test ', html_file) g = open(html_file, 'w') g.write(hstring) g.close()
def make_html(root, converge_plot, te_plot, tr_plot, spec_tot_plot, spec_plot, complete_message=['test'], errors=['test', 'test2']): ''' Make an html file that collates all the results ''' string = xhtml.begin('%s: How well did the Python run go?' % root) string += xhtml.paragraph( 'Provide an overview of whether the run of %s has succeeded' % root) string += xhtml.add_list(complete_message) string += xhtml.hline() string += xhtml.h2('Did the run converge?') if os.path.isfile('./diag_%s/convergence.png' % root): string += xhtml.image('file:./diag_%s/convergence.png' % root) else: string += xhtml.paragraph( 'There is no convergence plot. OK if no ionization cycles') string += xhtml.paragraph(convergence_message) string += xhtml.paragraph(convergence2) # print('Test ',converge_plot) string += xhtml.image('file:%s' % (converge_plot)) string += xhtml.hline() string += xhtml.h2('What do the temperatures look like?') string += xhtml.image('file:%s' % (te_plot)) string += xhtml.image('file:%s' % (tr_plot)) # string+=xhtml.image('file:./diag_%s/%s_t_e.png' % (root,root)) # string+=xhtml.image('file:./diag_%s/%s_t_r.png' % (root,root)) string += xhtml.hline() string += xhtml.h2( 'What do the total spectra look like (somewhat smoothed)?') if os.path.isfile(spec_tot_plot): string += xhtml.image('file:%s' % (spec_tot_plot)) else: string += xhtml.paragraph( 'There is no total spectrum plot. OK if no ionization cycles') string += xhtml.hline() string += xhtml.h2( 'What do the final spectra look like (somewhat smoothed)?') if spec_plot != 'None': string += xhtml.image('file:%s' % (spec_plot)) else: string += xhtml.paragraph( 'There is no plot of a detailed spectrum, probably because detailed spectra were not created' ) string += xhtml.hline() string += xhtml.h2('Errors and Warnings') string += xhtml.paragraph(error_description) string += xhtml.preformat(errors) string += xhtml.hline() # Now add the parameter file so we can see what we have string += xhtml.h2('The parameter file used:') x = open(root + '.pf') lines = x.readlines() string += xhtml.add_list(lines) string += xhtml.hline() string += xhtml.end() # print(string) g = open(root + '.html', 'w') g.write(string)