From 9152900f6692f761806ea118f3bd1be76b59cb03 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Sun, 2 Aug 2020 17:47:07 +0200 Subject: [PATCH] Simplify code remove superfluous temporary variables `pinlist`, `wirerow` --- src/wireviz/Harness.py | 43 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index c46e157..6c99fa7 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -106,28 +106,27 @@ class Harness: html = [x.replace('>', colorbar) for x in html] if connector.style != 'simple': - pinlist = [] pinhtml = [] + pinhtml.append('') + for pin, pinlabel in zip(connector.pins, connector.pinlabels): if connector.hide_disconnected_pins and not connector.visible_pins.get(pin, False): continue - pinlist.append([f'' if connector.ports_left else None, - f'' if pinlabel else '', - f'' if connector.ports_right else None]) - - pinhtml.append('
{pin}{pinlabel}{pin}
') - for i, pin in enumerate(pinlist): pinhtml.append('') - for column in pin: - if column is not None: - pinhtml.append(f'{column}') + if connector.ports_left: + pinhtml.append(f'') + if pinlabel: + pinhtml.append(f'') + if connector.ports_right: + pinhtml.append(f'') pinhtml.append('') + pinhtml.append('
{pin}{pinlabel}{pin}
') + pinhtml = '\n'.join(pinhtml) html = [x.replace('', pinhtml) for x in html] html = '\n'.join(html) - dot.node(connector.name, label=f'<\n{html}\n>', shape='none', margin='0', style='filled', fillcolor='white') if len(connector.loops) > 0: @@ -187,19 +186,17 @@ class Harness: wirehtml.append(' ') for i, connection_color in enumerate(cable.colors, 1): - wirerow = [f'', - wv_colors.translate_color(connection_color, self.color_mode), - f''] wirehtml.append('') - for cell in wirerow: - wirehtml.append(f'{cell}') + wirehtml.append(f'') + wirehtml.append(f'{wv_colors.translate_color(connection_color, self.color_mode)}') + wirehtml.append(f'') wirehtml.append('') bgcolors = ['#000000'] + get_color_hex(connection_color, pad=pad) + ['#000000'] - wirehtml.append(f'') + wirehtml.append(f'') wirehtml.append('') for j, bgcolor in enumerate(bgcolors[::-1]): # Reverse to match the curved wires when more than 2 colors - wirehtml.append(f'') + wirehtml.append(f'') wirehtml.append('
') wirehtml.append('') 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)) # print parameters into a table row under the wire if(len(wireidentification) > 0): - wirehtml.append(f'') + wirehtml.append('') wirehtml.append('') for attrib in wireidentification: wirehtml.append(f'') @@ -222,11 +219,11 @@ class Harness: wirehtml.append('') if cable.shield: - wirerow = ['', 'Shield', ''] wirehtml.append('') # spacer wirehtml.append('') - for cell in wirerow: - wirehtml.append(f'') + wirehtml.append('') + wirehtml.append('') + wirehtml.append('') wirehtml.append('') if isinstance(cable.shield, str): # shield is shown with specified color and black borders @@ -235,7 +232,7 @@ class Harness: else: # shield is shown as a thin black wire attributes = f'height="2" bgcolor="#000000" border="0"' - wirehtml.append(f'') + wirehtml.append(f'') wirehtml.append('') wirehtml.append('
{attrib}
 
{cell}Shield
 
')