Alert on RATP failures
This commit is contained in:
parent
24f8c46ff6
commit
18ab123c3a
3 changed files with 54 additions and 25 deletions
|
|
@ -79,35 +79,42 @@ class AlertsModule:
|
|||
self.icon_size = 50
|
||||
self.alerts = alerts
|
||||
|
||||
def draw_module(self, config, width, height):
|
||||
def draw_module(self, config, width, height, font_size=16):
|
||||
image = Image.new('RGBA', (width, height), "#000")
|
||||
draw = ImageDraw.Draw(image)
|
||||
align = 0
|
||||
|
||||
more_alerts = 0
|
||||
if len(self.alerts) > 0:
|
||||
fnt_R = ImageFont.truetype(config.fnt_R_path, 16)
|
||||
fnt_B = ImageFont.truetype(config.fnt_RB_path, 16)
|
||||
fnt_R = ImageFont.truetype(config.fnt_R_path, font_size)
|
||||
fnt_B = ImageFont.truetype(config.fnt_RB_path, font_size)
|
||||
|
||||
align = 9
|
||||
for alert in self.alerts:
|
||||
if alert["icon"] is not None:
|
||||
if callable(alert["icon"]):
|
||||
icon_img = alert["icon"](size=int(font_size*self.icon_size/16))
|
||||
image.paste(icon_img, (int(self.icon_size / 2 - font_size*self.icon_size/32), align), icon_img)
|
||||
else:
|
||||
color_img = Image.new('RGB', (self.icon_size, self.icon_size), "#fff")
|
||||
icon_img = Image.open("icons/" + alert["icon"]).resize((self.icon_size, self.icon_size))
|
||||
image.paste(color_img, (0, align - 5), icon_img)
|
||||
image.paste(color_img, (0, align), icon_img)
|
||||
|
||||
draw.text(
|
||||
if "title" in alert:
|
||||
draw.text(
|
||||
((self.icon_size if alert["icon"] is not None else 0) - 5, align),
|
||||
alert["title"],
|
||||
fill="white", anchor="lt", font=fnt_B
|
||||
)
|
||||
)
|
||||
if "subtitle" in alert and alert["subtitle"]:
|
||||
draw.text(
|
||||
((self.icon_size if alert["icon"] is not None else 0) + fnt_B.getsize(alert["title"])[0], align + 3),
|
||||
((self.icon_size if alert["icon"] is not None else 0) + (fnt_B.getsize(alert["title"])[0] if "title" in alert else 0), align + 3),
|
||||
alert["subtitle"],
|
||||
fill="white", anchor="lt", font=fnt_R
|
||||
)
|
||||
|
||||
align += fnt_B.getsize(alert["title"])[1]
|
||||
if "title" in alert:
|
||||
align += fnt_B.getsize(alert["title"])[1]
|
||||
|
||||
align += display_longtext(
|
||||
draw,
|
||||
|
|
@ -117,8 +124,21 @@ class AlertsModule:
|
|||
maxwidth=width-self.icon_size-5
|
||||
)
|
||||
align += 7
|
||||
if align > height:
|
||||
more_alerts += 1
|
||||
|
||||
image = image.crop((0,0,width, align))
|
||||
image = image.crop((0,0,width, min(align, height)))
|
||||
|
||||
if more_alerts > 0 and font_size > 12:
|
||||
return self.draw_module(config, width, height, font_size-1)
|
||||
elif more_alerts > 0:
|
||||
draw = ImageDraw.Draw(image)
|
||||
draw.rectangle((0, height-font_size, width, height), fill="black")
|
||||
draw.text(
|
||||
(width - 3, height),
|
||||
("%d alertes supplémentaires" if more_alerts > 1 else "%d alerte supplémentaire") % more_alerts,
|
||||
fill="white", anchor="rb", font=fnt_B
|
||||
)
|
||||
|
||||
return image
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue