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)
|
|
|
|
|
2019-07-13 08:05:35 +02:00
|
|
|
|
2019-02-28 15:17:43 +01:00
|
|
|
class WeatherHeaderDesign (DesignEntity):
|
|
|
|
"""Defines a top area that displays basic weather information"""
|
2019-07-13 08:05:35 +02:00
|
|
|
|
|
|
|
def __init__(self, size, weather):
|
2019-02-28 15:17:43 +01:00
|
|
|
super(WeatherHeaderDesign, self).__init__(size)
|
|
|
|
self.__weather__ = weather
|
|
|
|
self.__first_render__()
|
|
|
|
|
2019-07-13 08:05:35 +02:00
|
|
|
def __first_render__(self):
|
2019-02-28 15:17:43 +01:00
|
|
|
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-07-13 08:05:35 +02:00
|
|
|
temperature = cur_weather.air_temperature + \
|
|
|
|
" " + self.__get_unit__(("°C", "°F"))
|
|
|
|
if units == "aviation": # pick up aviation
|
2019-05-15 09:14:22 +02:00
|
|
|
if cur_weather.wind_deg == None:
|
|
|
|
cur_weather.wind_deg = ""
|
2019-07-13 08:05:35 +02:00
|
|
|
elif len(cur_weather.wind_deg) == 1: # if deg is 2, add two zeros for format
|
2019-05-15 09:14:22 +02:00
|
|
|
cur_weather.wind_deg = "00" + cur_weather.wind_deg
|
2019-07-13 08:05:35 +02:00
|
|
|
elif len(cur_weather.wind_deg) == 2:
|
2019-05-15 09:14:22 +02:00
|
|
|
cur_weather.wind_deg = "0" + cur_weather.wind_deg
|
2019-07-13 08:05:35 +02:00
|
|
|
if int(cur_weather.wind_speed) < 10:
|
|
|
|
windspeed = cur_weather.wind_deg + "@" + "0" + cur_weather.wind_speed + \
|
|
|
|
self.__get_unit__(
|
|
|
|
("", "")) # added degrees, if wind<10 add a 0 to make two digit
|
2019-05-15 06:15:38 +02:00
|
|
|
else:
|
2019-07-13 08:05:35 +02:00
|
|
|
windspeed = cur_weather.wind_deg + "@" + cur_weather.wind_speed + \
|
|
|
|
self.__get_unit__(("", "")) # added degrees
|
2019-05-15 06:15:38 +02:00
|
|
|
else:
|
2019-07-13 08:05:35 +02:00
|
|
|
windspeed = cur_weather.wind_speed + " " + \
|
|
|
|
self.__get_unit__(("km/h", "mph"))
|
2019-02-28 15:17:43 +01:00
|
|
|
|
2019-07-13 08:05:35 +02:00
|
|
|
self.__draw_text__(temperature, self.__abs_pos__((0.87, 0)), (50, 35))
|
|
|
|
self.__draw_text__(windspeed, self.__abs_pos__(
|
|
|
|
(0.297, 0.05)), (100, 35))
|
|
|
|
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))
|
2019-02-28 15:17:43 +01:00
|
|
|
|
|
|
|
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))
|
2019-07-13 08:05:35 +02:00
|
|
|
self.draw_image(
|
|
|
|
wpath + weathericons[cur_weather.icon] + '.jpeg', self.__abs_pos__(wiconplace))
|
2019-02-28 15:17:43 +01:00
|
|
|
|
2019-07-13 08:05:35 +02:00
|
|
|
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
|
|
|
|
2019-07-13 08:05:35 +02:00
|
|
|
def __abs_pos__(self, pos):
|
2019-02-28 15:17:43 +01:00
|
|
|
return (int(pos[0] * self.size[0]), int(pos[1] * self.size[1]))
|
|
|
|
|
2019-07-13 08:05:35 +02:00
|
|
|
def __draw_text__(self, text, pos, size):
|
|
|
|
txt = TextDesign(size, fontsize=18, text=text,
|
|
|
|
verticalalignment="center", horizontalalignment="center")
|
2019-02-28 15:17:43 +01:00
|
|
|
txt.pos = pos
|
|
|
|
self.draw_design(txt)
|
|
|
|
|
2019-07-13 08:05:35 +02:00
|
|
|
def __get_unit__(self, tuple):
|
2019-05-15 06:23:08 +02:00
|
|
|
if units == "metric" or units == "aviation":
|
2019-02-28 15:17:43 +01:00
|
|
|
return tuple[0]
|
|
|
|
else:
|
|
|
|
return tuple[1]
|
|
|
|
|
2019-07-13 08:05:35 +02:00
|
|
|
def __get_time__(self, time):
|
2019-02-28 15:17:43 +01:00
|
|
|
if hours == "24":
|
|
|
|
return time.strftime('%H:%M')
|
|
|
|
else:
|
2019-05-15 06:15:38 +02:00
|
|
|
return time.strftime('%I:%M')
|