changed config structure

This commit is contained in:
2023-11-24 15:01:51 +01:00
parent bf2663e9d7
commit 371c1d3cca
3 changed files with 67 additions and 39 deletions

View File

@@ -1,10 +1,38 @@
import json
from typing import Any
import re
class Config:
def __init__(self) -> None:
with open("config.json", "r") as f:
self.params = json.load(f)
DEFAULT_FONT_FAMILY = "Ubuntu Mono"
DEFAULT_FONT_SIZE = 16
ITALIC_FONT_FAMILY = "Ubuntu Mono"
ITALIC_FONT_SIZE = 14
BACKGROUND_COLOR = [255, 255, 255]
TEXT_COLOR = [0, 0, 0]
LINK_COLOR = [0, 0, 0]
BIT_I_COLOR = [0, 0, 0]
BORDER_COLOR = [0, 0, 0]
BIT_WIDTH = 30
BIT_HEIGHT = 30
DESCRIPTION_MARGIN = 10
DASH_LENGTH = 6
DASH_SPACE = 4
ARROW_SIZE = 10
MARGINS = [20, 20, 20, 20]
ARROW_MARGIN = 4
VALUES_GAP = 5
ARROW_LABEL_DISTANCE = 5
def get(self, param: str) -> Any:
return self.params[param]
def __init__(self, path: str = "config.json") -> None:
self.load(path)
def load(self, path: str) -> None:
with open(path, "r") as f:
config = json.load(f)
for k, v in config.items():
k = Config.formatKey(k)
if hasattr(Config, k):
setattr(Config, k, v)
def formatKey(key: str) -> str:
return re.sub(r"([a-z])([A-Z])", r"\1_\2", key).upper()