Skip to content

Commit

Permalink
Merge pull request #72 from CollinHeist/develop
Browse files Browse the repository at this point in the history
Simplify repeated custom font specification
  • Loading branch information
CollinHeist authored Apr 12, 2022
2 parents bb7994a + 896803f commit bf51135
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
24 changes: 20 additions & 4 deletions modules/Font.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,46 @@ class Font:
interline spacing.
"""

def __init__(self, yaml: dict, card_class: 'CardType',
def __init__(self, yaml, font_map: dict, card_class: 'CardType',
series_info: 'SeriesInfo') -> None:
"""
Constructs a new instance of a Font for the given YAML, CardType, and
series.
:param yaml: 'font' dictionary from a series YAML file.
:type yaml: Dict or str. If str, must be a key of
font_map.
:param font_map: Map of font labels to custom font
dictionaries.
:param card_class: CardType class to use values from.
:param series_info: Associated SeriesInfo (for logging).
"""

# Assume object is valid to start with
self.valid = True

# If the given value is a key of the font map, use those values instead
if isinstance(yaml, str) and yaml in font_map:
yaml = font_map[yaml]

# If font YAML (either from map or directly) is not a dictionary, bad!
if not isinstance(yaml, dict):
log.error(f'Invalid font for series "{series_info}"')
self.valid = False
yaml = {}

# Store arguments
self.__yaml = yaml
self.__card_class = card_class
self.__series_info = series_info

# This font's FontValidator object
# Use the global FontValidator object
self.__validator = global_preferences.fv

# Generic font attributes
self.set_default()

# Parse YAML
self.valid = True
# Parse YAML, update validity
self.__parse_attributes()


Expand Down
10 changes: 7 additions & 3 deletions modules/PreferenceParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,20 +273,24 @@ def iterate_series_files(self) -> [Show]:
continue

# Get library map for this file; error+skip missing library paths
libraries = file_yaml.get('libraries', {})
if not all('path' in libraries[library] for library in libraries):
library_map = file_yaml.get('libraries', {})
if not all('path' in library_map[lib] for lib in library_map):
log.error(f'Libraries in series file "{file_object.resolve()}" '
f'are missing their "path" attributes.')
continue

# Get font map for this file
font_map = file_yaml.get('fonts', {})

# Go through each series in this file
for show_name in tqdm(file_yaml['series'], leave=False,
desc='Creating Shows'):
# Yield the Show object created from this entry
yield Show(
show_name,
file_yaml['series'][show_name],
libraries,
library_map,
font_map,
self.source_directory,
)

Expand Down
7 changes: 5 additions & 2 deletions modules/Show.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class Show:
"""


def __init__(self, name: str, yaml_dict: dict, library_map: dict,
source_directory: Path) -> None:
def __init__(self, name: str, yaml_dict: dict, library_map: dict,
font_map: dict, source_directory: Path) -> None:
"""
Constructs a new instance of a Show object from the given YAML
dictionary, library map, and referencing the base source directory. If
Expand All @@ -37,6 +37,8 @@ def __init__(self, name: str, yaml_dict: dict, library_map: dict,
as found in a card YAML file.
:param library_map: Map of library titles to media
directories.
:param font_map: Map of font labels to custom font
descriptions.
:param source_directory: Base source directory this show should
search for and place source images.
"""
Expand Down Expand Up @@ -82,6 +84,7 @@ def __init__(self, name: str, yaml_dict: dict, library_map: dict,
self.__parse_yaml()
self.font = Font(
self.__yaml.get('font', {}),
font_map,
self.card_class,
self.series_info
)
Expand Down

0 comments on commit bf51135

Please sign in to comment.