From feff47f47b9c0f7121544699bb0b092b563a8e74 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Sat, 14 Nov 2020 09:43:01 +0100 Subject: [PATCH] Add option to add colors to connector pins (#141) --- src/wireviz/DataClasses.py | 20 ++++++-------------- src/wireviz/Harness.py | 14 +++++++++++++- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index a9ce303f..35003075 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 @@ -119,23 +120,14 @@ 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: - 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') + if not self.pincount: + 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 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)) - if not self.pinlabels: - self.pinlabels = [''] * self.pincount if len(self.pins) != len(set(self.pins)): raise Exception('Pins are not unique') diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 835ed651..be8cf1a5 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,7 +111,7 @@ def create_graph(self) -> Graph: pinhtml = [] pinhtml.append('') - for pin, pinlabel in zip(connector.pins, connector.pinlabels): + 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(' ') @@ -118,6 +119,17 @@ 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( ' ') + else: + pinhtml.append( ' ') + if connector.ports_right: pinhtml.append(f' ') pinhtml.append(' ')
{pin}{pinlabel}{pincolor}') + pinhtml.append( ' ') + pinhtml.append(f' ') + pinhtml.append( '
') + pinhtml.append( '
{pin}