Split MoonPhaseModule and SunModule
This commit is contained in:
parent
c03e90d38a
commit
e7a1eac8d7
19
main.py
19
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:
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user