2019-02-28 15:17:43 +01:00
|
|
|
from DesignEntity import DesignEntity
|
2019-04-14 10:42:14 +02:00
|
|
|
from Assets import no_response, windicon, tempicon, sunseticon, sunriseicon, wpath, weathericons, humicon
|
2019-02-28 15:17:43 +01:00
|
|
|
from TextDesign import TextDesign
|
2019-03-09 15:46:42 +01:00
|
|
|
from settings import units, hours
|
2019-02-28 15:17:43 +01:00
|
|
|
|
|
|
|
wiconplace = (0, 0)
|
|
|
|
tempplace = (0.779, 0)
|
|
|
|
humplace = (0.779, 0.486)
|
|
|
|
windiconspace = (0.206, 0)
|
|
|
|
sunriseplace = (0.55, 0)
|
|
|
|
sunsetplace = (0.55, 0.486)
|
|
|
|
|
|
|
|
class WeatherHeaderDesign (DesignEntity):
|
|
|
|
"""Defines a top area that displays basic weather information"""
|
|
|
|
def __init__ (self, size, weather):
|
|
|
|
super(WeatherHeaderDesign, self).__init__(size)
|
|
|
|
self.__weather__ = weather
|
|
|
|
self.__first_render__()
|
|
|
|
|
|
|
|
def __first_render__ (self):
|
|
|
|
if self.__weather__.is_available() is False:
|
|
|
|
self.__render_missing_connection__()
|
|
|
|
return
|
|
|
|
|
2019-03-09 15:46:42 +01:00
|
|
|
cur_weather = self.__weather__.get_today_forecast()
|
2019-02-28 15:17:43 +01:00
|
|
|
|
2019-04-14 10:42:14 +02:00
|
|
|
if cur_weather == None:
|
|
|
|
self.__render_missing_connection__()
|
|
|
|
return
|
|
|
|
|
2019-02-28 15:17:43 +01:00
|
|
|
temperature = cur_weather.air_temperature + " " + self.__get_unit__(("°C", "°F"))
|
|
|
|
windspeed = cur_weather.wind_speed + " " + self.__get_unit__(("km/h", "mph"))
|
|
|
|
|
|
|
|
self.__draw_text__(temperature, self.__abs_pos__((0.87, 0)), (50,35))
|
2019-02-28 20:35:01 +01:00
|
|
|
self.__draw_text__(windspeed, self.__abs_pos__((0.297, 0.05)), (100,35))
|
2019-02-28 15:17:43 +01:00
|
|
|
self.__draw_text__(self.__get_time__(cur_weather.sunrise), self.__abs_pos__((0.64,0)), (50,35))
|
|
|
|
self.__draw_text__(self.__get_time__(cur_weather.sunset), self.__abs_pos__((0.64,0.486)), (50,35))
|
|
|
|
self.__draw_text__(cur_weather.air_humidity + " %", self.__abs_pos__((0.87,0.486)), (50,35))
|
|
|
|
self.__draw_text__(cur_weather.short_description, self.__abs_pos__((0.182,0.486)), (144,35))
|
|
|
|
|
|
|
|
self.draw(windicon, self.__abs_pos__(windiconspace))
|
|
|
|
self.draw(sunseticon, self.__abs_pos__(sunsetplace))
|
|
|
|
self.draw(sunriseicon, self.__abs_pos__(sunriseplace))
|
|
|
|
self.draw(humicon, self.__abs_pos__(humplace))
|
|
|
|
self.draw(tempicon, self.__abs_pos__(tempplace))
|
|
|
|
self.draw_image(wpath + weathericons[cur_weather.icon] + '.jpeg', self.__abs_pos__(wiconplace))
|
|
|
|
|
|
|
|
def __render_missing_connection__ (self):
|
2019-04-14 10:42:14 +02:00
|
|
|
self.draw(no_response, self.__abs_pos__(wiconplace))
|
2019-02-28 15:17:43 +01:00
|
|
|
|
|
|
|
def __abs_pos__ (self, pos):
|
|
|
|
return (int(pos[0] * self.size[0]), int(pos[1] * self.size[1]))
|
|
|
|
|
|
|
|
def __draw_text__ (self, text, pos, size):
|
|
|
|
txt = TextDesign(size, fontsize=18, text=text, verticalalignment="center", horizontalalignment="center")
|
|
|
|
txt.pos = pos
|
|
|
|
self.draw_design(txt)
|
|
|
|
|
|
|
|
def __get_unit__ (self, tuple):
|
|
|
|
if units == "metric":
|
|
|
|
return tuple[0]
|
|
|
|
else:
|
|
|
|
return tuple[1]
|
|
|
|
|
|
|
|
def __get_time__ (self, time):
|
|
|
|
if hours == "24":
|
|
|
|
return time.strftime('%H:%M')
|
|
|
|
else:
|
|
|
|
return time.strftime('%I:%M')
|