Simplify code
remove superfluous temporary variables `pinlist`, `wirerow`
This commit is contained in:
parent
f383afa7ff
commit
9152900f66
@ -106,28 +106,27 @@ class Harness:
|
|||||||
html = [x.replace('><!-- colorbar --></td>', colorbar) for x in html]
|
html = [x.replace('><!-- colorbar --></td>', colorbar) for x in html]
|
||||||
|
|
||||||
if connector.style != 'simple':
|
if connector.style != 'simple':
|
||||||
pinlist = []
|
|
||||||
pinhtml = []
|
pinhtml = []
|
||||||
|
pinhtml.append('<table border="0" cellspacing="0" cellpadding="3" cellborder="1">')
|
||||||
|
|
||||||
for pin, pinlabel in zip(connector.pins, connector.pinlabels):
|
for pin, pinlabel in zip(connector.pins, connector.pinlabels):
|
||||||
if connector.hide_disconnected_pins and not connector.visible_pins.get(pin, False):
|
if connector.hide_disconnected_pins and not connector.visible_pins.get(pin, False):
|
||||||
continue
|
continue
|
||||||
pinlist.append([f'<td port="p{pin}l">{pin}</td>' if connector.ports_left else None,
|
|
||||||
f'<td>{pinlabel}</td>' if pinlabel else '',
|
|
||||||
f'<td port="p{pin}r">{pin}</td>' if connector.ports_right else None])
|
|
||||||
|
|
||||||
pinhtml.append('<table border="0" cellspacing="0" cellpadding="3" cellborder="1">')
|
|
||||||
for i, pin in enumerate(pinlist):
|
|
||||||
pinhtml.append('<tr>')
|
pinhtml.append('<tr>')
|
||||||
for column in pin:
|
if connector.ports_left:
|
||||||
if column is not None:
|
pinhtml.append(f'<td port="p{pin}l">{pin}</td>')
|
||||||
pinhtml.append(f'{column}')
|
if pinlabel:
|
||||||
|
pinhtml.append(f'<td>{pinlabel}</td>')
|
||||||
|
if connector.ports_right:
|
||||||
|
pinhtml.append(f'<td port="p{pin}r">{pin}</td>')
|
||||||
pinhtml.append('</tr>')
|
pinhtml.append('</tr>')
|
||||||
|
|
||||||
pinhtml.append('</table>')
|
pinhtml.append('</table>')
|
||||||
|
|
||||||
pinhtml = '\n'.join(pinhtml)
|
pinhtml = '\n'.join(pinhtml)
|
||||||
html = [x.replace('<!-- connector table -->', pinhtml) for x in html]
|
html = [x.replace('<!-- connector table -->', pinhtml) for x in html]
|
||||||
|
|
||||||
html = '\n'.join(html)
|
html = '\n'.join(html)
|
||||||
|
|
||||||
dot.node(connector.name, label=f'<\n{html}\n>', shape='none', margin='0', style='filled', fillcolor='white')
|
dot.node(connector.name, label=f'<\n{html}\n>', shape='none', margin='0', style='filled', fillcolor='white')
|
||||||
|
|
||||||
if len(connector.loops) > 0:
|
if len(connector.loops) > 0:
|
||||||
@ -187,19 +186,17 @@ class Harness:
|
|||||||
wirehtml.append('<tr><td> </td></tr>')
|
wirehtml.append('<tr><td> </td></tr>')
|
||||||
|
|
||||||
for i, connection_color in enumerate(cable.colors, 1):
|
for i, connection_color in enumerate(cable.colors, 1):
|
||||||
wirerow = [f'<!-- {i}_in -->',
|
|
||||||
wv_colors.translate_color(connection_color, self.color_mode),
|
|
||||||
f'<!-- {i}_out -->']
|
|
||||||
wirehtml.append('<tr>')
|
wirehtml.append('<tr>')
|
||||||
for cell in wirerow:
|
wirehtml.append(f'<td><!-- {i}_in --></td>')
|
||||||
wirehtml.append(f'<td>{cell}</td>')
|
wirehtml.append(f'<td>{wv_colors.translate_color(connection_color, self.color_mode)}</td>')
|
||||||
|
wirehtml.append(f'<td><!-- {i}_out --></td>')
|
||||||
wirehtml.append('</tr>')
|
wirehtml.append('</tr>')
|
||||||
|
|
||||||
bgcolors = ['#000000'] + get_color_hex(connection_color, pad=pad) + ['#000000']
|
bgcolors = ['#000000'] + get_color_hex(connection_color, pad=pad) + ['#000000']
|
||||||
wirehtml.append(f'<tr><td colspan="{len(wirerow)}" border="0" cellspacing="0" cellpadding="0" port="w{i}" height="{(2 * len(bgcolors))}">')
|
wirehtml.append(f'<tr><td colspan="3" border="0" cellspacing="0" cellpadding="0" port="w{i}" height="{(2 * len(bgcolors))}">')
|
||||||
wirehtml.append('<table cellspacing="0" cellborder="0" border="0">')
|
wirehtml.append('<table cellspacing="0" cellborder="0" border="0">')
|
||||||
for j, bgcolor in enumerate(bgcolors[::-1]): # Reverse to match the curved wires when more than 2 colors
|
for j, bgcolor in enumerate(bgcolors[::-1]): # Reverse to match the curved wires when more than 2 colors
|
||||||
wirehtml.append(f'<tr><td colspan="{len(wirerow)}" cellpadding="0" height="2" bgcolor="{bgcolor if bgcolor != "" else wv_colors.default_color}" border="0"></td></tr>')
|
wirehtml.append(f'<tr><td colspan="3" cellpadding="0" height="2" bgcolor="{bgcolor if bgcolor != "" else wv_colors.default_color}" border="0"></td></tr>')
|
||||||
wirehtml.append('</table>')
|
wirehtml.append('</table>')
|
||||||
wirehtml.append('</td></tr>')
|
wirehtml.append('</td></tr>')
|
||||||
if(cable.category == 'bundle'): # for bundles individual wires can have part information
|
if(cable.category == 'bundle'): # for bundles individual wires can have part information
|
||||||
@ -214,7 +211,7 @@ class Harness:
|
|||||||
wireidentification.append(html_line_breaks(manufacturer_info))
|
wireidentification.append(html_line_breaks(manufacturer_info))
|
||||||
# print parameters into a table row under the wire
|
# print parameters into a table row under the wire
|
||||||
if(len(wireidentification) > 0):
|
if(len(wireidentification) > 0):
|
||||||
wirehtml.append(f'<tr><td colspan="{len(wirerow)}">')
|
wirehtml.append('<tr><td colspan="3">')
|
||||||
wirehtml.append('<table border="0" cellspacing="0" cellborder="0"><tr>')
|
wirehtml.append('<table border="0" cellspacing="0" cellborder="0"><tr>')
|
||||||
for attrib in wireidentification:
|
for attrib in wireidentification:
|
||||||
wirehtml.append(f'<td>{attrib}</td>')
|
wirehtml.append(f'<td>{attrib}</td>')
|
||||||
@ -222,11 +219,11 @@ class Harness:
|
|||||||
wirehtml.append('</td></tr>')
|
wirehtml.append('</td></tr>')
|
||||||
|
|
||||||
if cable.shield:
|
if cable.shield:
|
||||||
wirerow = ['<!-- s_in -->', 'Shield', '<!-- s_out -->']
|
|
||||||
wirehtml.append('<tr><td> </td></tr>') # spacer
|
wirehtml.append('<tr><td> </td></tr>') # spacer
|
||||||
wirehtml.append('<tr>')
|
wirehtml.append('<tr>')
|
||||||
for cell in wirerow:
|
wirehtml.append('<td><!-- s_in --></td>')
|
||||||
wirehtml.append(f'<td>{cell}</td>')
|
wirehtml.append('<td>Shield</td>')
|
||||||
|
wirehtml.append('<td><!-- s_out --></td>')
|
||||||
wirehtml.append('</tr>')
|
wirehtml.append('</tr>')
|
||||||
if isinstance(cable.shield, str):
|
if isinstance(cable.shield, str):
|
||||||
# shield is shown with specified color and black borders
|
# shield is shown with specified color and black borders
|
||||||
@ -235,7 +232,7 @@ class Harness:
|
|||||||
else:
|
else:
|
||||||
# shield is shown as a thin black wire
|
# shield is shown as a thin black wire
|
||||||
attributes = f'height="2" bgcolor="#000000" border="0"'
|
attributes = f'height="2" bgcolor="#000000" border="0"'
|
||||||
wirehtml.append(f'<tr><td colspan="{len(wirerow)}" cellpadding="0" {attributes} port="ws"></td></tr>')
|
wirehtml.append(f'<tr><td colspan="3" cellpadding="0" {attributes} port="ws"></td></tr>')
|
||||||
|
|
||||||
wirehtml.append('<tr><td> </td></tr>')
|
wirehtml.append('<tr><td> </td></tr>')
|
||||||
wirehtml.append('</table>')
|
wirehtml.append('</table>')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user