Fix pillow 10
continuous-integration/drone/push Build is passing Details

This commit is contained in:
nemunaire 2023-12-09 17:40:39 +01:00
parent 24ebfb1941
commit 6a5b3471f2
4 changed files with 27 additions and 26 deletions

View File

@ -122,13 +122,13 @@ class AlertsModule:
)
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] 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"],
fill="white", anchor="ls", font=fnt_R
)
if "title" in alert:
align += fnt_B.getsize(alert["title"])[1]
align += fnt_B.getbbox(alert["title"])[3]
align += display_longtext(
draw,
@ -208,7 +208,7 @@ def display_longtext(draw, pos, text, font, anchor="lt", maxwidth=9999, maxlines
cur = ""
while len(words) > 0:
added = (" " if len(cur) > 0 else "") + words[0]
width = font.getsize(cur + added)[0]
width = font.getlength(cur + added)
if width < maxwidth:
words.pop(0)
cur += added
@ -224,7 +224,7 @@ def display_longtext(draw, pos, text, font, anchor="lt", maxwidth=9999, maxlines
lines[-1] += ""
break
line_height = font.getsize("test")[1]
line_height = font.getbbox("test")[3]
if anchor[1] == "m":
y -= line_height * len(lines) / 2
elif anchor[1] == "b":

View File

@ -326,7 +326,7 @@ class IcalModule:
)
if "new_start" in evt:
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"
)
draw.text(
@ -336,7 +336,7 @@ class IcalModule:
)
if "alert" in evt:
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"],
fill="black", anchor="lt", font=fnt_R
)
@ -344,7 +344,7 @@ class IcalModule:
if "location" in evt and now.day == evt["start"].day:
if isinstance(evt["start"], datetime):
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"],
fill="black", anchor="lt", font=fnt_R
)
@ -357,9 +357,9 @@ class IcalModule:
if "info" in evt:
if isinstance(evt["start"], datetime):
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"],
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:
align += display_longtext(draw,
@ -371,9 +371,9 @@ class IcalModule:
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')))):
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"),
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]
)

View File

@ -100,7 +100,7 @@ class IDFMAPI:
period = re.compile('Période :[^.]+. ')
period2 = re.compile('Dates? :[^.]+. ')
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('&nbsp;', ' ').replace('&#160;', ' ').replace('&#8217;', "'").replace('&#224;', 'à').replace('&#233;', 'é').replace('&#232;', 'è').replace('&#234;', 'ê').replace('&#251;', 'û').replace('&#206;', 'Î').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('&nbsp;', ' ').replace('&#160;', ' ').replace('&#8217;', "'").replace('&#224;', 'à').replace('&#233;', 'é').replace('&#232;', 'è').replace('&#234;', 'ê').replace('&#251;', 'û').replace('&#206;', 'Î').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"):
if mode == "M":
@ -417,10 +417,10 @@ class RATPNextStopModule:
align_x = line_height * 2
sz = fnt_B.getsize(dest)[0]
sz = fnt_B.getlength(dest)
while sz > max_dest:
dest = dest[:-1]
sz = fnt_B.getsize(dest)[0]
sz = fnt_B.getlength(dest)
draw.text(
(align_x, align),
@ -436,7 +436,7 @@ class RATPNextStopModule:
msg["message"],
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 += int(line_height * 0.33)

View File

@ -18,9 +18,9 @@ def draw_format_infos(infos, width, height, fnt_R, fnt_B, label_margin, align_he
nb_infos = len(infos.keys())
size = 0
for k,v in infos.items():
size += fnt_R.getsize(k)[0]
size += fnt_R.getlength(k)
size += label_margin
size += fnt_B.getsize(v)[0]
size += fnt_B.getlength(v)
margin = (width - size) / nb_infos
align = 0
@ -32,13 +32,13 @@ def draw_format_infos(infos, width, height, fnt_R, fnt_B, label_margin, align_he
k,
font=fnt_R, **kwargs
)
align += fnt_R.getsize(k)[0] + label_margin
align += fnt_R.getlength(k) + label_margin
draw.text(
(align, align_height),
v,
font=fnt_B, **kwargs
)
align += fnt_B.getsize(v)[0] + margin
align += fnt_B.getlength(v) + margin
return image
@ -51,8 +51,9 @@ def draw_format_array(infos, width, height, fnt_R, fnt_B, label_margin, align_he
title_hsize = 0
text_hsize = 0
for k,v in infos.items():
ksize,ksizeH = fnt_R.getsize(k)
vsize,vsizeH = fnt_B.getsize(v)
print(fnt_R.getbbox(k))
_,_,ksize,ksizeH = fnt_R.getbbox(k)
_,_,vsize,vsizeH = fnt_B.getbbox(v)
if title_hsize < ksizeH:
title_hsize = ksizeH
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:
align += margin / 2
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(
(align + (0 if "anchor" not in kwargs or kwargs["anchor"][0] != "m" else size/2), align_height-title_hsize/2),
k,
@ -185,14 +186,14 @@ class WeatherSunModule:
if info == "":
continue
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
draw.text(
(align, height / 2),
info,
fill="black", anchor="lm", font=fnt_R
)
align += fnt_R.getsize(info)[0]
align += fnt_R.getlength(info)
align += 10
return image
@ -215,7 +216,7 @@ class WeatherRainModule:
icon_path = "wi-snowflake-cold.png"
elif thisdayweather["daily_chance_of_rain"] > 0:
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"
else:
icon_path = "wi-umbrella.png"
@ -333,7 +334,7 @@ class WeeklyWeatherModule:
"%d˚" % math.trunc(day["mintemp_c"]),
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(
(day_size + (width - day_size - summary_size) / 2, (i + 1) * day_size - 6),
day["date"].strftime("%a") + " : ",