Added highlight box around current day.
This commit is contained in:
parent
e19bfa0b0b
commit
60b94c6783
1 changed files with 30 additions and 21 deletions
|
@ -6,15 +6,18 @@ from datetime import datetime, timedelta
|
|||
from WeatherHeaderDesign import WeatherHeaderDesign
|
||||
from PIL import ImageDraw
|
||||
from TextDesign import TextDesign
|
||||
from BoxDesign import BoxDesign
|
||||
from EllipseDesign import EllipseDesign
|
||||
|
||||
weatherheadersize = (1,0.113)
|
||||
seperatorplace = (0, 0.113)
|
||||
monthplace = (0, 0.11)
|
||||
monthplace = (0, 0.12)
|
||||
monthboxsize = (1, 0.085)
|
||||
daynumberboxsize = (0.143, 0.143)
|
||||
dayhighlightboxsize = (0.143, 0.07)
|
||||
daynumbersize = 25
|
||||
monthtextsize = 40
|
||||
monthovposition = (0, 0.225)
|
||||
monthovposition = (0, 0.23)
|
||||
monthovsize = (1, 0.5)
|
||||
weekdayrowpos = (0, 0.209)
|
||||
weekrowboxsize = (1, 0.044)
|
||||
|
@ -38,7 +41,7 @@ class MonthOvPanel (PanelDesign):
|
|||
self.__draw_seperator__()
|
||||
self.__draw_month_overview__()
|
||||
self.__draw_week_row__()
|
||||
|
||||
|
||||
def add_weather (self, weather):
|
||||
self.draw_design(WeatherHeaderDesign(self.__abs_pos__(weatherheadersize), weather))
|
||||
|
||||
|
@ -48,23 +51,23 @@ class MonthOvPanel (PanelDesign):
|
|||
def add_rssfeed (self, rss):
|
||||
raise NotImplementedError("Functions needs to be implemented")
|
||||
|
||||
def __abs_pos__(self, pos, size=None):
|
||||
def __abs_pos__ (self, pos, size = None):
|
||||
if size is None:
|
||||
size = self.size
|
||||
return (int(pos[0] * size[0]), int(pos[1] * size[1]))
|
||||
|
||||
def __draw_seperator__(self):
|
||||
def __draw_seperator__ (self):
|
||||
"""Draw a line seperating the weather and Calendar section"""
|
||||
ImageDraw.Draw(self.__image__).line( [self.__abs_pos__(seperatorplace), self.__abs_pos__((1, seperatorplace[1]))], fill='red', width=5)
|
||||
ImageDraw.Draw(self.__image__).line([ self.__abs_pos__(seperatorplace), self.__abs_pos__((1, seperatorplace[1])) ], fill='red', width=5)
|
||||
|
||||
def __draw_day_number__(self, number, pos):
|
||||
def __draw_day_number__ (self, number, pos):
|
||||
if number <= 0:
|
||||
return
|
||||
txt = TextDesign(self.__abs_pos__(daynumberboxsize), fontsize=daynumbersize, text=str(number), verticalalignment="center", horizontalalignment="center")
|
||||
txt.pos = pos
|
||||
self.draw_design(txt)
|
||||
|
||||
def __draw_month_name__(self):
|
||||
def __draw_month_name__ (self):
|
||||
"""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")
|
||||
|
@ -76,7 +79,7 @@ class MonthOvPanel (PanelDesign):
|
|||
partialwidth = maxwidth / 7
|
||||
partialheight = maxheight / 5
|
||||
posx, posy = self.__abs_pos__(monthovposition)
|
||||
return (posx + day_of_week * partialwidth, posy + week_in_month * partialheight)
|
||||
return (int(posx + day_of_week * partialwidth), int(posy + week_in_month * partialheight))
|
||||
|
||||
def __draw_month_overview__ (self):
|
||||
"""Using the built-in calendar function, draw icons for each
|
||||
|
@ -86,6 +89,8 @@ class MonthOvPanel (PanelDesign):
|
|||
for numbers in week:
|
||||
self.__draw_day_number__(numbers, self.__get_day_pos__(cal.index(week), week.index(numbers)))
|
||||
|
||||
self.__draw_highlight_box__(self.__abs_pos__(dayhighlightboxsize), self.__get_today_box_pos__(), width=3)
|
||||
|
||||
def __draw_week_row__ (self):
|
||||
week_days = self.__get_week_days_ordered__()
|
||||
|
||||
|
@ -94,25 +99,29 @@ class MonthOvPanel (PanelDesign):
|
|||
txt.pos = self.__get_week_day_pos__(day_of_week)
|
||||
self.draw_design(txt)
|
||||
|
||||
self.__draw_highlight_box__(self.__abs_pos__(weekrownameboxsize), self.__get_week_day_pos__(datetime.now().weekday()))
|
||||
self.__draw_highlight_box__(self.__abs_pos__(weekrownameboxsize), self.__get_week_day_pos__(datetime.now().weekday()), width=1)
|
||||
|
||||
def __get_week_day_pos__(self, day_of_week):
|
||||
def __get_week_day_pos__ (self, day_of_week):
|
||||
maxwidth, _ = self.__abs_pos__(monthovsize)
|
||||
partialwidth = maxwidth / 7
|
||||
posx, posy = self.__abs_pos__(weekdayrowpos)
|
||||
return (posx + day_of_week * partialwidth, posy)
|
||||
return (int(posx + day_of_week * partialwidth), int(posy))
|
||||
|
||||
def __draw_highlight_box__(self, size, pos, color='black'):
|
||||
topleft = pos
|
||||
bottomright = (pos[0] + size[0], pos[1] + size[1])
|
||||
ImageDraw.Draw(self.__image__).rectangle([topleft, bottomright], outline=color)
|
||||
def __get_today_box_pos__ (self):
|
||||
x, y = self.__get_day_pos__(int(datetime.now().day / 7), datetime.now().weekday())
|
||||
return (x, y + (self.__abs_pos__(daynumberboxsize)[1] - self.__abs_pos__(dayhighlightboxsize)[1]) / 2)
|
||||
|
||||
def __draw_highlight_circle__(self, size, pos, color='black'):
|
||||
topleft = pos
|
||||
bottomright = (pos[0] + size[0], pos[1] + size[1])
|
||||
ImageDraw.Draw(self.__image__).ellipse([topleft, bottomright], outline=color)
|
||||
def __draw_highlight_box__ (self, size, pos, color='black', width=1):
|
||||
design = BoxDesign(size, outline=color, width = width)
|
||||
design.pos = pos
|
||||
self.draw_design(design)
|
||||
|
||||
def __get_week_days_ordered__(self):
|
||||
def __draw_highlight_circle__ (self, size, pos, color = 'black', width=1):
|
||||
design = EllipseDesign(size, outline=color, width = width)
|
||||
design.pos = pos
|
||||
self.draw_design(design)
|
||||
|
||||
def __get_week_days_ordered__ (self):
|
||||
cur_weekday = datetime.now().weekday()
|
||||
correction = -cur_weekday
|
||||
if week_starts_on == "Sunday":
|
||||
|
|
Loading…
Reference in a new issue