Compare commits
86 commits
Author | SHA1 | Date | |
---|---|---|---|
4df439018e | |||
d830281789 | |||
cd68d4c02b | |||
|
4faf625a70 | ||
4a7eb40bb1 | |||
eaa3de9d79 | |||
b7ede5a026 | |||
83f8f37447 | |||
30eb1e4cdd | |||
d3f46c820e | |||
89f9f6d8fc | |||
36f8c35170 | |||
79acea5668 | |||
8e4fbfdfd9 | |||
1e0f59739f | |||
5d881753b8 | |||
ae3b72c86a | |||
387fdb813f | |||
3309dde202 | |||
6bda730c61 | |||
016d022303 | |||
eeb9e03547 | |||
059fc84cb3 | |||
fdb4331aec | |||
464f489ebd | |||
2269bcf3fa | |||
0200116d88 | |||
ad79095a9d | |||
b58357927f | |||
b74def5bbf | |||
2a36a9a6ce | |||
ba8c95ff67 | |||
ccf28e52b7 | |||
8652ef187c | |||
2bbb19b53e | |||
00a05a1a6e | |||
2a94c1fb90 | |||
|
d8a1c1c250 | ||
f53faee1a5 | |||
95bbc8fb59 | |||
9b1ceba95e | |||
aa34b8bc4f | |||
1a62d9d929 | |||
|
d768712181 | ||
f1cc271e3b | |||
08d30bf7d7 | |||
d4df70ce39 | |||
62dd01fb00 | |||
|
f22f4b825f | ||
|
61fd7af37a | ||
3bd7b55010 | |||
1a50ff5cca | |||
3bac199949 | |||
f417fdbe3e | |||
4d3c2cfbd7 | |||
51d4e20553 | |||
083f4bbf6f | |||
710255604a | |||
d2fa6d8fd7 | |||
a7c7a3e553 | |||
b01942b39d | |||
99929d63a4 | |||
1e8d02dc41 | |||
8211b9829e | |||
07c2484849 | |||
5dcae2d435 | |||
28938b45f8 | |||
7ead3c39c1 | |||
6504851aa1 | |||
69f12de1e5 | |||
64b704c10f | |||
08cc2b7daa | |||
6c4eb5c220 | |||
69d1041f98 | |||
76495bd16c | |||
16f38a9102 | |||
d431dae196 | |||
29eddbbd18 | |||
843163dbda | |||
460c1e8a54 | |||
54a53316cc | |||
|
a6ee7fffa1 | ||
383c7b7121 | |||
b0e5e931f3 | |||
1390f3630a | |||
426291f828 |
62 changed files with 2106 additions and 817 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -16,4 +16,6 @@
|
|||
/Calendar/CalendarEvent.pyc
|
||||
/Calendar/design_exported_old.png
|
||||
/Calendar/settings_dev.py
|
||||
/Calendar/settings_pers.py
|
||||
/.vscode
|
||||
/Calendar/images/
|
|
@ -1,21 +1,25 @@
|
|||
from DesignEntity import DesignEntity
|
||||
from Assets import defaultfontsize, colors
|
||||
from Assets import defaultfontsize, colors, defaultfont, path
|
||||
from datetime import datetime, date, timedelta
|
||||
from TableTextDesign import TableTextDesign
|
||||
from PIL import ImageDraw
|
||||
from TableDesign import TableDesign
|
||||
from PIL import ImageDraw, ImageFont
|
||||
from TextFormatter import date_summary_str, event_prefix_str
|
||||
from settings import line_thickness
|
||||
|
||||
separator_width = line_thickness
|
||||
|
||||
line_width = 1
|
||||
|
||||
class AgendaListDesign (DesignEntity):
|
||||
'''Lists upcoming events in chronological order and groups them by days'''
|
||||
def __init__ (self, size, calendar, line_spacing = 3, col_spacing = 8, text_size = defaultfontsize, start_date = date.today(), always_add_start_row = True):
|
||||
|
||||
def __init__(self, size, calendar, line_spacing=0, col_spacing=8, text_size=defaultfontsize, start_date=date.today(), always_add_start_row=True, day_limit_foresight=91):
|
||||
super(AgendaListDesign, self).__init__(size)
|
||||
self.calendar = calendar
|
||||
self.line_spacing = line_spacing
|
||||
self.col_spacing = col_spacing
|
||||
self.text_size = text_size
|
||||
self.start_dt = datetime(start_date.year, start_date.month, start_date.day)
|
||||
self.day_limit_foresight = day_limit_foresight
|
||||
self.start_dt = date(start_date.year, start_date.month, start_date.day)
|
||||
self.always_add_start_row = always_add_start_row
|
||||
|
||||
def __finish_image__(self):
|
||||
|
@ -25,7 +29,7 @@ class AgendaListDesign (DesignEntity):
|
|||
self.__draw_lines__()
|
||||
|
||||
def __calculate_parameter__(self):
|
||||
self.__line_height__ = self.line_spacing + int(self.text_size)
|
||||
self.__line_height__ = self.line_spacing + self.__get_text_height__()
|
||||
self.__event_number__ = int(int(self.size[1]) // self.__line_height__)
|
||||
self.__date_fontsize__ = self.text_size
|
||||
self.__date_linespace__ = self.line_spacing
|
||||
|
@ -34,7 +38,8 @@ class AgendaListDesign (DesignEntity):
|
|||
self.infos = []
|
||||
self.cell_props = []
|
||||
fetch_day = self.start_dt
|
||||
while len(self.infos) < self.__event_number__:
|
||||
days_foresight = 0
|
||||
while len(self.infos) < self.__event_number__ and days_foresight < self.day_limit_foresight:
|
||||
day_events = self.calendar.get_day_events(fetch_day)
|
||||
fetch_day_added_once = False
|
||||
for event in day_events:
|
||||
|
@ -51,6 +56,7 @@ class AgendaListDesign (DesignEntity):
|
|||
|
||||
self.infos.append(row)
|
||||
fetch_day = fetch_day + timedelta(1)
|
||||
days_foresight = days_foresight + 1
|
||||
|
||||
if self.infos[0][1] != date_summary_str(self.start_dt) and self.always_add_start_row:
|
||||
row = ["", date_summary_str(self.start_dt), "", ""]
|
||||
|
@ -59,7 +65,8 @@ class AgendaListDesign (DesignEntity):
|
|||
self.cell_props.insert(0, props)
|
||||
|
||||
def __draw_infos__(self):
|
||||
table = TableTextDesign(self.size, self.infos, fontsize = self.__date_fontsize__, line_spacing=self.__date_linespace__, col_spacing = self.col_spacing, cell_properties=self.cell_props)
|
||||
table = TableDesign(self.size, self.infos, fontsize=self.__date_fontsize__,
|
||||
line_spacing=self.__date_linespace__, col_spacing=self.col_spacing, cell_properties=self.cell_props)
|
||||
self.draw_design(table)
|
||||
|
||||
def __draw_lines__(self):
|
||||
|
@ -72,7 +79,8 @@ class AgendaListDesign (DesignEntity):
|
|||
pos = (0, ypos)
|
||||
positions = [pos, (self.size[0], ypos)]
|
||||
|
||||
ImageDraw.Draw(self.__image__).line(positions, fill=colors["fg"], width=line_width)
|
||||
ImageDraw.Draw(self.__image__).line(
|
||||
positions, fill=colors["fg"], width=separator_width)
|
||||
|
||||
def __get_row_props__(self, event=None):
|
||||
color = colors["fg"]
|
||||
|
@ -88,3 +96,6 @@ class AgendaListDesign (DesignEntity):
|
|||
"background_color": bg_color
|
||||
}
|
||||
return [default_cell, default_cell, cell, cell]
|
||||
|
||||
def __get_text_height__(self):
|
||||
return ImageFont.truetype(path + defaultfont, self.text_size).font.height
|
||||
|
|
|
@ -1,25 +1,29 @@
|
|||
from PanelDesign import PanelDesign
|
||||
from AgendaListDesign import AgendaListDesign
|
||||
from WeatherHeaderDesign import WeatherHeaderDesign
|
||||
from settings import general_settings
|
||||
from settings import general_settings, line_thickness
|
||||
from PIL import ImageDraw
|
||||
from Assets import colors
|
||||
from RssPostListDesign import RssPostListDesign
|
||||
from CryptoListDesign import CryptoListDesign
|
||||
|
||||
agenda_ypadding = 5
|
||||
weatherheader_height = 0.113
|
||||
seperator_width = 3
|
||||
seperator_width = line_thickness
|
||||
infolist_size = (1, 0.24)
|
||||
infolist_padding = 5
|
||||
infolist_padding = 0
|
||||
|
||||
|
||||
class AgendaListPanel (PanelDesign):
|
||||
'''Lists upcoming events in chronological order and groups them by days'''
|
||||
|
||||
def __init__(self, size):
|
||||
super(AgendaListPanel, self).__init__(size)
|
||||
self.weather_size = (0, 0)
|
||||
self.info_size = (0, 0)
|
||||
if general_settings["weather-info"]:
|
||||
self.weather_size = (self.size[0], self.size[1] * weatherheader_height)
|
||||
self.weather_size = (
|
||||
self.size[0], self.size[1] * weatherheader_height)
|
||||
|
||||
def add_weather(self, weather):
|
||||
self.weather = weather
|
||||
|
@ -40,16 +44,32 @@ class AgendaListPanel (PanelDesign):
|
|||
|
||||
self.__draw_seperator__(1-infolist_size[1], colors["fg"])
|
||||
|
||||
def add_taks (self, tasks):
|
||||
def add_tasks(self, tasks):
|
||||
pass
|
||||
|
||||
def add_crypto(self, crypto):
|
||||
if general_settings["info-area"] != "crypto":
|
||||
return
|
||||
|
||||
self.info_size = self.__abs_pos__(infolist_size)
|
||||
pos = (0, self.size[1] - self.info_size[1] + infolist_padding)
|
||||
|
||||
list = CryptoListDesign(self.info_size, crypto)
|
||||
height = list.get_estimated_height()
|
||||
list.pos = (pos[0], pos[1] + (self.info_size[1] - height))
|
||||
self.draw_design(list)
|
||||
|
||||
self.info_size = (self.size[0], height)
|
||||
self.__draw_seperator__(list.pos[1] / self.size[1], colors["fg"])
|
||||
|
||||
def __finish_panel__(self):
|
||||
self.__draw_calendar__()
|
||||
if general_settings["weather-info"]:
|
||||
self.__draw_weather__()
|
||||
|
||||
def __draw_seperator__(self, height, color):
|
||||
ImageDraw.Draw(self.__image__).line([ self.__abs_pos__((0, height)), self.__abs_pos__((1, height)) ], fill=color, width=seperator_width)
|
||||
ImageDraw.Draw(self.__image__).line([self.__abs_pos__(
|
||||
(0, height)), self.__abs_pos__((1, height))], fill=color, width=seperator_width)
|
||||
|
||||
def __abs_pos__(self, pos, size=None):
|
||||
if size is None:
|
||||
|
@ -57,7 +77,8 @@ class AgendaListPanel (PanelDesign):
|
|||
return (int(pos[0] * size[0]), int(pos[1] * size[1]))
|
||||
|
||||
def __draw_calendar__(self):
|
||||
size = (self.size[0], self.size[1] - self.weather_size[1] - self.info_size[1] - agenda_ypadding)
|
||||
size = (self.size[0], self.size[1] - self.weather_size[1] -
|
||||
self.info_size[1] - agenda_ypadding)
|
||||
|
||||
agenda = AgendaListDesign(size, self.calendar)
|
||||
agenda.pos = (0, agenda_ypadding + self.weather_size[1])
|
||||
|
|
|
@ -32,12 +32,6 @@ fonts = {
|
|||
defaultfont = fonts[font_boldness]
|
||||
defaultfontsize = int(font_size)
|
||||
|
||||
datetime_locals = {
|
||||
"de" : "de_DE.UTF-8",
|
||||
"en" : "en_US.UTF-8",
|
||||
"zh_TW" : "zh_TW.UTF-8"
|
||||
}
|
||||
|
||||
weathericons = {
|
||||
'01d': 'wi-day-sunny', '02d': 'wi-day-cloudy', '03d': 'wi-cloudy',
|
||||
'04d': 'wi-cloudy-windy', '09d': 'wi-showers', '10d': 'wi-rain',
|
||||
|
@ -53,3 +47,49 @@ colors = {
|
|||
"fg": "black",
|
||||
"bg": "white"
|
||||
}
|
||||
|
||||
supported_img_formats = [
|
||||
"BMP",
|
||||
"DIB",
|
||||
"EPS",
|
||||
"GIF",
|
||||
"ICNS",
|
||||
"ICO",
|
||||
"IM",
|
||||
"JPG",
|
||||
"JPEG",
|
||||
"J2K",
|
||||
"J2P",
|
||||
"JPX",
|
||||
"MSP",
|
||||
"PCX",
|
||||
"PNG",
|
||||
"PPM",
|
||||
"SGI",
|
||||
"SPI",
|
||||
"TGA",
|
||||
"TIFF",
|
||||
"WEBP",
|
||||
"XBM",
|
||||
"BLP",
|
||||
"CUR",
|
||||
"DCX",
|
||||
"DDS",
|
||||
"FLI",
|
||||
"FLC",
|
||||
"FPX",
|
||||
"FTEX",
|
||||
"GBR",
|
||||
"GD",
|
||||
"IMT",
|
||||
"IPTC",
|
||||
"NAA",
|
||||
"MCIDAS",
|
||||
"MIC",
|
||||
"MPO",
|
||||
"PCD",
|
||||
"PIXAR",
|
||||
"PSD",
|
||||
"WAL",
|
||||
"XPM",
|
||||
]
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
from DesignEntity import DesignEntity
|
||||
from PIL import ImageDraw, ImageOps
|
||||
|
||||
|
||||
class BoxDesign (DesignEntity):
|
||||
"""Redefinition of ImageDraw.Draw.Rectangle"""
|
||||
|
||||
def __init__(self, size, fill=None, outline=None, width=0):
|
||||
super(BoxDesign, self).__init__((size[0]+1, size[1]+1), mask=True)
|
||||
self.size = size
|
||||
|
@ -17,4 +19,5 @@ class BoxDesign (DesignEntity):
|
|||
self.corners = [topleft, bottomright]
|
||||
|
||||
def __finish_image__(self):
|
||||
ImageDraw.Draw(self.__image__).rectangle(self.corners, fill=self.fill, outline=self.outline, width=self.width)
|
||||
ImageDraw.Draw(self.__image__).rectangle(
|
||||
self.corners, fill=self.fill, outline=self.outline, width=self.width)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class CalendarEvent (object):
|
||||
"""Defines a calendar event, independent of any implementation"""
|
||||
|
||||
def __init__(self):
|
||||
self.begin_datetime = None
|
||||
self.end_datetime = None
|
||||
|
@ -14,6 +15,7 @@ class CalendarEvent (object):
|
|||
self.highlight = None
|
||||
|
||||
self.calendar_name = None
|
||||
self.calendar_url = None
|
||||
|
||||
self.location = None
|
||||
self.fetch_datetime = None
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
from DataSourceInterface import DataSourceInterface
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from datetime import datetime, timezone, timedelta, date
|
||||
from dateutil.rrule import rrulestr
|
||||
from dateutil.parser import parse
|
||||
import calendar
|
||||
from CalendarEvent import CalendarEvent
|
||||
|
||||
|
||||
class CalendarInterface (DataSourceInterface):
|
||||
"""Interface for fetching and processing calendar event information."""
|
||||
|
||||
def __init__(self):
|
||||
self.events = []
|
||||
self.reload()
|
||||
self.excluded_urls = []
|
||||
|
||||
def reload(self):
|
||||
if self.is_available() == False:
|
||||
|
@ -16,47 +19,55 @@ class CalendarInterface (DataSourceInterface):
|
|||
self.events = self.__get_events__()
|
||||
self.events = self.__sort_events__(self.events)
|
||||
|
||||
def exclude_calendars(self, urls=[]):
|
||||
self.excluded_urls = urls
|
||||
|
||||
def __sort_events__(self, events):
|
||||
events.sort(key=lambda x: x.begin_datetime)
|
||||
return events
|
||||
|
||||
def __sort_event_types__(self, events):
|
||||
multiday = [ev for ev in events if ev.multiday]
|
||||
allday = [ev for ev in events if ev.allday and ev.multiday == False]
|
||||
timed = [ev for ev in events if ev.allday ==
|
||||
False and ev.multiday == False]
|
||||
return multiday + allday + timed
|
||||
|
||||
def __get_events__(self):
|
||||
raise NotImplementedError("Functions needs to be implemented")
|
||||
|
||||
def get_upcoming_events (self, timespan = None):
|
||||
def get_upcoming_events(self, timespan=None, start_time=None):
|
||||
if timespan is None:
|
||||
timespan = timedelta(31)
|
||||
return self.__get_events_in_range__(datetime.now(timezone.utc), timespan)
|
||||
if start_time == None:
|
||||
local_tzinfo = datetime.now(timezone.utc).astimezone().tzinfo
|
||||
start_time = datetime.now(local_tzinfo)
|
||||
return self.__get_events_in_range__(start_time, timespan)
|
||||
|
||||
def get_today_events(self):
|
||||
return self.get_day_events(datetime.today())
|
||||
return self.get_day_events(date.today())
|
||||
|
||||
def get_day_events (self, date):
|
||||
if type(date) is not type(date):
|
||||
raise TypeError("get_day_events only takes date-objects as parameters, not \"%s\"" % str(type(date)))
|
||||
day_start = datetime(date.year, date.month, date.day, 0, 0, 0, 0, timezone.utc)
|
||||
def get_day_events(self, day):
|
||||
if type(day) is not type(date.today()):
|
||||
raise TypeError(
|
||||
"get_day_events only takes date-objects as parameters, not \"%s\"" % str(type(day)))
|
||||
local_tzinfo = datetime.now(timezone.utc).astimezone().tzinfo
|
||||
day_start = datetime(day.year, day.month, day.day,
|
||||
0, 0, 0, 0, local_tzinfo)
|
||||
return self.__get_events_in_range__(day_start, timedelta(1))
|
||||
|
||||
def get_month_events (self, month = -1):
|
||||
def get_month_events(self, month=-1, year=-1):
|
||||
if month < 0:
|
||||
month = datetime.now().month
|
||||
if year < 0:
|
||||
year = datetime.now().year
|
||||
|
||||
month_start = datetime(datetime.now().year, month, 1, 0, 0, 0, 0, timezone.utc)
|
||||
month_days = calendar.monthrange(month_start.year, month_start.month)[1]
|
||||
local_tzinfo = datetime.now(timezone.utc).astimezone().tzinfo
|
||||
month_start = datetime(year, month, 1, 0, 0, 0, 0, local_tzinfo)
|
||||
month_days = calendar.monthrange(
|
||||
month_start.year, month_start.month)[1]
|
||||
return self.__get_events_in_range__(month_start, timedelta(month_days))
|
||||
|
||||
def get_week_events (self, week = -1):
|
||||
raise NotImplementedError("Support dropped. Needs update.")
|
||||
if week < 0 and week_starts_on == "Monday":
|
||||
week = int(datetime.now().strftime('%W')) + 1
|
||||
elif week < 0:
|
||||
week = int(datetime.now().strftime('%U')) + 1
|
||||
|
||||
if week_starts_on == "Monday":
|
||||
return self.__get_events_in_range__(lambda x : int(x.begin_datetime.strftime('%W')) + 1 == week or int(x.end_datetime.strftime('%W')) + 1 == week)
|
||||
else:
|
||||
return self.__get_events_in_range__(lambda x : int(x.begin_datetime.strftime('%U')) + 1 == week or int(x.end_datetime.strftime('%U')) + 1 == week)
|
||||
|
||||
def __get_events_in_range__(self, start, duration):
|
||||
if self.events is None:
|
||||
return []
|
||||
|
@ -66,12 +77,17 @@ class CalendarInterface (DataSourceInterface):
|
|||
|
||||
events_in_range = []
|
||||
for event in self.events:
|
||||
event_occurrence = self.__get_if_event_in_range__(event, start, duration)
|
||||
# Is excluded?
|
||||
if event.calendar_url in self.excluded_urls:
|
||||
continue
|
||||
|
||||
event_occurrence = self.__get_if_event_in_range__(
|
||||
event, start, duration)
|
||||
if event_occurrence:
|
||||
events_in_range.extend(event_occurrence)
|
||||
|
||||
events_in_range = self.__sort_events__(events_in_range)
|
||||
return events_in_range
|
||||
return self.__sort_event_types__(events_in_range)
|
||||
|
||||
def __get_if_event_in_range__(self, event, start, duration):
|
||||
'''Returns list or None'''
|
||||
|
@ -88,14 +104,10 @@ class CalendarInterface (DataSourceInterface):
|
|||
first_start = start
|
||||
first_duration = duration
|
||||
second_start = event.begin_datetime
|
||||
second_duration = event.duration
|
||||
else:
|
||||
first_start = event.begin_datetime
|
||||
first_duration = event.duration
|
||||
second_start = start
|
||||
second_duration = duration
|
||||
|
||||
event_end = event.begin_datetime + event.duration
|
||||
|
||||
if (second_start - first_start) < first_duration:
|
||||
return [event]
|
||||
|
@ -106,37 +118,65 @@ class CalendarInterface (DataSourceInterface):
|
|||
end = start + duration
|
||||
occurrences = []
|
||||
|
||||
try:
|
||||
r_string = ""
|
||||
r_string = self.__add_timezoneawarness__(event.rrule)
|
||||
rule = rrulestr(r_string, dtstart=event.begin_datetime)
|
||||
for occurrence in rule:
|
||||
if occurrence - end > timedelta(0):
|
||||
return occurrences
|
||||
merged_event = self.__merge_event_data__(event, start=occurrence)
|
||||
merged_event = self.__merge_event_data__(
|
||||
event, start=occurrence)
|
||||
if self.__is_onetime_in_range__(merged_event, start, duration):
|
||||
occurrences.append(merged_event)
|
||||
return occurrences
|
||||
except Exception as ex:
|
||||
print("\"is_repeating_in_range\" failed while processing: dtstart="+str(event.begin_datetime) +
|
||||
" dtstart.tzinfo="+str(event.begin_datetime.tzinfo)+" rrule="+r_string)
|
||||
raise ex
|
||||
|
||||
def __merge_event_data__(self, event, start=None):
|
||||
if start is not None:
|
||||
event.begin_datetime = start
|
||||
event.end_datetime = start + event.duration
|
||||
merged_event = CalendarEvent()
|
||||
|
||||
return event
|
||||
merged_event.begin_datetime = event.begin_datetime
|
||||
merged_event.end_datetime = event.end_datetime
|
||||
merged_event.duration = event.duration
|
||||
merged_event.allday = event.allday
|
||||
merged_event.multiday = event.multiday
|
||||
merged_event.rrule = event.rrule
|
||||
|
||||
merged_event.title = event.title
|
||||
merged_event.description = event.description
|
||||
merged_event.attendees = event.attendees
|
||||
merged_event.highlight = event.highlight
|
||||
|
||||
merged_event.calendar_name = event.calendar_name
|
||||
merged_event.calendar_url = event.calendar_url
|
||||
|
||||
merged_event.location = event.location
|
||||
merged_event.fetch_datetime = event.fetch_datetime
|
||||
|
||||
if start is not None:
|
||||
merged_event.begin_datetime = start
|
||||
merged_event.end_datetime = start + event.duration
|
||||
|
||||
return merged_event
|
||||
|
||||
def __add_timezoneawarness__(self, rrule):
|
||||
"""UNTIL must be specified in UTC when DTSTART is timezone-aware (which it is)"""
|
||||
if "UNTIL" not in rrule:
|
||||
return rrule
|
||||
|
||||
timezone_str = "T000000Z"
|
||||
until_example = "UNTIL=YYYYMMDD"
|
||||
until_template = "UNTIL=YYYYMMDD"
|
||||
|
||||
until_index = rrule.index("UNTIL")
|
||||
|
||||
tz_index = until_index + len(until_example)
|
||||
if tz_index < 0 or tz_index >= len(rrule):
|
||||
return rrule
|
||||
|
||||
if rrule[tz_index] is "T":
|
||||
tz_index = until_index + len(until_template)
|
||||
if until_index < 0 or (tz_index < len(rrule) and rrule[tz_index] is "T"):
|
||||
return rrule
|
||||
|
||||
if tz_index == len(rrule):
|
||||
return rrule + timezone_str
|
||||
else:
|
||||
return rrule[:tz_index] + timezone_str + rrule[tz_index:]
|
10
Calendar/CryptoCoin.py
Normal file
10
Calendar/CryptoCoin.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
class CryptoCoin(object):
|
||||
def __init__(self):
|
||||
self.name = None
|
||||
self.symbol = None
|
||||
self.price = None
|
||||
self.day_change = None
|
||||
self.currency = None
|
||||
self.datetime = None
|
||||
|
||||
self.fetch_datetime = None
|
17
Calendar/CryptoInterface.py
Normal file
17
Calendar/CryptoInterface.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
from DataSourceInterface import DataSourceInterface
|
||||
|
||||
|
||||
class CryptoInterface(DataSourceInterface):
|
||||
def __init__(self):
|
||||
self.crypto_coins = []
|
||||
|
||||
def reload(self):
|
||||
if self.is_available() == False:
|
||||
return
|
||||
self.crypto_coins = self.__get_coins__()
|
||||
|
||||
def __get_coins__(self):
|
||||
raise NotImplementedError("Function needs to be implemented")
|
||||
|
||||
def get_coins(self):
|
||||
return self.crypto_coins
|
39
Calendar/CryptoListDesign.py
Normal file
39
Calendar/CryptoListDesign.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
from DesignEntity import DesignEntity
|
||||
from TableDesign import TableDesign
|
||||
from Assets import defaultfontsize
|
||||
from GeckoCrypto import GeckoCrypto
|
||||
from settings import crypto_coins
|
||||
|
||||
xpadding = 5
|
||||
|
||||
|
||||
class CryptoListDesign (DesignEntity):
|
||||
def __init__(self, size, crypto, text_size=defaultfontsize):
|
||||
super(CryptoListDesign, self).__init__(size)
|
||||
self.crypto = crypto
|
||||
self.text_size = text_size
|
||||
self.matrix = self.__get_matrix__()
|
||||
|
||||
def __finish_image__(self):
|
||||
col_spacing = 10
|
||||
if len(self.matrix) > 0:
|
||||
col_spacing = (self.size[0] / len(self.matrix[0])) * 0.5
|
||||
|
||||
table_design = TableDesign(self.size, matrix=self.matrix, col_spacing=col_spacing,
|
||||
fontsize=self.text_size, mask=False, truncate_rows=True)
|
||||
table_design.pos = (xpadding, 0)
|
||||
self.draw_design(table_design)
|
||||
|
||||
def __get_matrix__(self):
|
||||
matrix = []
|
||||
coins = self.crypto.get_coins()
|
||||
for coin in coins:
|
||||
row = [coin.symbol.upper(), coin.name, coin.currency + " " +
|
||||
str(coin.price), "% " + str(coin.day_change)]
|
||||
matrix.append(row)
|
||||
return matrix
|
||||
|
||||
def get_estimated_height(self):
|
||||
line_height = self.text_size * 1.25
|
||||
height = line_height * len(self.matrix)
|
||||
return height
|
|
@ -1,5 +1,6 @@
|
|||
class DataSourceInterface (object):
|
||||
"""Interface for child interfaces that fetch data."""
|
||||
|
||||
def is_available(self):
|
||||
raise NotImplementedError("Functions needs to be implemented")
|
||||
|
||||
|
|
33
Calendar/DayBoxDesign.py
Normal file
33
Calendar/DayBoxDesign.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
from DesignEntity import DesignEntity
|
||||
from SingelDayEventListDesign import SingelDayEventListDesign
|
||||
from TextDesign import TextDesign
|
||||
|
||||
header_height = 0.2
|
||||
|
||||
|
||||
class DayBoxDesign (DesignEntity):
|
||||
"""Represents a day with its events in a box."""
|
||||
|
||||
def __init__(self, size, date):
|
||||
super(DayBoxDesign, self).__init__(size)
|
||||
self.date = date
|
||||
|
||||
def add_calendar(self, calendar):
|
||||
self.calendar = calendar
|
||||
|
||||
def __finish_image__(self):
|
||||
self.__draw_header__()
|
||||
self.__draw_events__()
|
||||
|
||||
def __draw_header__(self):
|
||||
pass
|
||||
|
||||
def __draw_events__(self):
|
||||
events = self.calendar.get_day_events(self.date)
|
||||
|
||||
pos = (0, self.size[1] * header_height)
|
||||
size = (self.size[0], self.size[1] - pos[1])
|
||||
|
||||
event_list = SingelDayEventListDesign(size, events)
|
||||
event_list.pos = pos
|
||||
self.draw_design(event_list)
|
151
Calendar/DayFocusListPanel.py
Normal file
151
Calendar/DayFocusListPanel.py
Normal file
|
@ -0,0 +1,151 @@
|
|||
from datetime import date, datetime, timedelta, timezone
|
||||
from settings import line_thickness, general_settings
|
||||
from DayHeaderDesign import DayHeaderDesign
|
||||
from HourListDesign import HourListDesign
|
||||
from DayRowDesign import DayRowDesign
|
||||
from PanelDesign import PanelDesign
|
||||
from Assets import colors
|
||||
from PIL import ImageDraw
|
||||
|
||||
HEADER_SIZE = (1, 0.2)
|
||||
HOURLIST_HEIGHT = 0.3
|
||||
HOURLIST_SIZE = (1, HOURLIST_HEIGHT)
|
||||
DAYLIST_YPOS = HEADER_SIZE[1] + HOURLIST_SIZE[1]
|
||||
DAYLIST_HEIGHT = 1 - HEADER_SIZE[1] - HOURLIST_SIZE[1]
|
||||
DAYLIST_SIZE = (1, DAYLIST_HEIGHT)
|
||||
HOURS_COUNT = 6
|
||||
DAYROW_MIN_FORMAT = 40 / 384
|
||||
DAYROW_MAX_FORMAT = 60 / 384
|
||||
PANEL_LINE_THICKNESS = line_thickness
|
||||
|
||||
|
||||
class DayFocusListPanel (PanelDesign):
|
||||
"""Shows Day-View for today and a short Day-List for
|
||||
the upcoming days."""
|
||||
|
||||
def __init__(self, size):
|
||||
super(DayFocusListPanel, self).__init__(size)
|
||||
self.hours_count = HOURS_COUNT
|
||||
self.__init_modules__()
|
||||
|
||||
def __abs_co__(self, coordinates):
|
||||
return (int(coordinates[0] * self.size[0]), int(coordinates[1] * self.size[1]))
|
||||
|
||||
def __init_modules__(self):
|
||||
self.__init_header__()
|
||||
self.__init_hourlist__()
|
||||
self.__init_daylist__()
|
||||
|
||||
def __init_header__(self):
|
||||
self.__header__ = DayHeaderDesign(
|
||||
self.__abs_co__(HEADER_SIZE), date.today())
|
||||
self.__header__.pos = (0, 0)
|
||||
|
||||
def __init_hourlist__(self):
|
||||
start, end = self.__get_current_hour_range__()
|
||||
size = self.__abs_co__(HOURLIST_SIZE)
|
||||
|
||||
self.__hourlist__ = HourListDesign(size, start, end)
|
||||
self.__hourlist__.pos = (0, self.__header__.size[1])
|
||||
|
||||
def __init_daylist__(self):
|
||||
self.__daylist_rows__ = []
|
||||
self.__calc_dayrow_size__()
|
||||
self.__create_day_rows__()
|
||||
|
||||
def __calc_dayrow_size__(self):
|
||||
max_area_height = DAYLIST_HEIGHT * self.size[1]
|
||||
max_row_number = max_area_height / (DAYROW_MIN_FORMAT * self.size[0])
|
||||
min_row_number = max_area_height / (DAYROW_MAX_FORMAT * self.size[0])
|
||||
average_row_number = (max_row_number + min_row_number) / 2
|
||||
self.dayrow_count = round(average_row_number)
|
||||
row_height = max_area_height / self.dayrow_count
|
||||
self.dayrow_size = (1, row_height / self.size[1])
|
||||
|
||||
def __create_day_rows__(self):
|
||||
following_days = self.__get_following_days__()
|
||||
for i, date in enumerate(following_days):
|
||||
row = DayRowDesign(self.__abs_co__(self.dayrow_size), date)
|
||||
row.pos = self.__get_day_row_pos__(i)
|
||||
self.__daylist_rows__.append(row)
|
||||
|
||||
def __get_following_days__(self):
|
||||
following_days = []
|
||||
for i in range(self.dayrow_count):
|
||||
following_days.append(date.today() + timedelta(days=i + 1))
|
||||
return following_days
|
||||
|
||||
def __get_day_row_pos__(self, i):
|
||||
ypos = self.size[1] * DAYLIST_YPOS
|
||||
down_shift = i * self.dayrow_size[1] * self.size[1]
|
||||
return (0, int(ypos + down_shift))
|
||||
|
||||
def __finish_panel__(self):
|
||||
self.draw_design(self.__header__)
|
||||
self.draw_design(self.__hourlist__)
|
||||
|
||||
for row in self.__daylist_rows__:
|
||||
self.draw_design(row)
|
||||
self.__draw_daylist_lines__()
|
||||
|
||||
def __draw_daylist_lines__(self):
|
||||
positions = []
|
||||
for i in range(len(self.__daylist_rows__)):
|
||||
positions.append(self.__get_day_row_pos__(i)[1])
|
||||
for ypos in positions:
|
||||
line_start = (0, ypos)
|
||||
line_end = (self.size[0], ypos)
|
||||
ImageDraw.Draw(self.__image__).line(
|
||||
[line_start, line_end], fill=colors["fg"], width=PANEL_LINE_THICKNESS)
|
||||
|
||||
def __get_current_hour_range__(self):
|
||||
start_hour = datetime.now().hour
|
||||
additional_hours = self.hours_count - 1
|
||||
|
||||
if start_hour + additional_hours > 23:
|
||||
start_hour = 23 - additional_hours
|
||||
|
||||
return start_hour, start_hour + additional_hours
|
||||
|
||||
def add_weather(self, weather):
|
||||
self.__header__.add_weather(weather)
|
||||
|
||||
def add_calendar(self, calendar):
|
||||
allday_ev, timed_ev = self.__split_events__(
|
||||
calendar.get_today_events())
|
||||
self.__header__.add_events(allday_ev)
|
||||
self.__hourlist__.add_events(timed_ev)
|
||||
|
||||
self.__add_calendar_daylist__(calendar)
|
||||
|
||||
def __split_events__(self, events):
|
||||
allday_ev = []
|
||||
timed_ev = []
|
||||
|
||||
for event in events:
|
||||
if event.allday:
|
||||
allday_ev.append(event)
|
||||
elif event.multiday:
|
||||
if self.__is_today__(event.begin_datetime):
|
||||
timed_ev.append(event)
|
||||
elif self.__is_today__(event.end_datetime):
|
||||
timed_ev.append(event)
|
||||
else:
|
||||
allday_ev.append(event)
|
||||
else:
|
||||
timed_ev.append(event)
|
||||
return allday_ev, timed_ev
|
||||
|
||||
def __is_today__(self, dt):
|
||||
today = date.today()
|
||||
return dt.day == today.day and \
|
||||
dt.month == today.month and \
|
||||
dt.year == today.year
|
||||
|
||||
def __add_calendar_daylist__(self, calendar):
|
||||
calendar.exclude_calendars(general_settings["extra-excluded-urls"])
|
||||
|
||||
for row in self.__daylist_rows__:
|
||||
row.add_calendar(calendar)
|
||||
|
||||
calendar.exclude_calendars()
|
|
@ -2,7 +2,7 @@ from DesignEntity import DesignEntity
|
|||
from PIL import ImageDraw
|
||||
from TextDesign import TextDesign
|
||||
from WeatherColumnDesign import WeatherColumnDesign
|
||||
from datetime import date, timedelta, datetime
|
||||
from datetime import date, timedelta, datetime, timezone
|
||||
from SingelDayEventListDesign import SingelDayEventListDesign
|
||||
from Assets import fonts, colors, defaultfontsize
|
||||
from settings import general_settings
|
||||
|
@ -11,21 +11,26 @@ from BoxDesign import BoxDesign
|
|||
numberbox_ypos = 0.15
|
||||
numberbox_height = 1 - 2 * numberbox_ypos
|
||||
number_height = numberbox_height * 0.83
|
||||
number_boxypos = 0.17
|
||||
month_height = numberbox_height / 4
|
||||
monthbox_xpadding = 0.013
|
||||
monthbox_ypadding = -0.05
|
||||
monthbox_width = 1 - numberbox_ypos - monthbox_xpadding
|
||||
weekday_height = numberbox_height * 0.19
|
||||
weathercolumn_y_size = (0.4, 1)
|
||||
weekdaybox_height = 0.22
|
||||
weekday_height = numberbox_height * 0.19
|
||||
weekdaybox_height = (weekday_height / numberbox_height) * 1.5
|
||||
eventlist_static_fontsize = defaultfontsize
|
||||
eventlist_padding = monthbox_xpadding
|
||||
eventlist_xpadding = monthbox_xpadding
|
||||
eventlist_ypadding = 0.01
|
||||
|
||||
numberbox_font_color = colors["bg"]
|
||||
numberbox_background_color = colors["hl"]
|
||||
weekday_font = fonts["bold"]
|
||||
|
||||
|
||||
class DayHeaderDesign (DesignEntity):
|
||||
"""Detailed and big view of a given date."""
|
||||
|
||||
def __init__(self, size, date):
|
||||
super(DayHeaderDesign, self).__init__(size)
|
||||
self.weather_column_width = 0
|
||||
|
@ -35,9 +40,11 @@ class DayHeaderDesign (DesignEntity):
|
|||
if general_settings["weather-info"] == False:
|
||||
return
|
||||
|
||||
forecast = weather.get_forecast_in_days(self.date.day - date.today().day)
|
||||
forecast = weather.get_forecast_in_days(
|
||||
self.date.day - date.today().day)
|
||||
self.weather_column_width = weathercolumn_y_size[0] * self.size[1]
|
||||
size = (self.weather_column_width, weathercolumn_y_size[1] * self.size[1])
|
||||
size = (self.weather_column_width,
|
||||
weathercolumn_y_size[1] * self.size[1])
|
||||
pos = (self.size[0] - size[0], 0)
|
||||
|
||||
design = WeatherColumnDesign(size, forecast)
|
||||
|
@ -45,9 +52,12 @@ class DayHeaderDesign (DesignEntity):
|
|||
self.draw_design(design)
|
||||
|
||||
def add_calendar(self, calendar):
|
||||
now = datetime.now()
|
||||
time_until_tomorrow = (datetime(now.year, now.month, now.day) + timedelta(1)) - now
|
||||
self.__draw_event_list__(calendar.get_upcoming_events(time_until_tomorrow))
|
||||
local_tzinfo = datetime.now(timezone.utc).astimezone().tzinfo
|
||||
now = datetime.now(local_tzinfo)
|
||||
time_until_tomorrow = (datetime(
|
||||
now.year, now.month, now.day, 0, 0, 0, 0, local_tzinfo) + timedelta(1)) - now
|
||||
self.__draw_event_list__(
|
||||
calendar.get_upcoming_events(time_until_tomorrow, now))
|
||||
|
||||
def add_events(self, events):
|
||||
self.__draw_event_list__(events)
|
||||
|
@ -55,6 +65,9 @@ class DayHeaderDesign (DesignEntity):
|
|||
def add_rssfeed(self, rss):
|
||||
pass
|
||||
|
||||
def add_crypto(self, crypto):
|
||||
pass
|
||||
|
||||
def __finish_image__(self):
|
||||
self.__draw_number_square__()
|
||||
self.__draw_month__()
|
||||
|
@ -63,23 +76,28 @@ class DayHeaderDesign (DesignEntity):
|
|||
box_ypos = numberbox_ypos * self.size[1]
|
||||
box_xpos = numberbox_ypos * self.size[1]
|
||||
box_height = numberbox_height * self.size[1]
|
||||
padding = eventlist_padding * self.size[0]
|
||||
monthbox_height = month_height * self.size[1]
|
||||
pos = (box_xpos + box_height + padding, box_ypos + monthbox_height + padding)
|
||||
size = (self.size[0] - pos[0] - self.weather_column_width, self.size[1] - pos[1] - box_ypos)
|
||||
xpadding = eventlist_xpadding * self.size[0]
|
||||
ypadding = eventlist_ypadding * self.size[1]
|
||||
monthbox_height = (monthbox_ypadding + month_height) * self.size[1]
|
||||
pos = (box_xpos + box_height + xpadding,
|
||||
box_ypos + monthbox_height + ypadding)
|
||||
size = (self.size[0] - pos[0] - self.weather_column_width,
|
||||
self.size[1] - pos[1] - box_ypos)
|
||||
fontsize = eventlist_static_fontsize
|
||||
|
||||
rel_dates = [self.date for _ in range(len(events))]
|
||||
event_list = SingelDayEventListDesign(size, events, fontsize, event_prefix_rel_dates = rel_dates)
|
||||
event_list = SingelDayEventListDesign(
|
||||
size, events, fontsize, event_prefix_rel_dates=rel_dates)
|
||||
event_list.pos = pos
|
||||
self.draw_design(event_list)
|
||||
|
||||
def __draw_month__(self):
|
||||
font_size = int(month_height * self.size[1])
|
||||
padding = int(monthbox_xpadding * self.size[0])
|
||||
xpadding = int(monthbox_xpadding * self.size[0])
|
||||
ypadding = int(monthbox_ypadding * self.size[1])
|
||||
box_ypos = int(numberbox_ypos * self.size[1])
|
||||
box_height = int(numberbox_height * self.size[1])
|
||||
box_pos = (box_ypos + box_height + padding, box_ypos)
|
||||
box_pos = (box_ypos + box_height + xpadding, box_ypos + ypadding)
|
||||
box_size = (int(monthbox_width * self.size[0]), box_height)
|
||||
|
||||
month_name = self.date.strftime("%B")
|
||||
|
@ -104,11 +122,13 @@ class DayHeaderDesign (DesignEntity):
|
|||
font_size = number_height * self.size[1]
|
||||
box_height = numberbox_height * self.size[1]
|
||||
box_ypos = numberbox_ypos * self.size[1]
|
||||
size = (box_height, box_height)
|
||||
pos = (box_ypos, box_ypos)
|
||||
ypadding = number_boxypos * box_height
|
||||
size = (box_height, box_height - ypadding)
|
||||
pos = (box_ypos, box_ypos + ypadding)
|
||||
|
||||
day_text = self.__get_day_text__()
|
||||
number = TextDesign(size, text=day_text, background_color=numberbox_background_color, color=numberbox_font_color, fontsize=font_size, horizontalalignment="center", verticalalignment="center")
|
||||
number = TextDesign(size, text=day_text, background_color=numberbox_background_color,
|
||||
color=numberbox_font_color, fontsize=font_size, horizontalalignment="center", verticalalignment="center")
|
||||
number.pos = pos
|
||||
number.mask = False
|
||||
self.draw_design(number)
|
||||
|
@ -121,7 +141,8 @@ class DayHeaderDesign (DesignEntity):
|
|||
pos = (box_ypos, box_ypos)
|
||||
|
||||
week_day_name = self.date.strftime("%A")
|
||||
week_day = TextDesign(size, text=week_day_name, background_color=numberbox_background_color, color=numberbox_font_color, fontsize=font_size, horizontalalignment="center", verticalalignment = "center", font=weekday_font)
|
||||
week_day = TextDesign(size, text=week_day_name, background_color=numberbox_background_color, color=numberbox_font_color,
|
||||
fontsize=font_size, horizontalalignment="center", verticalalignment="center", font=weekday_font)
|
||||
week_day.pos = pos
|
||||
week_day.mask = False
|
||||
self.draw_design(week_day)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from PanelDesign import PanelDesign
|
||||
from Assets import *
|
||||
from settings import *
|
||||
from Assets import colors
|
||||
from settings import general_settings
|
||||
import calendar as callib
|
||||
from datetime import datetime, timedelta, date
|
||||
from PIL import ImageDraw
|
||||
|
@ -8,10 +8,13 @@ from TextDesign import TextDesign
|
|||
from DayHeaderDesign import DayHeaderDesign
|
||||
from DayRowDesign import DayRowDesign
|
||||
from RssPostListDesign import RssPostListDesign
|
||||
from CryptoListDesign import CryptoListDesign
|
||||
from settings import line_thickness
|
||||
from math import ceil
|
||||
|
||||
todayheader_pos = (0, 0)
|
||||
todayheader_size = (1, 0.25)
|
||||
lines_thickness = 1
|
||||
lines_thickness = line_thickness
|
||||
infoarea_replacedrowscount = 3
|
||||
|
||||
dayrowsarea_ypos = todayheader_size[1]
|
||||
|
@ -19,10 +22,13 @@ dayrowsarea_height = 1 - todayheader_size[1]
|
|||
dayrow_min_format = 50 / 384
|
||||
dayrow_max_format = 70 / 384
|
||||
rss_y_padding = 5
|
||||
crypto_y_padding = 5
|
||||
|
||||
|
||||
class DayListPanel (PanelDesign):
|
||||
"""Overview that focuses on the current day and
|
||||
lists following days in a list below."""
|
||||
|
||||
def __init__(self, size):
|
||||
super(DayListPanel, self).__init__(size)
|
||||
self.__day_rows__ = []
|
||||
|
@ -45,10 +51,19 @@ class DayListPanel (PanelDesign):
|
|||
for row in self.__day_rows__:
|
||||
row.add_rssfeed(rss)
|
||||
if general_settings["info-area"] is "rss":
|
||||
self.__day_rows__ = self.__day_rows__[:-infoarea_replacedrowscount]
|
||||
self.__draw_rss_infoarea__(rss)
|
||||
|
||||
def add_crypto(self, crypto):
|
||||
if general_settings["info-area"] is "crypto":
|
||||
self.__draw_crypto_infoarea__(crypto)
|
||||
|
||||
def add_tasks(self, tasks):
|
||||
pass
|
||||
|
||||
def __draw_rss_infoarea__(self, rss):
|
||||
height = infoarea_replacedrowscount * self.dayrow_size[1] * self.size[1] - rss_y_padding
|
||||
height = infoarea_replacedrowscount * \
|
||||
self.dayrow_size[1] * self.size[1] - rss_y_padding
|
||||
ypos = self.size[1] - height
|
||||
size = (self.size[0], height)
|
||||
pos = (0, ypos)
|
||||
|
@ -57,6 +72,22 @@ class DayListPanel (PanelDesign):
|
|||
design.pos = pos
|
||||
self.draw_design(design)
|
||||
|
||||
def __draw_crypto_infoarea__(self, crypto):
|
||||
height = infoarea_replacedrowscount * \
|
||||
self.dayrow_size[1] * self.size[1] - crypto_y_padding
|
||||
ypos = self.size[1] - height
|
||||
size = (self.size[0], height)
|
||||
pos = (0, ypos)
|
||||
|
||||
design = CryptoListDesign(size, crypto)
|
||||
acutal_height = design.get_estimated_height()
|
||||
design.pos = (pos[0], pos[1] + (height - acutal_height))
|
||||
self.draw_design(design)
|
||||
|
||||
replaced_rows = ceil(
|
||||
acutal_height / (self.dayrow_size[1] * self.size[1]))
|
||||
self.__day_rows__ = self.__day_rows__[:-replaced_rows]
|
||||
|
||||
def __draw_day_rows__(self):
|
||||
following_days = self.__get_following_days__()
|
||||
for i, date in enumerate(following_days):
|
||||
|
@ -78,9 +109,6 @@ class DayListPanel (PanelDesign):
|
|||
row_height = max_area_height / self.dayrow_count
|
||||
self.dayrow_size = (1, row_height / self.size[1])
|
||||
|
||||
if general_settings["info-area"] in ["rss"]:
|
||||
self.dayrow_count -= infoarea_replacedrowscount
|
||||
|
||||
def __get_following_days__(self):
|
||||
following_days = []
|
||||
for i in range(self.dayrow_count):
|
||||
|
@ -88,18 +116,20 @@ class DayListPanel (PanelDesign):
|
|||
return following_days
|
||||
|
||||
def __draw_today_header__(self):
|
||||
header = DayHeaderDesign(self.__abs_co__(todayheader_size), date.today())
|
||||
header = DayHeaderDesign(self.__abs_co__(
|
||||
todayheader_size), date.today())
|
||||
header.pos = self.__abs_co__(todayheader_pos)
|
||||
self.__day_rows__.append(header)
|
||||
|
||||
def __draw_lines__(self):
|
||||
positions = []
|
||||
for i in range(self.dayrow_count + 1):
|
||||
for i in range(len(self.__day_rows__)):
|
||||
positions.append(self.__get_day_row_pos__(i)[1])
|
||||
for ypos in positions:
|
||||
line_start = (0, ypos)
|
||||
line_end = (self.size[0], ypos)
|
||||
ImageDraw.Draw(self.__image__).line([line_start, line_end], fill=colors["fg"], width=lines_thickness)
|
||||
ImageDraw.Draw(self.__image__).line(
|
||||
[line_start, line_end], fill=colors["fg"], width=lines_thickness)
|
||||
|
||||
def __finish_panel__(self):
|
||||
for design in self.__day_rows__:
|
||||
|
|
|
@ -1,26 +1,29 @@
|
|||
from PIL import ImageDraw, Image
|
||||
from TextDesign import TextDesign
|
||||
from settings import week_starts_on, owm_paid_subscription
|
||||
from settings import week_starts_on, owm_paid_subscription, general_settings
|
||||
from DesignEntity import DesignEntity
|
||||
from datetime import datetime
|
||||
from Assets import weathericons, wpath, fonts, colors, defaultfontsize
|
||||
from SingelDayEventListDesign import SingelDayEventListDesign
|
||||
|
||||
daynumber_y_size = (1, 0.65)
|
||||
daynumber_y_size = (1, 0.60)
|
||||
weekday_y_size = (daynumber_y_size[0], 1 - daynumber_y_size[1])
|
||||
weekday_ypos = daynumber_y_size[1]
|
||||
daynumber_fontsize = daynumber_y_size[1] * 0.8
|
||||
weekday_fontsize = weekday_y_size[1] * 0.75
|
||||
daynumber_fontsize = daynumber_y_size[1] * 0.85
|
||||
daynumber_ypadding = 0.1
|
||||
weekday_fontsize = weekday_y_size[1] * 0.65
|
||||
weathericon_ypos = 0.1
|
||||
weathericon_height = 1 - 2 * weathericon_ypos
|
||||
eventlist_xpadding = 5
|
||||
eventlist_ypos = 0.1
|
||||
eventlist_y_fontsize = 0.2 * defaultfontsize / 14
|
||||
eventlist_ypos = 0.02
|
||||
eventlist_y_fontsize = 0.2
|
||||
|
||||
font = fonts["light"]
|
||||
|
||||
|
||||
class DayRowDesign (DesignEntity):
|
||||
"""Detailed view of a given date."""
|
||||
|
||||
def __init__(self, size, date):
|
||||
super(DayRowDesign, self).__init__(size)
|
||||
self.__init_image__()
|
||||
|
@ -41,7 +44,7 @@ class DayRowDesign (DesignEntity):
|
|||
number_width = daynumber_y_size[0] * self.size[1]
|
||||
ypos = eventlist_ypos * self.size[1]
|
||||
weather_width = 0
|
||||
if owm_paid_subscription:
|
||||
if owm_paid_subscription and general_settings["weather-info"]:
|
||||
weather_width = weathericon_height * self.size[1]
|
||||
pos = (number_width + eventlist_xpadding, ypos)
|
||||
size = (self.size[0] - pos[0] - weather_width, self.size[1] - pos[1])
|
||||
|
@ -49,12 +52,14 @@ class DayRowDesign (DesignEntity):
|
|||
|
||||
events = calendar.get_day_events(self.date)
|
||||
rel_dates = [self.date for _ in range(len(events))]
|
||||
event_list = SingelDayEventListDesign(size, events, fontsize, line_spacing=0, event_prefix_rel_dates = rel_dates)
|
||||
event_list = SingelDayEventListDesign(
|
||||
size, events, fontsize, event_prefix_rel_dates=rel_dates)
|
||||
event_list.pos = pos
|
||||
self.draw_design(event_list)
|
||||
|
||||
def __draw_forecast__(self, weather):
|
||||
forecast = weather.get_forecast_in_days(self.date.day - datetime.today().day)
|
||||
forecast = weather.get_forecast_in_days(
|
||||
self.date.day - datetime.today().day)
|
||||
|
||||
if forecast is None:
|
||||
return
|
||||
|
@ -68,34 +73,38 @@ class DayRowDesign (DesignEntity):
|
|||
self.draw(resized_icon, pos)
|
||||
|
||||
def __finish_image__(self):
|
||||
self.__draw_day_number__()
|
||||
self.__draw_weekday__()
|
||||
self.__draw_day_number__()
|
||||
|
||||
def __draw_weekday__(self):
|
||||
font_size = int(weekday_fontsize * self.size[1])
|
||||
size = (weekday_y_size[0] * self.size[1], weekday_y_size[1] * self.size[1])
|
||||
size = (weekday_y_size[0] * self.size[1],
|
||||
weekday_y_size[1] * self.size[1])
|
||||
ypos = weekday_ypos * self.size[1]
|
||||
pos = (0, ypos)
|
||||
|
||||
color = self.__get_day_color__()
|
||||
week_day_name = self.date.strftime("%a")
|
||||
|
||||
week_day = TextDesign(size, text=week_day_name, font=font, color=color, fontsize=font_size, horizontalalignment="center", verticalalignment="top")
|
||||
week_day = TextDesign(size, text=week_day_name, font=font, color=color,
|
||||
fontsize=font_size, horizontalalignment="center", verticalalignment="top")
|
||||
week_day.pos = pos
|
||||
week_day.mask = False
|
||||
self.draw_design(week_day)
|
||||
|
||||
def __draw_day_number__(self):
|
||||
font_size = int(daynumber_fontsize * self.size[1])
|
||||
size = (daynumber_y_size[0] * self.size[1], daynumber_y_size[1] * self.size[1])
|
||||
pos = (0, 0)
|
||||
ypadding = daynumber_ypadding * self.size[1]
|
||||
size = (daynumber_y_size[0] * self.size[1],
|
||||
daynumber_y_size[1] * self.size[1])
|
||||
pos = (0, ypadding)
|
||||
|
||||
day_text = self.__get_day_text__()
|
||||
color = self.__get_day_color__()
|
||||
|
||||
number = TextDesign(size, text=day_text, font=font, color=color, fontsize=font_size, horizontalalignment="center", verticalalignment="bottom")
|
||||
number = TextDesign(size, text=day_text, font=font, color=color,
|
||||
fontsize=font_size, horizontalalignment="center", verticalalignment="bottom")
|
||||
number.pos = pos
|
||||
number.mask = False
|
||||
self.draw_design(number)
|
||||
|
||||
def __abs_co__(self, coordinates):
|
||||
|
|
|
@ -7,6 +7,8 @@ from RssPostListDesign import RssPostListDesign
|
|||
from PIL import ImageDraw
|
||||
from Assets import colors
|
||||
from EventListDesign import EventListDesign
|
||||
from CryptoListDesign import CryptoListDesign
|
||||
|
||||
|
||||
header_size = (1, 0.2)
|
||||
hourlist_size = (1, 1 - header_size[1])
|
||||
|
@ -16,9 +18,11 @@ infoarea_replaced_hours = 4
|
|||
infoarea_borderline_width = 1
|
||||
infoarea_padding = 5
|
||||
|
||||
|
||||
class DayViewPanel (PanelDesign):
|
||||
"""Overview that focuses on the current day and
|
||||
shows a timeline split into hours."""
|
||||
|
||||
def __init__(self, size):
|
||||
super(DayViewPanel, self).__init__(size)
|
||||
self.shownhours_count = default_shownhours_count
|
||||
|
@ -34,7 +38,8 @@ class DayViewPanel (PanelDesign):
|
|||
self.__header__.add_weather(weather)
|
||||
|
||||
def add_calendar(self, calendar):
|
||||
allday_ev, timed_ev = self.__split_events__(calendar.get_today_events())
|
||||
allday_ev, timed_ev = self.__split_events__(
|
||||
calendar.get_today_events())
|
||||
self.__header__.add_events(allday_ev)
|
||||
self.__hourlist__.add_events(timed_ev)
|
||||
|
||||
|
@ -47,16 +52,23 @@ class DayViewPanel (PanelDesign):
|
|||
self.__draw_rss_feed__(rss)
|
||||
self.__draw_infoarea_line__()
|
||||
|
||||
def add_crypto(self, crypto):
|
||||
if general_settings["info-area"] == "crypto":
|
||||
self.__draw_crypto_feed__(crypto)
|
||||
self.__draw_infoarea_line__()
|
||||
|
||||
def __draw_infoarea_line__(self):
|
||||
height = infoarea_replaced_hours * self.__hourlist__.row_size[1]
|
||||
ypos = self.size[1] - height
|
||||
|
||||
line_start = (0, ypos)
|
||||
line_end = (self.size[0], ypos)
|
||||
ImageDraw.Draw(self.__image__).line([ line_start, line_end ], fill=colors["fg"], width=infoarea_borderline_width)
|
||||
ImageDraw.Draw(self.__image__).line(
|
||||
[line_start, line_end], fill=colors["fg"], width=infoarea_borderline_width)
|
||||
|
||||
def __draw_rss_feed__(self, rss):
|
||||
height = infoarea_replaced_hours * self.__hourlist__.row_size[1] - infoarea_padding
|
||||
height = infoarea_replaced_hours * \
|
||||
self.__hourlist__.row_size[1] - infoarea_padding
|
||||
size = (self.size[0], height)
|
||||
pos = (0, self.size[1] - size[1])
|
||||
|
||||
|
@ -64,8 +76,20 @@ class DayViewPanel (PanelDesign):
|
|||
rss.pos = pos
|
||||
self.draw_design(rss)
|
||||
|
||||
def __draw_crypto_feed__(self, crypto):
|
||||
height = infoarea_replaced_hours * \
|
||||
self.__hourlist__.row_size[1] - infoarea_padding
|
||||
size = (self.size[0], height)
|
||||
pos = (0, self.size[1] - size[1])
|
||||
|
||||
crypto = CryptoListDesign(size, crypto)
|
||||
acutal_height = crypto.get_estimated_height()
|
||||
crypto.pos = (pos[0], pos[1] + (height - acutal_height))
|
||||
self.draw_design(crypto)
|
||||
|
||||
def __draw_event_list__(self, calendar):
|
||||
height = infoarea_replaced_hours * self.__hourlist__.row_size[1] - infoarea_padding
|
||||
height = infoarea_replaced_hours * \
|
||||
self.__hourlist__.row_size[1] - infoarea_padding
|
||||
size = (self.size[0], height)
|
||||
pos = (0, self.size[1] - size[1])
|
||||
|
||||
|
@ -73,7 +97,7 @@ class DayViewPanel (PanelDesign):
|
|||
events.pos = pos
|
||||
self.draw_design(events)
|
||||
|
||||
def add_taks (self, tasks):
|
||||
def add_tasks(self, tasks):
|
||||
pass
|
||||
|
||||
def __finish_panel__(self):
|
||||
|
@ -81,13 +105,15 @@ class DayViewPanel (PanelDesign):
|
|||
self.draw_design(self.__hourlist__)
|
||||
|
||||
def __init_header__(self):
|
||||
self.__header__ = DayHeaderDesign(self.__abs_co__(header_size), date.today())
|
||||
self.__header__ = DayHeaderDesign(
|
||||
self.__abs_co__(header_size), date.today())
|
||||
self.__header__.pos = (0, 0)
|
||||
|
||||
def __init_hourlist__(self):
|
||||
start, end = self.__get_current_hour_range__()
|
||||
size = self.__abs_co__(hourlist_size)
|
||||
size = (size[0], size[1] * self.shownhours_count / default_shownhours_count)
|
||||
size = (size[0], size[1] * self.shownhours_count /
|
||||
default_shownhours_count)
|
||||
|
||||
self.__hourlist__ = HourListDesign(size, start, end)
|
||||
self.__hourlist__.pos = (0, self.__header__.size[1])
|
||||
|
@ -113,16 +139,8 @@ class DayViewPanel (PanelDesign):
|
|||
allday_ev.append(event)
|
||||
elif event.multiday:
|
||||
if self.__is_today__(event.begin_datetime):
|
||||
today = date.today()
|
||||
tzinfo = event.end_datetime.tzinfo
|
||||
event.end_datetime = datetime(today.year, today.month, today.day, 0, 0, 0, 0, tzinfo) + timedelta(1)
|
||||
event.duration = timedelta(0, 0, 0, 0, event.begin_datetime.minute, event.begin_datetime.hour)
|
||||
timed_ev.append(event)
|
||||
elif self.__is_today__(event.end_datetime):
|
||||
today = date.today()
|
||||
tzinfo = event.begin_datetime.tzinfo
|
||||
event.begin_datetime = datetime(today.year, today.month, today.day, 0, 0, 0, 0, tzinfo)
|
||||
event.duration = timedelta(0, 0, 0, 0, event.end_datetime.minute, event.end_datetime.hour)
|
||||
timed_ev.append(event)
|
||||
else:
|
||||
allday_ev.append(event)
|
||||
|
|
|
@ -3,8 +3,10 @@ from Assets import weathericons
|
|||
from datetime import datetime
|
||||
import traceback
|
||||
|
||||
|
||||
class DebugConsole (DebugInterface):
|
||||
"""Defines concrete console export of debug objects"""
|
||||
|
||||
def print_event(self, event):
|
||||
print("\nCalendarEvent:")
|
||||
print("---------------------")
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class DebugInterface (object):
|
||||
"""Defines general interface for debugging operations"""
|
||||
|
||||
def print_event(self, event):
|
||||
raise NotImplementedError("Functions needs to be implemented")
|
||||
|
||||
|
|
|
@ -3,11 +3,19 @@ from Assets import colors
|
|||
|
||||
masking_threshold = 200
|
||||
|
||||
|
||||
class DesignEntity (object):
|
||||
"""General entity that can be drawn on to a panel design or
|
||||
other design entities."""
|
||||
|
||||
def __init__(self, size, mask=False, invert_mask=False, color_key=False):
|
||||
self.size = size
|
||||
# Are dimensions >= 0?
|
||||
if self.size[0] < 0:
|
||||
self.size = (0, self.size[1])
|
||||
if self.size[1] < 0:
|
||||
self.size = (self.size[0], 0)
|
||||
|
||||
self.pos = (0, 0)
|
||||
self.mask = mask
|
||||
self.invert_mask = invert_mask
|
||||
|
@ -17,7 +25,7 @@ class DesignEntity (object):
|
|||
|
||||
def __init_image__(self, color=colors["bg"]):
|
||||
rounded_size = (int(self.size[0]), int(self.size[1]))
|
||||
self.__image__ = Image.new('RGB', rounded_size, color=color)
|
||||
self.__image__ = Image.new('RGBA', rounded_size, color=color)
|
||||
|
||||
def get_image(self):
|
||||
if self.__finished_image__ is False:
|
||||
|
@ -29,11 +37,13 @@ class DesignEntity (object):
|
|||
rounded_pos = (int(pos[0]), int(pos[1]))
|
||||
img_mask = None
|
||||
if mask:
|
||||
img_mask = self.__get_mask__(subimage, invert_mask=invert_mask, color_key=color_key)
|
||||
img_mask = self.__get_mask__(
|
||||
subimage, invert_mask=invert_mask, color_key=color_key)
|
||||
self.__image__.paste(subimage, rounded_pos, mask=img_mask)
|
||||
|
||||
def draw_design(self, entity):
|
||||
self.draw(entity.get_image(), entity.pos, entity.mask, entity.invert_mask, entity.color_key)
|
||||
self.draw(entity.get_image(), entity.pos, entity.mask,
|
||||
entity.invert_mask, entity.color_key)
|
||||
|
||||
def draw_image(self, path, pos):
|
||||
self.draw(Image.open(path), pos)
|
||||
|
@ -44,7 +54,8 @@ class DesignEntity (object):
|
|||
def __get_mask__(self, image, invert_mask, color_key):
|
||||
mask = image.convert('L')
|
||||
if color_key:
|
||||
mask = mask.point(lambda p : 0 if p < masking_threshold else 255, '1').convert('L')
|
||||
mask = mask.point(lambda p: 0 if p <
|
||||
masking_threshold else 255, '1').convert('L')
|
||||
if invert_mask:
|
||||
mask = ImageOps.invert(mask)
|
||||
return ImageOps.invert(mask)
|
99
Calendar/Dictionary.py
Normal file
99
Calendar/Dictionary.py
Normal file
|
@ -0,0 +1,99 @@
|
|||
default_language = "en"
|
||||
|
||||
'''Characters following '*' are placeholders and will be replaced by some number/text/etc.'''
|
||||
|
||||
'''Events'''
|
||||
more_events = {
|
||||
'en': '+ *0 more',
|
||||
'de': '+ *0 weitere'
|
||||
}
|
||||
multiday_events = {
|
||||
'en': 'Multi-day',
|
||||
'de': 'Mehrtägig'
|
||||
}
|
||||
allday_events = {
|
||||
'en': 'All-day',
|
||||
'de': 'Ganztägig'
|
||||
}
|
||||
|
||||
'''Weather'''
|
||||
rain_weather = {
|
||||
'en': 'Rain',
|
||||
'de': 'Regen'
|
||||
}
|
||||
clear_weather = {
|
||||
'en': 'Clear',
|
||||
'de': 'Klar'
|
||||
}
|
||||
clouds_weather = {
|
||||
'en': 'Clouds',
|
||||
'de': 'Wolken'
|
||||
}
|
||||
thunderstorm_weather = {
|
||||
'en': 'Thunderstorm',
|
||||
'de': 'Gewitter'
|
||||
}
|
||||
drizzle_weather = {
|
||||
'en': 'Drizzle',
|
||||
'de': 'Niesel'
|
||||
}
|
||||
snow_weather = {
|
||||
'en': 'Snow',
|
||||
'de': 'Schnee'
|
||||
}
|
||||
mist_weather = {
|
||||
'en': 'Mist',
|
||||
'de': 'Nebel'
|
||||
}
|
||||
smoke_weather = {
|
||||
'en': 'Smoke',
|
||||
'de': 'Rauch'
|
||||
}
|
||||
haze_weather = {
|
||||
'en': 'Haze',
|
||||
'de': 'Nebel'
|
||||
}
|
||||
dust_weather = {
|
||||
'en': 'Dust',
|
||||
'de': 'Staub'
|
||||
}
|
||||
fog_weather = {
|
||||
'en': 'Fog',
|
||||
'de': 'Nebel'
|
||||
}
|
||||
sand_weather = {
|
||||
'en': 'Sand',
|
||||
'de': 'Sand'
|
||||
}
|
||||
ash_weather = {
|
||||
'en': 'Ash',
|
||||
'de': 'Asche'
|
||||
}
|
||||
squall_weather = {
|
||||
'en': 'Squall',
|
||||
'de': 'Sturm'
|
||||
}
|
||||
tornado_weather = {
|
||||
'en': 'Tornado',
|
||||
'de': 'Tornado'
|
||||
}
|
||||
dictionary_collection = [
|
||||
rain_weather,
|
||||
clear_weather,
|
||||
dust_weather,
|
||||
squall_weather,
|
||||
tornado_weather,
|
||||
clouds_weather,
|
||||
thunderstorm_weather,
|
||||
smoke_weather,
|
||||
ash_weather,
|
||||
sand_weather,
|
||||
fog_weather,
|
||||
haze_weather,
|
||||
mist_weather,
|
||||
drizzle_weather,
|
||||
snow_weather,
|
||||
more_events,
|
||||
allday_events,
|
||||
multiday_events
|
||||
]
|
29
Calendar/DictionaryMapper.py
Normal file
29
Calendar/DictionaryMapper.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
from Dictionary import default_language
|
||||
from settings import language
|
||||
|
||||
'''Takes a collection of phrases and outputs the necessary text
|
||||
according to the language and inserts parameters.'''
|
||||
|
||||
|
||||
def get_text(dictionary, *params):
|
||||
text = dictionary[default_language]
|
||||
if language in dictionary.keys():
|
||||
text = dictionary[language]
|
||||
|
||||
return __insert_params__(text, params)
|
||||
|
||||
|
||||
def __insert_params__(text, params):
|
||||
index = 0
|
||||
while '*%d' % index in text and index < len(params):
|
||||
splitted = text.split('*%d' % index)
|
||||
text = splitted[0] + str(params[index]) + splitted[1]
|
||||
index += 1
|
||||
while '*' in text:
|
||||
splitted = text.split('*%d' % index)
|
||||
if len(splitted) > 1:
|
||||
text = splitted[0] + splitted[1].lstrip(' ')
|
||||
else:
|
||||
text = splitted[0].rsplit(' ')
|
||||
index += 1
|
||||
return text
|
|
@ -1,5 +1,6 @@
|
|||
class DisplayAdapter (object):
|
||||
"""Interface for CalendarDesign output channels."""
|
||||
|
||||
def __init__(self, width, height):
|
||||
self.width = width
|
||||
self.height = height
|
||||
|
|
|
@ -9,20 +9,30 @@ Copyright by aceisace
|
|||
"""
|
||||
from datetime import datetime
|
||||
from time import sleep
|
||||
from Assets import datetime_locals, path
|
||||
from Assets import path
|
||||
from LoopTimer import LoopTimer
|
||||
import locale
|
||||
from DebugConsole import DebugConsole
|
||||
from settings import language, render_to_display, render_to_file, display_colours, location, api_key, owm_paid_subscription, choosen_design, ical_urls, highlighted_ical_urls, rss_feeds, update_interval, calibrate_hours
|
||||
from settings import datetime_encoding, language, render_to_display, render_to_file, display_colours, location, api_key, owm_paid_subscription, choosen_design, ical_urls, highlighted_ical_urls, rss_feeds, update_interval, calibrate_hours, crypto_coins, max_loop_count, run_on_hour
|
||||
from MonthOvPanel import MonthOvPanel
|
||||
from DayListPanel import DayListPanel
|
||||
from DayViewPanel import DayViewPanel
|
||||
from DayFocusListPanel import DayFocusListPanel
|
||||
from MonthViewPanel import MonthViewPanel
|
||||
from AgendaListPanel import AgendaListPanel
|
||||
from ImageFramePanel import ImageFramePanel
|
||||
import OwmForecasts
|
||||
import IcalEvents
|
||||
import RssParserPosts
|
||||
import GeckoCrypto
|
||||
|
||||
all_locales = locale.locale_alias
|
||||
if language.lower() not in all_locales.keys():
|
||||
raise Exception(
|
||||
"The locale for \"%s\" is currently not supported! If you need support, please open an issue on github." % language)
|
||||
locale.setlocale(locale.LC_ALL, "%s.%s" % (
|
||||
all_locales[language.lower()].split('.')[0], datetime_encoding))
|
||||
|
||||
locale.setlocale(locale.LC_ALL, datetime_locals[language])
|
||||
debug = DebugConsole()
|
||||
output_adapters = []
|
||||
|
||||
|
@ -45,16 +55,24 @@ available_panels = {
|
|||
"day-list": DayListPanel,
|
||||
"month-overview": MonthOvPanel,
|
||||
"day-view": DayViewPanel,
|
||||
"agenda-list" : AgendaListPanel
|
||||
"day-focus-list": DayFocusListPanel,
|
||||
"agenda-list": AgendaListPanel,
|
||||
"month-view": MonthViewPanel,
|
||||
"image-frame": ImageFramePanel,
|
||||
}
|
||||
|
||||
loop_timer = LoopTimer(update_interval, run_on_hour=True)
|
||||
loop_timer = LoopTimer(
|
||||
update_interval, run_on_hour=run_on_hour, max_loop_count=max_loop_count)
|
||||
|
||||
"""Main loop starts from here"""
|
||||
|
||||
|
||||
def main():
|
||||
owm = OwmForecasts.OwmForecasts(location, api_key, paid_api=owm_paid_subscription)
|
||||
owm = OwmForecasts.OwmForecasts(
|
||||
location, api_key, paid_api=owm_paid_subscription)
|
||||
events_cal = IcalEvents.IcalEvents(ical_urls, highlighted_ical_urls)
|
||||
rss = RssParserPosts.RssParserPosts(rss_feeds)
|
||||
crypto = GeckoCrypto.GeckoCrypto(crypto_coins)
|
||||
|
||||
while True:
|
||||
loop_timer.begin_loop()
|
||||
|
@ -68,7 +86,8 @@ def main():
|
|||
if choosen_design in available_panels.keys():
|
||||
design = available_panels[choosen_design]((epd.width, epd.height))
|
||||
else:
|
||||
raise ImportError("choosen_design must be valid (" + choosen_design + ")")
|
||||
raise ImportError(
|
||||
"choosen_design must be valid (" + choosen_design + ")")
|
||||
|
||||
debug.print_line("Fetching weather information from open weather map")
|
||||
owm.reload()
|
||||
|
@ -82,22 +101,35 @@ def main():
|
|||
rss.reload()
|
||||
design.add_rssfeed(rss)
|
||||
|
||||
debug.print_line('Fetching crypto prices from coin gecko')
|
||||
crypto.reload()
|
||||
design.add_crypto(crypto)
|
||||
|
||||
debug.print_line("\nStarting to render")
|
||||
for i, output in enumerate(output_adapters):
|
||||
try:
|
||||
output.render(design)
|
||||
debug.print_line(str(i + 1) + " of " + str(len(output_adapters)) + " rendered")
|
||||
debug.print_line(str(i + 1) + " of " +
|
||||
str(len(output_adapters)) + " rendered")
|
||||
except BaseException as ex:
|
||||
debug.print_err(ex, "Failed to render output " + str(i + 1) + " of " + str(len(output_adapters)))
|
||||
debug.print_err(ex, "Failed to render output " +
|
||||
str(i + 1) + " of " + str(len(output_adapters)))
|
||||
|
||||
debug.print_line("=> Finished rendering" + "\n")
|
||||
|
||||
loop_timer.end_loop()
|
||||
sleep_time = loop_timer.time_until_next()
|
||||
|
||||
debug.print_line("This loop took " + str(loop_timer.get_last_duration()) + " to execute.")
|
||||
if loop_timer.was_last_loop():
|
||||
debug.print_line("Maximum loop count " +
|
||||
str(loop_timer.loop_count) + " reached, exiting.")
|
||||
return
|
||||
|
||||
sleep_time = loop_timer.time_until_next()
|
||||
debug.print_line("This loop took " +
|
||||
str(loop_timer.get_last_duration()) + " to execute.")
|
||||
debug.print_line("Sleeping " + str(sleep_time) + " until next loop.")
|
||||
sleep(sleep_time.total_seconds())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
from BoxDesign import BoxDesign
|
||||
from PIL import ImageDraw, ImageOps
|
||||
|
||||
|
||||
class EllipseDesign (BoxDesign):
|
||||
"""Redefinition of ImageDraw.Draw.Rectangle"""
|
||||
|
||||
def __init__(self, size, fill=None, outline=None, width=0):
|
||||
super(EllipseDesign, self).__init__(size, fill=fill, outline=outline, width=width)
|
||||
super(EllipseDesign, self).__init__(
|
||||
size, fill=fill, outline=outline, width=width)
|
||||
|
||||
def __finish_image__(self):
|
||||
ImageDraw.Draw(self.__image__).ellipse(self.corners, fill=self.fill, outline=self.outline, width=self.width)
|
||||
ImageDraw.Draw(self.__image__).ellipse(
|
||||
self.corners, fill=self.fill, outline=self.outline, width=self.width)
|
||||
|
|
|
@ -2,6 +2,7 @@ from EpdAdapter import EpdAdapter, DISPLAY_REFRESH, DATA_START_TRANSMISSION_1
|
|||
from settings import display_colours
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
|
||||
class Epd7in5Adapter (EpdAdapter):
|
||||
def __init__(self):
|
||||
super(Epd7in5Adapter, self).__init__(384, 640)
|
||||
|
@ -34,7 +35,7 @@ class Epd7in5Adapter (EpdAdapter):
|
|||
buf = [0x00] * int(self.height * self.width / 8)
|
||||
# Set buffer to value of Python Imaging Library image.
|
||||
# Image must be in mode 1.
|
||||
image_monocolor = image.convert('1') #with ot withour dithering?
|
||||
image_monocolor = image.convert('L') # with ot withour dithering?
|
||||
imwidth, imheight = image_monocolor.size
|
||||
if imwidth != self.height or imheight != self.width:
|
||||
raise ValueError('Image must be same dimensions as display \
|
||||
|
@ -44,7 +45,7 @@ class Epd7in5Adapter (EpdAdapter):
|
|||
for y in range(self.width):
|
||||
for x in range(self.height):
|
||||
# Set the bits for the column of pixels at the current position.
|
||||
if pixels[x, y] != 0:
|
||||
if pixels[x, y] >= 240: # White
|
||||
buf[int((x + y * self.height) / 8)] |= 0x80 >> (x % 8)
|
||||
return buf
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ from PIL import Image, ImageDraw
|
|||
from math import sqrt, pow
|
||||
import numpy as np
|
||||
|
||||
|
||||
class Epd7in5bAdapter (EpdAdapter):
|
||||
def __init__(self):
|
||||
super(Epd7in5bAdapter, self).__init__(384, 640)
|
||||
|
@ -54,16 +55,18 @@ class Epd7in5bAdapter (EpdAdapter):
|
|||
if image_buf[x, y, 1] == 255: # White
|
||||
buf[int((y + x * self.height) / 4)] |= 0xC0 >> (y % 4 * 2)
|
||||
elif image_buf[x, y, 0] == 0: # Black
|
||||
buf[int((y + x * self.height) / 4)] &= ~(0xC0 >> (y % 4 * 2))
|
||||
buf[int((y + x * self.height) / 4)
|
||||
] &= ~(0xC0 >> (y % 4 * 2))
|
||||
else: # Red
|
||||
buf[int((y + x * self.height) / 4)] &= ~(0xC0 >> (y % 4 * 2))
|
||||
buf[int((y + x * self.height) / 4)
|
||||
] &= ~(0xC0 >> (y % 4 * 2))
|
||||
buf[int((y + x * self.height) / 4)] |= 0x40 >> (y % 4 * 2)
|
||||
return buf
|
||||
|
||||
def __prepare_image__(self, image):
|
||||
buffer = np.array(image)
|
||||
r, g = buffer[:, :, 0], buffer[:, :, 1]
|
||||
buffer[np.logical_and(r > 240, g > 240)] = [255,255,255]
|
||||
buffer[np.logical_and(r > 220, g > 220)] = [255, 255, 255]
|
||||
buffer[r > g] = [255, 0, 0]
|
||||
buffer[r != 255] = [0, 0, 0]
|
||||
return buffer
|
||||
|
|
|
@ -48,8 +48,10 @@ AUTO_MEASUREMENT_VCOM = 0x80
|
|||
READ_VCOM_VALUE = 0x81
|
||||
VCM_DC_SETTING = 0x82
|
||||
|
||||
|
||||
class EpdAdapter (DisplayAdapter):
|
||||
"""Generalized adapter for epd7in5 and epd7in5b"""
|
||||
|
||||
def __init__(self, width, height):
|
||||
super(EpdAdapter, self).__init__(width, height)
|
||||
|
||||
|
@ -71,7 +73,7 @@ class EpdAdapter (DisplayAdapter):
|
|||
|
||||
print('Converting image to data and sending it to the display')
|
||||
print('This may take a while...' + '\n')
|
||||
prepared_image = design.get_image().rotate(270, expand=1)
|
||||
prepared_image = design.get_image().rotate(270, expand=1).convert("RGB")
|
||||
self.display_frame(self.get_frame_buffer(prepared_image))
|
||||
|
||||
# Powering off the E-Paper until the next loop
|
||||
|
@ -157,9 +159,14 @@ class EpdAdapter (DisplayAdapter):
|
|||
self.send_command(DEEP_SLEEP)
|
||||
self.send_data(0xa5)
|
||||
|
||||
def wait_until_idle (self):
|
||||
while(self.digital_read(self.busy_pin) == 0): # 0: busy, 1: idle
|
||||
self.delay_ms(100)
|
||||
def wait_until_idle(self, max_wait_seconds=60):
|
||||
wait_ms = 100
|
||||
count = 0
|
||||
while(self.digital_read(self.busy_pin) == 0 and wait_ms * count < max_wait_seconds * 1000): # 0: busy, 1: idle
|
||||
self.delay_ms(wait_ms)
|
||||
count += 1
|
||||
if wait_ms * count >= max_wait_seconds * 1000:
|
||||
print("Skipped idle confirmation")
|
||||
|
||||
def reset(self):
|
||||
self.digital_write(self.reset_pin, GPIO.LOW) # module reset
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
from DesignEntity import DesignEntity
|
||||
from TableTextDesign import TableTextDesign
|
||||
from settings import language
|
||||
from TableDesign import TableDesign
|
||||
from Assets import defaultfontsize, colors
|
||||
from TextFormatter import date_str
|
||||
from DictionaryMapper import get_text
|
||||
from Dictionary import more_events
|
||||
|
||||
|
||||
class EventListDesign (DesignEntity):
|
||||
"""Creates a TableTextDesign filled with event
|
||||
"""Creates a TableDesign filled with event
|
||||
begin date and title"""
|
||||
def __init__ (self, size, events, text_size = defaultfontsize, line_spacing = 2, col_spacing = 10, event_prefix_rel_dates = [], event_prefix_func = None, font_family = None, general_color = colors["fg"], background_color = colors["bg"], highlight_color = colors["hl"], show_more_info = False):
|
||||
|
||||
def __init__(self, size, events, text_size=defaultfontsize, line_spacing=0, col_spacing=10, event_prefix_rel_dates=[], event_prefix_func=None, font_family=None, general_color=colors["fg"], background_color=colors["bg"], highlight_color=colors["hl"], show_more_info=False):
|
||||
super(EventListDesign, self).__init__(size)
|
||||
self.events = events
|
||||
self.__event_matrix__ = []
|
||||
|
@ -26,15 +29,18 @@ class EventListDesign (DesignEntity):
|
|||
self.event_prefix_func = lambda x, y: date_str(x.begin_datetime)
|
||||
|
||||
def __finish_image__(self):
|
||||
self.visible_event_count = int(int(self.size[1] + self.line_spacing) // (self.line_spacing + int(self.text_size)))
|
||||
self.visible_event_count = int(int(
|
||||
self.size[1] + self.line_spacing) // (self.line_spacing + int(self.text_size)))
|
||||
self.__fill_event_matrix__()
|
||||
|
||||
col_hori_alignment = ['right', 'left']
|
||||
table_design = TableTextDesign(self.size, background_color = self.background_color, font=self.font_family, line_spacing=self.line_spacing, col_spacing=self.col_spacing, text_matrix=self.__event_matrix__, fontsize = self.text_size, column_horizontal_alignments=col_hori_alignment, mask=False, truncate_cols=False, cell_properties=self.__props_matrix__)
|
||||
table_design = TableDesign(self.size, background_color=self.background_color, font=self.font_family, line_spacing=self.line_spacing, col_spacing=self.col_spacing,
|
||||
matrix=self.__event_matrix__, fontsize=self.text_size, column_horizontal_alignments=col_hori_alignment, mask=False, truncate_cols=False, cell_properties=self.__props_matrix__)
|
||||
self.draw_design(table_design)
|
||||
|
||||
def __get_formatted_event__(self, event, index):
|
||||
rel_date = None if index < 0 or index >= len(self.event_prefix_rel_dates) else self.event_prefix_rel_dates[index]
|
||||
rel_date = None if index < 0 or index >= len(
|
||||
self.event_prefix_rel_dates) else self.event_prefix_rel_dates[index]
|
||||
prefix = self.event_prefix_func(event, rel_date)
|
||||
return [prefix, event.title]
|
||||
|
||||
|
@ -51,9 +57,9 @@ class EventListDesign (DesignEntity):
|
|||
return
|
||||
|
||||
additional_events_count = len(self.events) - len(visible_events)
|
||||
more_text = self.__get_more_text__()
|
||||
more_text = " " + get_text(more_events, additional_events_count)
|
||||
if additional_events_count > 0:
|
||||
self.__event_matrix__.append([ "", " + " + str(additional_events_count) + " " + more_text ])
|
||||
self.__event_matrix__.append(["", more_text])
|
||||
self.__props_matrix__.append(self.__get_row_props__())
|
||||
|
||||
def __get_row_props__(self, event=None):
|
||||
|
@ -66,10 +72,3 @@ class EventListDesign (DesignEntity):
|
|||
"background_color": bg_color
|
||||
}
|
||||
return [cell, cell]
|
||||
|
||||
def __get_more_text__ (self):
|
||||
more_texts = {
|
||||
"de" : "weitere",
|
||||
"en" : "more"
|
||||
}
|
||||
return more_texts[language]
|
68
Calendar/GeckoCrypto.py
Normal file
68
Calendar/GeckoCrypto.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
from CryptoInterface import CryptoInterface
|
||||
from datetime import datetime
|
||||
from CryptoCoin import CryptoCoin
|
||||
from urllib.request import urlopen
|
||||
import json
|
||||
import math
|
||||
|
||||
api_test_url = "https://api.coingecko.com/api/v3/ping"
|
||||
api_url = "https://api.coingecko.com/api/v3/"
|
||||
api_metadata_url = api_url + "coins/list"
|
||||
api_price_url = api_url + "simple/price"
|
||||
price_currency = "usd"
|
||||
price_currency_sign = "$"
|
||||
|
||||
|
||||
class GeckoCrypto(CryptoInterface):
|
||||
def __init__(self, coins):
|
||||
self.coin_ids = coins
|
||||
self.metadata = None
|
||||
super(GeckoCrypto, self).__init__()
|
||||
|
||||
def is_available(self):
|
||||
try:
|
||||
urlopen(api_test_url)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
def __get_coins__(self):
|
||||
if len(self.coin_ids) == 0:
|
||||
return []
|
||||
|
||||
self.__prepare_metadata__()
|
||||
coins = []
|
||||
for id in self.coin_ids:
|
||||
try:
|
||||
data = urlopen(api_price_url + "?include_24hr_change=true&ids=" +
|
||||
self.metadata[id]['id'] + "&vs_currencies=" + price_currency).read()
|
||||
dataJSON = json.loads(data.decode('utf-8'))
|
||||
raw = dataJSON[id][price_currency]
|
||||
price = math.ceil(raw*100) / 100
|
||||
change = dataJSON[id]['usd_24h_change']
|
||||
|
||||
coins.append(self.__build_coin__(id, price, change))
|
||||
except:
|
||||
print("Gecko-Error [" + id + "]")
|
||||
return coins
|
||||
|
||||
def __build_coin__(self, id, value, change):
|
||||
coin = CryptoCoin()
|
||||
|
||||
coin.name = self.metadata[id]['name']
|
||||
coin.day_change = round(change, 2)
|
||||
coin.price = value
|
||||
|
||||
coin.datetime = datetime.now()
|
||||
coin.fetch_datetime = datetime.now()
|
||||
coin.currency = price_currency_sign
|
||||
coin.symbol = self.metadata[id]['symbol']
|
||||
|
||||
return coin
|
||||
|
||||
def __prepare_metadata__(self):
|
||||
self.metadata = None
|
||||
data = urlopen(api_metadata_url).read()
|
||||
dataJSON = json.loads(data.decode('utf-8'))
|
||||
self.metadata = {coin['id'].lower(
|
||||
): coin for coin in dataJSON if coin['id'].lower() in self.coin_ids}
|
|
@ -1,24 +1,29 @@
|
|||
from DesignEntity import DesignEntity
|
||||
from settings import hours, language
|
||||
from settings import hours, language, line_thickness
|
||||
from TextDesign import TextDesign
|
||||
from PIL import ImageDraw
|
||||
from Assets import colors, defaultfontsize
|
||||
from Assets import colors, defaultfontsize, fonts
|
||||
from BoxDesign import BoxDesign
|
||||
from datetime import timedelta, datetime
|
||||
|
||||
hourbox_y_width = 1
|
||||
hour_box_fontsize = 0.8
|
||||
hoursubtext_fontsize = 0.8
|
||||
hoursubtext_height = 0.38
|
||||
hour_box_fontsize = 0.85
|
||||
hour_ypadding = 0.1
|
||||
hoursubtext_fontsize = 0.7
|
||||
hoursubtext_height = 0.45
|
||||
event_title_fontsize = defaultfontsize
|
||||
event_title_xpadding = 3
|
||||
event_title_ypadding = 5
|
||||
line_thickness = 1
|
||||
currenttimeline_thickness = 2
|
||||
line_thickness = line_thickness
|
||||
currenttimeline_thickness = line_thickness
|
||||
|
||||
event_title_font = fonts['bold']
|
||||
|
||||
|
||||
class HourListDesign (DesignEntity):
|
||||
"""Hours of a day are listed vertically and
|
||||
resemble a timeline."""
|
||||
|
||||
def __init__(self, size, first_hour=0, last_hour=23):
|
||||
super(HourListDesign, self).__init__(size)
|
||||
self.first_hour = first_hour
|
||||
|
@ -28,6 +33,7 @@ class HourListDesign (DesignEntity):
|
|||
|
||||
def add_events(self, events):
|
||||
self.events.extend(events)
|
||||
self.events.sort(key=lambda x: x.begin_datetime)
|
||||
|
||||
def __finish_image__(self):
|
||||
self.number_columns = self.__get_max_num_simultaneous_events__()
|
||||
|
@ -59,7 +65,8 @@ class HourListDesign (DesignEntity):
|
|||
for _ in range(self.number_columns):
|
||||
column_events.append(None)
|
||||
for event in self.events:
|
||||
column_events = self.__update_columns_events__(column_events, event)
|
||||
column_events = self.__update_columns_events__(
|
||||
column_events, event)
|
||||
self.__draw_event__(event, column_events.index(event))
|
||||
|
||||
def __update_columns_events__(self, column_events, new_event):
|
||||
|
@ -80,17 +87,20 @@ class HourListDesign (DesignEntity):
|
|||
def __draw_row__(self, hour):
|
||||
subtext_height = self.row_size[1] * hoursubtext_height
|
||||
sub_fontsize = subtext_height * hoursubtext_fontsize
|
||||
ypadding = hour_ypadding * self.row_size[1]
|
||||
width = hourbox_y_width * self.row_size[1]
|
||||
height = self.row_size[1] - subtext_height
|
||||
size = (width, height)
|
||||
pos = (0, self.__get_ypos_for_time__(hour))
|
||||
pos = (0, self.__get_ypos_for_time__(hour) + ypadding)
|
||||
fontsize = size[1] * hour_box_fontsize
|
||||
|
||||
txt = TextDesign(size, text=self.__get_hour_text__(hour), fontsize=fontsize, verticalalignment="bottom", horizontalalignment="center")
|
||||
txt = TextDesign(size, text=self.__get_hour_text__(
|
||||
hour), fontsize=fontsize, verticalalignment="bottom", horizontalalignment="center")
|
||||
txt.pos = pos
|
||||
self.draw_design(txt)
|
||||
|
||||
sub = TextDesign((width, subtext_height), text=self.__get_hour_sub_text__(hour), fontsize=sub_fontsize, verticalalignment="top", horizontalalignment="center")
|
||||
sub = TextDesign((width, subtext_height), text=self.__get_hour_sub_text__(
|
||||
hour), fontsize=sub_fontsize, verticalalignment="top", horizontalalignment="center")
|
||||
sub.pos = (0, height + self.__get_ypos_for_time__(hour))
|
||||
self.draw_design(sub)
|
||||
|
||||
|
@ -99,7 +109,8 @@ class HourListDesign (DesignEntity):
|
|||
ypos = i * self.row_size[1]
|
||||
line_start = (0, ypos)
|
||||
line_end = (self.size[0], ypos)
|
||||
ImageDraw.Draw(self.__image__).line([ line_start, line_end ], fill=colors["fg"], width=line_thickness)
|
||||
ImageDraw.Draw(self.__image__).line(
|
||||
[line_start, line_end], fill=colors["fg"], width=line_thickness)
|
||||
|
||||
def __get_hour_sub_text__(self, hour):
|
||||
if hours == "12":
|
||||
|
@ -140,25 +151,31 @@ class HourListDesign (DesignEntity):
|
|||
|
||||
text = event.title
|
||||
text_color = colors["bg"]
|
||||
textbox_size = (size[0] - event_title_xpadding, size[1] - event_title_ypadding)
|
||||
txt = TextDesign(textbox_size, text = text, fontsize=event_title_fontsize, color=text_color, background_color=box_color, wrap=True)
|
||||
textbox_size = (size[0] - event_title_xpadding,
|
||||
size[1] - event_title_ypadding)
|
||||
txt = TextDesign(textbox_size, text=text, font=event_title_font,
|
||||
fontsize=event_title_fontsize, color=text_color, background_color=box_color, wrap=True)
|
||||
txt.mask = False
|
||||
txt.pos = (pos[0] + event_title_xpadding, pos[1] + event_title_ypadding)
|
||||
txt.pos = (pos[0] + event_title_xpadding,
|
||||
pos[1] + event_title_ypadding)
|
||||
self.draw_design(txt)
|
||||
|
||||
half_ypadding = int(event_title_ypadding / 2)
|
||||
line_start = (pos[0] + event_title_xpadding, pos[1] + half_ypadding)
|
||||
line_end = (pos[0] + size[0] - event_title_xpadding, pos[1] + half_ypadding)
|
||||
ImageDraw.Draw(self.__image__).line([ line_start, line_end ], fill=colors["bg"], width=1)
|
||||
line_end = (pos[0] + size[0] - event_title_xpadding,
|
||||
pos[1] + half_ypadding)
|
||||
ImageDraw.Draw(self.__image__).line(
|
||||
[line_start, line_end], fill=colors["bg"], width=1)
|
||||
|
||||
def __get_max_num_simultaneous_events__(self):
|
||||
parallelity_count = 1
|
||||
|
||||
for index, event in enumerate(self.events):
|
||||
current_parallelity = 1
|
||||
preceding = self.events[:index] #Assumption: Events are ordered chronologically
|
||||
# Assumption: Events are ordered chronologically
|
||||
preceding = self.events[:index]
|
||||
for pre_event in preceding:
|
||||
if self.__are_simultaneous__(event, pre_event):
|
||||
if self.__are_simultaneous__(pre_event, event):
|
||||
current_parallelity += 1
|
||||
if parallelity_count < current_parallelity:
|
||||
parallelity_count = current_parallelity
|
||||
|
@ -178,4 +195,5 @@ class HourListDesign (DesignEntity):
|
|||
|
||||
line_start = (0, ypos)
|
||||
line_end = (self.size[0], ypos)
|
||||
ImageDraw.Draw(self.__image__).line([ line_start, line_end ], fill=colors["hl"], width=currenttimeline_thickness)
|
||||
ImageDraw.Draw(self.__image__).line(
|
||||
[line_start, line_end], fill=colors["hl"], width=currenttimeline_thickness)
|
||||
|
|
|
@ -6,18 +6,22 @@ import re
|
|||
from settings import week_starts_on
|
||||
from urllib.request import urlopen
|
||||
|
||||
|
||||
class IcalEvents(CalendarInterface):
|
||||
"""Fetches events from ical addresses."""
|
||||
|
||||
def __init__(self, urls, highlighted_urls=None):
|
||||
self.urls = urls
|
||||
self.highlighted_urls = highlighted_urls
|
||||
super(IcalEvents, self).__init__()
|
||||
|
||||
def is_available(self):
|
||||
for url in self.urls + self.highlighted_urls:
|
||||
try:
|
||||
urlopen("https://google.com", timeout=2)
|
||||
urlopen(url)
|
||||
return True
|
||||
except:
|
||||
pass
|
||||
return False
|
||||
|
||||
def __get_events__(self):
|
||||
|
@ -35,17 +39,19 @@ class IcalEvents(CalendarInterface):
|
|||
|
||||
def __get_events_from_urls__(self, urls):
|
||||
loaded_events = []
|
||||
try:
|
||||
|
||||
if urls is None:
|
||||
return loaded_events
|
||||
|
||||
for calendar in urls:
|
||||
try:
|
||||
decode = str(urlopen(calendar).read().decode())
|
||||
decode = self.__remove_alarms__(decode)
|
||||
|
||||
ical = Calendar(decode)
|
||||
for event in ical.events:
|
||||
cal_event = CalendarEvent()
|
||||
cal_event.calendar_url = calendar
|
||||
|
||||
cal_event.fetch_datetime = datetime.now(timezone.utc)
|
||||
cal_event.begin_datetime = event.begin.datetime
|
||||
|
@ -57,22 +63,35 @@ class IcalEvents(CalendarInterface):
|
|||
cal_event.allday = event.all_day
|
||||
cal_event.rrule = self.__extract_rrule__(event)
|
||||
|
||||
cal_event.begin_datetime = cal_event.begin_datetime.astimezone(None)
|
||||
cal_event.end_datetime = cal_event.end_datetime.astimezone(None)
|
||||
cal_event.begin_datetime = cal_event.begin_datetime.astimezone(
|
||||
None)
|
||||
cal_event.end_datetime = cal_event.end_datetime.astimezone(
|
||||
None)
|
||||
|
||||
if cal_event.allday:
|
||||
cal_event.end_datetime = cal_event.end_datetime - timedelta(1)
|
||||
cal_event.duration = cal_event.duration - timedelta(1)
|
||||
cal_event = self.__fix_allday__(cal_event)
|
||||
|
||||
cal_event.multiday = self.__is_multiday__(cal_event)
|
||||
|
||||
loaded_events.append(cal_event)
|
||||
return loaded_events
|
||||
except BaseException as ex:
|
||||
print("ICal-Error [" + calendar + "]")
|
||||
print(ex)
|
||||
return loaded_events
|
||||
|
||||
def __fix_allday__(self, event):
|
||||
local_tzinfo = datetime.now(timezone.utc).astimezone().tzinfo
|
||||
begin_utc = event.begin_datetime.astimezone(timezone.utc)
|
||||
end_utc = event.end_datetime.astimezone(timezone.utc)
|
||||
|
||||
event.begin_datetime = datetime(
|
||||
begin_utc.year, begin_utc.month, begin_utc.day, 0, 0, 0, 0, local_tzinfo)
|
||||
event.end_datetime = datetime(
|
||||
end_utc.year, end_utc.month, end_utc.day, 0, 0, 0, 0, local_tzinfo) - timedelta(1)
|
||||
event.duration = event.end_datetime - event.begin_datetime
|
||||
|
||||
return event
|
||||
|
||||
def __remove_alarms__(self, decode):
|
||||
alarm_begin = 'BEGIN:VALARM'
|
||||
alarm_end = 'END:VALARM'
|
||||
|
@ -83,7 +102,9 @@ class IcalEvents(CalendarInterface):
|
|||
beginAlarmIndex = decode.find(alarm_begin)
|
||||
if beginAlarmIndex >= 0:
|
||||
endAlarmIndex = decode.find(alarm_end, beginAlarmIndex)
|
||||
decode = decode[:beginAlarmIndex] + decode[endAlarmIndex + len(alarm_end) + len(lineseparation):]
|
||||
decode = decode[:beginAlarmIndex] + \
|
||||
decode[endAlarmIndex +
|
||||
len(alarm_end) + len(lineseparation):]
|
||||
return decode
|
||||
|
||||
def __extract_rrule__(self, event):
|
||||
|
|
86
Calendar/ImageDesign.py
Normal file
86
Calendar/ImageDesign.py
Normal file
|
@ -0,0 +1,86 @@
|
|||
from DesignEntity import DesignEntity
|
||||
from Assets import path as application_path
|
||||
from PIL import Image, ExifTags
|
||||
|
||||
|
||||
class ImageDesign (DesignEntity):
|
||||
"""Creates a TableDesign filled with rss post
|
||||
date and title"""
|
||||
|
||||
# fill: "none" : original size, "stretch" : strech to fill, "scale" : scale to fill, "border" : scale until one side touches border
|
||||
def __init__(self, size, path, fill="none", color="RGBA", dither=None):
|
||||
super(ImageDesign, self).__init__(size)
|
||||
self.set_path(path)
|
||||
self.fill = fill
|
||||
self.color = color
|
||||
self.dither = dither
|
||||
|
||||
def set_path(self, path):
|
||||
path = path.replace('\\', '/')
|
||||
if path[0] != '/' and ':' not in path[0:3]:
|
||||
path = application_path + '/' + path
|
||||
self.path = path
|
||||
|
||||
def __finish_image__(self):
|
||||
img = Image.open(self.path)
|
||||
img = img.convert(self.color, dither=self.dither)
|
||||
|
||||
img = self.__fix_orientation__(img)
|
||||
img = self.__resize_image__(img)
|
||||
pos = self.__get_centered_position__(img)
|
||||
|
||||
self.__init_image__("#00000000")
|
||||
self.draw(img, pos)
|
||||
|
||||
def __resize_image__(self, img):
|
||||
if self.fill is "none":
|
||||
return img
|
||||
|
||||
if self.fill is "stretch":
|
||||
img = img.resize(self.size, resample=Image.LANCZOS)
|
||||
|
||||
if self.fill is "scale":
|
||||
size = self.size
|
||||
img_proportions = img.width / img.height
|
||||
if img_proportions < size[0] / size[1]:
|
||||
size = (size[0], int(size[0] * (1 / img_proportions)))
|
||||
else:
|
||||
size = (int(size[1] * img_proportions), size[1])
|
||||
img = img.resize(size, resample=Image.LANCZOS)
|
||||
|
||||
if self.fill is "border":
|
||||
size = self.size
|
||||
img_proportions = img.width / img.height
|
||||
if img_proportions < size[0] / size[1]:
|
||||
size = (int(size[1] * img_proportions), size[1])
|
||||
else:
|
||||
size = (size[0], int(size[0] * (1 / img_proportions)))
|
||||
img = img.resize(size, resample=Image.LANCZOS)
|
||||
|
||||
return img
|
||||
|
||||
def __get_centered_position__(self, img):
|
||||
screen_size = self.size
|
||||
img_size = img.size
|
||||
|
||||
delta_size = [s - i for s, i in zip(screen_size, img_size)]
|
||||
delta_center_pos = [s / 2 for s in delta_size]
|
||||
|
||||
return delta_center_pos
|
||||
|
||||
def __fix_orientation__(self, img):
|
||||
if "parsed_exif" not in img.info.keys():
|
||||
return img
|
||||
|
||||
for orientation in ExifTags.TAGS.keys():
|
||||
if ExifTags.TAGS[orientation] == 'Orientation':
|
||||
break
|
||||
exif = img.info["parsed_exif"]
|
||||
|
||||
if exif[orientation] == 3:
|
||||
img = img.rotate(180, expand=True)
|
||||
elif exif[orientation] == 6:
|
||||
img = img.rotate(270, expand=True)
|
||||
elif exif[orientation] == 8:
|
||||
img = img.rotate(90, expand=True)
|
||||
return img
|
|
@ -1,10 +1,15 @@
|
|||
from DisplayAdapter import DisplayAdapter
|
||||
from Assets import path
|
||||
|
||||
|
||||
class ImageFileAdapter (DisplayAdapter):
|
||||
"""Saves design to an image file, can be used for debugging"""
|
||||
|
||||
def __init__(self, file_path=""):
|
||||
super(ImageFileAdapter, self).__init__(384, 640)
|
||||
self.file_path = file_path
|
||||
if self.file_path == "":
|
||||
self.file_path = path
|
||||
|
||||
def render(self, design):
|
||||
design.get_image().save(self.file_path + 'design_exported.png')
|
||||
|
|
46
Calendar/ImageFramePanel.py
Normal file
46
Calendar/ImageFramePanel.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
from PanelDesign import PanelDesign
|
||||
from settings import general_settings
|
||||
from Assets import supported_img_formats, path as application_path
|
||||
from os import listdir
|
||||
from os.path import isfile, join
|
||||
from ImageDesign import ImageDesign
|
||||
from random import choice
|
||||
|
||||
|
||||
class ImageFramePanel (PanelDesign):
|
||||
"""Converts the display into a digital frame and
|
||||
shows a slide show of images, iterating on each update"""
|
||||
|
||||
def __init__(self, size):
|
||||
super(ImageFramePanel, self).__init__(size)
|
||||
self.overlay_path = self.__complete_path__(
|
||||
general_settings["overlay-image"])
|
||||
self.image_folder_path = self.__complete_path__(
|
||||
general_settings["image-folder"])
|
||||
self.images = self.__extract_valid_img_paths__()
|
||||
self.__first_render__()
|
||||
|
||||
def __extract_valid_img_paths__(self):
|
||||
images = []
|
||||
for file in listdir(self.image_folder_path):
|
||||
file_path = join(self.image_folder_path, file).replace('\\', '/')
|
||||
if isfile(file_path) and self.overlay_path != file_path:
|
||||
if file.split('.')[-1].upper() in supported_img_formats:
|
||||
images.append(file_path)
|
||||
return images
|
||||
|
||||
def __complete_path__(self, path):
|
||||
path = path.replace('\\', '/')
|
||||
if path[0] != '/' and ':' not in path[0:3]:
|
||||
path = join(application_path, path)
|
||||
return path
|
||||
|
||||
def __first_render__(self):
|
||||
current_image = choice(self.images)
|
||||
img = ImageDesign(self.size, current_image, fill="scale", color="1")
|
||||
self.draw_design(img)
|
||||
|
||||
if self.overlay_path != "":
|
||||
overlay = ImageDesign(self.size, self.overlay_path)
|
||||
overlay.__finish_image__()
|
||||
self.__image__.alpha_composite(overlay.__image__)
|
|
@ -3,17 +3,21 @@ from datetime import datetime, timedelta
|
|||
min_sleep_minutes = 0
|
||||
max_history_entries = 25
|
||||
|
||||
|
||||
class LoopTimer (object):
|
||||
"""Manages loop times and sleeps until
|
||||
next loop."""
|
||||
def __init__ (self, loop_interval, run_on_hour = False):
|
||||
|
||||
def __init__(self, loop_interval, run_on_hour=False, max_loop_count=0):
|
||||
self.interval = int(str(loop_interval))
|
||||
self.on_hour = run_on_hour
|
||||
self.loop_history = []
|
||||
self.loop_count = 0
|
||||
self.max_loop_count = int(str(max_loop_count))
|
||||
|
||||
def begin_loop(self):
|
||||
begin_time = datetime.now()
|
||||
print('\n__________Starting new loop__________')
|
||||
print('\n__________Starting new loop [' + str(self.loop_count) + ']__________')
|
||||
print('Datetime: ' + str(begin_time) + '\n')
|
||||
self.__add_beginning__(begin_time)
|
||||
|
||||
|
@ -32,6 +36,15 @@ class LoopTimer (object):
|
|||
end_time = datetime.now()
|
||||
self.__add_ending__(end_time)
|
||||
|
||||
self.loop_count += 1
|
||||
while self.loop_count > 86400:
|
||||
self.loop_count -= 86400
|
||||
|
||||
def was_last_loop(self):
|
||||
if self.max_loop_count == 0:
|
||||
return False
|
||||
return self.max_loop_count <= self.loop_count
|
||||
|
||||
def get_current(self):
|
||||
return self.loop_history[-1]
|
||||
|
||||
|
|
|
@ -2,17 +2,20 @@ from DesignEntity import DesignEntity
|
|||
import calendar as callib
|
||||
from datetime import datetime, timedelta
|
||||
from TextDesign import TextDesign
|
||||
from Assets import *
|
||||
from settings import *
|
||||
from Assets import colors
|
||||
from settings import week_starts_on
|
||||
from BoxDesign import BoxDesign
|
||||
|
||||
daynumberboxsize = (0.143, 0.286)
|
||||
daynumberboxsize = (0.143, 0.2)
|
||||
dayhighlightboxsize = (0.143, 0.14)
|
||||
daynumbersize = 25
|
||||
daynumbersize = daynumberboxsize[0] * 0.45
|
||||
day_number_ypadding = -0.002
|
||||
|
||||
|
||||
class MonthBlockDesign (DesignEntity):
|
||||
"""Creates a view containing one week of the month in
|
||||
one row"""
|
||||
|
||||
def __init__(self, size, datetime_month, highlight_today=False):
|
||||
super(MonthBlockDesign, self).__init__(size, mask=True)
|
||||
self.month = datetime_month.month
|
||||
|
@ -29,10 +32,12 @@ class MonthBlockDesign (DesignEntity):
|
|||
cal = callib.monthcalendar(self.year, self.month)
|
||||
for week in cal:
|
||||
for numbers in week:
|
||||
self.__draw_day_number__(numbers, self.get_day_pos(cal.index(week), week.index(numbers)))
|
||||
self.__draw_day_number__(numbers, self.get_day_pos(
|
||||
cal.index(week), week.index(numbers)))
|
||||
|
||||
if self.highlight_today:
|
||||
self.__draw_highlight_box__(self.__abs_pos__(dayhighlightboxsize), self.__get_today_box_pos__(), width=3)
|
||||
self.__draw_highlight_box__(self.__abs_pos__(
|
||||
dayhighlightboxsize), self.__get_today_box_pos__(), width=3)
|
||||
|
||||
def __draw_highlight_box__(self, size, pos, color=colors["fg"], width=1):
|
||||
design = BoxDesign(size, outline=color, width=width)
|
||||
|
@ -42,8 +47,9 @@ class MonthBlockDesign (DesignEntity):
|
|||
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
|
||||
txt = TextDesign(self.__abs_pos__(daynumberboxsize), fontsize=daynumbersize *
|
||||
self.size[0], text=str(number), verticalalignment="center", horizontalalignment="center")
|
||||
txt.pos = (pos[0], pos[1] + day_number_ypadding * self.size[1])
|
||||
self.draw_design(txt)
|
||||
|
||||
def get_day_pos(self, week_in_month, day_of_week, rel_pos=(0, 0)):
|
||||
|
@ -53,7 +59,8 @@ class MonthBlockDesign (DesignEntity):
|
|||
return (int(rel_pos[0] + day_of_week * partialwidth), int(rel_pos[1] + week_in_month * partialheight))
|
||||
|
||||
def __get_today_box_pos__(self):
|
||||
x, y = self.get_day_pos(self.__get_week_of_month__(datetime.now()), self.__get_day_of_week__(datetime.now()))
|
||||
x, y = self.get_day_pos(self.__get_week_of_month__(
|
||||
datetime.now()), self.__get_day_of_week__(datetime.now()))
|
||||
return (x, int(y + (self.__abs_pos__(daynumberboxsize)[1] - self.__abs_pos__(dayhighlightboxsize)[1]) / 2))
|
||||
|
||||
def __get_week_of_month__(self, date):
|
||||
|
@ -73,7 +80,8 @@ class MonthBlockDesign (DesignEntity):
|
|||
|
||||
weekdays = []
|
||||
for i in range(7):
|
||||
weekdays.append((datetime.now() + timedelta(days=(i + correction))).strftime("%a"))
|
||||
weekdays.append(
|
||||
(datetime.now() + timedelta(days=(i + correction))).strftime("%a"))
|
||||
|
||||
return weekdays
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from PanelDesign import PanelDesign
|
||||
from Assets import *
|
||||
from settings import *
|
||||
from Assets import colors
|
||||
from settings import general_settings, week_starts_on
|
||||
import calendar as callib
|
||||
from datetime import datetime, timedelta
|
||||
from WeatherHeaderDesign import WeatherHeaderDesign
|
||||
|
@ -12,24 +12,28 @@ from MonthBlockDesign import MonthBlockDesign, daynumberboxsize
|
|||
from EventListDesign import EventListDesign
|
||||
from RssPostListDesign import RssPostListDesign
|
||||
from settings import general_settings
|
||||
from CryptoListDesign import CryptoListDesign
|
||||
|
||||
|
||||
weatherheadersize = (1, 0.113)
|
||||
monthtextsize = 40
|
||||
monthovsize = (1, 0.5)
|
||||
monthovposition = (0, 0.23 - weatherheadersize[1])
|
||||
seperatorplace = (0, 0.113)
|
||||
monthplace = (0, 0.12 - weatherheadersize[1])
|
||||
monthboxsize = (1, 0.085)
|
||||
monthtextsize = monthboxsize[1] * 0.75
|
||||
monthplace = (0, 0.11 - weatherheadersize[1])
|
||||
monthovsize = (1, 0.48)
|
||||
monthovposition = (0, 0.25 - weatherheadersize[1])
|
||||
seperatorplace = (0, 0.113)
|
||||
weekdayrowpos = (0, 0.209 - weatherheadersize[1])
|
||||
weekrowboxsize = (1, 0.044)
|
||||
weekdaytextsize = 18
|
||||
weekdaytextsize = 0.7 * weekrowboxsize[1]
|
||||
weekdaytextpadding = -0.001
|
||||
weekrownameboxsize = (0.143, 0.044)
|
||||
eventcirclehorizontalsize = 0.100
|
||||
infolistsize = (1, 0.77 + weatherheadersize[1])
|
||||
|
||||
|
||||
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)
|
||||
self.weather_header_height = 0
|
||||
|
@ -50,7 +54,8 @@ class MonthOvPanel (PanelDesign):
|
|||
if general_settings["weather-info"]:
|
||||
self.__draw_seperator__()
|
||||
|
||||
self.month_block = MonthBlockDesign(self.__abs_pos__(monthovsize), datetime.now(), highlight_today = True)
|
||||
self.month_block = MonthBlockDesign(self.__abs_pos__(
|
||||
monthovsize), datetime.now(), highlight_today=True)
|
||||
pos = self.__abs_pos__(monthovposition)
|
||||
pos = (pos[0], pos[1] + self.weather_header_height)
|
||||
self.month_block.pos = pos
|
||||
|
@ -59,15 +64,24 @@ class MonthOvPanel (PanelDesign):
|
|||
def add_weather(self, weather):
|
||||
if general_settings["weather-info"] == False:
|
||||
return
|
||||
self.draw_design(WeatherHeaderDesign(self.__abs_pos__(weatherheadersize), weather))
|
||||
self.draw_design(WeatherHeaderDesign(
|
||||
self.__abs_pos__(weatherheadersize), weather))
|
||||
|
||||
def add_rssfeed(self, rss):
|
||||
if general_settings["info-area"] is "rss":
|
||||
self.__draw_rss_post_list_to_bottom__(rss)
|
||||
|
||||
def add_crypto(self, crypto):
|
||||
if general_settings["info-area"] is "crypto":
|
||||
self.__draw_crypto_post_list_to_bottom__(crypto)
|
||||
|
||||
def add_tasks(self, tasks):
|
||||
pass
|
||||
|
||||
def add_calendar(self, calendar):
|
||||
if general_settings["highlight-event-days"]:
|
||||
month_events = list(set([ (event.begin_datetime.day, event.begin_datetime.month, event.begin_datetime.year) for event in calendar.get_month_events()]))
|
||||
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)
|
||||
|
||||
|
@ -77,21 +91,35 @@ class MonthOvPanel (PanelDesign):
|
|||
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)
|
||||
size = (size[0], size[1] - month_height - self.weather_header_height)
|
||||
size = (self.size[0], self.size[1] - (month_pos[1] +
|
||||
month_height + self.weather_header_height))
|
||||
info_list = RssPostListDesign(size, rss)
|
||||
info_list.pos = (int(month_pos[0]), int(month_pos[1] + month_height + self.weather_header_height))
|
||||
info_list.pos = (
|
||||
int(month_pos[0]), month_pos[1] + month_height + self.weather_header_height)
|
||||
self.draw_design(info_list)
|
||||
|
||||
def __draw_crypto_post_list_to_bottom__(self, crypto):
|
||||
month_pos = self.__abs_pos__(monthovposition)
|
||||
month_height = self.month_block.get_real_height()
|
||||
size = (self.size[0], self.size[1] - (month_pos[1] +
|
||||
month_height + self.weather_header_height))
|
||||
|
||||
info_list = CryptoListDesign(size, crypto)
|
||||
list_height = info_list.get_estimated_height()
|
||||
info_list.pos = (int(month_pos[0]), month_pos[1] + month_height +
|
||||
self.weather_header_height + (size[1] - list_height))
|
||||
self.draw_design(info_list)
|
||||
|
||||
def __draw_event_list_to_bottom__(self, calendar):
|
||||
month_pos = self.__abs_pos__(monthovposition)
|
||||
month_height = self.month_block.get_real_height()
|
||||
size = self.__abs_pos__(infolistsize)
|
||||
size = (size[0], size[1] - month_height - self.weather_header_height)
|
||||
size = (self.size[0], self.size[1] - (month_pos[1] +
|
||||
month_height + self.weather_header_height))
|
||||
|
||||
events = calendar.get_upcoming_events()
|
||||
info_list = EventListDesign(size, events)
|
||||
info_list.pos = (int(month_pos[0]), int(month_pos[1] + month_height + self.weather_header_height))
|
||||
info_list.pos = (int(month_pos[0]), int(
|
||||
month_pos[1] + month_height + self.weather_header_height))
|
||||
self.draw_design(info_list)
|
||||
|
||||
def __draw_highlight_event_day__(self, date):
|
||||
|
@ -100,9 +128,12 @@ class MonthOvPanel (PanelDesign):
|
|||
|
||||
side_length = int(eventcirclehorizontalsize * self.size[0])
|
||||
circle_size = (side_length, side_length)
|
||||
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)
|
||||
place_size = (self.month_block.size[0] * daynumberboxsize[0], self.month_block.size[1] * daynumberboxsize[1])
|
||||
pos = (int(pos[0] + (place_size[0] - circle_size[0]) / 2), int(pos[1] + (place_size[1] - circle_size[1]) / 2))
|
||||
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)
|
||||
place_size = (self.month_block.size[0] * daynumberboxsize[0],
|
||||
self.month_block.size[1] * daynumberboxsize[1])
|
||||
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)
|
||||
|
||||
def __abs_pos__(self, pos, size=None):
|
||||
|
@ -112,23 +143,28 @@ class MonthOvPanel (PanelDesign):
|
|||
|
||||
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_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")
|
||||
txt = TextDesign(self.__abs_pos__(monthboxsize), fontsize=monthtextsize *
|
||||
self.size[1], text=month, verticalalignment="center", horizontalalignment="center")
|
||||
pos = self.__abs_pos__(monthplace)
|
||||
txt.pos = (pos[0], pos[1] + self.weather_header_height)
|
||||
self.draw_design(txt)
|
||||
|
||||
def __draw_week_row__(self):
|
||||
for day_of_week, day in enumerate(self.__week_days__):
|
||||
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)
|
||||
txt = TextDesign(self.__abs_pos__(weekrownameboxsize), fontsize=weekdaytextsize *
|
||||
self.size[1], text=str(day), verticalalignment="center", horizontalalignment="center")
|
||||
pos = self.__get_week_day_pos__(day_of_week)
|
||||
txt.pos = (pos[0], pos[1] + weekdaytextpadding * self.size[1])
|
||||
self.draw_design(txt)
|
||||
|
||||
self.__draw_highlight_box__(self.__abs_pos__(weekrownameboxsize), self.__get_week_day_pos__(self.__get_day_of_week__(datetime.now())), width=1)
|
||||
self.__draw_highlight_box__(self.__abs_pos__(weekrownameboxsize), self.__get_week_day_pos__(
|
||||
self.__get_day_of_week__(datetime.now())), width=1)
|
||||
|
||||
def __get_week_day_pos__(self, day_of_week):
|
||||
maxwidth, _ = self.__abs_pos__(monthovsize)
|
||||
|
@ -154,7 +190,8 @@ class MonthOvPanel (PanelDesign):
|
|||
|
||||
weekdays = []
|
||||
for i in range(7):
|
||||
weekdays.append((datetime.now() + timedelta(days=(i + correction))).strftime("%a"))
|
||||
weekdays.append(
|
||||
(datetime.now() + timedelta(days=(i + correction))).strftime("%a"))
|
||||
|
||||
return weekdays
|
||||
|
||||
|
|
133
Calendar/MonthViewPanel.py
Normal file
133
Calendar/MonthViewPanel.py
Normal file
|
@ -0,0 +1,133 @@
|
|||
from PanelDesign import PanelDesign
|
||||
from settings import general_settings, week_starts_on, line_thickness
|
||||
from PIL import ImageDraw
|
||||
from datetime import date
|
||||
from Assets import colors
|
||||
import calendar as callib
|
||||
from TableDesign import TableDesign
|
||||
from DayBoxDesign import DayBoxDesign
|
||||
from RssPostListDesign import RssPostListDesign
|
||||
from WeatherHeaderDesign import WeatherHeaderDesign
|
||||
from CryptoListDesign import CryptoListDesign
|
||||
|
||||
weather_height = 0.113
|
||||
info_height = 0.25
|
||||
info_padding = 5
|
||||
seperator_width = line_thickness
|
||||
|
||||
|
||||
class MonthViewPanel (PanelDesign):
|
||||
"""Displays a grid of the day of the current month
|
||||
with detailed event descriptions."""
|
||||
|
||||
def __init__(self, size, month=None, year=None):
|
||||
super(MonthViewPanel, self).__init__(size)
|
||||
self.day_table = []
|
||||
self.month = month
|
||||
if self.month == None:
|
||||
self.month = date.today().month
|
||||
self.year = year
|
||||
if self.year == None:
|
||||
self.year = date.today().year
|
||||
self.__init_sizes__()
|
||||
self.__init_day_boxes__()
|
||||
|
||||
def __init_sizes__(self):
|
||||
self.weather_height = 0
|
||||
self.info_height = 0
|
||||
if general_settings["info-area"] in ["events", "rss", "crypto"]:
|
||||
self.info_height = info_height
|
||||
if general_settings["weather-info"]:
|
||||
self.weather_height = weather_height
|
||||
self.day_area_height = 1 - self.weather_height - self.info_height
|
||||
self.day_area_ypos = self.weather_height
|
||||
|
||||
self.week_count = self.__get_week_count__()
|
||||
|
||||
area_height = self.size[1] * self.day_area_height
|
||||
area_width = self.size[0]
|
||||
self.day_box_size = (area_width / 7, area_height / self.week_count)
|
||||
|
||||
def add_weather(self, weather):
|
||||
if general_settings["weather-info"] == False:
|
||||
return
|
||||
size = (self.size[0], self.size[1] * self.weather_height)
|
||||
|
||||
header = WeatherHeaderDesign(size, weather)
|
||||
self.draw_design(header)
|
||||
self.__draw_seperator__(size[1], colors["hl"])
|
||||
|
||||
def add_calendar(self, calendar):
|
||||
self.__add_calendar_to_days__(calendar)
|
||||
|
||||
def __add_calendar_to_days__(self, calendar):
|
||||
for week in self.day_table:
|
||||
for day in week:
|
||||
if day != None:
|
||||
day.add_calendar(calendar)
|
||||
|
||||
def add_rssfeed(self, rss):
|
||||
if general_settings["info-area"] != "rss":
|
||||
return
|
||||
|
||||
size = (self.size[0], self.size[1] * self.info_height)
|
||||
pos = (0, self.size[1] - size[1] + info_padding)
|
||||
|
||||
rss = RssPostListDesign(size, rss)
|
||||
rss.pos = pos
|
||||
self.draw_design(rss)
|
||||
|
||||
def add_tasks(self, tasks):
|
||||
pass
|
||||
|
||||
def add_crypto(self, crypto):
|
||||
if general_settings["info-area"] == "crypto":
|
||||
self.__draw_crypto__(crypto)
|
||||
|
||||
def __draw_crypto__(self, crypto):
|
||||
size = (self.size[0], self.size[1] * self.info_height)
|
||||
pos = (0, self.size[1] - size[1])
|
||||
|
||||
crypto = CryptoListDesign(size, crypto)
|
||||
crypto.pos = (pos[0], pos[1] + (size[1] -
|
||||
crypto.get_estimated_height()))
|
||||
self.draw_design(crypto)
|
||||
|
||||
def __finish_panel__(self):
|
||||
self.__draw_days__()
|
||||
|
||||
def __draw_days__(self):
|
||||
size = (self.size[0], self.size[1] * self.day_area_height)
|
||||
pos = (0, self.size[1] * self.day_area_ypos)
|
||||
|
||||
table = TableDesign(size, matrix=self.day_table)
|
||||
table.pos = pos
|
||||
self.draw_design(table)
|
||||
|
||||
def __draw_seperator__(self, height, color):
|
||||
ImageDraw.Draw(self.__image__).line(
|
||||
[(0, height * self.size[1]), (self.size[0], height * self.size[1])], fill=color, width=seperator_width)
|
||||
|
||||
def __init_day_boxes__(self):
|
||||
if week_starts_on == "Monday":
|
||||
callib.setfirstweekday(callib.MONDAY)
|
||||
elif week_starts_on == "Sunday":
|
||||
callib.setfirstweekday(callib.SUNDAY)
|
||||
|
||||
weeks = callib.monthcalendar(self.year, self.month)
|
||||
for i, week in enumerate(weeks):
|
||||
self.day_table.append([])
|
||||
for day in week:
|
||||
self.day_table[i].append(self.__create_day__(day))
|
||||
|
||||
def __create_day__(self, day):
|
||||
if day == None or day == 0:
|
||||
return None
|
||||
|
||||
design = DayBoxDesign(self.day_box_size, date(
|
||||
self.year, self.month, int(day)))
|
||||
|
||||
return design
|
||||
|
||||
def __get_week_count__(self):
|
||||
return len(callib.monthcalendar(self.year, self.month))
|
|
@ -2,16 +2,20 @@ from WeatherForecast import WeatherForecast
|
|||
from WeatherInterface import WeatherInterface
|
||||
import pyowm
|
||||
from datetime import datetime
|
||||
from settings import units
|
||||
from settings import units, language
|
||||
from Translator import translate
|
||||
|
||||
|
||||
class OwmForecasts (WeatherInterface):
|
||||
"""Fetches weather through the Openweathermap-api."""
|
||||
|
||||
def __init__(self, location, api_key, paid_api=False):
|
||||
self.subscription = "pro" if paid_api else None
|
||||
self.api_key = api_key
|
||||
self.units = units
|
||||
self.location = location
|
||||
self.api = pyowm.OWM(self.api_key, subscription_type=self.subscription)
|
||||
self.api = pyowm.OWM(
|
||||
self.api_key, subscription_type=self.subscription, language=language)
|
||||
|
||||
def is_available(self):
|
||||
try:
|
||||
|
@ -57,24 +61,41 @@ class OwmForecasts (WeatherInterface):
|
|||
forecast_object.units = self.units
|
||||
forecast_object.fetch_datetime = datetime.now()
|
||||
forecast_object.location = location
|
||||
forecast_object.datetime = weather.get_reference_time(timeformat='date')
|
||||
forecast_object.datetime = weather.get_reference_time(
|
||||
timeformat='date')
|
||||
|
||||
forecast_object.icon = weather.get_weather_icon_name()
|
||||
forecast_object.air_humidity = str(weather.get_humidity())
|
||||
forecast_object.clouds = str(weather.get_clouds())
|
||||
forecast_object.short_description = str(weather.get_status())
|
||||
forecast_object.detailed_description = str(weather.get_detailed_status())
|
||||
forecast_object.short_description = translate(
|
||||
str(weather.get_status()))
|
||||
forecast_object.detailed_description = str(
|
||||
weather.get_detailed_status())
|
||||
forecast_object.air_pressure = str(weather.get_pressure()['press'])
|
||||
if 'deg' in weather.get_wind().keys():
|
||||
forecast_object.wind_deg = str(int(weather.get_wind()['deg']))
|
||||
|
||||
if forecast_object.units == "metric":
|
||||
forecast_object.air_temperature = str(int(weather.get_temperature(unit='celsius')['temp']))
|
||||
forecast_object.wind_speed = str(int(weather.get_wind()['speed']))
|
||||
forecast_object.air_temperature = str(
|
||||
int(weather.get_temperature(unit='celsius')['temp']))
|
||||
forecast_object.wind_speed = str(
|
||||
int(weather.get_wind()['speed'])) # kmh
|
||||
|
||||
if forecast_object.units == "aviation":
|
||||
forecast_object.air_temperature = str(
|
||||
int(weather.get_temperature(unit='celsius')['temp']))
|
||||
forecast_object.wind_speed = str(
|
||||
int(weather.get_wind()['speed'] * 1.94384)) # knots
|
||||
|
||||
if forecast_object.units == "imperial":
|
||||
forecast_object.air_temperature = str(int(weather.get_temperature('fahrenheit')['temp']))
|
||||
forecast_object.wind_speed = str(int(weather.get_wind()['speed'] * 0.621))
|
||||
forecast_object.air_temperature = str(
|
||||
int(weather.get_temperature('fahrenheit')['temp']))
|
||||
forecast_object.wind_speed = str(
|
||||
int(weather.get_wind()['speed'] * 0.621)) # mph
|
||||
|
||||
forecast_object.sunrise = datetime.fromtimestamp(int(weather.get_sunrise_time(timeformat='unix')))
|
||||
forecast_object.sunset = datetime.fromtimestamp(int(weather.get_sunset_time(timeformat='unix')))
|
||||
forecast_object.sunrise = datetime.fromtimestamp(
|
||||
int(weather.get_sunrise_time(timeformat='unix')))
|
||||
forecast_object.sunset = datetime.fromtimestamp(
|
||||
int(weather.get_sunset_time(timeformat='unix')))
|
||||
|
||||
return forecast_object
|
|
@ -3,23 +3,28 @@ from TechnicalDataDesign import TechnicalDataDesign
|
|||
from settings import print_technical_data
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class PanelDesign (DesignEntity):
|
||||
"""Defined general interface for panel designs."""
|
||||
|
||||
def __init__(self, size):
|
||||
super(PanelDesign, self).__init__(size)
|
||||
self.start_timestamp = datetime.now()
|
||||
|
||||
def add_weather(self, weather):
|
||||
raise NotImplementedError("Functions needs to be implemented")
|
||||
pass
|
||||
|
||||
def add_calendar(self, calendar):
|
||||
raise NotImplementedError("Functions needs to be implemented")
|
||||
pass
|
||||
|
||||
def add_rssfeed(self, rss):
|
||||
raise NotImplementedError("Functions needs to be implemented")
|
||||
pass
|
||||
|
||||
def add_taks (self, tasks):
|
||||
raise NotImplementedError("Functions needs to be implemented")
|
||||
def add_tasks(self, tasks):
|
||||
pass
|
||||
|
||||
def add_crypto(self, crypto):
|
||||
pass
|
||||
|
||||
def __finish_panel__(self):
|
||||
pass
|
||||
|
@ -28,6 +33,7 @@ class PanelDesign (DesignEntity):
|
|||
self.__finish_panel__()
|
||||
|
||||
if print_technical_data:
|
||||
td = TechnicalDataDesign(self.size, self.start_timestamp, datetime.now())
|
||||
td = TechnicalDataDesign(
|
||||
self.size, self.start_timestamp, datetime.now())
|
||||
td.mask = True
|
||||
self.draw_design(td)
|
|
@ -1,11 +1,12 @@
|
|||
from DataSourceInterface import DataSourceInterface
|
||||
from datetime import datetime, timezone, timedelta
|
||||
|
||||
|
||||
class RssInterface(DataSourceInterface):
|
||||
"""Interface for fetching and processing rss post information."""
|
||||
|
||||
def __init__(self):
|
||||
self.loaded_posts = []
|
||||
self.reload()
|
||||
|
||||
def reload(self):
|
||||
if self.is_available() == False:
|
||||
|
|
|
@ -6,15 +6,22 @@ from urllib.request import urlopen
|
|||
|
||||
max_range_days = 14
|
||||
|
||||
|
||||
class RssParserPosts (RssInterface):
|
||||
"""Fetches posts from url-addresses via rss parser."""
|
||||
|
||||
def __init__(self, urls):
|
||||
self.urls = urls
|
||||
super(RssParserPosts, self).__init__()
|
||||
|
||||
def is_available(self):
|
||||
try:
|
||||
urlopen("https://google.com", timeout=2)
|
||||
testurl = ""
|
||||
if self.urls:
|
||||
testurl = self.urls[0]
|
||||
else:
|
||||
return False
|
||||
urlopen(testurl)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
@ -48,4 +55,3 @@ class RssParserPosts (RssInterface):
|
|||
start_index = link.find('://') + 3
|
||||
end_index = link[start_index:].find('/') + start_index
|
||||
return link[start_index: end_index]
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
class RssPost(object):
|
||||
"""Defines a rss post, independent of any implementation"""
|
||||
|
||||
def __init__(self):
|
||||
self.title = None
|
||||
self.description = None
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
from DesignEntity import DesignEntity
|
||||
from TableTextDesign import TableTextDesign
|
||||
from TableDesign import TableDesign
|
||||
from Assets import defaultfontsize
|
||||
|
||||
|
||||
class RssPostListDesign (DesignEntity):
|
||||
"""Creates a TableTextDesign filled with rss post
|
||||
"""Creates a TableDesign filled with rss post
|
||||
date and title"""
|
||||
|
||||
def __init__(self, size, rssfeed, text_size=defaultfontsize):
|
||||
super(RssPostListDesign, self).__init__(size)
|
||||
self.rssfeed = rssfeed
|
||||
|
@ -14,7 +16,8 @@ class RssPostListDesign (DesignEntity):
|
|||
def __finish_image__(self):
|
||||
self.__fill_post_matrix__()
|
||||
|
||||
table_design = TableTextDesign(self.size, line_spacing=5, col_spacing=3, text_matrix=self.__post_matrix__, fontsize = self.text_size, mask=False, truncate_cols=False, wrap=True)
|
||||
table_design = TableDesign(self.size, line_spacing=2, col_spacing=3, matrix=self.__post_matrix__,
|
||||
fontsize=self.text_size, mask=False, wrap=True, truncate_rows=True)
|
||||
self.draw_design(table_design)
|
||||
|
||||
def __get_formatted_post__(self, post):
|
||||
|
|
|
@ -5,8 +5,11 @@ from TextFormatter import event_prefix_str_sum
|
|||
|
||||
font = fonts["regular"]
|
||||
|
||||
|
||||
class SingelDayEventListDesign (EventListDesign):
|
||||
"""Specialized event list for day list design."""
|
||||
def __init__ (self, size, events, font_size = defaultfontsize, line_spacing=2, event_prefix_rel_dates = [], col_spacing=5, general_color=colors["fg"], background_color=colors["bg"], highlight_color=colors["hl"]):
|
||||
prefix_func = lambda x, rel_date : event_prefix_str_sum(x, rel_date)
|
||||
super().__init__(size, events, text_size=font_size, line_spacing=line_spacing, col_spacing=col_spacing, event_prefix_rel_dates = event_prefix_rel_dates, event_prefix_func=prefix_func, font_family=font, show_more_info=True, general_color=general_color, background_color=background_color, highlight_color = highlight_color)
|
||||
|
||||
def __init__(self, size, events, font_size=defaultfontsize, line_spacing=0, event_prefix_rel_dates=[], col_spacing=5, general_color=colors["fg"], background_color=colors["bg"], highlight_color=colors["hl"]):
|
||||
def prefix_func(x, rel_date): return event_prefix_str_sum(x, rel_date)
|
||||
super().__init__(size, events, text_size=font_size, line_spacing=line_spacing, col_spacing=col_spacing, event_prefix_rel_dates=event_prefix_rel_dates,
|
||||
event_prefix_func=prefix_func, font_family=font, show_more_info=True, general_color=general_color, background_color=background_color, highlight_color=highlight_color)
|
||||
|
|
|
@ -1,20 +1,25 @@
|
|||
from TextDesign import TextDesign
|
||||
from TextWraper import wrap_text_with_font
|
||||
from Assets import defaultfontsize, colors
|
||||
from DesignEntity import DesignEntity
|
||||
|
||||
|
||||
default_props = {
|
||||
"color": colors["fg"],
|
||||
"background_color" : colors["bg"]
|
||||
"background_color": colors["bg"],
|
||||
"font-size": defaultfontsize
|
||||
}
|
||||
|
||||
class TableTextDesign (TextDesign):
|
||||
"""Gets a matrix with text that is than
|
||||
|
||||
class TableDesign (TextDesign):
|
||||
"""Gets a matrix with text or designs that is than
|
||||
displayed in a table without borders."""
|
||||
def __init__ (self, size, text_matrix, max_col_size = None, max_row_size = None, font = None, fontsize = defaultfontsize, column_horizontal_alignments = [], mask = True, line_spacing = 0, col_spacing = 0, truncate_rows = True, truncate_cols = True, wrap = False, truncate_text=True, truncate_suffix="...", cell_properties=None, background_color = colors["bg"]):
|
||||
super(TableTextDesign, self).__init__(size, font=font, fontsize=fontsize, mask=mask)
|
||||
|
||||
def __init__(self, size, matrix, max_col_size=None, max_row_size=None, font=None, fontsize=defaultfontsize, column_horizontal_alignments=[], mask=True, line_spacing=0, col_spacing=0, truncate_rows=True, truncate_cols=True, wrap=False, truncate_text=True, truncate_suffix="...", cell_properties=None, background_color=colors["bg"]):
|
||||
super(TableDesign, self).__init__(
|
||||
size, font=font, fontsize=fontsize, mask=mask)
|
||||
self.__init_image__(background_color)
|
||||
self.matrix = text_matrix
|
||||
self.matrix = matrix
|
||||
self.max_col_size = max_col_size
|
||||
self.max_row_size = max_row_size
|
||||
self.line_spacing = line_spacing
|
||||
|
@ -28,6 +33,7 @@ class TableTextDesign (TextDesign):
|
|||
self.truncate_text = truncate_text
|
||||
self.truncate_suffix = truncate_suffix
|
||||
self.cell_properties = cell_properties
|
||||
default_props["font-size"] = fontsize
|
||||
|
||||
def __finish_image__(self):
|
||||
if len(self.matrix) is 0:
|
||||
|
@ -42,11 +48,10 @@ class TableTextDesign (TextDesign):
|
|||
if self.max_col_size is not None:
|
||||
return
|
||||
|
||||
font = self.__get_font__()
|
||||
col_sizes = []
|
||||
for c in range(len(self.matrix[0])): # amout of columns
|
||||
for r in range(len(self.matrix)):
|
||||
row_col_size = font.getsize(self.matrix[r][c])[0] #get width of text in that row/col
|
||||
row_col_size = self.__get_cell_size__(r, c)[0]
|
||||
if len(col_sizes) - 1 < c:
|
||||
col_sizes.append(row_col_size)
|
||||
elif row_col_size > col_sizes[c]:
|
||||
|
@ -64,14 +69,10 @@ class TableTextDesign (TextDesign):
|
|||
if self.max_row_size is not None:
|
||||
return
|
||||
|
||||
font = self.__get_font__()
|
||||
row_sizes = []
|
||||
for r in range(len(self.matrix)):
|
||||
for c in range(len(self.matrix[0])): # amout of columns
|
||||
cell_text = self.matrix[r][c]
|
||||
if self.wrap:
|
||||
cell_text = wrap_text_with_font(cell_text, self.max_col_size[c], font)
|
||||
col_row_size = font.getsize_multiline(cell_text)[1] #get height of text in that col/row
|
||||
col_row_size = self.__get_cell_size__(r, c)[1]
|
||||
if len(row_sizes) - 1 < r:
|
||||
row_sizes.append(col_row_size)
|
||||
elif col_row_size > row_sizes[r]:
|
||||
|
@ -79,6 +80,27 @@ class TableTextDesign (TextDesign):
|
|||
|
||||
self.max_row_size = row_sizes
|
||||
|
||||
def __get_cell_size__(self, r, c):
|
||||
content = self.matrix[r][c]
|
||||
size = (0, 0)
|
||||
|
||||
if content == None:
|
||||
return size
|
||||
elif type(content) == str:
|
||||
font = self.__get_font__()
|
||||
# get width of text in that row/col
|
||||
width = font.getsize(self.matrix[r][c])[0]
|
||||
if self.wrap and self.max_col_size != None:
|
||||
content = wrap_text_with_font(
|
||||
content, self.max_col_size[c], font)
|
||||
line_count = content.count('\n') + 1
|
||||
height = font.font.height * line_count # get height of text in that col/row
|
||||
size = (width, height)
|
||||
else: # DesignEntity
|
||||
size = content.size
|
||||
|
||||
return size
|
||||
|
||||
def __get_truncated_counts__(self):
|
||||
max_col = 0
|
||||
if self.truncate_cols:
|
||||
|
@ -99,18 +121,43 @@ class TableTextDesign (TextDesign):
|
|||
def __print_table__(self, matrix):
|
||||
for r in range(self.max_row):
|
||||
for c in range(self.max_col):
|
||||
size = self.cell_sizes[r][c]
|
||||
pos = self.__get_cell_pos__(r,c)
|
||||
self.__draw_text__(pos, size, r, c)
|
||||
self.__draw_cell__(r, c)
|
||||
|
||||
def __draw_text__(self, pos, size, row, col):
|
||||
color = self.__get_cell_prop__(row, col, "color")
|
||||
bg_color = self.__get_cell_prop__(row, col, "background_color")
|
||||
fontsize = self.__get_cell_prop__(row, col, "font-size")
|
||||
|
||||
design = TextDesign(size, text=self.matrix[row][col], font=self.font_family, color=color, background_color=bg_color, fontsize=self.font_size, horizontalalignment=self.__get_col_hori_alignment__(col), wrap=self.wrap, truncate=self.truncate_text, truncate_suffix=self.truncate_suffix)
|
||||
design = TextDesign(size, text=self.matrix[row][col], font=self.font_family, color=color, background_color=bg_color, fontsize=fontsize,
|
||||
horizontalalignment=self.__get_col_hori_alignment__(col), wrap=self.wrap, truncate=self.truncate_text, truncate_suffix=self.truncate_suffix)
|
||||
design.pos = pos
|
||||
design.mask = False
|
||||
self.draw_design(design)
|
||||
|
||||
def __draw_design__(self, pos, size, row, col):
|
||||
bg_color = self.__get_cell_prop__(row, col, "background_color")
|
||||
|
||||
source_design = self.matrix[row][col]
|
||||
source_design.mask = False
|
||||
|
||||
framed_design = DesignEntity(size, mask=False)
|
||||
framed_design.__init_image__(color=bg_color)
|
||||
framed_design.draw_design(source_design)
|
||||
|
||||
framed_design.pos = pos
|
||||
self.draw_design(framed_design)
|
||||
|
||||
def __draw_cell__(self, row, col):
|
||||
size = self.cell_sizes[row][col]
|
||||
pos = self.__get_cell_pos__(row, col)
|
||||
|
||||
if self.matrix[row][col] == None:
|
||||
return
|
||||
elif type(self.matrix[row][col]) == str:
|
||||
self.__draw_text__(pos, size, row, col)
|
||||
else:
|
||||
self.__draw_design__(pos, size, row, col)
|
||||
|
||||
def __get_cell_pos__(self, row, col):
|
||||
xpos, ypos = (0, 0)
|
||||
for c in range(col):
|
||||
|
@ -138,7 +185,8 @@ class TableTextDesign (TextDesign):
|
|||
def __get_cell_prop__(self, r, c, prop):
|
||||
if self.cell_properties is None:
|
||||
return default_props[prop]
|
||||
try:
|
||||
|
||||
if r < len(self.cell_properties) and c < len(self.cell_properties[r]) and prop in self.cell_properties[r][c].keys():
|
||||
return self.cell_properties[r][c][prop]
|
||||
except:
|
||||
else:
|
||||
return default_props[prop]
|
|
@ -4,8 +4,10 @@ from Assets import colors
|
|||
|
||||
font_size = 20
|
||||
|
||||
|
||||
class TechnicalDataDesign(DesignEntity):
|
||||
'''Prints data about the current loop ontop of the panel'''
|
||||
|
||||
def __init__(self, size, start, stop):
|
||||
super(TechnicalDataDesign, self).__init__(size, mask=True)
|
||||
self.start = start
|
||||
|
|
|
@ -3,12 +3,13 @@ from PIL import ImageFont, ImageDraw, ImageOps
|
|||
from Assets import path, defaultfont, colors, defaultfontsize
|
||||
from TextWraper import wrap_text_with_font
|
||||
|
||||
paddingcorrection = -3
|
||||
truncateerror_fontsize = 0.5
|
||||
|
||||
|
||||
class TextDesign (DesignEntity):
|
||||
"""Object that manages all information relevant to text
|
||||
and prints it to an image"""
|
||||
|
||||
def __init__(self, size, color=colors["fg"], background_color=colors["bg"], font=None, fontsize=defaultfontsize, text="", horizontalalignment="left", verticalalignment="top", mask=True, truncate=False, truncate_suffix='...', wrap=False):
|
||||
super(TextDesign, self).__init__(size, mask=mask)
|
||||
if font is None:
|
||||
|
@ -37,19 +38,22 @@ class TextDesign (DesignEntity):
|
|||
if self.wrap:
|
||||
self.__wrap_text__()
|
||||
pos = self.__pos_from_alignment__()
|
||||
ImageDraw.Draw(self.__image__).text(pos, self.text, fill=self.color, font=self.__font__)
|
||||
ImageDraw.Draw(self.__image__).text(
|
||||
pos, self.text, fill=self.color, font=self.__font__)
|
||||
|
||||
def __truncate_text__(self):
|
||||
if self.__font__.getsize_multiline(self.text)[0] <= self.size[0]: #does not need truncating
|
||||
# does not need truncating
|
||||
if self.__font__.getsize_multiline(self.text)[0] <= self.size[0]:
|
||||
return
|
||||
suffix_length = self.__font__.getsize_multiline(self.truncate_suffix)[0]
|
||||
suffix_length = self.__font__.getsize_multiline(
|
||||
self.truncate_suffix)[0]
|
||||
while len(self.text) > 1 and self.__font__.getsize_multiline(self.text)[0] + suffix_length >= self.size[0]:
|
||||
self.text = self.text[0:-1]
|
||||
self.text = self.text.rstrip(' ')
|
||||
self.text += self.truncate_suffix
|
||||
|
||||
def __pos_from_alignment__(self):
|
||||
width, height = self.__font__.getsize_multiline(self.text)
|
||||
width, height = self.__get_text_size__()
|
||||
x, y = 0, 0
|
||||
|
||||
if self.vertical_alignment == "center":
|
||||
|
@ -62,7 +66,12 @@ class TextDesign (DesignEntity):
|
|||
elif self.horizontal_alignment == "right":
|
||||
x = int(self.size[0] - width)
|
||||
|
||||
return (x, y + paddingcorrection)
|
||||
return (x, y)
|
||||
|
||||
def __get_text_size__(self):
|
||||
widht = self.__font__.getsize_multiline(self.text)[0]
|
||||
height = (self.text.count('\n') + 1) * self.__font__.font.height
|
||||
return widht, height
|
||||
|
||||
def __wrap_text__(self):
|
||||
self.text = wrap_text_with_font(self.text, self.size[0], self.__font__)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
from settings import hours, language
|
||||
from datetime import timedelta, datetime, timezone
|
||||
from DictionaryMapper import get_text
|
||||
from Dictionary import multiday_events, allday_events
|
||||
|
||||
first_occurrence_char = '['
|
||||
middle_occurrence_char = '|'
|
||||
|
@ -10,17 +12,6 @@ until_character = ' - '
|
|||
allday_character = "•"
|
||||
multiday_character = allday_character + allday_character
|
||||
|
||||
allday_lang = {
|
||||
"en" : "All day",
|
||||
"de" : "Ganztägig"
|
||||
}
|
||||
allday_detailed = allday_lang[language]
|
||||
|
||||
multiday_lang = {
|
||||
"en" : "Multi-day",
|
||||
"de" : "Mehrtägig"
|
||||
}
|
||||
multiday_detailed = multiday_lang[language]
|
||||
|
||||
def time_str(dt):
|
||||
if hours is "12":
|
||||
|
@ -30,6 +21,7 @@ def time_str (dt):
|
|||
else:
|
||||
return str(dt)
|
||||
|
||||
|
||||
def event_prefix_str_md_dif(event, relative_date=None):
|
||||
if relative_date is None:
|
||||
relative_date = event.begin_datetime.date()
|
||||
|
@ -52,15 +44,17 @@ def event_prefix_str_md_dif (event, relative_date=None):
|
|||
event.allday = True
|
||||
return multiday_end_character + event_time_summary(event) + multiday_begin_character
|
||||
|
||||
|
||||
def event_prefix_str(event, relative_date=None):
|
||||
if relative_date is None:
|
||||
relative_date = event.begin_datetime.date()
|
||||
|
||||
if event.multiday:
|
||||
return multiday_detailed
|
||||
return get_text(multiday_events)
|
||||
else:
|
||||
return event_time_detailed(event)
|
||||
|
||||
|
||||
def event_prefix_str_sum(event, relative_date=None):
|
||||
if relative_date is None:
|
||||
relative_date = event.begin_datetime.date()
|
||||
|
@ -70,26 +64,31 @@ def event_prefix_str_sum (event, relative_date=None):
|
|||
else:
|
||||
return event_time_summary(event)
|
||||
|
||||
|
||||
def event_time_summary(event):
|
||||
if event.allday:
|
||||
return allday_character
|
||||
else:
|
||||
return time_str(event.begin_datetime)
|
||||
|
||||
|
||||
def event_time_detailed(event):
|
||||
if event.allday:
|
||||
return allday_detailed
|
||||
return get_text(allday_events)
|
||||
else:
|
||||
return time_str(event.begin_datetime) + until_character + time_str(event.end_datetime)
|
||||
|
||||
|
||||
def date_str(dt):
|
||||
return remove_leading_zero(dt.strftime('%d. %b'))
|
||||
|
||||
|
||||
def remove_leading_zero(text):
|
||||
while text[0] is '0':
|
||||
text = text[1:]
|
||||
return text
|
||||
|
||||
|
||||
def date_summary_str(dt):
|
||||
day = remove_leading_zero(dt.strftime("%d"))
|
||||
if language is "en":
|
||||
|
@ -99,11 +98,13 @@ def date_summary_str(dt):
|
|||
else:
|
||||
return dt.strftime('%a ' + day + '. %b')
|
||||
|
||||
|
||||
def __equal__(dt1, dt2):
|
||||
return dt1.day == dt2.day and \
|
||||
dt1.month == dt2.month and \
|
||||
dt1.year == dt2.year
|
||||
|
||||
|
||||
def __day_duration__(dt):
|
||||
day_begin = datetime(dt.year, dt.month, dt.day, 0, 0, 0, 0, timezone.utc)
|
||||
return dt - day_begin
|
|
@ -1,10 +1,11 @@
|
|||
from Assets import path, defaultfont
|
||||
from PIL import ImageFont
|
||||
|
||||
|
||||
def wrap_text_with_font(text, width, font):
|
||||
words = text.split(' ')
|
||||
result = ""
|
||||
for index, word in enumerate(words):
|
||||
for word in words:
|
||||
until_current = (result + " " + word).strip()
|
||||
txt_width, _ = font.getsize_multiline(until_current)
|
||||
if txt_width > width:
|
||||
|
@ -14,5 +15,6 @@ def wrap_text_with_font (text, width, font):
|
|||
result += word
|
||||
return result.strip()
|
||||
|
||||
|
||||
def wrap_text(text, width, font_size, font_family=defaultfont):
|
||||
return wrap_text_with_font(text, width, ImageFont.truetype(path + font_family, int(font_size)))
|
26
Calendar/Translator.py
Normal file
26
Calendar/Translator.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
from Dictionary import default_language, dictionary_collection
|
||||
from settings import language
|
||||
|
||||
'''Looks up a phrase in a given dictionary-collection
|
||||
and returns the translated phrase'''
|
||||
|
||||
|
||||
def translate(phrase, target_lang=language, dictionary_collection=dictionary_collection):
|
||||
dictionary = find_dictionary(phrase, dictionary_collection)
|
||||
|
||||
if dictionary == None:
|
||||
return phrase
|
||||
|
||||
if target_lang in dictionary.keys():
|
||||
return dictionary[target_lang]
|
||||
elif '_' in target_lang and target_lang.split('_')[0] in dictionary.keys():
|
||||
return dictionary[target_lang.split('_')[0]]
|
||||
else:
|
||||
return dictionary[default_language]
|
||||
|
||||
|
||||
def find_dictionary(phrase, dictionary_collection=dictionary_collection):
|
||||
for dictionary in dictionary_collection:
|
||||
if phrase in dictionary.values():
|
||||
return dictionary
|
||||
return None
|
|
@ -1,6 +1,6 @@
|
|||
from DesignEntity import DesignEntity
|
||||
from TextDesign import TextDesign
|
||||
from TableTextDesign import TableTextDesign
|
||||
from TableDesign import TableDesign
|
||||
from Assets import wpath, weathericons, tempicon, humicon, windicon, no_response, colors, defaultfontsize
|
||||
from PIL import Image
|
||||
from settings import hours
|
||||
|
@ -9,11 +9,14 @@ icon_xpos = 0.1
|
|||
icon_x_ypos = 0
|
||||
icon_width = 1 - 2 * icon_xpos
|
||||
info_x_ypos = icon_x_ypos + icon_width
|
||||
info_yresize = -0.05
|
||||
fontsize_static = defaultfontsize
|
||||
max_symbol_y_width = 0.15
|
||||
|
||||
|
||||
class WeatherColumnDesign (DesignEntity):
|
||||
"""Displays weather information in a column"""
|
||||
|
||||
def __init__(self, size, forecast):
|
||||
super().__init__(size)
|
||||
self.forecast = forecast
|
||||
|
@ -27,9 +30,26 @@ class WeatherColumnDesign (DesignEntity):
|
|||
self.__draw_infos__(self.forecast)
|
||||
|
||||
def __draw_infos__(self, forecast):
|
||||
temperature = forecast.air_temperature + " " + self.__get_unit__(("°C", "°F"))
|
||||
temperature = forecast.air_temperature + \
|
||||
" " + self.__get_unit__(("°C", "°F"))
|
||||
humidity = forecast.air_humidity + "%"
|
||||
windspeed = forecast.wind_speed + " " + self.__get_unit__(("km/h", "mph"))
|
||||
if forecast.units == "aviation":
|
||||
if forecast.wind_deg == None:
|
||||
forecast.wind_deg = ""
|
||||
elif len(forecast.wind_deg) == 1:
|
||||
forecast.wind_deg = "00" + forecast.wind_deg
|
||||
elif len(forecast.wind_deg) == 2:
|
||||
forecast.wind_deg = "0" + forecast.wind_deg
|
||||
if int(forecast.wind_speed) < 10:
|
||||
windspeed = forecast.wind_deg + "@" + "0" + forecast.wind_speed + \
|
||||
self.__get_unit__(
|
||||
("", "")) # added degrees, if wind<10 add a 0 to make two digit
|
||||
else:
|
||||
windspeed = forecast.wind_deg + "@" + forecast.wind_speed + \
|
||||
self.__get_unit__(("", "")) # added degrees
|
||||
else:
|
||||
windspeed = forecast.wind_speed + " " + \
|
||||
self.__get_unit__(("km/h", "mph"))
|
||||
|
||||
numbers_list = [[forecast.short_description],
|
||||
[temperature],
|
||||
|
@ -38,10 +58,13 @@ class WeatherColumnDesign (DesignEntity):
|
|||
|
||||
ypos = info_x_ypos * self.size[0]
|
||||
pos = (0, ypos)
|
||||
size = (self.size[0], self.size[1] - pos[1])
|
||||
line_spacing = (size[1] - len(numbers_list) * fontsize_static) / (len(numbers_list) + 1)
|
||||
size = (self.size[0], self.size[1] +
|
||||
info_yresize * self.size[1] - pos[1])
|
||||
line_spacing = (size[1] - len(numbers_list) *
|
||||
fontsize_static) / (len(numbers_list) + 1)
|
||||
|
||||
table = TableTextDesign(size, numbers_list, fontsize=fontsize_static, line_spacing=line_spacing, column_horizontal_alignments=[ "center" ], max_col_size=[ size[0] ], truncate_text=False)
|
||||
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)
|
||||
table.pos = pos
|
||||
self.draw_design(table)
|
||||
|
||||
|
@ -52,7 +75,8 @@ class WeatherColumnDesign (DesignEntity):
|
|||
ypos = icon_x_ypos * self.size[0]
|
||||
pos = (xpos, ypos)
|
||||
|
||||
self.__draw_resized_path_at__(wpath + weathericons[icon_id] + ".jpeg", pos, size)
|
||||
self.__draw_resized_path_at__(
|
||||
wpath + weathericons[icon_id] + ".jpeg", pos, size)
|
||||
|
||||
def __draw_no_response__(self):
|
||||
width = int(icon_width * self.size[0])
|
||||
|
@ -72,9 +96,8 @@ class WeatherColumnDesign (DesignEntity):
|
|||
resized_img = img.resize(size, resample=Image.LANCZOS)
|
||||
self.draw(resized_img, pos)
|
||||
|
||||
|
||||
def __get_unit__(self, tuple):
|
||||
if self.forecast.units == "metric":
|
||||
if self.forecast.units == "metric" or self.forecast.units == "aviation":
|
||||
return tuple[0]
|
||||
else:
|
||||
return tuple[1]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class WeatherForecast (object):
|
||||
"""Defines a weather forecast, independent of any implementation"""
|
||||
|
||||
def __init__(self):
|
||||
self.air_temperature = None
|
||||
self.air_pressure = None
|
||||
|
@ -11,6 +12,7 @@ class WeatherForecast (object):
|
|||
self.sunset = None
|
||||
self.moon_phase = None
|
||||
self.wind_speed = None
|
||||
self.wind_deg = None
|
||||
self.clouds = None
|
||||
|
||||
self.icon = None
|
||||
|
|
|
@ -10,8 +10,10 @@ 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
|
||||
|
@ -28,22 +30,45 @@ class WeatherHeaderDesign (DesignEntity):
|
|||
self.__render_missing_connection__()
|
||||
return
|
||||
|
||||
temperature = cur_weather.air_temperature + " " + self.__get_unit__(("°C", "°F"))
|
||||
windspeed = cur_weather.wind_speed + " " + self.__get_unit__(("km/h", "mph"))
|
||||
temperature = cur_weather.air_temperature + \
|
||||
" " + self.__get_unit__(("°C", "°F"))
|
||||
if units == "aviation": # pick up aviation
|
||||
if cur_weather.wind_deg == None:
|
||||
cur_weather.wind_deg = ""
|
||||
elif len(cur_weather.wind_deg) == 1: # if deg is 2, add two zeros for format
|
||||
cur_weather.wind_deg = "00" + cur_weather.wind_deg
|
||||
elif len(cur_weather.wind_deg) == 2:
|
||||
cur_weather.wind_deg = "0" + cur_weather.wind_deg
|
||||
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
|
||||
else:
|
||||
windspeed = cur_weather.wind_deg + "@" + cur_weather.wind_speed + \
|
||||
self.__get_unit__(("", "")) # added degrees
|
||||
else:
|
||||
windspeed = cur_weather.wind_speed + " " + \
|
||||
self.__get_unit__(("km/h", "mph"))
|
||||
|
||||
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))
|
||||
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))
|
||||
|
||||
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))
|
||||
self.draw_image(
|
||||
wpath + weathericons[cur_weather.icon] + '.jpeg', self.__abs_pos__(wiconplace))
|
||||
|
||||
def __render_missing_connection__(self):
|
||||
self.draw(no_response, self.__abs_pos__(wiconplace))
|
||||
|
@ -52,12 +77,13 @@ class WeatherHeaderDesign (DesignEntity):
|
|||
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 = 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":
|
||||
if units == "metric" or units == "aviation":
|
||||
return tuple[0]
|
||||
else:
|
||||
return tuple[1]
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
from DataSourceInterface import DataSourceInterface
|
||||
|
||||
|
||||
class WeatherInterface (DataSourceInterface):
|
||||
"""Interface for fetching and processing weather forecast information."""
|
||||
|
||||
def get_forecast_in_days(self, offset_by_days, location=None):
|
||||
raise NotImplementedError("Functions needs to be implemented")
|
||||
|
||||
|
|
|
@ -1,35 +1,43 @@
|
|||
""" To quickly get started, fill in the following details:"""
|
||||
|
||||
ical_urls = [
|
||||
"https://calendar.google.com/calendar/ical/en.usa%23holiday%40group.v.calendar.google.com/public/basic.ics"
|
||||
]
|
||||
|
||||
highlighted_ical_urls = [
|
||||
]
|
||||
|
||||
rss_feeds = [
|
||||
"http://feeds.bbci.co.uk/news/world/rss.xml#"
|
||||
]
|
||||
|
||||
crypto_coins = [
|
||||
]
|
||||
|
||||
api_key = ""
|
||||
owm_paid_subscription = False
|
||||
location = "Julich, DE"
|
||||
location = "Berlin, DE"
|
||||
week_starts_on = "Monday"
|
||||
display_colours = "bwr"
|
||||
language = "en"
|
||||
units = "metric"
|
||||
datetime_encoding = "UTF-8" # UTF-8
|
||||
units = "metric" # aviation (celcius,degrees/knots), metric (celcius,kmh), imperial(f,mph)
|
||||
hours = "24"
|
||||
update_interval = 60
|
||||
max_loop_count = 0 # From 0 to 86400 representing the maximum number the loop is executed, with 0 being unlimited
|
||||
run_on_hour = True # If True, updates calendar every full hour, ignoring differing update_interval
|
||||
|
||||
|
||||
"""DESIGN"""
|
||||
font_size = 14 # does not affect every text
|
||||
font_boldness = "semibold" # extralight, light, regular, semibold, bold, extrabold
|
||||
choosen_design = "month-overview" # month-overview, day-list, day-view, agenda-list
|
||||
line_thickness = 1 # 1-3 Thickness advised
|
||||
choosen_design = "month-overview" # month-overview, day-list, day-view, day-focus-list, agenda-list, month-view, image-frame
|
||||
general_settings = { # General settings that designs may use
|
||||
"info-area" : "rss", # empty, events, rss
|
||||
"info-area" : "rss", # empty, events, rss, crypto
|
||||
"highlight-event-days" : True,
|
||||
"weather-info" : True
|
||||
"weather-info" : True,
|
||||
"image-folder" : "",
|
||||
"overlay-image" : "", # Size must be 384x640px with default display
|
||||
"extra-excluded-urls" : []
|
||||
}
|
||||
|
||||
|
||||
|
|
15
Changelog.md
15
Changelog.md
|
@ -4,6 +4,21 @@ The order is from latest to oldest and structured in the following way:
|
|||
* Version name with date of publishing
|
||||
* Sections with either 'added', 'fixed', 'updated' and 'changed'
|
||||
|
||||
## [1.7] Mid April 2019
|
||||
|
||||
### Added
|
||||
* Added agenda-list panel
|
||||
* Added day-view panel
|
||||
* Added offline calendar and rss support
|
||||
* Added more settings
|
||||
* Added support for multi-day and repeating events
|
||||
|
||||
### Changed
|
||||
* Improved internal event management
|
||||
|
||||
### Removed
|
||||
* Bugs
|
||||
|
||||
## [1.6] Mid March 2019
|
||||
|
||||
### Added
|
||||
|
|
BIN
Gallery/day-focus-list_example.png
Normal file
BIN
Gallery/day-focus-list_example.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
BIN
Gallery/image-frame_example.png
Normal file
BIN
Gallery/image-frame_example.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 62 KiB |
|
@ -1,15 +1,13 @@
|
|||
### This file contains features in planning for the next release
|
||||
|
||||
# For version 1.7
|
||||
# For version 1.8
|
||||
|
||||
## Installer
|
||||
* Optimise the installer by adding a few more options when updating
|
||||
|
||||
## Main script
|
||||
* Implement weekly view (may take a lot of time)
|
||||
* Implement multi-calendar panel
|
||||
* Implement feature to fetch tasks
|
||||
* Add code in E-Paper.py for fixing errors related to the iCalendar (ics.py is pretty picky)
|
||||
* Fix a bug where past events are shown along with ones in the future
|
||||
* Add support for ics files along with iCalendar URLs
|
||||
* Allow connecting to the openweathermap API servers even when the SSL certificate has expired
|
||||
* Try using the weathericons.io font instead of icons
|
||||
|
|
38
README.md
38
README.md
|
@ -1,29 +1,36 @@
|
|||
# NOT ACTIVELY MAINTAINED ANY LONGER
|
||||
Since [aceisace/Inkycal](https://github.com/aceisace/Inkycal) has grown significantly and is far superior in many ways, I will no longer focus on mainting my own fork. The ical implementation might also not be super reliable in this project.
|
||||
|
||||
# E-Paper Calendar
|
||||
|
||||
This is a software written in python3 that allows you to transform an E-Paper display (like the kindle) into an information display. It fetches live data from Openweathermap (a weather info provider), rss-feeds and your Online Calendar (Google/Yahoo Calendar/...) and displays them on a large, beautiful and ultra-low power E-Paper display. It's ideal for staying organised and keeping track of important details without having to check them up online.
|
||||
This is a software written in python3 that allows you to transform an E-Paper display (like the kindle) into an information display. It fetches live data from Openweathermap (a weather info provider), rss-feeds and your Online Calendar (Google/Yahoo Calendar/...) and displays them on a large, beautiful and ultra-low power E-Paper display. It's ideal for staying organised and keeping track of important details without having to check them up online. It can also be used as an image frame.
|
||||
|
||||
This software fully supports the 3-Colour **and** 2-Colour version of the 7.5" E-Paper display from waveshare/gooddisplay and works with Raspberry Pi 2, 3 and 0 (Zero, Zero W, Zero WH).
|
||||
|
||||
**To get started, follow the instructions below.**
|
||||
|
||||
## News:
|
||||
* **Version 1.7 released with two new designs, offline support and improved support for events** (Mid April 2019)
|
||||
* **Specified README for this fork, added new design and many options** (Mid March 2019)
|
||||
* **Version 1.5 released with a new layout, displayed events and many back-end improvements** (Early February 2019)
|
||||
* **Added Support for the 2-Colour E-Paper Display as well!** (Late September 2018)
|
||||
* **Added Support for Raspbian Stretch lite.** (Late September 2018)
|
||||
|
||||
<img src="https://github.com/mgfcf/E-Paper-Calendar/blob/master/Gallery/day-list_example.png" width="270"><img src="https://github.com/mgfcf/E-Paper-Calendar/blob/master/Gallery/month-overview_example.png" width="270"><img src="https://github.com/mgfcf/E-Paper-Calendar/blob/master/Gallery/agenda-list_example.png" width="270"><img src="https://github.com/mgfcf/E-Paper-Calendar/blob/master/Gallery/day-view_example.png" width="270">
|
||||
<img src="https://code.giller.dev/m.giller/E-Paper-Calendar/raw/branch/master/Gallery/day-list_example.png" width="270"><img src="https://code.giller.dev/m.giller/E-Paper-Calendar/raw/branch/master/Gallery/month-overview_example.png" width="270"><img src="https://code.giller.dev/m.giller/E-Paper-Calendar/raw/branch/master/Gallery/agenda-list_example.png" width="270"><img src="https://code.giller.dev/m.giller/E-Paper-Calendar/raw/branch/master/Gallery/day-view_example.png" width="270"><img src="https://code.giller.dev/m.giller/E-Paper-Calendar/raw/branch/master/Gallery/day-focus-list_example.png" width="270"><img src="https://code.giller.dev/m.giller/E-Paper-Calendar/raw/branch/master/Gallery/image-frame_example.png" width="270">
|
||||
|
||||
1.: Day-List Panel
|
||||
2.: Month-Overview Panel
|
||||
3.: Agenda-List Panel
|
||||
4.: Day-View Panel
|
||||
1.: Day-List Panel 
|
||||
2.: Month-Overview Panel 
|
||||
3.: Agenda-List Panel<br>
|
||||
4.: Day-View Panel 
|
||||
5.: Day-Focus-List Panel 
|
||||
6.: Image-Frame Panel
|
||||
|
||||
## Main features
|
||||
* Display a calendar with one of multiple designes
|
||||
* Optionally get RSS-Feed fetched and shown
|
||||
* Syncronise events from any online calendar (like google, yahoo, etc.)
|
||||
* Get live weather data (including temperature, humidity, etc.) using openweathermap api
|
||||
* Only show a slideshow of images
|
||||
|
||||
## Hardware required
|
||||
* 7.5" 3-Colour E-Paper Display (Black, White, Red/Yellow) with driver hat from [waveshare](https://www.waveshare.com/product/7.5inch-e-paper-hat-b.htm)
|
||||
|
@ -56,7 +63,7 @@ If the Installer should fail for any reason, kindly open an issue and paste the
|
|||
|
||||
This is how the installer will run:
|
||||
|
||||
<img src="https://github.com/mgfcf/E-Paper-Calendar/blob/master/Gallery/Installer-v1.2-screenshot.png" width="700">
|
||||
<img src="https://code.giller.dev/m.giller/E-Paper-Calendar/raw/branch/master/Gallery/Installer-v1.2-screenshot.png" width="700">
|
||||
|
||||
## Adding details to the programm
|
||||
Once the packages are installed, navigate to the home directory, open 'E-Paper-Master' and open the file 'settings.py' inside the Calendar folder. Adjust the values as needed. You can use the table below as a reference.
|
||||
|
@ -65,28 +72,35 @@ Once the packages are installed, navigate to the home directory, open 'E-Paper-M
|
|||
| Parameter | Description |
|
||||
| --- | --- |
|
||||
| ical_urls | Your iCalendar URL/s. To add more than one URL, seperate each with a comma. |
|
||||
| highlighted_ical_urls | Your iCalendar URL/s that should be higlighted in comparison the ical_urls. To add more than one URL, seperate each with a comma. |
|
||||
| highlighted_ical_urls | Your iCalendar URL/s that should be higlighted in comparison to the ical_urls. To add more than one URL, seperate each with a comma. |
|
||||
| rss_feeds | All the sources for your rss-feed. To add more than one URL, seperate each with a comma. |
|
||||
| api_key | Your __personal__ openweathermap API-key which you can generate and find in your Account info. |
|
||||
| owm_paid_subscription | If you have a paid owm subscription you can set it to `True` and in some panels receive forecast information. |
|
||||
| location | Location refers to the closest weather station from your place. It isn't necessarily the place you live in. To find this location, type your city name in the search box on [openweathermap](https://openweathermap.org/). The output should be in the following format: City Name, Country ISO-Code. Not sure what your ISO code is? Check here: [(find iso-code)](https://countrycode.org/). |
|
||||
| week_starts_on | When does the work start on your Region? Possible options are `"Monday"` or `"Sunday"`. |
|
||||
| week_starts_on | When does the work start in your region? Possible options are `"Monday"` or `"Sunday"`. |
|
||||
| display_colours | This should normally be set by the installer when you choose the type of your display. Options include `"bw"` if you're using the black and white E-Paper or `"bwr"` when you're using the black-white-red or black-white-yellow E-Paper.|
|
||||
| language | Choosing the language allows changing the language of the month and week-icons. Possible options are `"en"` for english and `"de"` for german.|
|
||||
|units| Selecting units allows switching units from km/h (kilometer per hour) and °C (degree Celcius) to mph (miles per hour) and °F (degree Fahrenheit). Possible options are `"metric"` or `"imperial"`. |
|
||||
| language | Sets the language and the related locale for datetime-information. Some texts depend on additional translations that can be added to the dictionary-file.|
|
||||
| datetime_encoding | Sets the encoding that will be used in the datetime-texts (month, weekday, ...). Default is `"UTF-8"`. Not to confuse with the full locale, this is only the encoding. |
|
||||
|units| Selecting units allows switching units from km/h (kilometer per hour) and °C (degree Celcius) to mph (miles per hour) and °F (degree Fahrenheit). Possible options are `"metric"`, `"imperial"` or `"aviation"` (Celsius, Degree/Knots). |
|
||||
|hours | Which time format do you prefer? This will change the sunrise and sunset times from 24-hours format to 12-hours format. Possible options are `"24"` for 24-hours and `"12"` for 12-hours.|
|
||||
|update_interval | The update delay between two updates in minutes. By default there is always an update on a full hour.|
|
||||
|max_loop_count | From 0 to 86400 representing the maximum number of times the loop is going to be executed, with `0` being unlimited.|
|
||||
|run_on_hour | If `True`, updates calendar every full hour, ignoring differing update_interval.|
|
||||
|
||||
### Design
|
||||
| Parameter | Description |
|
||||
| --- | --- |
|
||||
| font_size | Varies the size of the font. Can be any number >0. In some cases the size of the font is fixed by the design. Default value is `14`. |
|
||||
| font_boldness | Varies the boldness of the font. Can be one of `extralight`, `light`, `regular`, `semibold`, `bold` or `extrabold`. In some cases the boldness of the font is fixed by the design. Default value is `regular`. |
|
||||
| choosen_design | Sets the desired panel design. Can be one of `month-overview` or `day-list`. |
|
||||
| choosen_design | Sets the desired panel design. |
|
||||
| line_thickness | Varies the boldness of separation lines in the chosen design. |
|
||||
| general_settings | A dictionary containing options that some designs use to optimize there design. Possible options are as follows: |
|
||||
| `"info-area"` | Defines the content type of an additionaly info area on the design. Can be one of `"rss"`, `"events"` or empty, to remove this area or keep it clean. |
|
||||
| `"highlight-event-days"` | If set to `True`, days with events are highlighted in contrast to days without events. |
|
||||
| `"weather-info"` | If set to `False`, weather info areas disappear and make room for events/rss/etc. (depends on the design). |
|
||||
| `"image-folder"` | Set a relative or absolute path to a folder containing images that you want to see fullscreen with the `"image-frame"` design activated. |
|
||||
| `"overlay-image"` | Set a relative or absolute path to an image with the same size as the screen (default: 384x640px) to show some static information over every image shown in the `"image-frame"` design. If the overlay image is contained within the `"image-folder"`, it will not be included into the slideshow. |
|
||||
| `"extra-excluded-urls"` | A list of calendar urls that may be excluded in some panels in certain areas. |
|
||||
|
||||
### Debug
|
||||
| Parameter | Description |
|
||||
|
|
Loading…
Reference in a new issue