Use new icons for RATP module
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
4b80ff19dc
commit
2b4968c566
441 changed files with 52 additions and 33 deletions
|
|
@ -214,24 +214,27 @@ class IDFMAPI:
|
|||
|
||||
return None
|
||||
|
||||
def get_line_icon(config, mode, line, size, fill="gray"):
|
||||
def get_line_icon(config, mode, line, size, fill="gray", state=""):
|
||||
if mode == "M" or mode == "metros":
|
||||
icon_mode = "metro"
|
||||
line = line.replace("B", "bis")
|
||||
elif mode == "T" or mode == "tramways":
|
||||
icon_mode = "tram"
|
||||
line = line.replace("T", "").lower()
|
||||
elif mode == "R" or mode == "rers":
|
||||
icon_mode = "RER"
|
||||
|
||||
if mode != "buses":
|
||||
img = Image.open(os.path.join(config.icons_dir, "ratp", "lignes", icon_mode + "_" + line + "_NB" + state + "_RVB.png"))
|
||||
return img.resize((int(size), int(img.height * size / img.width)))
|
||||
|
||||
|
||||
width = int(size * 1.38) if mode == "buses" or mode == "tramways" else size
|
||||
image = Image.new('RGBA', (width, size), '#fff0')
|
||||
draw = ImageDraw.Draw(image)
|
||||
|
||||
fnt_icon = ImageFont.truetype(os.path.join(config.fonts_dir, IDFMAPI.fnt_RB_path), size-3)
|
||||
|
||||
if mode == "M" or mode == "metros":
|
||||
draw.ellipse((0, 0, width, size), fill=fill)
|
||||
elif mode == "T" or mode == "tramways":
|
||||
if fill == "black":
|
||||
draw.rectangle((0, 0, width, size), fill=fill)
|
||||
draw.rectangle((0, 0, width, 1), fill=fill if fill != "black" else "gray")
|
||||
draw.rectangle((0, size-2, width, size), fill=fill if fill != "black" else "gray")
|
||||
elif (mode == "R" or mode == "rers") and "rounded_rectangle" in draw.__dict__:
|
||||
draw.rounded_rectangle((0, 0, width, size), radius=4, fill=fill)
|
||||
else:
|
||||
draw.rectangle((0, 0, width, size), fill=fill)
|
||||
draw.rectangle((0, 0, width, size), fill=fill)
|
||||
draw.text((int(width / 2), int(size / 2)), line, fill="white" if (fill == "black" and mode == "tramways") or (fill != "white" and mode != "tramways") or (fill == "white" and mode == "tramways") else "black", anchor="mm", font=fnt_icon)
|
||||
|
||||
return image
|
||||
|
|
@ -253,16 +256,16 @@ class RATPWeatherModule:
|
|||
if mode[0].upper() + line not in self.major_lines:
|
||||
continue
|
||||
|
||||
def alert_icon(mode, line):
|
||||
def alert_icon(mode, line, state):
|
||||
def icon(size=64):
|
||||
image = Image.new('RGB', (size, size), '#000')
|
||||
|
||||
white = Image.new('RGB', (int(size / 2), int(size / 2)), '#fff')
|
||||
mode_icon = Image.open(os.path.join(config.icons_dir, mode + ".png")).resize((int(size/2), int(size/2)))
|
||||
image.paste(white, (-5,0), mode_icon)
|
||||
|
||||
line_icon = IDFMAPI.get_line_icon(config, mode, line, int(size/2), fill="white")
|
||||
image.paste(line_icon, (int(size/2) - 5,0), line_icon)
|
||||
line_icon = IDFMAPI.get_line_icon(config, mode, line, int(size/2), fill="white", state=state)
|
||||
if state == "":
|
||||
white = Image.new('RGB', (line_icon.width, line_icon.height), '#fff')
|
||||
image.paste(white, (int(size/4),0), line_icon)
|
||||
else:
|
||||
image.paste(line_icon, (int(size/4),0), line_icon)
|
||||
|
||||
return image
|
||||
return icon
|
||||
|
|
@ -279,6 +282,8 @@ class RATPWeatherModule:
|
|||
|
||||
subtitle = ""
|
||||
oneline = False
|
||||
state_type = ""
|
||||
state_importance = ""
|
||||
|
||||
if "applicationPeriods" in disruption:
|
||||
now = datetime.now()
|
||||
|
|
@ -304,6 +309,19 @@ class RATPWeatherModule:
|
|||
|
||||
if "cause" in disruption and disruption["cause"].lower() == "travaux" and begin > now:
|
||||
oneline = True
|
||||
state_type = "travaux"
|
||||
elif "cause" in disruption and disruption["cause"].lower() == "travaux":
|
||||
state_type = "travaux"
|
||||
else:
|
||||
state_type = "trafic"
|
||||
|
||||
if "severity" in disruption:
|
||||
if disruption["severity"] == "NO_SERVICE" or disruption["severity"] == "BLOQUANTE":
|
||||
state_importance = "grand"
|
||||
elif disruption["severity"] == "REDUCED_SERVICE" or disruption["severity"] == "UNKNOWN_EFFECT" or disruption["severity"] == "OTHER_EFFECT":
|
||||
state_importance = "moyen"
|
||||
else:
|
||||
state_importance = "petit"
|
||||
|
||||
if len(application_periods) == 0:
|
||||
continue
|
||||
|
|
@ -318,11 +336,11 @@ class RATPWeatherModule:
|
|||
"title": disruption["title"],
|
||||
"subtitle": subtitle,
|
||||
"description": IDFMAPI.fromHTMLDisruption(disruption["message"]),
|
||||
"icon": alert_icon(mode, line),
|
||||
"icon": alert_icon(mode, line, ("_" + state_type + "_" + state_importance) if state_type != "" else ""),
|
||||
"oneline": oneline,
|
||||
}
|
||||
|
||||
def draw_module(self, config, width, height, line_height=19):
|
||||
def draw_module(self, config, width, height, line_height=22):
|
||||
image = Image.new('RGB', (width, height), '#fff')
|
||||
draw = ImageDraw.Draw(image)
|
||||
|
||||
|
|
@ -334,16 +352,10 @@ class RATPWeatherModule:
|
|||
if mode != "rers" and mode != "buses":
|
||||
align_x = 0
|
||||
|
||||
# display mode icon
|
||||
icon = Image.open(os.path.join(config.icons_dir, mode + ".png")).resize((line_height, line_height))
|
||||
image.paste(icon, (align_x,align_y), icon)
|
||||
|
||||
align_x += line_height + 10
|
||||
|
||||
for line in weather[mode]:
|
||||
if align_x + line_height >= width:
|
||||
align_x = line_height + 10
|
||||
align_y += line_height + 6
|
||||
align_x = 0
|
||||
align_y += int(1.5 * line_height)
|
||||
|
||||
states = []
|
||||
for disruption in weather[mode][line]:
|
||||
|
|
@ -369,23 +381,30 @@ class RATPWeatherModule:
|
|||
else:
|
||||
states.append(disruption["severity"])
|
||||
|
||||
state = ""
|
||||
fill = "darkgray"
|
||||
if "NO_SERVICE" in states:
|
||||
fill = "black"
|
||||
state = "_trafic_grand"
|
||||
elif "REDUCED_SERVICE" in states or "UNKNOWN_EFFECT" in states or "OTHER_EFFECT" in states:
|
||||
fill = "teal"
|
||||
state = "_trafic_moyen"
|
||||
elif "BLOQUANTE TRAVAUX" in states:
|
||||
fill = "teal"
|
||||
state = "_travaux_moyen"
|
||||
elif len(states) > 0:
|
||||
fill = "gray"
|
||||
state = "_trafic_petit"
|
||||
|
||||
icon = IDFMAPI.get_line_icon(config, mode, line, line_height, fill=fill)
|
||||
icon = IDFMAPI.get_line_icon(config, mode, line, line_height, fill=fill, state=state)
|
||||
image.paste(icon, (align_x, align_y), icon)
|
||||
|
||||
align_x += icon.width + 5
|
||||
|
||||
if mode != "metros" and mode != "tramways":
|
||||
align_y += line_height + 10
|
||||
align_y += int(1.5 * line_height)
|
||||
else:
|
||||
align_y += 10
|
||||
align_x += int(1.5 * line_height)
|
||||
|
||||
return image
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue