2019-03-09 15:23:09 +01:00
|
|
|
from DesignEntity import DesignEntity
|
2019-03-09 21:28:02 +01:00
|
|
|
from TextDesign import TextDesign
|
2019-05-01 07:17:40 +02:00
|
|
|
from TableDesign import TableDesign
|
2019-04-08 15:42:30 +02:00
|
|
|
from Assets import wpath, weathericons, tempicon, humicon, windicon, no_response, colors, defaultfontsize
|
2019-03-09 21:28:02 +01:00
|
|
|
from PIL import Image
|
|
|
|
from settings import hours
|
2019-03-09 15:23:09 +01:00
|
|
|
|
2019-03-09 21:28:02 +01:00
|
|
|
icon_xpos = 0.1
|
2019-03-23 12:23:14 +01:00
|
|
|
icon_x_ypos = 0
|
2019-03-09 21:28:02 +01:00
|
|
|
icon_width = 1 - 2 * icon_xpos
|
|
|
|
info_x_ypos = icon_x_ypos + icon_width
|
2019-05-11 21:37:16 +02:00
|
|
|
info_yresize = -0.05
|
2019-04-08 15:42:30 +02:00
|
|
|
fontsize_static = defaultfontsize
|
2019-03-09 21:28:02 +01:00
|
|
|
max_symbol_y_width = 0.15
|
|
|
|
|
|
|
|
class WeatherColumnDesign (DesignEntity):
|
2019-03-09 15:23:09 +01:00
|
|
|
"""Displays weather information in a column"""
|
2019-03-09 21:28:02 +01:00
|
|
|
def __init__ (self, size, forecast):
|
2019-03-09 15:23:09 +01:00
|
|
|
super().__init__(size)
|
2019-03-09 21:28:02 +01:00
|
|
|
self.forecast = forecast
|
|
|
|
|
|
|
|
def __finish_image__ (self):
|
|
|
|
if self.forecast is None:
|
2019-03-09 21:30:22 +01:00
|
|
|
self.__draw_no_response__()
|
2019-03-09 21:28:02 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
self.__draw_icon__(self.forecast.icon)
|
2019-04-17 17:23:41 +02:00
|
|
|
self.__draw_infos__(self.forecast)
|
2019-03-09 21:28:02 +01:00
|
|
|
|
2019-04-17 17:23:41 +02:00
|
|
|
def __draw_infos__ (self, forecast):
|
2019-03-09 21:28:02 +01:00
|
|
|
temperature = forecast.air_temperature + " " + self.__get_unit__(("°C", "°F"))
|
|
|
|
humidity = forecast.air_humidity + "%"
|
|
|
|
windspeed = forecast.wind_speed + " " + self.__get_unit__(("km/h", "mph"))
|
|
|
|
|
2019-04-17 17:23:41 +02:00
|
|
|
numbers_list = [ [ forecast.short_description ],
|
|
|
|
[ temperature ],
|
2019-03-09 21:28:02 +01:00
|
|
|
[ humidity ],
|
2019-05-11 21:37:16 +02:00
|
|
|
[ windspeed ]]
|
2019-03-09 21:28:02 +01:00
|
|
|
|
2019-04-17 17:23:41 +02:00
|
|
|
ypos = info_x_ypos * self.size[0]
|
2019-03-09 21:28:02 +01:00
|
|
|
pos = (0, ypos)
|
2019-05-11 21:37:16 +02:00
|
|
|
size = (self.size[0], self.size[1] + info_yresize * self.size[1] - pos[1])
|
2019-04-17 17:23:41 +02:00
|
|
|
line_spacing = (size[1] - len(numbers_list) * fontsize_static) / (len(numbers_list) + 1)
|
2019-03-09 21:28:02 +01:00
|
|
|
|
2019-05-11 21:37:16 +02:00
|
|
|
table = TableDesign(size, numbers_list, fontsize=fontsize_static, line_spacing=line_spacing, column_horizontal_alignments=[ "center" ], max_col_size=[ size[0] ], truncate_text=False, truncate_rows=False)
|
2019-03-09 21:28:02 +01:00
|
|
|
table.pos = pos
|
|
|
|
self.draw_design(table)
|
|
|
|
|
|
|
|
def __draw_icon__ (self, icon_id):
|
|
|
|
width = int(icon_width * self.size[0])
|
|
|
|
size = (width, width)
|
|
|
|
xpos = icon_xpos * self.size[0]
|
|
|
|
ypos = icon_x_ypos * self.size[0]
|
|
|
|
pos = (xpos, ypos)
|
|
|
|
|
|
|
|
self.__draw_resized_path_at__(wpath + weathericons[icon_id] + ".jpeg", pos, size)
|
|
|
|
|
2019-03-09 21:30:22 +01:00
|
|
|
def __draw_no_response__ (self):
|
2019-03-09 21:28:02 +01:00
|
|
|
width = int(icon_width * self.size[0])
|
|
|
|
size = (width, width)
|
|
|
|
xpos = icon_xpos * self.size[0]
|
|
|
|
ypos = icon_x_ypos * self.size[0]
|
|
|
|
pos = (xpos, ypos)
|
|
|
|
|
2019-03-09 21:30:22 +01:00
|
|
|
self.__draw_resized_image_at__(no_response, pos, size)
|
2019-03-09 21:28:02 +01:00
|
|
|
|
|
|
|
def __draw_resized_path_at__ (self, path, pos, size):
|
|
|
|
img = Image.open(path)
|
|
|
|
self.__draw_resized_image_at__(img, pos, size)
|
|
|
|
|
|
|
|
def __draw_resized_image_at__ (self, img, pos, size):
|
|
|
|
size = (int(size[0]), int(size[1]))
|
|
|
|
resized_img = img.resize(size, resample=Image.LANCZOS)
|
|
|
|
self.draw(resized_img, pos)
|
|
|
|
|
|
|
|
|
|
|
|
def __get_unit__ (self, tuple):
|
|
|
|
if self.forecast.units == "metric":
|
|
|
|
return tuple[0]
|
|
|
|
else:
|
|
|
|
return tuple[1]
|
|
|
|
|
|
|
|
def __abs_co__ (self, coordinates):
|
|
|
|
return (coordinates[0] * self.size[0], coordinates[1] * self.size[1])
|
2019-03-09 15:23:09 +01:00
|
|
|
|
2019-03-09 21:28:02 +01:00
|
|
|
def __get_time__ (self, time):
|
|
|
|
if hours == "24":
|
|
|
|
return time.strftime('%H:%M')
|
|
|
|
else:
|
|
|
|
return time.strftime('%I:%M')
|