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