Skip to content

Commit feff47f

Browse files
authored
Add option to add colors to connector pins (#141)
1 parent 64bd34a commit feff47f

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/wireviz/DataClasses.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class Connector:
9696
notes: Optional[MultilineHypertext] = None
9797
pinlabels: List[Pin] = field(default_factory=list)
9898
pins: List[Pin] = field(default_factory=list)
99+
pincolors: List[Color] = field(default_factory=list)
99100
color: Optional[Color] = None
100101
show_name: Optional[bool] = None
101102
show_pincount: Optional[bool] = None
@@ -119,23 +120,14 @@ def __post_init__(self) -> None:
119120
raise Exception('Connectors with style set to simple may only have one pin')
120121
self.pincount = 1
121122

122-
if self.pincount is None:
123-
if self.pinlabels:
124-
self.pincount = len(self.pinlabels)
125-
elif self.pins:
126-
self.pincount = len(self.pins)
127-
else:
128-
raise Exception('You need to specify at least one, pincount, pins or pinlabels')
129-
130-
if self.pinlabels and self.pins:
131-
if len(self.pinlabels) != len(self.pins):
132-
raise Exception('Given pins and pinlabels size mismatch')
123+
if not self.pincount:
124+
self.pincount = max(len(self.pins), len(self.pinlabels), len(self.pincolors))
125+
if not self.pincount:
126+
raise Exception('You need to specify at least one, pincount, pins, pinlabels, or pincolors')
133127

134-
# create default lists for pins (sequential) and pinlabels (blank) if not specified
128+
# create default list for pins (sequential) if not specified
135129
if not self.pins:
136130
self.pins = list(range(1, self.pincount + 1))
137-
if not self.pinlabels:
138-
self.pinlabels = [''] * self.pincount
139131

140132
if len(self.pins) != len(set(self.pins)):
141133
raise Exception('Pins are not unique')

src/wireviz/Harness.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from collections import Counter
1313
from typing import List, Union
1414
from pathlib import Path
15+
from itertools import zip_longest
1516
import re
1617

1718

@@ -110,14 +111,25 @@ def create_graph(self) -> Graph:
110111
pinhtml = []
111112
pinhtml.append('<table border="0" cellspacing="0" cellpadding="3" cellborder="1">')
112113

113-
for pin, pinlabel in zip(connector.pins, connector.pinlabels):
114+
for pin, pinlabel, pincolor in zip_longest(connector.pins, connector.pinlabels, connector.pincolors):
114115
if connector.hide_disconnected_pins and not connector.visible_pins.get(pin, False):
115116
continue
116117
pinhtml.append(' <tr>')
117118
if connector.ports_left:
118119
pinhtml.append(f' <td port="p{pin}l">{pin}</td>')
119120
if pinlabel:
120121
pinhtml.append(f' <td>{pinlabel}</td>')
122+
if connector.pincolors:
123+
if pincolor in wv_colors._color_hex.keys():
124+
pinhtml.append(f' <td sides="tbl">{pincolor}</td>')
125+
pinhtml.append( ' <td sides="tbr">')
126+
pinhtml.append( ' <table border="0" cellborder="1"><tr>')
127+
pinhtml.append(f' <td bgcolor="{wv_colors.translate_color(pincolor, "HEX")}" width="8" height="8" fixedsize="true"></td>')
128+
pinhtml.append( ' </tr></table>')
129+
pinhtml.append( ' </td>')
130+
else:
131+
pinhtml.append( ' <td colspan="2"></td>')
132+
121133
if connector.ports_right:
122134
pinhtml.append(f' <td port="p{pin}r">{pin}</td>')
123135
pinhtml.append(' </tr>')

0 commit comments

Comments
 (0)