-
Notifications
You must be signed in to change notification settings - Fork 0
/
labellib.py
72 lines (59 loc) · 1.84 KB
/
labellib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from pathlib import Path
from typing import Tuple
from uuid import uuid4
import pygame
class MetaLabel:
"""Meta class for labels"""
data_path: Path = Path("data")
font_path: Path = data_path.joinpath("fonts")
def __init__(
self,
uuid,
label,
rel_coord_x,
rel_coord_y,
font_name,
font_color,
font_size,
):
self.uuid: str = uuid
self.label = label
self.rel_coord_x = rel_coord_x
self.rel_coord_y = rel_coord_y
self.font_name = font_name
self.font_color = font_color
self.font_size = font_size
self.hidden: bool = False
if not self.font_path.joinpath(font_name).exists:
raise FileNotFoundError(f"Font {font_name} not found")
self.font = pygame.font.SysFont(
self.font_path.joinpath(font_name).as_posix(), font_size, False
)
def __str__(self):
return f"{self.uuid}: {self.label}"
def hide(self) -> None:
"""Hide label"""
self.hidden = True
def draw(self) -> pygame.Surface:
"""Draw label"""
label_surf = self.font.render(self.label, True, self.font_color)
return label_surf
class Label(MetaLabel):
"""Standart label class"""
font_name: str = "ConsolaMono-Book.ttf"
font_color: Tuple[int, int, int] = (0, 0, 0)
font_size: int = 16
def __init__(self, label, rel_coord_x, rel_coord_y):
self.uuid: str = str(uuid4())
self.label = label
self.coord_x = rel_coord_x
self.coord_y = rel_coord_y
super().__init__(
self.uuid,
label,
rel_coord_x,
rel_coord_y,
self.font_name,
self.font_color,
self.font_size,
)