From 78cfcd16c06789a00b4e5062bd9a6d6b54d260c8 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Thu, 6 Aug 2020 09:24:48 -0300 Subject: [PATCH] Added option to disable the red color for empty cells. Applies only when using colors for column types. Is for HTML and XLSX --- kiplot/bom/html_writer.py | 6 ++++-- kiplot/bom/xlsx_writer.py | 10 ++++++---- kiplot/out_bom.py | 4 ++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/kiplot/bom/html_writer.py b/kiplot/bom/html_writer.py index 20a21d31..c1ec1e29 100644 --- a/kiplot/bom/html_writer.py +++ b/kiplot/bom/html_writer.py @@ -98,6 +98,7 @@ def content_table(html, groups, headings, head_names, cfg, link_datasheet, link_ html.write(" \n") rc = 0 + hl_empty = cfg.html.highlight_empty for i, group in enumerate(groups): if (cfg.ignore_dnf and not group.is_fitted()) != dnf: continue @@ -114,7 +115,7 @@ def content_table(html, groups, headings, head_names, cfg, link_datasheet, link_ r = '' + r + '' if col_colors: # Empty cell? - if len(r) == 0 or r.strip() == "~": + if hl_empty and (len(r) == 0 or r.strip() == "~"): cl = 'empty' else: cl = cell_class(headings[n]) @@ -241,7 +242,8 @@ def write_html(filename, groups, headings, head_names, cfg): html.write('KiCad Fields (default)\n') html.write('Generated Fields\n') html.write('User Fields\n') - html.write('Empty Fields\n') + if hl_empty: + html.write('Empty Fields\n') html.write('\n') html.write("") diff --git a/kiplot/bom/xlsx_writer.py b/kiplot/bom/xlsx_writer.py index b68d723a..4ea039fc 100644 --- a/kiplot/bom/xlsx_writer.py +++ b/kiplot/bom/xlsx_writer.py @@ -170,13 +170,14 @@ def insert_logo(worksheet, image_data): return 0 -def create_color_ref(workbook, col_colors, fmt_cols): +def create_color_ref(workbook, col_colors, hl_empty, fmt_cols): if col_colors: worksheet = workbook.add_worksheet('Colors') worksheet.write_string(0, 0, 'KiCad Fields (default)', fmt_cols[0][0]) worksheet.write_string(1, 0, 'Generated Fields', fmt_cols[1][0]) worksheet.write_string(2, 0, 'User Fields', fmt_cols[2][0]) - worksheet.write_string(3, 0, 'Empty Fields', fmt_cols[3][0]) + if hl_empty: + worksheet.write_string(3, 0, 'Empty Fields', fmt_cols[3][0]) worksheet.set_column(0, 0, 50) @@ -252,6 +253,7 @@ def write_xlsx(filename, groups, col_fields, head_names, cfg): # Body row_count += 1 + hl_empty = cfg.xlsx.highlight_empty for i, group in enumerate(groups): if (cfg.ignore_dnf and not group.is_fitted()) != dnf: continue @@ -263,7 +265,7 @@ def write_xlsx(filename, groups, col_fields, head_names, cfg): # Fill the row for i in range(len(row)): cell = row[i] - if len(cell) == 0 or cell.strip() == "~": + if hl_empty and (len(cell) == 0 or cell.strip() == "~"): fmt = col_fmt[-1][row_count % 2] else: fmt = col_fmt[i][row_count % 2] @@ -327,7 +329,7 @@ def write_xlsx(filename, groups, col_fields, head_names, cfg): worksheet.set_landscape() # Add a sheet for the color references - create_color_ref(workbook, cfg.xlsx.col_colors, fmt_cols) + create_color_ref(workbook, cfg.xlsx.col_colors, hl_empty, fmt_cols) workbook.close() return True diff --git a/kiplot/out_bom.py b/kiplot/out_bom.py index 9b4b1f2c..332d066c 100644 --- a/kiplot/out_bom.py +++ b/kiplot/out_bom.py @@ -77,6 +77,8 @@ class BoMHTML(Optionable): """ Hide project information """ self.hide_stats_info = False """ Hide statistics information """ + self.highlight_empty = True + """ Use a color for empty cells. Applies only when `col_colors` is `true` """ self.logo = Optionable """ [string|boolean] PNG file to use as logo, use false to remove """ self.style = 'modern-blue' @@ -143,6 +145,8 @@ class BoMXLSX(Optionable): """ Hide project information """ self.hide_stats_info = False """ Hide statistics information """ + self.highlight_empty = True + """ Use a color for empty cells. Applies only when `col_colors` is `true` """ self.logo = Optionable """ [string|boolean] PNG file to use as logo, use false to remove """ self.max_col_width = 60