2021-12-29 19:52:41 +03:00
|
|
|
import os
|
|
|
|
|
|
|
|
from dataclasses import dataclass, field
|
|
|
|
from pathlib import Path
|
|
|
|
from typing import List
|
|
|
|
|
|
|
|
templates_path = os.path.join("/".join(os.path.dirname(os.path.abspath(__file__)).split('/')[:-1]), 'templates')
|
|
|
|
|
|
|
|
|
|
|
|
def __list_all_templates():
|
|
|
|
all_templates = [x.name for x in Path(templates_path).iterdir()
|
|
|
|
if x.is_dir() and not str(x).startswith('__') and not str(x).endswith('__')]
|
|
|
|
return all_templates
|
|
|
|
|
|
|
|
|
|
|
|
ALL_TEMPLATES = sorted(__list_all_templates())
|
|
|
|
__all__ = ALL_TEMPLATES + ["ALL_TEMPLATES"]
|
|
|
|
|
|
|
|
|
2022-01-22 09:17:42 +03:00
|
|
|
def default_factory_none() -> None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def default_factory_false() -> bool:
|
|
|
|
return False
|
|
|
|
|
2021-12-29 19:52:41 +03:00
|
|
|
|
|
|
|
@dataclass(frozen=False)
|
|
|
|
class TemplateColor:
|
|
|
|
color: str = ''
|
|
|
|
portrait_path: str = field(default_factory=str)
|
|
|
|
landscape_path: str = field(default_factory=str)
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass(frozen=False)
|
|
|
|
class Template:
|
|
|
|
manufacturer: str = field(default_factory=str)
|
|
|
|
name: str = field(default_factory=str)
|
|
|
|
type: str = field(default_factory=str)
|
|
|
|
year: int = field(default_factory=int)
|
2022-01-22 09:17:42 +03:00
|
|
|
resolution: str = field(default_factory=str)
|
2021-12-29 19:52:41 +03:00
|
|
|
example_path: str = field(default_factory=str)
|
|
|
|
|
|
|
|
colors: List[TemplateColor] = field(default_factory=list)
|
|
|
|
|
2022-01-22 09:17:42 +03:00
|
|
|
__template_path__: str = field(default_factory=str)
|
|
|
|
__colors__: dict = field(default_factory=dict)
|
|
|
|
|
|
|
|
__use_mask__: bool = field(default_factory=default_factory_false)
|
|
|
|
|
2021-12-29 19:52:41 +03:00
|
|
|
__portrait_width__: int = field(default_factory=int)
|
|
|
|
__portrait_height__: int = field(default_factory=int)
|
2022-01-22 09:17:42 +03:00
|
|
|
__portrait_x__: int = field(default_factory=int)
|
|
|
|
__portrait_y__: int = field(default_factory=int)
|
|
|
|
__portrait_mask__: str = field(default_factory=default_factory_none)
|
|
|
|
|
2021-12-29 19:52:41 +03:00
|
|
|
__landscape_width__: int = field(default_factory=int)
|
|
|
|
__landscape_height__: int = field(default_factory=int)
|
2022-01-22 09:17:42 +03:00
|
|
|
__landscape_x__: int = field(default_factory=int)
|
|
|
|
__landscape_y__: int = field(default_factory=int)
|
|
|
|
__landscape_mask__: str = field(default_factory=default_factory_none)
|
|
|
|
|
|
|
|
def __post_init__(self):
|
|
|
|
getattr(self, '__device_init__')()
|
|
|
|
|
|
|
|
self.example_path = '{}/{}/example.png'.format(templates_path, self.__template_path__)
|
|
|
|
|
|
|
|
self.colors = [
|
|
|
|
TemplateColor(
|
|
|
|
color=color,
|
|
|
|
portrait_path='{}/{}/{}/portrait.png'.format(templates_path, self.__template_path__, color_path),
|
|
|
|
landscape_path='{}/{}/{}/landscape.png'.format(templates_path, self.__template_path__, color_path),
|
|
|
|
) for color, color_path in self.__colors__.items()]
|
|
|
|
|
|
|
|
if self.__use_mask__:
|
|
|
|
self.__portrait_mask__ = '{}/{}/portrait-mask.png'.format(templates_path, self.__template_path__)
|
|
|
|
self.__landscape_mask__ = '{}/{}/landscape-mask.png'.format(templates_path, self.__template_path__)
|