Split MoonPhaseModule and SunModule

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

View file

@ -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):