Add different color printing modes
YE ye YELLOW yellow #FFFF00 #ffff00
This commit is contained in:
parent
c27f8dc825
commit
719ddd1e0d
@ -7,6 +7,8 @@ COLORS_I2C = ('BK', 'RD', 'YE', 'GN')
|
|||||||
|
|
||||||
PINOUT_SPI_DATAONLY = ('MISO','MOSI','SCK')
|
PINOUT_SPI_DATAONLY = ('MISO','MOSI','SCK')
|
||||||
|
|
||||||
|
wireviz.color_mode = 'SHORT' # short/SHORT/full/FULL/hex/HEX
|
||||||
|
|
||||||
# example 1
|
# example 1
|
||||||
X1 = wireviz.Node('X1', type='D-Sub', gender='female', pinout=PINOUT_SERIAL, ports_right=True)
|
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)
|
X2 = wireviz.Node('X2', type='Molex KK 254', gender='female', num_pins=6, ports_left=True)
|
||||||
|
|||||||
@ -2,20 +2,38 @@
|
|||||||
COLOR_CODE_DIN = ['WH','BN','GN','YE','GY','PK','BU','RD','BK','VT']
|
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_CODE_IEC = ['BN','RD','OG','YE','GN','BU','VT','GY','WH','BK']
|
||||||
|
|
||||||
color_dict = {'BK': '#000000',
|
color_hex = {
|
||||||
'WH': '#ffffff',
|
'BK': '#000000',
|
||||||
'GY': '#808080',
|
'WH': '#ffffff',
|
||||||
'PK': '#ff80c0',
|
'GY': '#808080',
|
||||||
'RD': '#ff0000',
|
'PK': '#ff80c0',
|
||||||
'OG': '#ff8000',
|
'RD': '#ff0000',
|
||||||
'YE': '#ffff00',
|
'OG': '#ff8000',
|
||||||
'GN': '#00ff00',
|
'YE': '#ffff00',
|
||||||
'TQ': '#00ffff',
|
'GN': '#00ff00',
|
||||||
'BU': '#0000ff',
|
'TQ': '#00ffff',
|
||||||
'VT': '#8000ff',
|
'BU': '#0000ff',
|
||||||
'BN': '#666600',
|
'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:
|
class Node:
|
||||||
|
|
||||||
def __init__(self, name, type=None, gender=None, show_name=True, num_pins=None, pinout=None, ports_left=False, ports_right=False):
|
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:
|
else:
|
||||||
l = []
|
l = []
|
||||||
for i,x in enumerate(self.colors,1):
|
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))
|
l.append('<w{wireno}>{wirecolor}'.format(wireno=i,wirecolor=x))
|
||||||
s = s + '|'.join(l)
|
s = s + '|'.join(l)
|
||||||
if self.shield == True:
|
if self.shield == True:
|
||||||
@ -237,8 +269,8 @@ class Cable:
|
|||||||
s = s + '{'
|
s = s + '{'
|
||||||
if isinstance(x[2], int):
|
if isinstance(x[2], int):
|
||||||
search_color = self.colors[x[2]-1]
|
search_color = self.colors[x[2]-1]
|
||||||
if search_color in color_dict:
|
if search_color in color_hex:
|
||||||
s = s + 'edge[color="#000000:{wire_color}:#000000"] '.format(wire_color=color_dict[search_color])
|
s = s + 'edge[color="#000000:{wire_color}:#000000"] '.format(wire_color=color_hex[search_color])
|
||||||
if x[1] is not None:
|
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 '')
|
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
|
s = s + t
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user