import columns from component import * import os BG_GEN = "#E6FFEE" BG_KICAD = "#FFE6B3" BG_USER = "#E6F9FF" #return a background color for a given column title def bgColor(col): #auto-generated columns if col == ColumnList.COL_GRP_QUANTITY: return BG_GEN #kicad protected columns elif col in ColumnList._COLUMNS_PROTECTED: return BG_KICAD #additional user columns else: return BG_USER def link(text): text = str(text) for t in ["http","https","ftp","www"]: if text.startswith(t): return '{t}'.format(t=text) return text """ Write BoM out to a HTML file filename = path to output file (must be a .htm or .html file) groups = [list of ComponentGroup groups] net = netlist object headings = [list of headings to display in the BoM file] prefs = BomPref object """ 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: #header html.write("\n") html.write("\n") #PCB info html.write("

KiBOM PCB Bill of Materials

\n") html.write("
Source File: {source}\n".format(source=net.getSource())) html.write("
Date: {date}\n".format(date=net.getDate())) html.write("
Schematic Version: {version}\n".format(version=net.getVersion())) html.write("
Total Components: {n}\n".format(n = sum([g.getCount() for g in groups]))) html.write("
Component Groups: {n}\n".format(n=len(groups))) html.write("
\n") html.write("

Component Groups

\n") html.write('

Kicad Fields (default)

\n'.format(bg=BG_KICAD)) html.write('

Generated Fields

\n'.format(bg=BG_GEN)) html.write('

User Fields

\n'.format(bg=BG_USER)) #component groups html.write('\n') #row titles: html.write("\n") if prefs.numberRows: html.write("\t\n") for i,h in enumerate(headings): #cell background color bg = bgColor(h) html.write('\t\n'.format( h=h, bg = ' bgcolor="{c}"'.format(c=bg) if bg else '')) html.write("\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("\n") if prefs.numberRows: html.write("\t\n".format(n=rowCount)) for n, r in enumerate(row): bg = bgColor(headings[n]) html.write('\t\n'.format(bg=' bgcolor={c}'.format(c=bg) if bg else '', val=link(r))) html.write("\n") html.write("
{h}
{n}{val}
\n") html.write("

\n") html.write("") except BaseException as e: print(str(e)) return False return True