Skip to content

Commit 4406816

Browse files
committed
Add option to add colors to connector pins (#141)
1 parent e2e8bbf commit 4406816

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/wireviz/DataClasses.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class Connector:
7878
notes: Optional[str] = None
7979
pinlabels: List[Any] = field(default_factory=list)
8080
pins: List[Any] = field(default_factory=list)
81+
pincolors: List[Any] = field(default_factory=list)
8182
color: Optional[str] = None
8283
show_name: bool = None
8384
show_pincount: bool = None
@@ -122,6 +123,9 @@ def __post_init__(self):
122123
if len(self.pins) != len(set(self.pins)):
123124
raise Exception('Pins are not unique')
124125

126+
if self.pincolors:
127+
self.pincolors.extend(["--"] * (len(self.pins) - len(self.pincolors))) # autofill missing pincolors as 'no color'
128+
125129
if self.show_name is None:
126130
self.show_name = not self.autogenerate # hide auto-generated designators by default
127131

src/wireviz/Harness.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,28 @@ def create_graph(self) -> Graph:
110110
pinhtml = []
111111
pinhtml.append('<table border="0" cellspacing="0" cellpadding="3" cellborder="1">')
112112

113-
for pin, pinlabel in zip(connector.pins, connector.pinlabels):
113+
# TODO: How to solve more elegantly?
114+
if connector.pincolors:
115+
pincolorlist = connector.pincolors
116+
else:
117+
pincolorlist = ['--'] * len(connector.pins) # currently need this list for use in zip function below
118+
119+
for pin, pinlabel, pincolor in zip(connector.pins, connector.pinlabels, pincolorlist):
114120
if connector.hide_disconnected_pins and not connector.visible_pins.get(pin, False):
115121
continue
116122
pinhtml.append(' <tr>')
117123
if connector.ports_left:
118124
pinhtml.append(f' <td port="p{pin}l">{pin}</td>')
119125
if pinlabel:
120126
pinhtml.append(f' <td>{pinlabel}</td>')
127+
if connector.pincolors:
128+
if pincolor in wv_colors._color_hex.keys():
129+
pinhtml.append(f'<td sides="tbl">{pincolor}</td>')
130+
pinhtml.append(f'<td sides="tbr"><table border="0" cellborder="1"><tr><td bgcolor="{wv_colors.translate_color(pincolor, "HEX")}" width="8" height="8" fixedsize="true"></td></tr></table></td>')
131+
else:
132+
pinhtml.append(f'<td sides="tbl"></td>')
133+
pinhtml.append(f'<td sides="tbr"></td>')
134+
121135
if connector.ports_right:
122136
pinhtml.append(f' <td port="p{pin}r">{pin}</td>')
123137
pinhtml.append(' </tr>')

0 commit comments

Comments
 (0)