From e7a1eac8d715903e314dabc8bece992e5d10cb2d Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sun, 14 Aug 2022 13:32:52 +0200 Subject: [PATCH] Split MoonPhaseModule and SunModule --- main.py | 19 ++++++++++++------- modules/weather.py | 34 +++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/main.py b/main.py index 819f758..0a7e5ed 100644 --- a/main.py +++ b/main.py @@ -53,15 +53,16 @@ def main(): image.paste(WeatherJumboCurrentModule().draw_module(config, 480, 150), (0, 50)) # rule - image.paste(modules.RuleModule().draw_module(config, 480, 1), (0, 192)) + image.paste(modules.RuleModule().draw_module(config, 450, 1), (30, 192)) # pluie from modules.weather import WeatherRainModule - image.paste(WeatherRainModule().draw_module(config, 480/2, 100), (0, 205)) + image.paste(WeatherRainModule().draw_module(config, 480-int(480/1.6), 94), (0, 205)) - # sunrise/moonrise - from modules.weather import WeatherSunMoonModule - image.paste(WeatherSunMoonModule().draw_module(config, int(480/2), 100), (int(480/2), 205)) + # moon phase + from modules.weather import WeatherMoonPhaseModule + moon = WeatherMoonPhaseModule().draw_module(config, 65, 65) + image.paste(moon, (0, 163), moon) # weekly weather from modules.weather import WeeklyWeatherModule @@ -76,11 +77,15 @@ def main(): from modules.weather import WeatherTemperatureModule image.paste(WeatherTemperatureModule().draw_module(config, 480, 200), (0, 580)) + # sunrise/set + from modules.weather import WeatherSunModule + image.paste(WeatherSunModule().draw_module(config, int(480/2), 20, start_align=5), (0, 780)) + fnt = ImageFont.truetype(config.fnt_R_path, 11) draw.text( - (5, 798), + (475, 798), "Dernière génération le " + datetime.now().strftime("%c"), - fill="black", anchor="lb", font=fnt + fill="black", anchor="rb", font=fnt ) try: diff --git a/modules/weather.py b/modules/weather.py index 62dfede..d9a6902 100644 --- a/modules/weather.py +++ b/modules/weather.py @@ -104,7 +104,7 @@ class WeatherJumboCurrentModule: self.middle_align = 1/3 def draw_module(self, config, width, height): - image = Image.new('RGB', (width, height), 'white') + image = Image.new('RGBA', (width, height), '#fff0') draw = ImageDraw.Draw(image) fnt_Big = ImageFont.truetype(config.fnt_RB_path, 33) @@ -143,42 +143,50 @@ class WeatherJumboCurrentModule: return image -class WeatherSunMoonModule: +class WeatherMoonPhaseModule: 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, 15) + image = Image.new('RGBA', (width, height), '#fff0') icon = Image.open("icons/" + WeatherAPI().get_moon_icon()).resize((height, height)) image.paste(icon, (0,0), icon) + return image + + +class WeatherSunModule: + + def draw_module(self, config, width, height, start_align=0): + image = Image.new('RGB', (width, height), '#fff') + draw = ImageDraw.Draw(image) + fnt_R = ImageFont.truetype(config.fnt_R_path, int(height*0.7)) + thisdayweather = WeatherAPI().get_daily()["data"][0] import time infos = { "sunrise": WeatherAPI().read_timestamp(thisdayweather["sunriseTime"]).strftime("%X"), "sunset": WeatherAPI().read_timestamp(thisdayweather["sunsetTime"]).strftime("%X"), - "4": "", } - i = 0 - line_size = int(height/len(infos.keys())) + align = start_align for icon, info in infos.items(): if info == "": continue - icon = Image.open("icons/wi-" + icon + ".png").resize((line_size, line_size)) - image.paste(icon, (height,i * line_size), icon) + icon = Image.open("icons/wi-" + icon + ".png").resize((height, height)) + image.paste(icon, (align,0), icon) + align += height + 2 draw.text( - (height + line_size, i * line_size + line_size / 2), + (align, height / 2), info, fill="black", anchor="lm", font=fnt_R ) - i += 1 + align += fnt_R.getsize(info)[0] + align += 10 return image + class WeatherRainModule: def draw_module(self, config, width, height):