connector: support image and notes
This commit is contained in:
parent
1b9ba0b03f
commit
3a3f609c41
39
src/wireviz/templates/connector.html
generated
39
src/wireviz/templates/connector.html
generated
@ -7,11 +7,28 @@
|
||||
<table border="0" cellborder="1" cellspacing="0" cellpadding="3" bgcolor="#FFFFFF">
|
||||
<tr>
|
||||
<td colspan="2"> <b> {{ designator }} </b> </td>
|
||||
<!-- <td> BOM: {{ bom_id }} </td> !-->
|
||||
{% if bom_id %}
|
||||
<td> BOM: {{ bom_id }} </td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- Part Number !-->
|
||||
{% if line_pn %}
|
||||
<tr>
|
||||
<td>
|
||||
<table border="0" cellborder="1" cellpadding="3" cellspacing="0">
|
||||
<tr>
|
||||
{% for item in line_pn %}
|
||||
<td> {{item}} </td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<!-- Info !-->
|
||||
<tr>
|
||||
<td>
|
||||
<table border="0" cellborder="1" cellpadding="3" cellspacing="0">
|
||||
@ -43,6 +60,26 @@
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- Image !-->
|
||||
{% if image %}
|
||||
<tr>
|
||||
<td>
|
||||
{% include "images.html" %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<!-- Additional Components !-->
|
||||
<!-- Notes !-->
|
||||
{% if line_notes %}
|
||||
<tr>
|
||||
<td>
|
||||
<table border="0" cellborder="1" cellpadding="3" cellspacing="0">
|
||||
<tr>
|
||||
<td> {{ line_notes }} </td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</table>
|
||||
|
||||
|
||||
16
src/wireviz/templates/images.html
generated
Normal file
16
src/wireviz/templates/images.html
generated
Normal file
@ -0,0 +1,16 @@
|
||||
{% if image %}
|
||||
<table border="0" cellborder="0" cellpadding="3" cellspacing="0" >
|
||||
<tr>
|
||||
<td balign="left" sides="TLR"><img scale="{{ image.scale }}" src="{{ image.src }}" /></td>
|
||||
</tr>
|
||||
{% if image.caption %}
|
||||
<tr>
|
||||
<td balign="left" sides="BLR">
|
||||
{{ image.caption }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</table>
|
||||
{% else %}
|
||||
<!-- No Image Defined !-->
|
||||
{% endif %}
|
||||
@ -46,6 +46,35 @@ def gv_pin_row(pin, connector) -> Tr:
|
||||
]
|
||||
return Tr(cells)
|
||||
|
||||
def image_and_caption_cells(component: Component) -> (Td, Td):
|
||||
if not component.image:
|
||||
return (None, None)
|
||||
|
||||
image_tag = Img(scale=component.image.scale, src=component.image.src)
|
||||
image_cell_inner = Td(image_tag, flat=True)
|
||||
if component.image.fixedsize:
|
||||
# further nest the image in a table with width/height/fixedsize parameters,
|
||||
# and place that table in a cell
|
||||
image_cell = Td(
|
||||
Table(Tr(image_cell_inner), border=0, cellborder=0, cellspacing=0, id="!")
|
||||
)
|
||||
else:
|
||||
image_cell = image_cell_inner
|
||||
|
||||
image_cell.update_attribs(
|
||||
balign="left",
|
||||
bgcolor=component.image.bgcolor.html,
|
||||
sides="TLR" if component.image.caption else None,
|
||||
)
|
||||
|
||||
if component.image.caption:
|
||||
caption_cell = Td(
|
||||
f"{html_line_breaks(component.image.caption)}", balign="left", sides="BLR"
|
||||
)
|
||||
else:
|
||||
caption_cell = None
|
||||
return (image_cell, caption_cell)
|
||||
|
||||
def gv_node_connector(connector: Connector) -> Table:
|
||||
pins = []
|
||||
use_left = bool(connector.ports_left)
|
||||
@ -64,10 +93,12 @@ def gv_node_connector(connector: Connector) -> Table:
|
||||
'has_pincolors': has_pincolors,
|
||||
})
|
||||
columns = 2 + (1 if use_left else 0) + (1 if use_right else 0)
|
||||
# TODO: group per line/item
|
||||
params = {
|
||||
'designator': f"{remove_links(connector.designator)}",
|
||||
'use_left': use_left,
|
||||
'use_right': use_right,
|
||||
'line_pn': partnumbers2list(connector.partnumbers),
|
||||
'pins': pins,
|
||||
'columns': columns,
|
||||
'bom_id': connector.bom_entry.id,
|
||||
@ -78,6 +109,8 @@ def gv_node_connector(connector: Connector) -> Table:
|
||||
'show_pincount': connector.show_pincount,
|
||||
'color': connector.color,
|
||||
'color_len': len(connector.color),
|
||||
'image': connector.image,
|
||||
'line_notes': html_line_breaks(connector.notes),
|
||||
}
|
||||
# TODO: extend connector style support
|
||||
is_simple_connector = connector.style == 'simple'
|
||||
@ -522,52 +555,6 @@ def color_minitable(color: Optional[MultiColor]) -> Union[Table, str]:
|
||||
)
|
||||
|
||||
|
||||
def image_and_caption_cells(component: Component) -> (Td, Td):
|
||||
if not component.image:
|
||||
return (None, None)
|
||||
|
||||
image_tag = Img(scale=component.image.scale, src=component.image.src)
|
||||
image_cell_inner = Td(image_tag, flat=True)
|
||||
if component.image.fixedsize:
|
||||
# further nest the image in a table with width/height/fixedsize parameters,
|
||||
# and place that table in a cell
|
||||
image_cell_inner.update_attribs(**html_size_attr_dict(component.image))
|
||||
image_cell = Td(
|
||||
Table(Tr(image_cell_inner), border=0, cellborder=0, cellspacing=0, id="!")
|
||||
)
|
||||
else:
|
||||
image_cell = image_cell_inner
|
||||
|
||||
image_cell.update_attribs(
|
||||
balign="left",
|
||||
bgcolor=component.image.bgcolor.html,
|
||||
sides="TLR" if component.image.caption else None,
|
||||
)
|
||||
|
||||
if component.image.caption:
|
||||
caption_cell = Td(
|
||||
f"{html_line_breaks(component.image.caption)}", balign="left", sides="BLR"
|
||||
)
|
||||
else:
|
||||
caption_cell = None
|
||||
return (image_cell, caption_cell)
|
||||
|
||||
|
||||
def html_size_attr_dict(image):
|
||||
# Return Graphviz HTML attributes to specify minimum or fixed size of a TABLE or TD object
|
||||
pass
|
||||
|
||||
attr_dict = {}
|
||||
if image:
|
||||
if image.width:
|
||||
attr_dict["width"] = image.width
|
||||
if image.height:
|
||||
attr_dict["height"] = image.height
|
||||
if image.fixedsize:
|
||||
attr_dict["fixedsize"] = "true"
|
||||
return attr_dict
|
||||
|
||||
|
||||
def set_dot_basics(dot, options):
|
||||
dot.body.append(f"// Graph generated by {APP_NAME} {__version__}\n")
|
||||
dot.body.append(f"// {APP_URL}\n")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user