AnP/Python/Managers/PrintTypesManager.py

79 lines
2.1 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Any, Self, Sequence
from Interfaces.Application.AnPInterface import AnPInterface
from Utils.Common import Common
from Utils.Checks import Check
class PrintTypesManager:
def __init__(self:Self, anp:AnPInterface) -> None:
self.anp:AnPInterface = anp
self.__print_types:list[list[str]] = [
["unkn", "unknown"]
]
self.update()
def update(self:Self) -> None:
key:str
for key in ("default_print_types_files", "print_types_files", "default_print_types", "print_types"):
self.add(self.anp.settings.get(key))
def reset(self:Self) -> None:
self.__print_types = [
["unkn", "unknown"]
]
self.update()
def get(self:Self, keys:str|Sequence[str]) -> str:
key:str
for key in Common.get_keys(keys):
block:list[str]
key = key.lower()
for block in self.__print_types:
if key in block:
return block[0].upper()
return self.__print_types[0][0].upper()
def add(self:Self, inputs:Any|None) -> None:
if Check.is_array(inputs):
for item in inputs:
if all(Check.is_key(subitem) for subitem in item):
main:str = item[0].lower()
i:int = 0
l:int = len(self.__print_types)
subitem:str
while i < l:
if main == self.__print_types[i][0]:
break
i += 1
if i == l:
self.__print_types.append([main])
for subitem in item[1:]:
subitem = subitem.lower()
if subitem not in self.__print_types[i]:
self.__print_types[i].append(subitem)
else:
subinputs:Any|None
for subinputs in item:
self.add(Common.load_json(subinputs))