Split MoonPhaseModule and SunModule

This commit is contained in:
nemunaire 2022-08-14 13:32:52 +02:00
parent c03e90d38a
commit e7a1eac8d7
2 changed files with 33 additions and 20 deletions

19
main.py
View File

@ -53,15 +53,16 @@ def main():
image.paste(WeatherJumboCurrentModule().draw_module(config, 480, 150), (0, 50)) image.paste(WeatherJumboCurrentModule().draw_module(config, 480, 150), (0, 50))
# rule # rule
image.paste(modules.RuleModule().draw_module(config, 480, 1), (0, 192)) image.paste(modules.RuleModule().draw_module(config, 450, 1), (30, 192))
# pluie # pluie
from modules.weather import WeatherRainModule 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 # moon phase
from modules.weather import WeatherSunMoonModule from modules.weather import WeatherMoonPhaseModule
image.paste(WeatherSunMoonModule().draw_module(config, int(480/2), 100), (int(480/2), 205)) moon = WeatherMoonPhaseModule().draw_module(config, 65, 65)
image.paste(moon, (0, 163), moon)
# weekly weather # weekly weather
from modules.weather import WeeklyWeatherModule from modules.weather import WeeklyWeatherModule
@ -76,11 +77,15 @@ def main():
from modules.weather import WeatherTemperatureModule from modules.weather import WeatherTemperatureModule
image.paste(WeatherTemperatureModule().draw_module(config, 480, 200), (0, 580)) 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) fnt = ImageFont.truetype(config.fnt_R_path, 11)
draw.text( draw.text(
(5, 798), (475, 798),
"Dernière génération le " + datetime.now().strftime("%c"), "Dernière génération le " + datetime.now().strftime("%c"),
fill="black", anchor="lb", font=fnt fill="black", anchor="rb", font=fnt
) )
try: try:

View File

@ -104,7 +104,7 @@ class WeatherJumboCurrentModule:
self.middle_align = 1/3 self.middle_align = 1/3
def draw_module(self, config, width, height): 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) draw = ImageDraw.Draw(image)
fnt_Big = ImageFont.truetype(config.fnt_RB_path, 33) fnt_Big = ImageFont.truetype(config.fnt_RB_path, 33)
@ -143,42 +143,50 @@ class WeatherJumboCurrentModule:
return image return image
class WeatherSunMoonModule: class WeatherMoonPhaseModule:
def draw_module(self, config, width, height): 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_R = ImageFont.truetype(config.fnt_R_path, 15)
icon = Image.open("icons/" + WeatherAPI().get_moon_icon()).resize((height, height)) icon = Image.open("icons/" + WeatherAPI().get_moon_icon()).resize((height, height))
image.paste(icon, (0,0), icon) 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] thisdayweather = WeatherAPI().get_daily()["data"][0]
import time import time
infos = { infos = {
"sunrise": WeatherAPI().read_timestamp(thisdayweather["sunriseTime"]).strftime("%X"), "sunrise": WeatherAPI().read_timestamp(thisdayweather["sunriseTime"]).strftime("%X"),
"sunset": WeatherAPI().read_timestamp(thisdayweather["sunsetTime"]).strftime("%X"), "sunset": WeatherAPI().read_timestamp(thisdayweather["sunsetTime"]).strftime("%X"),
"4": "",
} }
i = 0 align = start_align
line_size = int(height/len(infos.keys()))
for icon, info in infos.items(): for icon, info in infos.items():
if info == "": if info == "":
continue continue
icon = Image.open("icons/wi-" + icon + ".png").resize((line_size, line_size)) icon = Image.open("icons/wi-" + icon + ".png").resize((height, height))
image.paste(icon, (height,i * line_size), icon) image.paste(icon, (align,0), icon)
align += height + 2
draw.text( draw.text(
(height + line_size, i * line_size + line_size / 2), (align, height / 2),
info, info,
fill="black", anchor="lm", font=fnt_R fill="black", anchor="lm", font=fnt_R
) )
i += 1 align += fnt_R.getsize(info)[0]
align += 10
return image return image
class WeatherRainModule: class WeatherRainModule:
def draw_module(self, config, width, height): def draw_module(self, config, width, height):