From 8e680ee4dbbaf6f4d2dbefa356cd92c075f528d3 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Sat, 18 Jul 2020 12:28:52 +0200 Subject: [PATCH] Fine-tune multicolor wire PR - Remove modified background color -> should be discusses as a separate feature - Render shields as thin tinned wire with black border, safer for b&w priting than single light-gray line - Remove PE as color definition, since it is not, and should be called with GNYE - Clean up minor things --- setup.py | 1 + src/wireviz/Harness.py | 8 +++--- src/wireviz/wv_colors.py | 57 +++++++++++----------------------------- 3 files changed, 20 insertions(+), 46 deletions(-) diff --git a/setup.py b/setup.py index 950e3147..09621bb7 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ #!/usr/bin/python3 +# -*- coding: utf-8 -*- import os from setuptools import setup, find_packages diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index a55b16ca..a1a1e592 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -66,7 +66,7 @@ def create_graph(self) -> Graph: font = 'arial' dot.attr('graph', rankdir='LR', ranksep='2', - bgcolor=wv_colors.default_bknd_color, + bgcolor='white', nodesep='0.33', fontname=font) dot.attr('node', shape='record', @@ -203,7 +203,6 @@ def create_graph(self) -> Graph: html = f'{html}{bla}' html = f'{html}' - bgcolors = ['#000000'] + get_color_hex(connection_color) + ['#000000'] html = f'{html}' for j, bgcolor in enumerate(bgcolors[::-1]): # Reverse to match the curved wires when more than 2 colors @@ -224,7 +223,6 @@ def create_graph(self) -> Graph: for attrib in wireidentification: html = f'{html}' html = f'{html}
{attrib}
' - # html = html + '' if cable.shield: p = ['', 'Shield', ''] @@ -251,8 +249,8 @@ def create_graph(self) -> Graph: if isinstance(connection_color.via_port, int): # check if it's an actual wire and not a shield dot.attr('edge', color=':'.join(['#000000'] + wv_colors.get_color_hex(cable.colors[connection_color.via_port - 1]) + ['#000000'])) else: # it's a shield connection - dot.attr('edge', color='#000000') - + # shield is shown as a thin tinned wire + dot.attr('edge', color=':'.join(['#000000', wv_colors.get_color_hex('SN')[0], '#000000'])) if connection_color.from_port is not None: # connect to left from_ferrule = self.connectors[connection_color.from_name].category == 'ferrule' port = f':p{connection_color.from_port}r' if not from_ferrule else '' diff --git a/src/wireviz/wv_colors.py b/src/wireviz/wv_colors.py index e401fc67..02316198 100644 --- a/src/wireviz/wv_colors.py +++ b/src/wireviz/wv_colors.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- + import sys COLOR_CODES = { @@ -22,15 +23,8 @@ 'T568B': ['WHOG', 'OG', 'WHGN', 'BU', 'WHBU', 'GN', 'WHBN', 'BN'], } -default_color = '#ffffff' - -# default_bkgnd_color = '#ffffff' # white -default_bknd_color = '#fffbf8' # off-white beige-ish - # Convention: Color names should be 2 letters long, to allow for multicolored wires -shield_color = '#aaaaaa' # Tinned wire - _color_hex = { 'BK': '#000000', 'WH': '#ffffff', @@ -45,16 +39,10 @@ 'VT': '#8000ff', 'BN': '#895956', 'SL': '#708090', - # Faux-copper look, for bare CU wire - 'CU': '#d6775e', - # Silvery look for tinned bare wire - 'SN': '#aaaaaa', - # Darker silver for silvered wire - 'AG': '#84878c', - # Golden color for gold - 'AU': '#ffcf80', - # Yellow-green PE wire (matching actual wire colors, should prevent confusion with a yellow-green dual color wire - 'PE': '#54aa85:#f7f854:#54aa85', + 'CU': '#d6775e', # Faux-copper look, for bare CU wire + 'SN': '#aaaaaa', # Silvery look for tinned bare wire + 'AG': '#84878c', # Darker silver for silvered wire + 'AU': '#ffcf80', # Golden color for gold } _color_full = { @@ -75,10 +63,8 @@ 'SN': 'tinned copper', 'AG': 'silver wire', 'AU': 'gold wire', - 'PE': 'earth' } -# TODO Help wanted: can someone check the german translation? _color_ger = { 'BK': 'sw', 'WH': 'ws', @@ -92,28 +78,20 @@ 'BU': 'bl', 'VT': 'vi', 'BN': 'br', - # To the best of my ability, likely incorrect: - - # Slate --> Schieferfarbe --> SI ?? - 'SL': 'si', - # Copper - 'CU': 'cu', - # Tinned - 'SN': 'sn', - # Silver - 'AG': 'ag', - # Gold - 'AU': 'au', - # Earth - 'PE': 'pe' + 'SL': 'si', # Slate/Schiefer? + 'CU': 'ku', # Copper/Kupfer + 'SN': 'vz', # Tinned/verzinkt + 'AG': 'ag', # Silver + 'AU': 'au', # Gold } +color_default = '#ffffff' + def get_color_hex(input, pad=True): if input is None or input == '': - # print('Unspecified color requested', file=sys.stderr) - return [default_color] + return [color_default] if len(input) == 4: # give wires with EXACTLY 2 colors that striped/banded look input = input + input[:2] # hacky style fix: give single color wires a triple-up so that wires are the same size @@ -122,16 +100,14 @@ def get_color_hex(input, pad=True): try: output = [_color_hex[input[i:i + 2]] for i in range(0, len(input), 2)] except KeyError: - print("Unknown Color Specified", file=sys.stderr) - output = [default_color] - # raise Exception('Unknown Color Name') + print("Unknown color specified") + output = [color_default] return output def translate_color(input, color_mode): if input == '' or input is None: - # print('Unspecified color requested', file=sys.stderr) - return default_color + return color_default upper = color_mode.isupper() if not (color_mode.isupper() or color_mode.islower()): raise Exception('Unknown color mode capitalization') @@ -151,4 +127,3 @@ def translate_color(input, color_mode): return output.upper() else: return output.lower() -