Remove old stuff, slightly simplify code

This commit is contained in:
Daniel Rojas 2021-10-18 17:29:25 +02:00 committed by KV
parent d65222953e
commit 0078a18953

View File

@ -116,6 +116,21 @@ def gv_node_component(
return tbl return tbl
def make_list_of_cells(inp) -> List[Td]:
# inp may be List,
if isinstance(inp, List):
# ensure all list items are Td
list_out = [item if isinstance(item, Td) else Td(item) for item in inp]
return list_out
else:
if inp is None:
return []
if isinstance(inp, Td):
return [inp]
else:
return [Td(inp)]
def nested_table(cell_lists: List[Td]) -> Table: def nested_table(cell_lists: List[Td]) -> Table:
outer_table_attribs = { outer_table_attribs = {
"border": 0, "border": 0,
@ -156,21 +171,6 @@ def nested_table(cell_lists: List[Td]) -> Table:
return tbl return tbl
def make_list_of_cells(inp) -> List[Td]:
# inp may be List,
if isinstance(inp, List):
# ensure all list items are Td
list_out = [item if isinstance(item, Td) else Td(item) for item in inp]
return list_out
else:
if inp is None:
return []
if isinstance(inp, Td):
return [inp]
else:
return [Td(inp)]
def gv_pin_row(pin_index, pin_name, pin_label, pin_color, connector): def gv_pin_row(pin_index, pin_name, pin_label, pin_color, connector):
cell_pin_left = Td(pin_name, attribs={"port": f"p{pin_index+1}l"}) cell_pin_left = Td(pin_name, attribs={"port": f"p{pin_index+1}l"})
cell_pin_label = Td(pin_label, empty_is_none=True) cell_pin_label = Td(pin_label, empty_is_none=True)
@ -276,6 +276,18 @@ def colored_cell(contents, bgcolor) -> Td:
return Td(contents, attribs=attribs) return Td(contents, attribs=attribs)
def part_number_str_list(component: Component) -> List[str]:
cell_contents = [
pn_info_string(HEADER_PN, None, component.pn),
pn_info_string(HEADER_MPN, component.manufacturer, component.mpn),
pn_info_string(HEADER_SPN, component.supplier, component.spn),
]
if any(cell_contents):
return [html_line_breaks(cell) for cell in cell_contents]
else:
return None
def colorbar_cell(color) -> Td: def colorbar_cell(color) -> Td:
if color: if color:
colorbar_attribs = { colorbar_attribs = {
@ -287,15 +299,6 @@ def colorbar_cell(color) -> Td:
return None return None
# def html_image_new(image):
# from wireviz.DataClasses import Image
# if not image:
# return None
# image_tag = Img(attribs={"scale": image.scale, "src": image.src})
# image_table = Table(Tr(Td(image_tag, attribs=html_size_attr_dict(image))), attribs={"border": 0, "cellspacing": 0, "cellborder": 0})
# return image_table
def image_and_caption_cells(component: Component) -> (Td, Td): def image_and_caption_cells(component: Component) -> (Td, Td):
if not component.image: if not component.image:
return (None, None) return (None, None)
@ -326,65 +329,15 @@ def image_and_caption_cells(component: Component) -> (Td, Td):
image_cell.attribs = Attribs(outer_cell_attribs) image_cell.attribs = Attribs(outer_cell_attribs)
if component.image.caption: if component.image.caption:
caption_cell_attribs = {"balign": "left", "sides": "BLR", "id": "td_caption"}
caption_cell = Td( caption_cell = Td(
html_caption_new(component.image), attribs=caption_cell_attribs f"{html_line_breaks(component.image.caption)}",
attribs={"balign": "left", "sides": "BLR", "id": "td_caption"},
) )
else: else:
caption_cell = None caption_cell = None
return (image_cell, caption_cell) return (image_cell, caption_cell)
def part_number_str_list(component: Component) -> List[str]:
cell_contents = [
pn_info_string(HEADER_PN, None, component.pn),
pn_info_string(HEADER_MPN, component.manufacturer, component.mpn),
pn_info_string(HEADER_SPN, component.supplier, component.spn),
]
if any(cell_contents):
return [html_line_breaks(cell) for cell in cell_contents]
else:
return None
# def html_image(image):
# from wireviz.DataClasses import Image
# if not image:
# return None
# # The leading attributes belong to the preceeding tag. See where used below.
# html = f'{html_size_attr(image)}><img scale="{image.scale}" src="{image.src}"/>'
# if image.fixedsize:
# # Close the preceeding tag and enclose the image cell in a table without
# # borders to avoid narrow borders when the fixed width < the node width.
# html = f""">
# <table border="0" cellspacing="0" cellborder="0"><tr>
# <td{html}</td>
# </tr></table>
# """
# return f"""<tdX{' sides="TLR"' if image.caption else ''}{html_bgcolor_attr(image.bgcolor)}{html}"""
def html_caption_new(image):
from wireviz.DataClasses import Image
return f"{html_line_breaks(image.caption)}" if image and image.caption else None
# def html_size_attr(image):
# from wireviz.DataClasses import Image
#
# # Return Graphviz HTML attributes to specify minimum or fixed size of a TABLE or TD object
# return (
# (
# (f' width="{image.width}"' if image.width else "")
# + (f' height="{image.height}"' if image.height else "")
# + (' fixedsize="true"' if image.fixedsize else "")
# )
# if image
# else ""
# )
def html_size_attr_dict(image): def html_size_attr_dict(image):
# Return Graphviz HTML attributes to specify minimum or fixed size of a TABLE or TD object # Return Graphviz HTML attributes to specify minimum or fixed size of a TABLE or TD object
from wireviz.DataClasses import Image from wireviz.DataClasses import Image