Move color type aliases into wv_colors.py to avoid circular imports
This commit is contained in:
parent
c34946183e
commit
7125f28760
@ -6,7 +6,7 @@ from dataclasses import dataclass, field, InitVar
|
||||
from pathlib import Path
|
||||
|
||||
from wireviz.wv_helper import int2tuple, aspect_ratio
|
||||
from wireviz import wv_colors
|
||||
from wireviz.wv_colors import Color, Colors, ColorMode, ColorScheme, COLOR_CODES
|
||||
|
||||
|
||||
# Each type alias have their legal values described in comments - validation might be implemented in the future
|
||||
@ -19,12 +19,8 @@ Designator = PlainText # Case insensitive unique name of connector or cable
|
||||
ConnectorMultiplier = PlainText # = Literal['pincount', 'populated']
|
||||
CableMultiplier = PlainText # = Literal['wirecount', 'terminations', 'length', 'total_length']
|
||||
ImageScale = PlainText # = Literal['false', 'true', 'width', 'height', 'both']
|
||||
Color = PlainText # Two-letter color name = Literal[wv_colors._color_hex.keys()]
|
||||
ColorMode = PlainText # = Literal['full', 'FULL', 'hex', 'HEX', 'short', 'SHORT', 'ger', 'GER']
|
||||
ColorScheme = PlainText # Color scheme name = Literal[wv_colors.COLOR_CODES.keys()]
|
||||
|
||||
# Type combinations
|
||||
Colors = PlainText # One or more two-letter color names (Color) concatenated into one string
|
||||
Pin = Union[int, PlainText] # Pin identifier
|
||||
PinIndex = int # Zero-based pin index
|
||||
Wire = Union[int, PlainText] # Wire number or Literal['s'] for shield
|
||||
@ -284,9 +280,9 @@ class Cable:
|
||||
if self.colors: # use custom color palette (partly or looped if needed)
|
||||
pass
|
||||
elif self.color_code: # use standard color palette (partly or looped if needed)
|
||||
if self.color_code not in wv_colors.COLOR_CODES:
|
||||
if self.color_code not in COLOR_CODES:
|
||||
raise Exception('Unknown color code')
|
||||
self.colors = wv_colors.COLOR_CODES[self.color_code]
|
||||
self.colors = COLOR_CODES[self.color_code]
|
||||
else: # no colors defined, add dummy colors
|
||||
self.colors = [''] * self.wirecount
|
||||
|
||||
|
||||
@ -3,8 +3,6 @@
|
||||
|
||||
from typing import Dict, List
|
||||
|
||||
from wireviz.DataClasses import Color, Colors
|
||||
|
||||
COLOR_CODES = {
|
||||
'DIN': ['WH', 'BN', 'GN', 'YE', 'GY', 'PK', 'BU', 'RD', 'BK', 'VT', 'GYPK', 'RDBU', 'WHGN', 'BNGN', 'WHYE', 'YEBN',
|
||||
'WHGY', 'GYBN', 'WHPK', 'PKBN', 'WHBU', 'BNBU', 'WHRD', 'BNRD', 'WHBK', 'BNBK', 'GYGN', 'YEGY', 'PKGN',
|
||||
@ -112,7 +110,14 @@ color_default = '#ffffff'
|
||||
_hex_digits = set('0123456789abcdefABCDEF')
|
||||
|
||||
|
||||
def get_color_hex(input, pad=False):
|
||||
# Literal type aliases below are commented to avoid requiring python 3.8
|
||||
Color = str # Two-letter color name = Literal[_color_hex.keys()]
|
||||
Colors = str # One or more two-letter color names (Color) concatenated into one string
|
||||
ColorMode = str # = Literal['full', 'FULL', 'hex', 'HEX', 'short', 'SHORT', 'ger', 'GER']
|
||||
ColorScheme = str # Color scheme name = Literal[COLOR_CODES.keys()]
|
||||
|
||||
|
||||
def get_color_hex(input: Colors, pad: bool = False) -> List[str]:
|
||||
"""Return list of hex colors from either a string of color names or :-separated hex colors."""
|
||||
if input is None or input == '':
|
||||
return [color_default]
|
||||
@ -156,7 +161,7 @@ def get_color_translation(translate: Dict[Color, str], input: Colors) -> List[st
|
||||
[translate.get(input[i:i+2], '??') for i in range(0, len(input), 2)]
|
||||
|
||||
|
||||
def translate_color(input, color_mode):
|
||||
def translate_color(input: Colors, color_mode: ColorMode) -> str:
|
||||
if input == '' or input is None:
|
||||
return ''
|
||||
upper = color_mode.isupper()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user