Test additional component table (WIP)
This commit is contained in:
parent
26b505120a
commit
1799490bf2
@ -7,6 +7,7 @@ from pathlib import Path
|
||||
from wireviz.wv_helper import int2tuple, aspect_ratio
|
||||
from wireviz.wv_colors import Color, Colors, ColorMode, ColorScheme, COLOR_CODES
|
||||
from wireviz.wv_bom_new import Bom_hash, Bom_hash_list
|
||||
from wireviz.wv_gv_html import nested_html_table, bom_bubble
|
||||
|
||||
# Each type alias have their legal values described in comments - validation might be implemented in the future
|
||||
PlainText = str # Text not containing HTML tags nor newlines
|
||||
@ -180,6 +181,15 @@ class TopLevelGraphicalComponent(GraphicalComponent):
|
||||
|
||||
show_name: bool = True
|
||||
|
||||
def gen_add_bom_table(self):
|
||||
if self.additional_components:
|
||||
rows = []
|
||||
for comp in self.additional_components:
|
||||
rows.append([bom_bubble(comp.bom_id), comp.qty, comp.description, comp.pn])
|
||||
return rows
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
@dataclass
|
||||
class Connector(TopLevelGraphicalComponent):
|
||||
@ -241,7 +251,6 @@ class Connector(TopLevelGraphicalComponent):
|
||||
def activate_pin(self, pin: Pin) -> None:
|
||||
self.visible_pins[pin] = True
|
||||
|
||||
@property
|
||||
def qty_factor(self, qty_multiplier: Optional[ConnectorMultiplier]) -> int:
|
||||
if not qty_multiplier:
|
||||
return 1
|
||||
@ -376,7 +385,6 @@ class Cable(TopLevelGraphicalComponent):
|
||||
for i, _ in enumerate(from_pin):
|
||||
self.connections.append(Connection(from_name, from_pin[i], via_wire[i], to_name, to_pin[i]))
|
||||
|
||||
@property
|
||||
def qty_factor(self, qty_multiplier: Optional[CableMultiplier]) -> float:
|
||||
if not qty_multiplier:
|
||||
return 1
|
||||
|
||||
@ -13,14 +13,14 @@ from wireviz.DataClasses import AdditionalComponent, Metadata, Options, Tweak, C
|
||||
from wireviz.wv_colors import get_color_hex, translate_color
|
||||
from wireviz.wv_gv_html import nested_html_table, \
|
||||
html_bgcolor_attr, html_bgcolor, html_colorbar, \
|
||||
html_image, html_caption, remove_links, html_line_breaks, bom_bubble
|
||||
html_image, html_caption, remove_links, html_line_breaks, bom_bubble, html_table
|
||||
# from wireviz.wv_bom import pn_info_string, component_table_entry, \
|
||||
# get_additional_component_table, bom_list, generate_bom, \
|
||||
# HEADER_PN, HEADER_MPN, HEADER_SPN
|
||||
from wireviz.wv_bom_new import pn_info_string, HEADER_PN, HEADER_MPN, HEADER_SPN
|
||||
from wireviz.wv_html import generate_html_output
|
||||
from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, flatten2d, \
|
||||
open_file_read, open_file_write
|
||||
open_file_read, open_file_write, remove_empty_columns
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -192,9 +192,10 @@ class Harness:
|
||||
html_colorbar(connector.color)],
|
||||
'<!-- connector table -->' if connector.style != 'simple' else None,
|
||||
[html_image(connector.image)],
|
||||
[html_caption(connector.image)]]
|
||||
[html_caption(connector.image)],
|
||||
html_table(remove_empty_columns(connector.gen_add_bom_table()), 2)]
|
||||
# rows.extend(get_additional_component_table(self, connector))
|
||||
rows.append(['Reimplement additional component table!'])
|
||||
# rows.append()
|
||||
rows.append([html_line_breaks(connector.notes)])
|
||||
html.extend(nested_html_table(rows, html_bgcolor_attr(connector.bgcolor)))
|
||||
|
||||
@ -522,8 +523,8 @@ class Harness:
|
||||
bomlist = [[]]
|
||||
# HTML output
|
||||
generate_html_output(filename, bomlist, self.metadata, self.options)
|
||||
|
||||
def bom(self):
|
||||
if not self._bom:
|
||||
self._bom = generate_bom(self)
|
||||
return self._bom
|
||||
#
|
||||
# def bom(self):
|
||||
# if not self._bom:
|
||||
# self._bom = generate_bom(self)
|
||||
# return self._bom
|
||||
|
||||
@ -32,6 +32,18 @@ def nested_html_table(rows: List[Union[str, List[Optional[str]], None]], table_a
|
||||
html.append('</table>')
|
||||
return html
|
||||
|
||||
def html_table(rows: List[List[str]], indent_level: int = 0) -> str:
|
||||
html = []
|
||||
html.append('<table border="0" cellspacing="0" cellpadding="3" cellborder="1">')
|
||||
for row in rows:
|
||||
html.append(' <tr>')
|
||||
for item in row:
|
||||
html.append(f' <td>{item}</td>')
|
||||
html.append(' </tr>')
|
||||
html.append('</table>')
|
||||
html = [' '*indent_level + row for row in html]
|
||||
return '\n'.join(html)
|
||||
|
||||
def html_bgcolor_attr(color: Color) -> str:
|
||||
"""Return attributes for bgcolor or '' if no color."""
|
||||
return f' bgcolor="{translate_color(color, "HEX")}"' if color else ''
|
||||
@ -75,6 +87,5 @@ def html_size_attr(image):
|
||||
def html_line_breaks(inp):
|
||||
return remove_links(inp).replace('\n', '<br />') if isinstance(inp, str) else inp
|
||||
|
||||
|
||||
def bom_bubble(inp):
|
||||
return(f'<table border="0"><tr><td border="1" style="rounded">{inp}</td></tr></table>')
|
||||
|
||||
@ -116,3 +116,9 @@ def aspect_ratio(image_src):
|
||||
except Exception as error:
|
||||
print(f'aspect_ratio(): {type(error).__name__}: {error}')
|
||||
return 1 # Assume 1:1 when unable to read actual image size
|
||||
|
||||
def remove_empty_columns(inp: List[List]) -> List[List]:
|
||||
transp = list(map(list, zip(*inp))) # transpose list
|
||||
transp = [item for item in transp if any(item)] # remove empty rows (easier)
|
||||
out = list(map(list, zip(*transp))) # transpose back
|
||||
return out
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user