From af4730a96474cf086f05b72e37db7e2ab16d22c2 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 12 Aug 2022 13:04:21 +0200 Subject: [PATCH] Improve positions --- modules/weather.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/modules/weather.py b/modules/weather.py index 444c818..943cea6 100644 --- a/modules/weather.py +++ b/modules/weather.py @@ -239,7 +239,8 @@ class WeeklyWeatherModule: def draw_module(self, config, width, height): image = Image.new('RGB', (width, height), 'white') draw = ImageDraw.Draw(image) - fnt_R = ImageFont.truetype(config.fnt_R_path, 12) + fnt_R = ImageFont.truetype(config.fnt_R_path, 14) + fnt_B = ImageFont.truetype(config.fnt_RB_path, 14) weekweather = WeatherAPI().get_daily() daysweather = weekweather["data"] @@ -247,10 +248,11 @@ class WeeklyWeatherModule: nbdays = len(daysweather[self.first_day:self.first_day+self.limit_futur]) day_size = int(height / (nbdays + 1)) - draw.text( - (day_size + 3, day_size / 2), - "%s" % (weekweather["summary"]), - fill="black", anchor="lm", font=fnt_R + display_longtext(draw, + (day_size + (width - day_size)/2, day_size / 2 + 5), + weekweather["summary"], + fill="black", anchor="mm", font=fnt_B, + maxwidth=width - day_size ) temp = [] @@ -271,10 +273,16 @@ class WeeklyWeatherModule: "%d˚" % math.trunc(day["temperatureLow"]), fill="black", anchor="rt", font=fnt_R ) + summary_size = fnt_R.getsize(WeatherAPI().read_timestamp(day["time"]).strftime("%a") + " : " + day["summary"])[0] draw.text( - (day_size + (width - day_size) / 2, (i + 1) * day_size - 4), + (day_size + (width - day_size - summary_size) / 2, (i + 1) * day_size - 6), + WeatherAPI().read_timestamp(day["time"]).strftime("%a") + " : ", + fill="#666", anchor="ls", font=fnt_R + ) + draw.text( + (day_size + (width - day_size + summary_size) / 2, (i + 1) * day_size - 6), day["summary"], - fill="black", anchor="mb", font=fnt_R + fill="black", anchor="rs", font=fnt_R ) draw.text( (day_size + int((day["temperatureHigh"]-t_min)*t_scale) + 2, i * day_size + 4),