New option to expand alerts on the graphic

This commit is contained in:
nemunaire 2023-01-19 12:56:44 +01:00
parent 2bd7fafaa5
commit c84449f034
2 changed files with 11 additions and 3 deletions

12
main.py
View File

@ -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,
)

View File

@ -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