From 09bf090f8380cdcb02247f2843776261d526158f Mon Sep 17 00:00:00 2001 From: Tom Ward Date: Mon, 15 Jan 2024 22:48:34 +0000 Subject: [PATCH] Add fast train icon to indicate which trains are fast or not. This also adds initial support for rendering glyphs, though generating the python files is a little finicky as it stands. This will only show if "slow_stations" are provided. --- assets/fast_icon.png | Bin 0 -> 1252 bytes manifest.py | 1 + src/assets/__init__.py | 4 ++- src/assets/fast_train_icon.py | 23 +++++++++++++++ src/glyphs.py | 54 ++++++++++++++++++++++++++++++++++ src/main.py | 3 +- src/widgets.py | 13 +++++++- 7 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 assets/fast_icon.png create mode 100644 src/assets/fast_train_icon.py create mode 100644 src/glyphs.py diff --git a/assets/fast_icon.png b/assets/fast_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..b77c8c4332f414bdde52d20356b80bd102ba7a72 GIT binary patch literal 1252 zcmVBE1ZQLxAY_vg;$?V;oX(lt{{G@3qJ`_O^!KmPq;Qw2}Cn0L9?Tam?khm;cmfj@-EE=vY<#k5o0f^m&*sM6pBI0EL{uRZtU4R5Z z`^X8`V)zNfJ8YaF;u6EP09P2E5Ad?jnUOMxUqvh^s*L``+lU9}BlcPZ2XpY-jyyG} zttleQMaed+noc9ry@UIIwng1*#M^^UkFzj+6yF25_LnMhmf?pGpH<}CbcnAmX|u%; z|7E#p3GpKUUAw%6atiT2#A8)^yd3Cssj4^8z$>TJnP(8+gLrkpJj%xIMEtceUz`ec zeo~wa<_{hK;NmJRuzL3+9o0iVC08s$)vACv7|KExH6jmbd4gn8^0FkllzkRT6fd|P0n zrwSVAXrbt(XrcJk;OyVRDf#{Yw^VBW$m{6QFhZvPBk<6w!tZERBfJcLd1$M3&)TehHS09YRtkN(Z(GDi^F2;vKBX;HY+Q*UEnTqUvgh@A9J5aYSek}G;8j! zqp=F+X_rylpF&#LEj%b>g+0Q~5^H*5N-?MwSLAe5T{?GXqX;9WfX;*4pXw6&V*io?m|<6;W0GAb4f<-njQ>$>Q>9MPr@ zwU=n+0I+*9IKpp9{{0u*d8K7@p9VPmCp-6AwmA>rtOL;dXv;Q$XXCx^0IWWyc=l3w zC&Xgk0yx!!!@*Zi8qcdA>-AfBZYACT*nGWS|NH%Vee(m<-vGFv{{#Oecnig2*2@3@ z061k>NoGw=04e|g00;m9hiL!=000010000Q0000000N)_00aO40096101u!800aO4 z0096100;m8005TWB_jX;08L3mK~xwSjgG+%03ZlLW9$Eax$=Nx#-?7%0vnWEH59X#TfkXU>pGZHo1b(Cw00OU3Tq)~+UnS#mYhoy{)uuOR^X7aP0) O0000 None: + """Renders glyph into the provided display at position [x, y].""" + framebuffer.blit(self._framebuf, x, y, -1) + + def max_bounds(self) -> tuple[int, int]: + """Returns the max bounds for Glyph.""" + return self._glyph.width(), self._glyph.height() + + +FAST_TRAIN_ICON = Glyph(assets.fast_train_icon) diff --git a/src/main.py b/src/main.py index c0d24bd..073cd68 100644 --- a/src/main.py +++ b/src/main.py @@ -34,9 +34,9 @@ import config as config_module import display import fonts +import glyphs import logging from setup import server -import time_range import trains import utils import widgets @@ -132,6 +132,7 @@ def _render_thread( fonts.DEFAULT_FONT, # Don't render seconds on e-paper displays. render_seconds=(config.display.type != 'epd29b'), + fast_train_icon=glyphs.FAST_TRAIN_ICON, ) non_active = widgets.MessageWidget( screen, _DISPLAY_NOT_ACTIVE, fonts.DEFAULT_FONT diff --git a/src/widgets.py b/src/widgets.py index 636da5e..e203c6f 100644 --- a/src/widgets.py +++ b/src/widgets.py @@ -20,6 +20,7 @@ import display import fonts +import glyphs import trains @@ -163,19 +164,24 @@ def __init__( font: fonts.Font, width: int, status_font: fonts.Font | None = None, + fast_train_icon: glyphs.Glyph | None = None, ): super().__init__(screen) self._font = font self._width = width self._status_font = status_font if status_font else font + self._fast_train_icon = fast_train_icon self._max_clock_width = self._font.calculate_bounds('00:00')[0] self._last_departure = None def bounds(self) -> tuple[int, int]: - return self._width, max( + max_height = max( self._font.max_bounds()[1], self._status_font.max_bounds()[1] ) + if self._fast_train_icon: + max_height = max(max_height, self._fast_train_icon.max_bounds()[1]) + return self._width, max_height def render( self, departure: trains.Departure | None, x: int, y: int, w: int, h: int @@ -193,6 +199,9 @@ def render( self._font.render_text(departure_time, self._screen, x, y) x += self._max_clock_width + 4 + if departure.fast_train and self._fast_train_icon: + self._fast_train_icon.render_glyph(self._screen, x, y) + x += self._fast_train_icon.max_bounds()[0] + 2 self._font.render_text(departure.destination, self._screen, x, y) if departure.cancelled: @@ -220,6 +229,7 @@ def __init__( tall_font: fonts.Font, default_font: fonts.Font, render_seconds: bool = True, + fast_train_icon: glyphs.Glyph | None = None, ): super().__init__(screen) self._departure_updater = departure_updater @@ -244,6 +254,7 @@ def __init__( bold_font if i == 0 else default_font, screen.width, default_font, + fast_train_icon, ) )