This commit is contained in:
parent
24ebfb1941
commit
6a5b3471f2
@ -122,13 +122,13 @@ class AlertsModule:
|
|||||||
)
|
)
|
||||||
if "subtitle" in alert and alert["subtitle"]:
|
if "subtitle" in alert and alert["subtitle"]:
|
||||||
draw.text(
|
draw.text(
|
||||||
((self.icon_size if alert["icon"] is not None else 0) + (fnt_B.getsize(alert["title"])[0] if "title" in alert else 0), align + 12),
|
((self.icon_size if alert["icon"] is not None else 0) + (fnt_B.getlength(alert["title"]) if "title" in alert else 0), align + 12),
|
||||||
alert["subtitle"],
|
alert["subtitle"],
|
||||||
fill="white", anchor="ls", font=fnt_R
|
fill="white", anchor="ls", font=fnt_R
|
||||||
)
|
)
|
||||||
|
|
||||||
if "title" in alert:
|
if "title" in alert:
|
||||||
align += fnt_B.getsize(alert["title"])[1]
|
align += fnt_B.getbbox(alert["title"])[3]
|
||||||
|
|
||||||
align += display_longtext(
|
align += display_longtext(
|
||||||
draw,
|
draw,
|
||||||
@ -208,7 +208,7 @@ def display_longtext(draw, pos, text, font, anchor="lt", maxwidth=9999, maxlines
|
|||||||
cur = ""
|
cur = ""
|
||||||
while len(words) > 0:
|
while len(words) > 0:
|
||||||
added = (" " if len(cur) > 0 else "") + words[0]
|
added = (" " if len(cur) > 0 else "") + words[0]
|
||||||
width = font.getsize(cur + added)[0]
|
width = font.getlength(cur + added)
|
||||||
if width < maxwidth:
|
if width < maxwidth:
|
||||||
words.pop(0)
|
words.pop(0)
|
||||||
cur += added
|
cur += added
|
||||||
@ -224,7 +224,7 @@ def display_longtext(draw, pos, text, font, anchor="lt", maxwidth=9999, maxlines
|
|||||||
lines[-1] += "…"
|
lines[-1] += "…"
|
||||||
break
|
break
|
||||||
|
|
||||||
line_height = font.getsize("test")[1]
|
line_height = font.getbbox("test")[3]
|
||||||
if anchor[1] == "m":
|
if anchor[1] == "m":
|
||||||
y -= line_height * len(lines) / 2
|
y -= line_height * len(lines) / 2
|
||||||
elif anchor[1] == "b":
|
elif anchor[1] == "b":
|
||||||
|
@ -326,7 +326,7 @@ class IcalModule:
|
|||||||
)
|
)
|
||||||
if "new_start" in evt:
|
if "new_start" in evt:
|
||||||
draw.line(
|
draw.line(
|
||||||
(2, align + line_height / 2.6, 2 + fnt_R.getsize(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M"))[0], align + line_height / 2.6),
|
(2, align + line_height / 2.6, 2 + fnt_R.getbbox(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M"))[0], align + line_height / 2.6),
|
||||||
fill="black"
|
fill="black"
|
||||||
)
|
)
|
||||||
draw.text(
|
draw.text(
|
||||||
@ -336,7 +336,7 @@ class IcalModule:
|
|||||||
)
|
)
|
||||||
if "alert" in evt:
|
if "alert" in evt:
|
||||||
draw.text(
|
draw.text(
|
||||||
(2 + fnt_R.getsize(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0], align+line_height*0.6),
|
(2 + fnt_R.getbbox(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0], align+line_height*0.6),
|
||||||
evt["alert"],
|
evt["alert"],
|
||||||
fill="black", anchor="lt", font=fnt_R
|
fill="black", anchor="lt", font=fnt_R
|
||||||
)
|
)
|
||||||
@ -344,7 +344,7 @@ class IcalModule:
|
|||||||
if "location" in evt and now.day == evt["start"].day:
|
if "location" in evt and now.day == evt["start"].day:
|
||||||
if isinstance(evt["start"], datetime):
|
if isinstance(evt["start"], datetime):
|
||||||
align += display_longtext(draw,
|
align += display_longtext(draw,
|
||||||
(2 + fnt_R.getsize(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0], align+line_height*0.6),
|
(2 + fnt_R.getbbox(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0], align+line_height*0.6),
|
||||||
evt["location"],
|
evt["location"],
|
||||||
fill="black", anchor="lt", font=fnt_R
|
fill="black", anchor="lt", font=fnt_R
|
||||||
)
|
)
|
||||||
@ -357,9 +357,9 @@ class IcalModule:
|
|||||||
if "info" in evt:
|
if "info" in evt:
|
||||||
if isinstance(evt["start"], datetime):
|
if isinstance(evt["start"], datetime):
|
||||||
align += display_longtext(draw,
|
align += display_longtext(draw,
|
||||||
(2 + fnt_R.getsize(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0], align+line_height*0.6),
|
(2 + fnt_R.getbbox(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0], align+line_height*0.6),
|
||||||
evt["info"],
|
evt["info"],
|
||||||
fill="black", anchor="lt", font=fnt_R, maxwidth=width - fnt_R.getsize(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0]
|
fill="black", anchor="lt", font=fnt_R, maxwidth=width - fnt_R.getbbox(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0]
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
align += display_longtext(draw,
|
align += display_longtext(draw,
|
||||||
@ -371,9 +371,9 @@ class IcalModule:
|
|||||||
pass
|
pass
|
||||||
elif "end" in evt and (("new_start" in evt and now > evt["new_start"].astimezone(pytz.timezone('Europe/Paris'))) or ("new_start" not in evt and now > evt["start"].astimezone(pytz.timezone('Europe/Paris')))):
|
elif "end" in evt and (("new_start" in evt and now > evt["new_start"].astimezone(pytz.timezone('Europe/Paris'))) or ("new_start" not in evt and now > evt["start"].astimezone(pytz.timezone('Europe/Paris')))):
|
||||||
align += display_longtext(draw,
|
align += display_longtext(draw,
|
||||||
(2 + fnt_R.getsize(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0], align+line_height*0.6),
|
(2 + fnt_R.getbbox(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0], align+line_height*0.6),
|
||||||
"Fin à " + (evt["new_end"] if "new_end" in evt else evt["end"]).astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M"),
|
"Fin à " + (evt["new_end"] if "new_end" in evt else evt["end"]).astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M"),
|
||||||
fill="black", anchor="lt", font=fnt_R, maxwidth=width - fnt_R.getsize(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0]
|
fill="black", anchor="lt", font=fnt_R, maxwidth=width - fnt_R.getbbox(evt["start"].astimezone(pytz.timezone('Europe/Paris')).strftime("%H:%M "))[0]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ class IDFMAPI:
|
|||||||
period = re.compile('Période :[^.]+. ')
|
period = re.compile('Période :[^.]+. ')
|
||||||
period2 = re.compile('Dates? :[^.]+. ')
|
period2 = re.compile('Dates? :[^.]+. ')
|
||||||
more = re.compile(" Plus d'informations sur [^.]+.")
|
more = re.compile(" Plus d'informations sur [^.]+.")
|
||||||
return re.sub(cleanr, '', re.sub(cleanrA, '', re.sub(period, '', re.sub(period2, '', re.sub(more, '', src.replace(' ', ' ').replace(' ', ' ').replace('’', "'").replace('à', 'à').replace('é', 'é').replace('è', 'è').replace('ê', 'ê').replace('û', 'û').replace('Î', 'Î').replace('<br>', ' ').replace('</p>', ' ').replace('Information Ile de France Mobilités :', '').replace("Les horaires du calculateur d'itinéraire tiennent compte des travaux. ", '').replace("à la demande de la Préfecture de Police et d'Île-de-France Mobilités, et ", '')))))).replace(" Pour plus d'informations,.", '').strip()
|
return re.sub(cleanr, '', re.sub(cleanrA, '', re.sub(period, '', re.sub(period2, '', re.sub(more, '', src.replace(' ', ' ').replace(' ', ' ').replace('’', "'").replace('à', 'à').replace('é', 'é').replace('è', 'è').replace('ê', 'ê').replace('û', 'û').replace('Î', 'Î').replace('<br>', ' ').replace('</p>', ' ').replace('Information Ile de France Mobilités :', '').replace("Les horaires du calculateur d'itinéraire tiennent compte des travaux. ", '').replace("à la demande de la Préfecture de Police et d'Île-de-France Mobilités, et ", '')))))).replace(" Pour plus d'informations,.", '').replace(" Pour plus d'informations, .", '').strip()
|
||||||
|
|
||||||
def get_schedules(self, mode, line, station, way="A+R"):
|
def get_schedules(self, mode, line, station, way="A+R"):
|
||||||
if mode == "M":
|
if mode == "M":
|
||||||
@ -417,10 +417,10 @@ class RATPNextStopModule:
|
|||||||
|
|
||||||
align_x = line_height * 2
|
align_x = line_height * 2
|
||||||
|
|
||||||
sz = fnt_B.getsize(dest)[0]
|
sz = fnt_B.getlength(dest)
|
||||||
while sz > max_dest:
|
while sz > max_dest:
|
||||||
dest = dest[:-1]
|
dest = dest[:-1]
|
||||||
sz = fnt_B.getsize(dest)[0]
|
sz = fnt_B.getlength(dest)
|
||||||
|
|
||||||
draw.text(
|
draw.text(
|
||||||
(align_x, align),
|
(align_x, align),
|
||||||
@ -436,7 +436,7 @@ class RATPNextStopModule:
|
|||||||
msg["message"],
|
msg["message"],
|
||||||
font=fnt_R, anchor="lt", fill="black"
|
font=fnt_R, anchor="lt", fill="black"
|
||||||
)
|
)
|
||||||
align_x += fnt_R.getsize(msg["message"])[0] + int(line_height/2.5)
|
align_x += fnt_R.getlength(msg["message"]) + int(line_height/2.5)
|
||||||
|
|
||||||
align += line_height
|
align += line_height
|
||||||
align += int(line_height * 0.33)
|
align += int(line_height * 0.33)
|
||||||
|
@ -18,9 +18,9 @@ def draw_format_infos(infos, width, height, fnt_R, fnt_B, label_margin, align_he
|
|||||||
nb_infos = len(infos.keys())
|
nb_infos = len(infos.keys())
|
||||||
size = 0
|
size = 0
|
||||||
for k,v in infos.items():
|
for k,v in infos.items():
|
||||||
size += fnt_R.getsize(k)[0]
|
size += fnt_R.getlength(k)
|
||||||
size += label_margin
|
size += label_margin
|
||||||
size += fnt_B.getsize(v)[0]
|
size += fnt_B.getlength(v)
|
||||||
|
|
||||||
margin = (width - size) / nb_infos
|
margin = (width - size) / nb_infos
|
||||||
align = 0
|
align = 0
|
||||||
@ -32,13 +32,13 @@ def draw_format_infos(infos, width, height, fnt_R, fnt_B, label_margin, align_he
|
|||||||
k,
|
k,
|
||||||
font=fnt_R, **kwargs
|
font=fnt_R, **kwargs
|
||||||
)
|
)
|
||||||
align += fnt_R.getsize(k)[0] + label_margin
|
align += fnt_R.getlength(k) + label_margin
|
||||||
draw.text(
|
draw.text(
|
||||||
(align, align_height),
|
(align, align_height),
|
||||||
v,
|
v,
|
||||||
font=fnt_B, **kwargs
|
font=fnt_B, **kwargs
|
||||||
)
|
)
|
||||||
align += fnt_B.getsize(v)[0] + margin
|
align += fnt_B.getlength(v) + margin
|
||||||
|
|
||||||
return image
|
return image
|
||||||
|
|
||||||
@ -51,8 +51,9 @@ def draw_format_array(infos, width, height, fnt_R, fnt_B, label_margin, align_he
|
|||||||
title_hsize = 0
|
title_hsize = 0
|
||||||
text_hsize = 0
|
text_hsize = 0
|
||||||
for k,v in infos.items():
|
for k,v in infos.items():
|
||||||
ksize,ksizeH = fnt_R.getsize(k)
|
print(fnt_R.getbbox(k))
|
||||||
vsize,vsizeH = fnt_B.getsize(v)
|
_,_,ksize,ksizeH = fnt_R.getbbox(k)
|
||||||
|
_,_,vsize,vsizeH = fnt_B.getbbox(v)
|
||||||
if title_hsize < ksizeH:
|
if title_hsize < ksizeH:
|
||||||
title_hsize = ksizeH
|
title_hsize = ksizeH
|
||||||
if text_hsize < vsizeH:
|
if text_hsize < vsizeH:
|
||||||
@ -65,7 +66,7 @@ def draw_format_array(infos, width, height, fnt_R, fnt_B, label_margin, align_he
|
|||||||
if margin_bf_first:
|
if margin_bf_first:
|
||||||
align += margin / 2
|
align += margin / 2
|
||||||
for k,v in infos.items():
|
for k,v in infos.items():
|
||||||
size = max(fnt_R.getsize(k)[0],fnt_B.getsize(v)[0])
|
size = max(fnt_R.getlength(k),fnt_B.getlength(v))
|
||||||
draw.text(
|
draw.text(
|
||||||
(align + (0 if "anchor" not in kwargs or kwargs["anchor"][0] != "m" else size/2), align_height-title_hsize/2),
|
(align + (0 if "anchor" not in kwargs or kwargs["anchor"][0] != "m" else size/2), align_height-title_hsize/2),
|
||||||
k,
|
k,
|
||||||
@ -185,14 +186,14 @@ class WeatherSunModule:
|
|||||||
if info == "":
|
if info == "":
|
||||||
continue
|
continue
|
||||||
icon = Image.open(os.path.join(config.icons_dir, "wi-" + icon + ".png")).resize((height, height))
|
icon = Image.open(os.path.join(config.icons_dir, "wi-" + icon + ".png")).resize((height, height))
|
||||||
image.paste(icon, (align,0), icon)
|
image.paste(icon, (int(align),0), icon)
|
||||||
align += height + 2
|
align += height + 2
|
||||||
draw.text(
|
draw.text(
|
||||||
(align, height / 2),
|
(align, height / 2),
|
||||||
info,
|
info,
|
||||||
fill="black", anchor="lm", font=fnt_R
|
fill="black", anchor="lm", font=fnt_R
|
||||||
)
|
)
|
||||||
align += fnt_R.getsize(info)[0]
|
align += fnt_R.getlength(info)
|
||||||
align += 10
|
align += 10
|
||||||
|
|
||||||
return image
|
return image
|
||||||
@ -215,7 +216,7 @@ class WeatherRainModule:
|
|||||||
icon_path = "wi-snowflake-cold.png"
|
icon_path = "wi-snowflake-cold.png"
|
||||||
elif thisdayweather["daily_chance_of_rain"] > 0:
|
elif thisdayweather["daily_chance_of_rain"] > 0:
|
||||||
gauge.add('Pluie', [{'value': thisdayweather["daily_chance_of_rain"] + 1}])
|
gauge.add('Pluie', [{'value': thisdayweather["daily_chance_of_rain"] + 1}])
|
||||||
if thisdayweather["gust_kph"] > 45:
|
if "gust_kph" in thisdayweather and thisdayweather["gust_kph"] > 45:
|
||||||
icon_path = "wi-wind-beaufort-6.png"
|
icon_path = "wi-wind-beaufort-6.png"
|
||||||
else:
|
else:
|
||||||
icon_path = "wi-umbrella.png"
|
icon_path = "wi-umbrella.png"
|
||||||
@ -333,7 +334,7 @@ class WeeklyWeatherModule:
|
|||||||
"%d˚" % math.trunc(day["mintemp_c"]),
|
"%d˚" % math.trunc(day["mintemp_c"]),
|
||||||
fill="black", anchor="rt", font=fnt_R
|
fill="black", anchor="rt", font=fnt_R
|
||||||
)
|
)
|
||||||
summary_size = fnt_R.getsize(day["date"].strftime("%a") + " : " + day["condition"]["text"])[0]
|
summary_size = fnt_R.getlength(day["date"].strftime("%a") + " : " + day["condition"]["text"])
|
||||||
draw.text(
|
draw.text(
|
||||||
(day_size + (width - day_size - summary_size) / 2, (i + 1) * day_size - 6),
|
(day_size + (width - day_size - summary_size) / 2, (i + 1) * day_size - 6),
|
||||||
day["date"].strftime("%a") + " : ",
|
day["date"].strftime("%a") + " : ",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user