Re-sort wv_colors.py
This commit is contained in:
parent
e95f4bd53b
commit
22cd25871c
@ -5,12 +5,16 @@ from dataclasses import dataclass, field
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
KnownColor = namedtuple("KnownColor", "html code_de full_en full_de")
|
padding_amount = 1
|
||||||
|
|
||||||
ColorOutputMode = Enum(
|
ColorOutputMode = Enum(
|
||||||
"ColorOutputMode", "EN_LOWER EN_UPPER DE_LOWER DE_UPPER HTML_LOWER HTML_UPPER"
|
"ColorOutputMode", "EN_LOWER EN_UPPER DE_LOWER DE_UPPER HTML_LOWER HTML_UPPER"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
color_output_mode = ColorOutputMode.EN_UPPER
|
||||||
|
|
||||||
|
KnownColor = namedtuple("KnownColor", "html code_de full_en full_de")
|
||||||
|
|
||||||
known_colors = { # v--------v--------- for future use
|
known_colors = { # v--------v--------- for future use
|
||||||
"BK": KnownColor("#000000", "sw", "black", "schwarz"),
|
"BK": KnownColor("#000000", "sw", "black", "schwarz"),
|
||||||
"WH": KnownColor("#ffffff", "ws", "white", "weiß"),
|
"WH": KnownColor("#ffffff", "ws", "white", "weiß"),
|
||||||
@ -35,10 +39,6 @@ known_colors = { # v--------v--------- for future use
|
|||||||
"GD": KnownColor("#ffcf80", "au", "gold", "Gold"),
|
"GD": KnownColor("#ffcf80", "au", "gold", "Gold"),
|
||||||
}
|
}
|
||||||
|
|
||||||
color_output_mode = ColorOutputMode.EN_UPPER
|
|
||||||
|
|
||||||
padding_amount = 1
|
|
||||||
|
|
||||||
|
|
||||||
def convert_case(inp):
|
def convert_case(inp):
|
||||||
if "_LOWER" in color_output_mode.name:
|
if "_LOWER" in color_output_mode.name:
|
||||||
@ -54,13 +54,6 @@ def get_color_by_colorcode_index(color_code: str, index: int) -> str:
|
|||||||
actual_index = index % num_colors_in_code # wrap around if index is out of bounds
|
actual_index = index % num_colors_in_code # wrap around if index is out of bounds
|
||||||
return COLOR_CODES[color_code][actual_index]
|
return COLOR_CODES[color_code][actual_index]
|
||||||
|
|
||||||
# # make color code loop around if more wires than colors
|
|
||||||
# if self.wirecount > len(self.colors):
|
|
||||||
# m = self.wirecount // len(self.colors) + 1
|
|
||||||
# self.colors = self.colors * int(m)
|
|
||||||
# # cut off excess after looping
|
|
||||||
# self.colors = self.colors[: self.wirecount]
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SingleColor:
|
class SingleColor:
|
||||||
@ -85,9 +78,8 @@ class SingleColor:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def known(self):
|
def known(self):
|
||||||
return (
|
# treat None as a known color
|
||||||
self.code_en.upper() in known_colors.keys() if self._code_en else True
|
return self.code_en.upper() in known_colors.keys() if self._code_en else True
|
||||||
) # ?
|
|
||||||
|
|
||||||
def __init__(self, inp):
|
def __init__(self, inp):
|
||||||
if inp is None:
|
if inp is None:
|
||||||
@ -101,7 +93,7 @@ class SingleColor:
|
|||||||
inp_upper = inp.upper()
|
inp_upper = inp.upper()
|
||||||
self._code_en = inp_upper
|
self._code_en = inp_upper
|
||||||
self._html = known_colors[inp_upper].html
|
self._html = known_colors[inp_upper].html
|
||||||
else: # assume valid HTML color
|
else: # assume it's a valid HTML color name
|
||||||
self._html = inp
|
self._html = inp
|
||||||
self._code_en = inp
|
self._code_en = inp
|
||||||
|
|
||||||
@ -152,9 +144,9 @@ class MultiColor:
|
|||||||
known = [item.upper() in known_colors.keys() for item in items]
|
known = [item.upper() in known_colors.keys() for item in items]
|
||||||
if all(known):
|
if all(known):
|
||||||
self.colors = [SingleColor(item) for item in items]
|
self.colors = [SingleColor(item) for item in items]
|
||||||
else: # assume it's a HTML color name
|
else: # assume it's a valud HTML color name
|
||||||
self.colors = [SingleColor(inp)]
|
self.colors = [SingleColor(inp)]
|
||||||
else: # assume it's a HTML color name
|
else: # assume it's a valid HTML color name
|
||||||
self.colors = [SingleColor(inp)]
|
self.colors = [SingleColor(inp)]
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user