Updated html_writer

This commit is contained in:
Oliver 2016-05-15 16:13:20 +10:00
parent 640e3d73f7
commit 725bf9f49c
1 changed files with 55 additions and 62 deletions

View File

@ -40,75 +40,68 @@ def WriteHTML(filename, groups, net, headings, prefs):
if not filename.endswith(".html") and not filename.endswith(".htm"):
print("{fn} is not a valid html file".format(fn=filename))
return False
try:
with open(filename,"w") as html:
with open(filename,"w") as html:
#header
html.write("<html>\n")
html.write("<body>\n")
#PCB info
html.write("<h2>KiBoM PCB Bill of Materials</h2>\n")
html.write("<br>Source File: {source}\n".format(source=net.getSource()))
html.write("<br>Date: {date}\n".format(date=net.getDate()))
html.write("<br>Schematic Version: {version}\n".format(version=net.getVersion()))
html.write("<br>Total Components: {n}\n".format(n = sum([g.getCount() for g in groups])))
html.write("<br>Component Groups: {n}\n".format(n=len(groups)))
html.write("<br>\n")
html.write("<h2>Component Groups</h2>\n")
html.write('<p style="background-color: {bg}">Kicad Fields (default)</p>\n'.format(bg=BG_KICAD))
html.write('<p style="background-color: {bg}">Generated Fields</p>\n'.format(bg=BG_GEN))
html.write('<p style="background-color: {bg}">User Fields</p>\n'.format(bg=BG_USER))
#component groups
html.write('<table border="1">\n')
#row titles:
html.write("<tr>\n")
if prefs.numberRows:
html.write("\t<th></th>\n")
for i,h in enumerate(headings):
#cell background color
bg = bgColor(h)
html.write('\t<th align="center"{bg}>{h}</th>\n'.format(
h=h,
bg = ' bgcolor="{c}"'.format(c=bg) if bg else ''))
html.write("</tr>\n")
rowCount = 0
for i,group in enumerate(groups):
if prefs.ignoreDNF and not group.isFitted(): continue
#header
html.write("<html>\n")
html.write("<body>\n")
row = group.getRow(headings)
#PCB info
html.write("<h2>KiBOM PCB Bill of Materials</h2>\n")
html.write("<br>Source File: {source}\n".format(source=net.getSource()))
html.write("<br>Date: {date}\n".format(date=net.getDate()))
html.write("<br>Schematic Version: {version}\n".format(version=net.getVersion()))
html.write("<br>Total Components: {n}\n".format(n = sum([g.getCount() for g in groups])))
html.write("<br>Component Groups: {n}\n".format(n=len(groups)))
html.write("<br>\n")
html.write("<h2>Component Groups</h2>\n")
html.write('<p style="background-color: {bg}">Kicad Fields (default)</p>\n'.format(bg=BG_KICAD))
html.write('<p style="background-color: {bg}">Generated Fields</p>\n'.format(bg=BG_GEN))
html.write('<p style="background-color: {bg}">User Fields</p>\n'.format(bg=BG_USER))
rowCount += 1
#component groups
html.write('<table border="1">\n')
#row titles:
html.write("<tr>\n")
if prefs.numberRows:
html.write("\t<th></th>\n")
for i,h in enumerate(headings):
#cell background color
bg = bgColor(h)
html.write('\t<th align="center"{bg}>{h}</th>\n'.format(
h=h,
bg = ' bgcolor="{c}"'.format(c=bg) if bg else ''))
html.write("\t<td>{n}</td>\n".format(n=rowCount))
for n, r in enumerate(row):
bg = bgColor(headings[n])
html.write('\t<td align="center"{bg}>{val}</td>\n'.format(bg=' bgcolor={c}'.format(c=bg) if bg else '', val=link(r)))
html.write("</tr>\n")
rowCount = 0
for i,group in enumerate(groups):
if prefs.ignoreDNF and not group.isFitted(): continue
row = group.getRow(headings)
rowCount += 1
html.write("<tr>\n")
if prefs.numberRows:
html.write("\t<td>{n}</td>\n".format(n=rowCount))
for n, r in enumerate(row):
bg = bgColor(headings[n])
html.write('\t<td align="center"{bg}>{val}</td>\n'.format(bg=' bgcolor={c}'.format(c=bg) if bg else '', val=link(r)))
html.write("</tr>\n")
html.write("</table>\n")
html.write("<br><br>\n")
html.write("</body></html>")
except BaseException as e:
print(str(e))
return False
html.write("</table>\n")
html.write("<br><br>\n")
html.write("</body></html>")
return True