Skip to content

Commit

Permalink
Add option to add colors to connector pins (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
formatc1702 committed Oct 23, 2020
1 parent e2e8bbf commit 4406816
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Connector:
notes: Optional[str] = None
pinlabels: List[Any] = field(default_factory=list)
pins: List[Any] = field(default_factory=list)
pincolors: List[Any] = field(default_factory=list)
color: Optional[str] = None
show_name: bool = None
show_pincount: bool = None
Expand Down Expand Up @@ -122,6 +123,9 @@ def __post_init__(self):
if len(self.pins) != len(set(self.pins)):
raise Exception('Pins are not unique')

if self.pincolors:
self.pincolors.extend(["--"] * (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

Expand Down
16 changes: 15 additions & 1 deletion src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,28 @@ def create_graph(self) -> Graph:
pinhtml = []
pinhtml.append('<table border="0" cellspacing="0" cellpadding="3" cellborder="1">')

for pin, pinlabel in zip(connector.pins, connector.pinlabels):
# TODO: How to solve more elegantly?
if connector.pincolors:
pincolorlist = connector.pincolors
else:
pincolorlist = ['--'] * len(connector.pins) # currently need this list for use in zip function below

for pin, pinlabel, pincolor in zip(connector.pins, connector.pinlabels, pincolorlist):
if connector.hide_disconnected_pins and not connector.visible_pins.get(pin, False):
continue
pinhtml.append(' <tr>')
if connector.ports_left:
pinhtml.append(f' <td port="p{pin}l">{pin}</td>')
if pinlabel:
pinhtml.append(f' <td>{pinlabel}</td>')
if connector.pincolors:
if pincolor in wv_colors._color_hex.keys():
pinhtml.append(f'<td sides="tbl">{pincolor}</td>')
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>')
else:
pinhtml.append(f'<td sides="tbl"></td>')
pinhtml.append(f'<td sides="tbr"></td>')

if connector.ports_right:
pinhtml.append(f' <td port="p{pin}r">{pin}</td>')
pinhtml.append(' </tr>')
Expand Down

0 comments on commit 4406816

Please sign in to comment.