From c84449f034fcb78fd5535dade9b2e2438e2fd551 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Thu, 19 Jan 2023 12:56:44 +0100 Subject: [PATCH] New option to expand alerts on the graphic --- main.py | 12 ++++++++++-- modules/__init__.py | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 4f3c278..d1ba51f 100644 --- a/main.py +++ b/main.py @@ -47,7 +47,7 @@ class WidgetPlacement: self.kwargs = kwargs -def main(only_on_coming_evt=False, ignore_module=[], force_coming_event=True, **config_args): +def main(only_on_coming_evt=False, ignore_module=[], force_coming_event=True, expand_alerts=False, **config_args): image = Image.new('1', (480, 800), 255) #image = Image.new('L', (480, 800), 'white') draw = ImageDraw.Draw(image) @@ -155,7 +155,7 @@ def main(only_on_coming_evt=False, ignore_module=[], force_coming_event=True, ** from modules import AlertsModule - mod = AlertsModule(alerts, ignore_module).draw_module(config, 480, min(317, 640 - NEXT_STOP_Y - occuped_space)) + mod, more_alerts = AlertsModule(alerts, ignore_module).draw_module(config, 480, min(317, 640 - NEXT_STOP_Y - occuped_space)) if NEXT_STOP_Y + occuped_space + mod.height > 580 or mod.height > 260: image.paste(mod, (0, 640-mod.height), mod) elif mod.height < 100: @@ -171,6 +171,11 @@ def main(only_on_coming_evt=False, ignore_module=[], force_coming_event=True, ** else: image.paste(WeatherTemperatureModule().draw_module(config, 480, 200), (0, 580)) + if expand_alerts and more_alerts > 0: + mod, more_alerts = AlertsModule(alerts, ignore_module).draw_module(config, 480, 785 - NEXT_STOP_Y - occuped_space) + image.paste(mod, (0, NEXT_STOP_Y + occuped_space), mod) + + fnt = ImageFont.truetype(config.fnt_R_path, 11) draw.text( (475, 798), @@ -201,6 +206,8 @@ if __name__ == '__main__': parser.add_argument('--ignore-module', '-I', nargs="*", default=[], help='Ignore the given modules') + parser.add_argument('--expand-alerts', '-A', action='store_const', const=True, + help='If needed, expand alerts on graphic') parser.add_argument('--force-coming-evt', '-E', action='store_const', const=True, help='Consider an event coming, whatever calendar says') parser.add_argument('--only-on-coming-evt', '-O', action='store_const', const=True, @@ -216,6 +223,7 @@ if __name__ == '__main__': args.only_on_coming_evt, args.ignore_module, args.force_coming_evt, + args.expand_alerts, cache_timeout=args.cache_timeout, max_cache_timeout=args.max_cache_timeout, ) diff --git a/modules/__init__.py b/modules/__init__.py index 731c6ed..0405d39 100644 --- a/modules/__init__.py +++ b/modules/__init__.py @@ -185,7 +185,7 @@ class AlertsModule: fill="white", anchor="rb", font=fnt_B ) - return image + return image, more_alerts def display_longtext(draw, pos, text, font, anchor="lt", maxwidth=9999, **kwargs): x,y = pos