Add different color printing modes

YE
ye
YELLOW
yellow
#FFFF00
#ffff00
This commit is contained in:
Daniel Rojas 2020-05-22 16:51:46 +02:00
parent c27f8dc825
commit 719ddd1e0d
2 changed files with 48 additions and 14 deletions

View File

@ -7,6 +7,8 @@ COLORS_I2C = ('BK', 'RD', 'YE', 'GN')
PINOUT_SPI_DATAONLY = ('MISO','MOSI','SCK')
wireviz.color_mode = 'SHORT' # short/SHORT/full/FULL/hex/HEX
# example 1
X1 = wireviz.Node('X1', type='D-Sub', gender='female', pinout=PINOUT_SERIAL, ports_right=True)
X2 = wireviz.Node('X2', type='Molex KK 254', gender='female', num_pins=6, ports_left=True)

View File

@ -2,20 +2,38 @@
COLOR_CODE_DIN = ['WH','BN','GN','YE','GY','PK','BU','RD','BK','VT']
COLOR_CODE_IEC = ['BN','RD','OG','YE','GN','BU','VT','GY','WH','BK']
color_dict = {'BK': '#000000',
'WH': '#ffffff',
'GY': '#808080',
'PK': '#ff80c0',
'RD': '#ff0000',
'OG': '#ff8000',
'YE': '#ffff00',
'GN': '#00ff00',
'TQ': '#00ffff',
'BU': '#0000ff',
'VT': '#8000ff',
'BN': '#666600',
color_hex = {
'BK': '#000000',
'WH': '#ffffff',
'GY': '#808080',
'PK': '#ff80c0',
'RD': '#ff0000',
'OG': '#ff8000',
'YE': '#ffff00',
'GN': '#00ff00',
'TQ': '#00ffff',
'BU': '#0000ff',
'VT': '#8000ff',
'BN': '#666600',
}
color_full = {
'BK': 'black',
'WH': 'white',
'GY': 'grey',
'PK': 'pink',
'RD': 'red',
'OG': 'orange',
'YE': 'yellow',
'GN': 'green',
'TQ': 'turquoise',
'BU': 'blue',
'VT': 'violet',
'BN': 'brown',
}
color_mode = 'SHORT'
class Node:
def __init__(self, name, type=None, gender=None, show_name=True, num_pins=None, pinout=None, ports_left=False, ports_right=False):
@ -213,6 +231,20 @@ class Cable:
else:
l = []
for i,x in enumerate(self.colors,1):
if color_mode == 'full':
x = color_full[x].lower()
elif color_mode == 'FULL':
x = color_hex[x].upper()
elif color_mode == 'hex':
x = color_hex[x].lower()
elif color_mode == 'HEX':
x = color_hex[x].upper()
elif color_mode == 'short':
x = x.lower()
elif color_mode == 'SHORT':
x = x.upper()
else:
raise Exception('Unknown color mode')
l.append('<w{wireno}>{wirecolor}'.format(wireno=i,wirecolor=x))
s = s + '|'.join(l)
if self.shield == True:
@ -237,8 +269,8 @@ class Cable:
s = s + '{'
if isinstance(x[2], int):
search_color = self.colors[x[2]-1]
if search_color in color_dict:
s = s + 'edge[color="#000000:{wire_color}:#000000"] '.format(wire_color=color_dict[search_color])
if search_color in color_hex:
s = s + 'edge[color="#000000:{wire_color}:#000000"] '.format(wire_color=color_hex[search_color])
if x[1] is not None:
t = '{from_name}:p{from_port} -> {via_name}:w{via_wire}{via_subport}; '.format(from_name=x[0],from_port=x[1],via_name=self.name, via_wire=x[2], via_subport='i' if self.show_pinout == True else '')
s = s + t