Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to add colors to connector pins #141

Merged
merged 4 commits into from
Nov 14, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
formatc1702 marked this conversation as resolved.
Show resolved Hide resolved
color: Optional[Color] = None
show_name: Optional[bool] = None
show_pincount: Optional[bool] = None
Expand All @@ -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:
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')
formatc1702 marked this conversation as resolved.
Show resolved Hide resolved

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
formatc1702 marked this conversation as resolved.
Show resolved Hide resolved
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')
Expand Down
10 changes: 9 additions & 1 deletion src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from collections import Counter
from typing import List, Union
from pathlib import Path
from itertools import zip_longest
import re


Expand Down Expand Up @@ -110,14 +111,21 @@ 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):
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(' <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>')
formatc1702 marked this conversation as resolved.
Show resolved Hide resolved
else:
pinhtml.append(f' <td colspan="2"></td>')
formatc1702 marked this conversation as resolved.
Show resolved Hide resolved

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