diff --git a/fonts/Exo2-Black.ttf b/fonts/Exo2-Black.ttf new file mode 100644 index 0000000000000000000000000000000000000000..475c7c743bf0afa02db58466fbdb6f3c9c6622d4 Binary files /dev/null and b/fonts/Exo2-Black.ttf differ diff --git a/fonts/Exo2-BlackItalic.ttf b/fonts/Exo2-BlackItalic.ttf new file mode 100644 index 0000000000000000000000000000000000000000..afd9c25671d550aa73e0c4474341cbf00fb79682 Binary files /dev/null and b/fonts/Exo2-BlackItalic.ttf differ diff --git a/fonts/Exo2-Bold.ttf b/fonts/Exo2-Bold.ttf new file mode 100644 index 0000000000000000000000000000000000000000..a03c09a50224778fc8ddba37707e74b11499bc52 Binary files /dev/null and b/fonts/Exo2-Bold.ttf differ diff --git a/fonts/Exo2-BoldItalic.ttf b/fonts/Exo2-BoldItalic.ttf new file mode 100644 index 0000000000000000000000000000000000000000..05dc3bd0094d44d4c162bf0b7da588068fbb1eaa Binary files /dev/null and b/fonts/Exo2-BoldItalic.ttf differ diff --git a/fonts/Exo2-ExtraBold.ttf b/fonts/Exo2-ExtraBold.ttf new file mode 100644 index 0000000000000000000000000000000000000000..a5b7c851c7cbe78ed2b5d7dc248dfcb0ad9352ab Binary files /dev/null and b/fonts/Exo2-ExtraBold.ttf differ diff --git a/fonts/Exo2-ExtraBoldItalic.ttf b/fonts/Exo2-ExtraBoldItalic.ttf new file mode 100644 index 0000000000000000000000000000000000000000..38d05f91d483584072b185556e53c56cf7556fe6 Binary files /dev/null and b/fonts/Exo2-ExtraBoldItalic.ttf differ diff --git a/fonts/Exo2-ExtraLight.ttf b/fonts/Exo2-ExtraLight.ttf new file mode 100644 index 0000000000000000000000000000000000000000..ef0508ee0671ce15c143b5f9feef05a8e8845e92 Binary files /dev/null and b/fonts/Exo2-ExtraLight.ttf differ diff --git a/fonts/Exo2-ExtraLightItalic.ttf b/fonts/Exo2-ExtraLightItalic.ttf new file mode 100644 index 0000000000000000000000000000000000000000..a49e5ac9c041a85feec32e26e9cb5bea5281a712 Binary files /dev/null and b/fonts/Exo2-ExtraLightItalic.ttf differ diff --git a/fonts/Exo2-Italic.ttf b/fonts/Exo2-Italic.ttf new file mode 100644 index 0000000000000000000000000000000000000000..83369a806a52d35c6ff137053dcdb34145dad648 Binary files /dev/null and b/fonts/Exo2-Italic.ttf differ diff --git a/fonts/Exo2-Light.ttf b/fonts/Exo2-Light.ttf new file mode 100644 index 0000000000000000000000000000000000000000..373dd2bc13a056d05f6ba7a88dbfb1004950e546 Binary files /dev/null and b/fonts/Exo2-Light.ttf differ diff --git a/fonts/Exo2-LightItalic.ttf b/fonts/Exo2-LightItalic.ttf new file mode 100644 index 0000000000000000000000000000000000000000..2d5a06c5e6a1a4ca0a1a169140820dade8796a22 Binary files /dev/null and b/fonts/Exo2-LightItalic.ttf differ diff --git a/fonts/Exo2-Medium.ttf b/fonts/Exo2-Medium.ttf new file mode 100644 index 0000000000000000000000000000000000000000..222831bbc7cdc8f9f296474846e0ab774e7caee0 Binary files /dev/null and b/fonts/Exo2-Medium.ttf differ diff --git a/fonts/Exo2-MediumItalic.ttf b/fonts/Exo2-MediumItalic.ttf new file mode 100644 index 0000000000000000000000000000000000000000..bd58ef7312b2b5712310508f26e9ff7c534a73e3 Binary files /dev/null and b/fonts/Exo2-MediumItalic.ttf differ diff --git a/fonts/Exo2-Regular.ttf b/fonts/Exo2-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..60b6b6a9821cad0ee047897c5557868dbb80f5cc Binary files /dev/null and b/fonts/Exo2-Regular.ttf differ diff --git a/fonts/Exo2-SemiBold.ttf b/fonts/Exo2-SemiBold.ttf new file mode 100644 index 0000000000000000000000000000000000000000..d81779e3f36862c862775073a0d47d4c035d6d1f Binary files /dev/null and b/fonts/Exo2-SemiBold.ttf differ diff --git a/fonts/Exo2-SemiBoldItalic.ttf b/fonts/Exo2-SemiBoldItalic.ttf new file mode 100644 index 0000000000000000000000000000000000000000..dc3d059445991ef9dce15545584fab039a8dd460 Binary files /dev/null and b/fonts/Exo2-SemiBoldItalic.ttf differ diff --git a/fonts/Exo2-Thin.ttf b/fonts/Exo2-Thin.ttf new file mode 100644 index 0000000000000000000000000000000000000000..a440fe046f0ae0f1d0f42cb96814c9fed4dbcd4a Binary files /dev/null and b/fonts/Exo2-Thin.ttf differ diff --git a/fonts/Exo2-ThinItalic.ttf b/fonts/Exo2-ThinItalic.ttf new file mode 100644 index 0000000000000000000000000000000000000000..3387dbaa214682a5a49eff100205989d49debfe8 Binary files /dev/null and b/fonts/Exo2-ThinItalic.ttf differ diff --git a/main.py b/main.py index 83394fe7398a83d020a0814f2adb2c90b77edd7b..b2098f9b5b704fee2620ad0925bcd13b97ea6988 100644 --- a/main.py +++ b/main.py @@ -40,6 +40,15 @@ mainthread_queue = queue.Queue() api_queue = queue.Queue() led_queue = queue.Queue() +@app.route("/") +def wr_index(): + return f""" + <h1>LED Clock</h1> + Available widgets: {PROP_AVAILABLE_WIDGETS}<br> + Available patterns: {PROP_AVAILABLE_PATTERNS}<br> + <a href="/api/get_config">Config</a> + """ + @app.route("/api/available_fonts") def wr_available_fonts(): return Response(json.dumps(pygame.font.get_fonts()), mimetype="application/json") diff --git a/num_utils.py b/num_utils.py index cc177288631b36392789486ecfda2506ca3d73e9..229d995af414033f0ac26dd215ce1dffa0d32753 100644 --- a/num_utils.py +++ b/num_utils.py @@ -1,3 +1,6 @@ +import os +import re + from config import * import socket @@ -29,3 +32,16 @@ def get_ip(): finally: s.close() return ip_addr + +def get_font_path_or_default(pygame, font_name: str|None, bold=False, italic=False) -> str: + if font_name is not None: + if re.match(r".+\.ttf", font_name): + if os.path.exists(font_name): + font_path = font_name + else: + font_path = pygame.font.get_default_font() + else: + font_path = pygame.font.match_font(font_name, bold, italic) + else: + font_path = pygame.font.get_default_font() + return font_path diff --git a/screenwidgets.py b/screenwidgets.py index 212ba41a4d17c6dd29882388c67437ea1c6eee1a..1f74d6d20ccc86b2771b5ae990f7a38d240ff626 100644 --- a/screenwidgets.py +++ b/screenwidgets.py @@ -1,8 +1,10 @@ import math +import os.path +import re from datetime import datetime from config import PROP_WINDOW_SCALE, PROP_SCREEN_WIDTH, PROP_SCREEN_HEIGHT -from num_utils import get_screen_centre, get_ip +from num_utils import get_screen_centre, get_ip, get_font_path_or_default class IWidgetMeta(type): @@ -36,10 +38,7 @@ class DigitalClockWidget(IWidget): self.pygame = config['pygame'] # Get the font path - if config.get("font_name", None) is not None: - self.font_path = self.pygame.font.match_font(config['font_name']) - else: - self.font_path = self.pygame.font.get_default_font() + self.font_path = get_font_path_or_default(self.pygame, config.get("font_name", None), config.get("font_bold", False), config.get("font_italic", False)) # Load the font self.font = self.pygame.font.Font(self.font_path, config.get("font_size", 36 * PROP_WINDOW_SCALE)) @@ -217,10 +216,7 @@ class IPShowWidget(IWidget): # Get the font path - if config.get("font_name", None) is not None: - self.font_path = self.pygame.font.match_font(config['font_name']) - else: - self.font_path = self.pygame.font.get_default_font() + self.font_path = get_font_path_or_default(self.pygame, config.get("font_name", None), config.get("font_bold", False), config.get("font_italic", False)) # Load the font self.font = self.pygame.font.Font(self.font_path, config.get("font_size", 15 * PROP_WINDOW_SCALE))