2019-02-28 15:17:43 +01:00
|
|
|
from PanelDesign import PanelDesign
|
2019-05-01 07:17:40 +02:00
|
|
|
from Assets import colors
|
|
|
|
from settings import general_settings, week_starts_on
|
2019-03-02 09:36:55 +01:00
|
|
|
import calendar as callib
|
2019-02-28 18:17:38 +01:00
|
|
|
from datetime import datetime, timedelta
|
2019-02-28 15:17:43 +01:00
|
|
|
from WeatherHeaderDesign import WeatherHeaderDesign
|
|
|
|
from PIL import ImageDraw
|
|
|
|
from TextDesign import TextDesign
|
2019-02-28 20:41:14 +01:00
|
|
|
from BoxDesign import BoxDesign
|
|
|
|
from EllipseDesign import EllipseDesign
|
2019-03-02 10:10:39 +01:00
|
|
|
from MonthBlockDesign import MonthBlockDesign, daynumberboxsize
|
2019-03-03 16:45:21 +01:00
|
|
|
from EventListDesign import EventListDesign
|
2019-03-04 20:10:08 +01:00
|
|
|
from RssPostListDesign import RssPostListDesign
|
2019-04-07 17:08:42 +02:00
|
|
|
from settings import general_settings
|
2019-02-28 15:17:43 +01:00
|
|
|
|
2019-04-07 17:08:42 +02:00
|
|
|
weatherheadersize = (1,0.113)
|
2019-03-02 10:10:39 +01:00
|
|
|
monthtextsize = 40
|
2019-05-01 19:06:37 +02:00
|
|
|
monthovsize = (1, 0.48)
|
|
|
|
monthovposition = (0, 0.25 - weatherheadersize[1])
|
2019-02-28 15:17:43 +01:00
|
|
|
seperatorplace = (0, 0.113)
|
2019-04-07 17:08:42 +02:00
|
|
|
monthplace = (0, 0.12 - weatherheadersize[1])
|
2019-02-28 15:17:43 +01:00
|
|
|
monthboxsize = (1, 0.085)
|
2019-04-07 17:08:42 +02:00
|
|
|
weekdayrowpos = (0, 0.209 - weatherheadersize[1])
|
2019-02-28 17:35:05 +01:00
|
|
|
weekrowboxsize = (1, 0.044)
|
2019-02-28 18:17:38 +01:00
|
|
|
weekdaytextsize = 18
|
|
|
|
weekrownameboxsize = (0.143, 0.044)
|
2019-03-02 09:36:55 +01:00
|
|
|
eventcirclehorizontalsize = 0.100
|
2019-04-07 17:08:42 +02:00
|
|
|
infolistsize = (1, 0.77 + weatherheadersize[1])
|
2019-02-28 15:17:43 +01:00
|
|
|
|
|
|
|
class MonthOvPanel (PanelDesign):
|
|
|
|
"""Overview that focuses on the current month and
|
|
|
|
some additional information in the bottom."""
|
|
|
|
def __init__ (self, size):
|
|
|
|
super(MonthOvPanel, self).__init__(size)
|
2019-04-07 17:08:42 +02:00
|
|
|
self.weather_header_height = 0
|
|
|
|
if general_settings["weather-info"]:
|
|
|
|
self.weather_header_height = self.size[1] * weatherheadersize[1]
|
2019-02-28 15:17:43 +01:00
|
|
|
self.__first_render__()
|
|
|
|
|
|
|
|
def __first_render__ (self):
|
2019-02-28 18:17:38 +01:00
|
|
|
if week_starts_on == "Monday":
|
2019-03-02 09:36:55 +01:00
|
|
|
callib.setfirstweekday(callib.MONDAY)
|
2019-02-28 18:17:38 +01:00
|
|
|
elif week_starts_on == "Sunday":
|
2019-03-02 09:36:55 +01:00
|
|
|
callib.setfirstweekday(callib.SUNDAY)
|
|
|
|
self.__week_days__ = self.__get_week_days_ordered__()
|
2019-02-28 18:17:38 +01:00
|
|
|
|
2019-02-28 15:17:43 +01:00
|
|
|
self.__draw_month_name__()
|
2019-02-28 17:35:05 +01:00
|
|
|
self.__draw_week_row__()
|
2019-02-28 20:41:14 +01:00
|
|
|
|
2019-04-07 17:08:42 +02:00
|
|
|
if general_settings["weather-info"]:
|
|
|
|
self.__draw_seperator__()
|
|
|
|
|
2019-03-02 10:10:39 +01:00
|
|
|
self.month_block = MonthBlockDesign(self.__abs_pos__(monthovsize), datetime.now(), highlight_today = True)
|
2019-04-07 17:08:42 +02:00
|
|
|
pos = self.__abs_pos__(monthovposition)
|
|
|
|
pos = (pos[0], pos[1] + self.weather_header_height)
|
|
|
|
self.month_block.pos = pos
|
2019-03-02 10:10:39 +01:00
|
|
|
self.draw_design(self.month_block)
|
|
|
|
|
2019-02-28 15:17:43 +01:00
|
|
|
def add_weather (self, weather):
|
2019-04-07 17:08:42 +02:00
|
|
|
if general_settings["weather-info"] == False:
|
|
|
|
return
|
2019-02-28 15:17:43 +01:00
|
|
|
self.draw_design(WeatherHeaderDesign(self.__abs_pos__(weatherheadersize), weather))
|
|
|
|
|
|
|
|
def add_rssfeed (self, rss):
|
2019-03-08 17:46:10 +01:00
|
|
|
if general_settings["info-area"] is "rss":
|
2019-03-06 22:15:08 +01:00
|
|
|
self.__draw_rss_post_list_to_bottom__(rss)
|
2019-02-28 15:17:43 +01:00
|
|
|
|
2019-03-02 09:36:55 +01:00
|
|
|
def add_calendar (self, calendar):
|
2019-03-08 17:46:10 +01:00
|
|
|
if general_settings["highlight-event-days"]:
|
2019-03-06 22:15:08 +01:00
|
|
|
month_events = list(set([ (event.begin_datetime.day, event.begin_datetime.month, event.begin_datetime.year) for event in calendar.get_month_events()]))
|
|
|
|
for event in month_events:
|
|
|
|
self.__draw_highlight_event_day__(event)
|
2019-03-02 09:36:55 +01:00
|
|
|
|
2019-03-08 17:46:10 +01:00
|
|
|
if general_settings["info-area"] is "events":
|
2019-03-06 22:15:08 +01:00
|
|
|
self.__draw_event_list_to_bottom__(calendar)
|
2019-03-03 16:45:21 +01:00
|
|
|
|
2019-03-04 20:10:08 +01:00
|
|
|
def __draw_rss_post_list_to_bottom__ (self, rss):
|
|
|
|
month_pos = self.__abs_pos__(monthovposition)
|
|
|
|
month_height = self.month_block.get_real_height()
|
|
|
|
size = self.__abs_pos__(infolistsize)
|
2019-04-07 17:08:42 +02:00
|
|
|
size = (size[0], size[1] - month_height - self.weather_header_height)
|
2019-03-24 21:27:32 +01:00
|
|
|
info_list = RssPostListDesign(size, rss)
|
2019-04-07 17:08:42 +02:00
|
|
|
info_list.pos = (int(month_pos[0]), int(month_pos[1] + month_height + self.weather_header_height))
|
2019-03-04 20:10:08 +01:00
|
|
|
self.draw_design(info_list)
|
|
|
|
|
2019-03-03 16:45:21 +01:00
|
|
|
def __draw_event_list_to_bottom__ (self, calendar):
|
|
|
|
month_pos = self.__abs_pos__(monthovposition)
|
|
|
|
month_height = self.month_block.get_real_height()
|
2019-03-04 20:10:08 +01:00
|
|
|
size = self.__abs_pos__(infolistsize)
|
2019-04-07 17:08:42 +02:00
|
|
|
size = (size[0], size[1] - month_height - self.weather_header_height)
|
2019-03-17 20:55:45 +01:00
|
|
|
|
|
|
|
events = calendar.get_upcoming_events()
|
2019-03-24 21:27:32 +01:00
|
|
|
info_list = EventListDesign(size, events)
|
2019-04-07 17:08:42 +02:00
|
|
|
info_list.pos = (int(month_pos[0]), int(month_pos[1] + month_height + self.weather_header_height))
|
2019-03-04 20:10:08 +01:00
|
|
|
self.draw_design(info_list)
|
2019-03-03 16:45:21 +01:00
|
|
|
|
2019-03-02 09:36:55 +01:00
|
|
|
def __draw_highlight_event_day__ (self, date):
|
|
|
|
first_month_week = datetime(date[2], date[1], 1).isocalendar()[1]
|
|
|
|
cur_date = datetime(date[2], date[1], date[0])
|
|
|
|
|
|
|
|
side_length = int(eventcirclehorizontalsize * self.size[0])
|
|
|
|
circle_size = (side_length,side_length)
|
2019-04-07 17:08:42 +02:00
|
|
|
pos = self.month_block.get_day_pos(cur_date.isocalendar()[1] - first_month_week, self.__get_day_of_week__(cur_date), rel_pos = self.month_block.pos)
|
2019-03-02 10:10:39 +01:00
|
|
|
place_size = (self.month_block.size[0] * daynumberboxsize[0], self.month_block.size[1] * daynumberboxsize[1])
|
2019-03-02 09:36:55 +01:00
|
|
|
pos = (int(pos[0] + (place_size[0] - circle_size[0]) / 2), int(pos[1] + (place_size[1] - circle_size[1]) / 2))
|
|
|
|
self.__draw_highlight_circle__(circle_size, pos, 'red', width=2)
|
|
|
|
|
2019-02-28 20:41:14 +01:00
|
|
|
def __abs_pos__ (self, pos, size = None):
|
2019-02-28 17:35:05 +01:00
|
|
|
if size is None:
|
|
|
|
size = self.size
|
|
|
|
return (int(pos[0] * size[0]), int(pos[1] * size[1]))
|
2019-02-28 15:17:43 +01:00
|
|
|
|
2019-02-28 20:41:14 +01:00
|
|
|
def __draw_seperator__ (self):
|
2019-02-28 15:17:43 +01:00
|
|
|
"""Draw a line seperating the weather and Calendar section"""
|
2019-02-28 20:41:14 +01:00
|
|
|
ImageDraw.Draw(self.__image__).line([ self.__abs_pos__(seperatorplace), self.__abs_pos__((1, seperatorplace[1])) ], fill='red', width=5)
|
2019-02-28 15:17:43 +01:00
|
|
|
|
2019-02-28 20:41:14 +01:00
|
|
|
def __draw_month_name__ (self):
|
2019-02-28 15:17:43 +01:00
|
|
|
"""Draw the icon with the current month's name"""
|
|
|
|
month = datetime.now().strftime("%B")
|
|
|
|
txt = TextDesign(self.__abs_pos__(monthboxsize), fontsize=monthtextsize, text=month, verticalalignment="center", horizontalalignment="center")
|
2019-04-07 17:08:42 +02:00
|
|
|
pos = self.__abs_pos__(monthplace)
|
|
|
|
txt.pos = (pos[0], pos[1] + self.weather_header_height)
|
2019-02-28 15:17:43 +01:00
|
|
|
self.draw_design(txt)
|
|
|
|
|
2019-02-28 17:35:05 +01:00
|
|
|
def __draw_week_row__ (self):
|
2019-03-02 09:36:55 +01:00
|
|
|
for day_of_week, day in enumerate(self.__week_days__):
|
2019-02-28 18:17:38 +01:00
|
|
|
txt = TextDesign(self.__abs_pos__(weekrownameboxsize), fontsize=weekdaytextsize, text=str(day), verticalalignment="center", horizontalalignment="center")
|
|
|
|
txt.pos = self.__get_week_day_pos__(day_of_week)
|
2019-02-28 17:35:05 +01:00
|
|
|
self.draw_design(txt)
|
|
|
|
|
2019-03-02 09:36:55 +01:00
|
|
|
self.__draw_highlight_box__(self.__abs_pos__(weekrownameboxsize), self.__get_week_day_pos__(self.__get_day_of_week__(datetime.now())), width=1)
|
2019-02-28 17:35:05 +01:00
|
|
|
|
2019-02-28 20:41:14 +01:00
|
|
|
def __get_week_day_pos__ (self, day_of_week):
|
2019-02-28 17:35:05 +01:00
|
|
|
maxwidth, _ = self.__abs_pos__(monthovsize)
|
|
|
|
partialwidth = maxwidth / 7
|
|
|
|
posx, posy = self.__abs_pos__(weekdayrowpos)
|
2019-04-07 17:08:42 +02:00
|
|
|
return (int(posx + day_of_week * partialwidth), int(posy + self.weather_header_height))
|
2019-02-28 20:41:14 +01:00
|
|
|
|
2019-04-05 11:37:51 +02:00
|
|
|
def __draw_highlight_box__ (self, size, pos, color = colors["fg"], width = 1):
|
2019-02-28 20:41:14 +01:00
|
|
|
design = BoxDesign(size, outline=color, width = width)
|
|
|
|
design.pos = pos
|
|
|
|
self.draw_design(design)
|
2019-02-28 17:35:05 +01:00
|
|
|
|
2019-04-05 11:37:51 +02:00
|
|
|
def __draw_highlight_circle__ (self, size, pos, color = colors["fg"], width = 1):
|
2019-02-28 20:41:14 +01:00
|
|
|
design = EllipseDesign(size, outline=color, width = width)
|
|
|
|
design.pos = pos
|
|
|
|
self.draw_design(design)
|
2019-02-28 18:17:38 +01:00
|
|
|
|
2019-02-28 20:41:14 +01:00
|
|
|
def __get_week_days_ordered__ (self):
|
2019-02-28 18:17:38 +01:00
|
|
|
cur_weekday = datetime.now().weekday()
|
|
|
|
correction = -cur_weekday
|
|
|
|
if week_starts_on == "Sunday":
|
|
|
|
correction -= 1
|
|
|
|
|
|
|
|
weekdays = []
|
|
|
|
for i in range(7):
|
|
|
|
weekdays.append((datetime.now() + timedelta(days=(i + correction))).strftime("%a"))
|
|
|
|
|
2019-03-02 10:10:39 +01:00
|
|
|
return weekdays
|
|
|
|
|
|
|
|
def __get_day_of_week__ (self, date):
|
|
|
|
return self.__week_days__.index(date.strftime("%a"))
|