rivet/config.py

42 lines
1.1 KiB
Python
Raw Normal View History

2023-11-24 13:34:44 +00:00
import json
2023-11-24 14:01:51 +00:00
import re
2023-11-24 13:34:44 +00:00
2024-03-24 10:33:34 +00:00
2023-11-24 13:34:44 +00:00
class Config:
2023-11-24 14:01:51 +00:00
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
FORCE_DESCS_ON_SIDE = False
WIDTH = 1200
HEIGHT = 800
2023-11-24 13:34:44 +00:00
2023-11-24 14:01:51 +00:00
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()