Make Options inherit from Look
Avoid the extra base part of the data structure.
This commit is contained in:
parent
8e09cb9841
commit
c87f0733b0
@ -42,11 +42,15 @@ class Look:
|
||||
fontname: Optional[PlainText] = None
|
||||
fontsize: Optional[Points] = None
|
||||
|
||||
def lookdict(self) -> dict:
|
||||
"""Return Look attributes as dict."""
|
||||
return {k:v for k,v in asdict(self).items() if k in asdict(DEFAULT_LOOK).keys()}
|
||||
|
||||
def _2dict(self) -> dict:
|
||||
"""Return dict of non-None strings with color values translated to hex."""
|
||||
return {
|
||||
k:translate_color(v, "hex") if 'color' in k else str(v)
|
||||
for k,v in asdict(self).items() if v is not None
|
||||
for k,v in self.lookdict().items() if v is not None
|
||||
}
|
||||
|
||||
def graph_args(self) -> dict:
|
||||
@ -78,8 +82,7 @@ DEFAULT_LOOK = Look(
|
||||
|
||||
|
||||
@dataclass
|
||||
class Options:
|
||||
base: Look = field(default_factory=dict)
|
||||
class Options(Look):
|
||||
node: Look = field(default_factory=dict)
|
||||
connector: Look = field(default_factory=dict)
|
||||
cable: Look = field(default_factory=dict)
|
||||
@ -89,8 +92,7 @@ class Options:
|
||||
|
||||
def __post_init__(self):
|
||||
# Build initialization dicts with default values followed by dict entries from YAML input.
|
||||
self.base = Look(**{**asdict(DEFAULT_LOOK), **self.base})
|
||||
self.node = Look(**{**asdict(self.base), **self.node})
|
||||
self.node = Look(**{**self.lookdict(), **self.node})
|
||||
self.connector = Look(**{**asdict(self.node), **self.connector})
|
||||
self.cable = Look(**{**asdict(self.node), **self.cable})
|
||||
self.bundle = Look(**{**asdict(self.cable), **self.bundle})
|
||||
|
||||
@ -98,15 +98,15 @@ class Harness:
|
||||
dot.attr('graph', rankdir='LR',
|
||||
ranksep='2',
|
||||
nodesep='0.33',
|
||||
**self.options.base.graph_args())
|
||||
**self.options.graph_args())
|
||||
dot.attr('node', shape='none',
|
||||
style='filled',
|
||||
width='0', height='0', margin='0', # Actual size of the node is entirely determined by the label.
|
||||
**self.options.node.node_args())
|
||||
dot.attr('edge', style='bold',
|
||||
**self.options.base.node_args())
|
||||
**self.options.node_args())
|
||||
|
||||
wire_border_hex = wv_colors.get_color_hex(self.options.base.bordercolor)[0]
|
||||
wire_border_hex = wv_colors.get_color_hex(self.options.bordercolor)[0]
|
||||
|
||||
# prepare ports on connectors depending on which side they will connect
|
||||
for _, cable in self.cables.items():
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
from dataclasses import asdict
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
@ -13,7 +14,7 @@ if __name__ == '__main__':
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from wireviz import __version__
|
||||
from wireviz.DataClasses import Metadata, Options, Tweak
|
||||
from wireviz.DataClasses import DEFAULT_LOOK, Metadata, Options, Tweak
|
||||
from wireviz.Harness import Harness
|
||||
from wireviz.wv_helper import expand, open_file_read
|
||||
|
||||
@ -37,7 +38,7 @@ def parse(yaml_input: str, file_out: (str, Path) = None, return_types: (None, st
|
||||
|
||||
harness = Harness(
|
||||
metadata = Metadata(**yaml_data.get('metadata', {})),
|
||||
options = Options(**yaml_data.get('options', {})),
|
||||
options = Options(**asdict(DEFAULT_LOOK), **yaml_data.get('options', {})),
|
||||
tweak = Tweak(**yaml_data.get('tweak', {})),
|
||||
)
|
||||
if 'title' not in harness.metadata:
|
||||
|
||||
@ -15,7 +15,7 @@ def generate_html_output(filename: Union[str, Path], bom_list: List[List[str]],
|
||||
file.write(' <meta charset="UTF-8">\n')
|
||||
file.write(f' <meta name="generator" content="{APP_NAME} {__version__} - {APP_URL}">\n')
|
||||
file.write(f' <title>{metadata["title"]}</title>\n')
|
||||
file.write(f'</head><body style="{options.base.html_style()}">\n')
|
||||
file.write(f'</head><body style="{options.html_style()}">\n')
|
||||
file.write(f'<h1>{metadata["title"]}</h1>\n')
|
||||
description = metadata.get('description')
|
||||
if description:
|
||||
@ -31,7 +31,7 @@ def generate_html_output(filename: Union[str, Path], bom_list: List[List[str]],
|
||||
|
||||
file.write('<h2>Bill of Materials</h2>\n')
|
||||
listy = flatten2d(bom_list)
|
||||
border = options.base.html_style(color_prefix="border: 1px solid", include_all=False)
|
||||
border = options.html_style(color_prefix="border: 1px solid", include_all=False)
|
||||
file.write(f'<table style="{border} border-spacing: 0px;">\n')
|
||||
file.write(' <tr>\n')
|
||||
for item in listy[0]:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user