From 711704dde9cb5a1c37daa87f278bf8dfec001061 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Fri, 23 Oct 2020 18:39:41 +0200 Subject: [PATCH 1/4] Add option to define connector pin colors (#141) --- src/wireviz/DataClasses.py | 4 ++++ src/wireviz/Harness.py | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index a9ce303f..30c589c3 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -96,6 +96,7 @@ class Connector: notes: Optional[MultilineHypertext] = None pinlabels: List[Pin] = field(default_factory=list) pins: List[Pin] = field(default_factory=list) + pincolors: List[Color] = field(default_factory=list) color: Optional[Color] = None show_name: Optional[bool] = None show_pincount: Optional[bool] = None @@ -140,6 +141,9 @@ def __post_init__(self) -> None: if len(self.pins) != len(set(self.pins)): raise Exception('Pins are not unique') + if self.pincolors: + self.pincolors.extend([None] * (len(self.pins) - len(self.pincolors))) # autofill missing pincolors as 'no color' + if self.show_name is None: self.show_name = not self.autogenerate # hide auto-generated designators by default diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 835ed651..b167a159 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -110,7 +110,9 @@ def create_graph(self) -> Graph: pinhtml = [] pinhtml.append('') - for pin, pinlabel in zip(connector.pins, connector.pinlabels): + for pin, pinlabel, pincolor in zip(connector.pins, + connector.pinlabels, + connector.pincolors if connector.pincolors else [None] * len(connector.pins)): if connector.hide_disconnected_pins and not connector.visible_pins.get(pin, False): continue pinhtml.append(' ') @@ -118,6 +120,14 @@ def create_graph(self) -> Graph: pinhtml.append(f' ') if pinlabel: pinhtml.append(f' ') + if connector.pincolors: + if pincolor in wv_colors._color_hex.keys(): + pinhtml.append(f'') + pinhtml.append(f'') + else: + pinhtml.append(f'') + pinhtml.append(f'') + if connector.ports_right: pinhtml.append(f' ') pinhtml.append(' ') From 4eea76736f724d4f4f24636bdf7d788de3f6eeef Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Tue, 10 Nov 2020 19:36:42 +0100 Subject: [PATCH 2/4] Implement changes suggested by @kvid --- src/wireviz/DataClasses.py | 18 +++--------------- src/wireviz/Harness.py | 12 +++++------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index 30c589c3..a138064f 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -120,30 +120,18 @@ def __post_init__(self) -> None: raise Exception('Connectors with style set to simple may only have one pin') self.pincount = 1 - if self.pincount is None: - if self.pinlabels: - self.pincount = len(self.pinlabels) - elif self.pins: - self.pincount = len(self.pins) - else: + if not self.pincount: + if not self.pins and not self.pinlabels: raise Exception('You need to specify at least one, pincount, pins or pinlabels') - - if self.pinlabels and self.pins: - if len(self.pinlabels) != len(self.pins): - raise Exception('Given pins and pinlabels size mismatch') + self.pincount = max(len(self.pins), len(self.pinlabels), len(self.pincolors)) # create default lists for pins (sequential) and pinlabels (blank) if not specified if not self.pins: self.pins = list(range(1, self.pincount + 1)) - if not self.pinlabels: - self.pinlabels = [''] * self.pincount if len(self.pins) != len(set(self.pins)): raise Exception('Pins are not unique') - if self.pincolors: - self.pincolors.extend([None] * (len(self.pins) - len(self.pincolors))) # autofill missing pincolors as 'no color' - if self.show_name is None: self.show_name = not self.autogenerate # hide auto-generated designators by default diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index b167a159..bbc68b79 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -12,6 +12,7 @@ from collections import Counter from typing import List, Union from pathlib import Path +from itertools import zip_longest import re @@ -110,9 +111,7 @@ def create_graph(self) -> Graph: pinhtml = [] pinhtml.append('
{pin}{pinlabel}{pincolor}
{pin}
') - for pin, pinlabel, pincolor in zip(connector.pins, - connector.pinlabels, - connector.pincolors if connector.pincolors else [None] * len(connector.pins)): + for pin, pinlabel, pincolor in zip_longest(connector.pins, connector.pinlabels, connector.pincolors): if connector.hide_disconnected_pins and not connector.visible_pins.get(pin, False): continue pinhtml.append(' ') @@ -122,11 +121,10 @@ def create_graph(self) -> Graph: pinhtml.append(f' ') if connector.pincolors: if pincolor in wv_colors._color_hex.keys(): - pinhtml.append(f'') - pinhtml.append(f'') + pinhtml.append(f' ') + pinhtml.append(f' ') else: - pinhtml.append(f'') - pinhtml.append(f'') + pinhtml.append(f' ') if connector.ports_right: pinhtml.append(f' ') From 03a207de92ea0758d291fcde1c2e7705424d66be Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Wed, 11 Nov 2020 15:00:32 +0100 Subject: [PATCH 3/4] Add more suggestions by @kvid --- src/wireviz/DataClasses.py | 2 +- src/wireviz/Harness.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index a138064f..bdc5be93 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -125,7 +125,7 @@ def __post_init__(self) -> None: raise Exception('You need to specify at least one, pincount, pins or pinlabels') self.pincount = max(len(self.pins), len(self.pinlabels), len(self.pincolors)) - # create default lists for pins (sequential) and pinlabels (blank) if not specified + # create default list for pins (sequential) if not specified if not self.pins: self.pins = list(range(1, self.pincount + 1)) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index bbc68b79..be8cf1a5 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -122,9 +122,13 @@ def create_graph(self) -> Graph: if connector.pincolors: if pincolor in wv_colors._color_hex.keys(): pinhtml.append(f' ') - pinhtml.append(f' ') + pinhtml.append( ' ') else: - pinhtml.append(f' ') + pinhtml.append( ' ') if connector.ports_right: pinhtml.append(f' ') From 0d62b01f31bb437cde8c15c03b6414b7ddf4f284 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Fri, 13 Nov 2020 15:27:15 +0100 Subject: [PATCH 4/4] Add suggestion by @kvid Co-authored-by: kvid --- src/wireviz/DataClasses.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index bdc5be93..35003075 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -121,9 +121,9 @@ def __post_init__(self) -> None: self.pincount = 1 if not self.pincount: - if not self.pins and not self.pinlabels: - raise Exception('You need to specify at least one, pincount, pins or pinlabels') self.pincount = max(len(self.pins), len(self.pinlabels), len(self.pincolors)) + if not self.pincount: + raise Exception('You need to specify at least one, pincount, pins, pinlabels, or pincolors') # create default list for pins (sequential) if not specified if not self.pins:
{pinlabel}{pincolor}
{pincolor}
{pin}{pincolor}
') + pinhtml.append( ' ') + pinhtml.append(f' ') + pinhtml.append( '
') + pinhtml.append( '
{pin}