diff --git a/.gitignore b/.gitignore index 1267cba..3f1a468 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ /Calendar/DataSourceInterface.pyc /Calendar/CalendarInterface.pyc /Calendar/CalendarEvent.pyc +/Calendar/design_exported_old.png diff --git a/Calendar/icon_positions_locations.py b/Calendar/Assets.py similarity index 91% rename from Calendar/icon_positions_locations.py rename to Calendar/Assets.py index 97c98de..7ce6509 100644 --- a/Calendar/icon_positions_locations.py +++ b/Calendar/Assets.py @@ -22,17 +22,12 @@ seperator = im_open(opath+'seperator.jpeg').convert('L') no_response= im_open(opath+'cloud-no-response.jpeg') sunriseicon = im_open(opath+'wi-sunrise.jpeg') sunseticon = im_open(opath+'wi-sunset.jpeg') -windicon = im_open(opath+'wi-strong-wind.jpeg') +windicon = im_open(opath+'wi-strong-wind.jpeg')# -wiconplace = (0, 0) -tempplace = (299, 0) -humplace = (299, 35) -seperatorplace = (0, 72) -monthplace = (0, 74) -weekplace = (3, 134) -windiconspace = (79, 0) -sunriseplace = (214, 0) -sunsetplace = (214, 35) +datetime_locals = { + "de" : "de_DE.UTF-8", + "en" : "en_US.UTF-8" +} e_col = 70 date_col = 0 @@ -111,4 +106,4 @@ weathericons = { '03n': 'wi-night-cloudy', '04n': 'wi-night-cloudy', '09n': 'wi-night-showers', '10n':'wi-night-rain', '11n':'wi-night-thunderstorm', '13n':'wi-night-snow', -'50n': 'wi-night-alt-cloudy-windy'} +'50n': 'wi-night-alt-cloudy-windy'} \ No newline at end of file diff --git a/Calendar/DebugConsole.py b/Calendar/DebugConsole.py index 199eabc..64d8009 100644 --- a/Calendar/DebugConsole.py +++ b/Calendar/DebugConsole.py @@ -1,5 +1,5 @@ from DebugInterface import DebugInterface -from icon_positions_locations import weathericons +from Assets import weathericons class DebugConsole (DebugInterface): """Defines concrete console export of debug objects""" diff --git a/Calendar/DesignEntity.py b/Calendar/DesignEntity.py new file mode 100644 index 0000000..75b8537 --- /dev/null +++ b/Calendar/DesignEntity.py @@ -0,0 +1,35 @@ +from PIL import Image, ImageOps, ImageDraw + +class DesignEntity (object): + """General entity that can be drawn on to a panel design or + other design entities.""" + def __init__ (self, size): + self.size = size + self.pos = (0, 0) + self.__init_image__() + self.is_bitmap = False + + def __init_image__ (self, color = 'white'): + self.__image__ = Image.new('L', self.size, color=color) + + def get_image (self): + self.__finish_image__() + return self.__image__ + + def draw (self, subimage, pos): + self.__image__.paste(subimage, pos) + + def draw_bitmap (self, subimage, pos): + ImageDraw.Draw(self.__image__).bitmap(pos, subimage) + + def draw_design (self, entity): + if entity.is_bitmap: + self.draw_bitmap(entity.get_image(), entity.pos) + else: + self.draw(entity.get_image(), entity.pos) + + def draw_image (self, path, pos): + self.draw(Image.open(path), pos) + + def __finish_image__ (self): + pass \ No newline at end of file diff --git a/Calendar/E-Paper.py b/Calendar/E-Paper.py index 8340ae6..2f87a5f 100644 --- a/Calendar/E-Paper.py +++ b/Calendar/E-Paper.py @@ -8,25 +8,19 @@ If you have any questions, feel free to open an issue at Github. Copyright by aceisace """ from __future__ import print_function -import calendar from datetime import datetime from time import sleep - +from Assets import datetime_locals +import locale from DebugConsole import DebugConsole - -debug = DebugConsole() - from settings import * -from icon_positions_locations import * - -from PIL import Image, ImageDraw, ImageFont, ImageOps +from MonthOvPanel import MonthOvPanel +from WeatherHeaderDesign import WeatherHeaderDesign import OwmForecasts import IcalEvents -try: - from urllib.request import urlopen -except Exception as e: - debug.print_line("Something didn't work right, maybe you're offline?" + e.reason) +locale.setlocale(locale.LC_ALL, datetime_locals[language]) +debug = DebugConsole() output_adapters = [] if render_to_file: @@ -44,11 +38,6 @@ if render_to_display: epd = Epd7in5Adapter.Epd7in5Adapter() output_adapters.append(epd) -EPD_WIDTH = epd.width -EPD_HEIGHT = epd.height -font = ImageFont.truetype(path + 'Assistant-Regular.ttf', 18) -im_open = Image.open - """Main loop starts from here""" def main (): while True: @@ -60,205 +49,125 @@ def main (): for i in range(1): debug.print_line('_________Starting new loop___________' + '\n') - """At the following hours (midnight, midday and 6 pm), perform - a calibration of the display's colours""" + debug.print_line('Date:'+ time.strftime('%a %d %b %y') + ', time: ' + time.strftime('%H:%M') + '\n') if hour in calibrate_hours: for output in output_adapters: output.calibrate() - debug.print_line('Date:'+ time.strftime('%a %d %b %y') + ', time: ' + time.strftime('%H:%M') + '\n') + design = MonthOvPanel((epd.width, epd.height)) - """Create a blank white page, for debugging, change mode to - to 'RGB' and and save the image by uncommenting the image.save - line at the bottom""" - image = Image.new('L', (EPD_HEIGHT, EPD_WIDTH), 'white') - draw = (ImageDraw.Draw(image)).bitmap - - """Draw the icon with the current month's name""" - image.paste(im_open(mpath + str(time.strftime("%B") + '.jpeg')), monthplace) - - """Draw a line seperating the weather and Calendar section""" - image.paste(seperator, seperatorplace) - - """Draw the icons with the weekday-names (Mon, Tue...) and - draw a circle on the current weekday""" - if (week_starts_on == "Monday"): - calendar.setfirstweekday(calendar.MONDAY) - image.paste(weekmon, weekplace) - draw(weekdaysmon[(time.strftime("%a"))], weekday) - - if (week_starts_on == "Sunday"): - calendar.setfirstweekday(calendar.SUNDAY) - image.paste(weeksun, weekplace) - draw(weekdayssun[(time.strftime("%a"))], weekday) - - """Using the built-in calendar function, draw icons for each - number of the month (1,2,3,...28,29,30)""" - cal = calendar.monthcalendar(time.year, time.month) - #debug.print_line(cal) #-uncomment for debugging with incorrect dates - - for numbers in cal[0]: - image.paste(im_open(dpath + str(numbers) + '.jpeg'), positions['a' + str(cal[0].index(numbers) + 1)]) - for numbers in cal[1]: - image.paste(im_open(dpath + str(numbers) + '.jpeg'), positions['b' + str(cal[1].index(numbers) + 1)]) - for numbers in cal[2]: - image.paste(im_open(dpath + str(numbers) + '.jpeg'), positions['c' + str(cal[2].index(numbers) + 1)]) - for numbers in cal[3]: - image.paste(im_open(dpath + str(numbers) + '.jpeg'), positions['d' + str(cal[3].index(numbers) + 1)]) - for numbers in cal[4]: - image.paste(im_open(dpath + str(numbers) + '.jpeg'), positions['e' + str(cal[4].index(numbers) + 1)]) - try: - for numbers in cal[5]: - image.paste(im_open(dpath + str(numbers) + '.jpeg'), positions['f' + str(cal[5].index(numbers) + 1)]) - except IndexError: - pass - - """Custom function to display text on the E-Paper. - Tuple refers to the x and y coordinates of the E-Paper display, - with (0, 0) being the top left corner of the display.""" - def write_text (box_width, box_height, text, tuple): - text_width, text_height = font.getsize(text) - if (text_width, text_height) > (box_width, box_height): - raise ValueError('Sorry, your text is too big for the box') - else: - x = int((box_width / 2) - (text_width / 2)) - y = int((box_height / 2) - (text_height / 2)) - space = Image.new('L', (box_width, box_height), color=255) - ImageDraw.Draw(space).text((x, y), text, fill=0, font=font) - image.paste(space, tuple) - - """ Handling Openweathermap API""" debug.print_line("Connecting to Openweathermap API servers...") - owm = OwmForecasts.OwmForecasts(api_key, units=units) - if owm.is_available() is True: - forecast = owm.get_today_forecast(location) - debug.print_forecast(forecast) + owm = OwmForecasts.OwmForecasts(api_key) + design.add_weather(OwmForecasts.OwmForecasts(api_key)) - if forecast.units == "metric": - write_text(50, 35, forecast.air_temperature + " °C", (334, 0)) - write_text(100, 35, forecast.wind_speed + " km/h", (114, 0)) + output_adapters[0].render(design) + return - if forecast.units == "imperial": - write_text(50, 35, forecast.air_temperature + " °F", (334, 0)) - write_text(100, 35, forecast.wind_speed + " mph", (114, 0)) - if hours == "24": - sunrisetime = str(forecast.sunrise.strftime('%H:%M')) - sunsettime = str(forecast.sunset.strftime('%H:%M')) - if hours == "12": - sunrisetime = str(forecast.sunrise.strftime('%I:%M')) - sunsettime = str(forecast.sunset.strftime('%I:%M')) - """Drawing the fetched weather icon""" - image.paste(im_open(wpath + weathericons[forecast.icon] + '.jpeg'), wiconplace) - """Drawing the fetched temperature""" - image.paste(tempicon, tempplace) - """Drawing the fetched humidity""" - image.paste(humicon, humplace) - write_text(50, 35, forecast.air_humidity + " %", (334, 35)) - """Drawing the fetched sunrise time""" - image.paste(sunriseicon, sunriseplace) - write_text(50, 35, sunrisetime, (249, 0)) - """Drawing the fetched sunset time""" - image.paste(sunseticon, sunsetplace) - write_text(50, 35, sunsettime, (249, 35)) - """Drawing the wind icon""" - image.paste(windicon, windiconspace) - """Write a short weather description""" - write_text(144, 35, forecast.short_description, (70, 35)) - else: - image.paste(no_response, wiconplace) - """Filter upcoming events from your iCalendar/s""" - debug.print_line('Fetching events from your calendar' + '\n') - events_cal = IcalEvents.IcalEvents(ical_urls) - for event in events_cal.get_month_events(): - debug.print_event(event) - upcoming = events_cal.get_upcoming_events() - events_this_month = events_cal.get_month_events() - events_this_month = [event.begin_datetime.day for event in events_this_month] - def takeDate (elem): - return elem.begin_datetime - upcoming.sort(key=takeDate) - del upcoming[4:] - # uncomment the following 2 lines to display the fetched events - # from your iCalendar - debug.print_line('Upcoming events:') - debug.print_line(upcoming) - debug.print_line('Month events:') - debug.print_line(events_this_month) - #Credit to Hubert for suggesting truncating event names - def write_text_left (box_width, box_height, text, tuple): - text_width, text_height = font.getsize(text) - while (text_width, text_height) > (box_width, box_height): - text=text[0:-1] - text_width, text_height = font.getsize(text) - y = int((box_height / 2) - (text_height / 2)) - space = Image.new('L', (box_width, box_height), color=255) - ImageDraw.Draw(space).text((0, y), text, fill=0, font=font) - image.paste(space, tuple) - """Write event dates and names on the E-Paper""" - for dates in range(len(upcoming)): - write_text(70, 25, (upcoming[dates].begin_datetime.strftime('%d %b')), date_positions['d' + str(dates + 1)]) - for events in range(len(upcoming)): - write_text_left(314, 25, (upcoming[events].title), event_positions['e' + str(events + 1)]) - """Draw smaller squares on days with events""" - for numbers in events_this_month: - if numbers in cal[0]: - draw(positions['a' + str(cal[0].index(numbers) + 1)], eventicon) - if numbers in cal[1]: - draw(positions['b' + str(cal[1].index(numbers) + 1)], eventicon) - if numbers in cal[2]: - draw(positions['c' + str(cal[2].index(numbers) + 1)], eventicon) - if numbers in cal[3]: - draw(positions['d' + str(cal[3].index(numbers) + 1)], eventicon) - if numbers in cal[4]: - draw(positions['e' + str(cal[4].index(numbers) + 1)], eventicon) - try: - if numbers in cal[5]: - draw(positions['f' + str(cal[5].index(numbers) + 1)], eventicon) - except IndexError: - pass - """Draw a larger square on today's date""" - today = time.day - if today in cal[0]: - draw(positions['a' + str(cal[0].index(today) + 1)], dateicon) - if today in cal[1]: - draw(positions['b' + str(cal[1].index(today) + 1)], dateicon) - if today in cal[2]: - draw(positions['c' + str(cal[2].index(today) + 1)], dateicon) - if today in cal[3]: - draw(positions['d' + str(cal[3].index(today) + 1)], dateicon) - if today in cal[4]: - draw(positions['e' + str(cal[4].index(today) + 1)], dateicon) - try: - if today in cal[5]: - draw(positions['f' + str(cal[5].index(today) + 1)], dateicon) - except IndexError: - pass + + #"""Filter upcoming events from your iCalendar/s""" + #debug.print_line('Fetching events from your calendar' + '\n') + + #events_cal = IcalEvents.IcalEvents(ical_urls) + + #for event in events_cal.get_month_events(): + # debug.print_event(event) + + #upcoming = events_cal.get_upcoming_events() + #events_this_month = events_cal.get_month_events() + #events_this_month = [event.begin_datetime.day for event in events_this_month] + + #def takeDate (elem): + # return elem.begin_datetime + + #upcoming.sort(key=takeDate) + + #del upcoming[4:] + ## uncomment the following 2 lines to display the fetched events + ## from your iCalendar + #debug.print_line('Upcoming events:') + #debug.print_line(upcoming) + #debug.print_line('Month events:') + #debug.print_line(events_this_month) + + ##Credit to Hubert for suggesting truncating event names + #def write_text_left (box_width, box_height, text, tuple): + # text_width, text_height = font.getsize(text) + # while (text_width, text_height) > (box_width, box_height): + # text=text[0:-1] + # text_width, text_height = font.getsize(text) + # y = int((box_height / 2) - (text_height / 2)) + # space = Image.new('L', (box_width, box_height), color=255) + # ImageDraw.Draw(space).text((0, y), text, fill=0, font=font) + # image.paste(space, tuple) + + #"""Write event dates and names on the E-Paper""" + #for dates in range(len(upcoming)): + # write_text(70, 25, (upcoming[dates].begin_datetime.strftime('%d %b')), date_positions['d' + str(dates + 1)]) + + #for events in range(len(upcoming)): + # write_text_left(314, 25, (upcoming[events].title), event_positions['e' + str(events + 1)]) + + #"""Draw smaller squares on days with events""" + #for numbers in events_this_month: + # if numbers in cal[0]: + # draw(positions['a' + str(cal[0].index(numbers) + 1)], eventicon) + # if numbers in cal[1]: + # draw(positions['b' + str(cal[1].index(numbers) + 1)], eventicon) + # if numbers in cal[2]: + # draw(positions['c' + str(cal[2].index(numbers) + 1)], eventicon) + # if numbers in cal[3]: + # draw(positions['d' + str(cal[3].index(numbers) + 1)], eventicon) + # if numbers in cal[4]: + # draw(positions['e' + str(cal[4].index(numbers) + 1)], eventicon) + # try: + # if numbers in cal[5]: + # draw(positions['f' + str(cal[5].index(numbers) + 1)], eventicon) + # except IndexError: + # pass + + #"""Draw a larger square on today's date""" + #today = time.day + #if today in cal[0]: + # draw(positions['a' + str(cal[0].index(today) + 1)], dateicon) + #if today in cal[1]: + # draw(positions['b' + str(cal[1].index(today) + 1)], dateicon) + #if today in cal[2]: + # draw(positions['c' + str(cal[2].index(today) + 1)], dateicon) + #if today in cal[3]: + # draw(positions['d' + str(cal[3].index(today) + 1)], dateicon) + #if today in cal[4]: + # draw(positions['e' + str(cal[4].index(today) + 1)], dateicon) + #try: + # if today in cal[5]: + # draw(positions['f' + str(cal[5].index(today) + 1)], dateicon) + #except IndexError: + # pass for output in output_adapters: - output.render(image) + output.render(design) debug.print_line("Finished rendering") diff --git a/Calendar/Epd7in5Adapter.py b/Calendar/Epd7in5Adapter.py index 4e73871..2852625 100644 --- a/Calendar/Epd7in5Adapter.py +++ b/Calendar/Epd7in5Adapter.py @@ -4,7 +4,7 @@ from PIL import Image, ImageDraw class Epd7in5Adapter (EpdAdapter): def __init__ (self): - super(Epd7in5Adapter, self).__init__(640, 384) + super(Epd7in5Adapter, self).__init__(384, 640) def display_frame (self, frame_buffer): self.send_command(DATA_START_TRANSMISSION_1) diff --git a/Calendar/Epd7in5bAdapter.py b/Calendar/Epd7in5bAdapter.py index 235e889..531272d 100644 --- a/Calendar/Epd7in5bAdapter.py +++ b/Calendar/Epd7in5bAdapter.py @@ -4,7 +4,7 @@ from PIL import Image, ImageDraw class Epd7in5bAdapter (EpdAdapter): def __init__ (self): - super(Epd7in5bAdapter, self).__init__(640, 384) + super(Epd7in5bAdapter, self).__init__(384, 640) def display_frame (self, frame_buffer): self.send_command(DATA_START_TRANSMISSION_1) diff --git a/Calendar/EpdAdapter.py b/Calendar/EpdAdapter.py index 1f7bda9..4817561 100644 --- a/Calendar/EpdAdapter.py +++ b/Calendar/EpdAdapter.py @@ -71,7 +71,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.rotate(270, expand=1) + prepared_image = design.get_image().rotate(270, expand=1) self.display_frame(self.get_frame_buffer(prepared_image)) # Powering off the E-Paper until the next loop diff --git a/Calendar/ImageFileAdapter.py b/Calendar/ImageFileAdapter.py index 308fe7c..874b47d 100644 --- a/Calendar/ImageFileAdapter.py +++ b/Calendar/ImageFileAdapter.py @@ -3,11 +3,11 @@ from DisplayAdapter import DisplayAdapter class ImageFileAdapter (DisplayAdapter): """Saves design to an image file, can be used for debugging""" def __init__ (self, file_path = ""): - super(ImageFileAdapter, self).__init__(640, 384) + super(ImageFileAdapter, self).__init__(384, 640) self.file_path = file_path def render (self, design): - design.save(self.file_path + 'design_exported.png') + design.get_image().save(self.file_path + 'design_exported.png') def calibrate (self): pass \ No newline at end of file diff --git a/Calendar/MonthOvPanel.py b/Calendar/MonthOvPanel.py new file mode 100644 index 0000000..2b65909 --- /dev/null +++ b/Calendar/MonthOvPanel.py @@ -0,0 +1,85 @@ +from PanelDesign import PanelDesign +from Assets import * +from settings import * +import calendar +from datetime import datetime +from WeatherHeaderDesign import WeatherHeaderDesign +from PIL import ImageDraw +from TextDesign import TextDesign + +weatherheadersize = (1,0.113) +seperatorplace = (0, 0.113) +monthplace = (0, 0.116) +weekplace = (0, 0.209) +monthboxsize = (1, 0.085) +daynumberboxsize = (0.143, 0.143) +daynumbersize = 28 +monthtextsize = 40 +monthovposition = (0, 0.225) +monthovsize = (1, 0.5) + +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.__first_render__() + + def __first_render__ (self): + time = datetime.now() + + self.__draw_month_name__() + self.__draw_seperator__() + """Draw the icons with the weekday-names (Mon, Tue...) and + draw a circle on the current weekday""" + #if (week_starts_on == "Monday"): + # calendar.setfirstweekday(calendar.MONDAY) + # self.draw(weekmon, self.__abs_pos__(weekplace)) + # self.draw_bitmap(weekday, weekdaysmon[(time.strftime("%a"))]) + #elif (week_starts_on == "Sunday"): + # calendar.setfirstweekday(calendar.SUNDAY) + # self.draw(weeksun, self.__abs_pos__(weekplace)) + # self.draw_bitmap(weekday, weekdayssun[(time.strftime("%a"))]) + """Using the built-in calendar function, draw icons for each + number of the month (1,2,3,...28,29,30)""" + cal = calendar.monthcalendar(time.year, time.month) + for week in cal: + for numbers in week: + self.__draw_day_number__(numbers, self.__get_day_pos__(cal.index(week), week.index(numbers))) + + def add_weather (self, weather): + self.draw_design(WeatherHeaderDesign(self.__abs_pos__(weatherheadersize), weather)) + + def add_calendar (self, calendar): + raise NotImplementedError("Functions needs to be implemented") + + def add_rssfeed (self, rss): + raise NotImplementedError("Functions needs to be implemented") + + def __abs_pos__(self, pos): + return (int(pos[0] * self.size[0]), int(pos[1] * self.size[1])) + + 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) + + def __draw_day_number__(self, number, pos): + if number <= 0: + return + txt = TextDesign(self.__abs_pos__(daynumberboxsize), fontsize=daynumbersize, text=str(number), verticalalignment="center", horizontalalignment="center") + txt.pos = pos + self.draw_design(txt) + + def __draw_month_name__(self): + """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.pos = self.__abs_pos__(monthplace) + self.draw_design(txt) + + def __get_day_pos__ (self, week_in_month, day_of_week): + maxwidth, maxheight = self.__abs_pos__(monthovsize) + partialwidth = maxwidth / 7 + partialheight = maxheight / 5 + posx, posy = self.__abs_pos__(monthovposition) + return (posx + day_of_week * partialwidth, posy + week_in_month * partialheight) \ No newline at end of file diff --git a/Calendar/PanelDesign.py b/Calendar/PanelDesign.py index a10ad8f..c4d89ca 100644 --- a/Calendar/PanelDesign.py +++ b/Calendar/PanelDesign.py @@ -1,11 +1,9 @@ -class PanelDesign(object): - """Defined general interface for panel designs.""" - def set_size(self, width, height): - self.width = width - self.height = height +from DesignEntity import DesignEntity - def get_image (self): - raise NotImplementedError("Functions needs to be implemented") +class PanelDesign (DesignEntity): + """Defined general interface for panel designs.""" + def __init__ (self, size): + super(PanelDesign, self).__init__(size) def add_weather (self, weather): raise NotImplementedError("Functions needs to be implemented") diff --git a/Calendar/TextDesign.py b/Calendar/TextDesign.py new file mode 100644 index 0000000..9fecac4 --- /dev/null +++ b/Calendar/TextDesign.py @@ -0,0 +1,38 @@ +from DesignEntity import DesignEntity +from PIL import ImageFont, ImageDraw, ImageOps +from Assets import path + +class TextDesign (DesignEntity): + """Object that manages all information relevant to text + and prints it to an image""" + def __init__ (self, size, font = "Assistant-Regular.ttf", fontsize = 12, text = "", horizontalalignment = "left", verticalalignment = "top"): + super(TextDesign, self).__init__(size) + self.font_family = font + self.font_size = fontsize + self.text = text + self.horizontal_alignment = horizontalalignment + self.vertical_alignment = verticalalignment + self.is_bitmap = True + + def __finish_image__ (self): + self.__init_image__() + self.__font__ = ImageFont.truetype(path + self.font_family, self.font_size) + pos = self.__pos_from_alignment__() + ImageDraw.Draw(self.__image__).text(pos, self.text, fill=0, font=self.__font__) + self.__image__ = ImageOps.invert(self.__image__) + + def __pos_from_alignment__ (self): + width, height = self.__font__.getsize(self.text) + x, y = 0, 0 + + if self.vertical_alignment == "center": + y = int((self.size[1] / 2) - (height / 2)) + elif self.vertical_alignment == "bottom": + y = int(self.size[1] - height) + + if self.horizontal_alignment == "center": + x = int((self.size[0] / 2) - (width / 2)) + elif self.vertical_alignment == "right": + x = int(self.size[0] - width) + + return (x, y) \ No newline at end of file diff --git a/Calendar/WeatherHeaderDesign.py b/Calendar/WeatherHeaderDesign.py new file mode 100644 index 0000000..2d3cedb --- /dev/null +++ b/Calendar/WeatherHeaderDesign.py @@ -0,0 +1,65 @@ +from DesignEntity import DesignEntity +from Assets import * +from TextDesign import TextDesign +from settings import units, hours, location + +wiconplace = (0, 0) +tempplace = (0.779, 0) +humplace = (0.779, 0.486) +windiconspace = (0.206, 0) +sunriseplace = (0.55, 0) +sunsetplace = (0.55, 0.486) + +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 + self.__first_render__() + + def __first_render__ (self): + if self.__weather__.is_available() is False: + self.__render_missing_connection__() + return + + cur_weather = self.__weather__.get_today_forecast(location) + + temperature = cur_weather.air_temperature + " " + self.__get_unit__(("°C", "°F")) + 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)), (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)) + + def __render_missing_connection__ (self): + self.draw_image(no_response, self.__abs_pos__(wiconplace)) + + def __abs_pos__ (self, pos): + 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.pos = pos + self.draw_design(txt) + + def __get_unit__ (self, tuple): + if units == "metric": + return tuple[0] + else: + return tuple[1] + + def __get_time__ (self, time): + if hours == "24": + return time.strftime('%H:%M') + else: + return time.strftime('%I:%M') \ No newline at end of file diff --git a/Calendar/days/0.jpeg b/Calendar/days/0.jpeg deleted file mode 100644 index 4209376..0000000 Binary files a/Calendar/days/0.jpeg and /dev/null differ diff --git a/Calendar/days/1.jpeg b/Calendar/days/1.jpeg deleted file mode 100644 index 4cf94fb..0000000 Binary files a/Calendar/days/1.jpeg and /dev/null differ diff --git a/Calendar/days/10.jpeg b/Calendar/days/10.jpeg deleted file mode 100644 index e143431..0000000 Binary files a/Calendar/days/10.jpeg and /dev/null differ diff --git a/Calendar/days/11.jpeg b/Calendar/days/11.jpeg deleted file mode 100644 index d11d522..0000000 Binary files a/Calendar/days/11.jpeg and /dev/null differ diff --git a/Calendar/days/12.jpeg b/Calendar/days/12.jpeg deleted file mode 100644 index 24735ce..0000000 Binary files a/Calendar/days/12.jpeg and /dev/null differ diff --git a/Calendar/days/13.jpeg b/Calendar/days/13.jpeg deleted file mode 100644 index e65044d..0000000 Binary files a/Calendar/days/13.jpeg and /dev/null differ diff --git a/Calendar/days/14.jpeg b/Calendar/days/14.jpeg deleted file mode 100644 index 2ac2226..0000000 Binary files a/Calendar/days/14.jpeg and /dev/null differ diff --git a/Calendar/days/15.jpeg b/Calendar/days/15.jpeg deleted file mode 100644 index 11d6c70..0000000 Binary files a/Calendar/days/15.jpeg and /dev/null differ diff --git a/Calendar/days/16.jpeg b/Calendar/days/16.jpeg deleted file mode 100644 index 5205f45..0000000 Binary files a/Calendar/days/16.jpeg and /dev/null differ diff --git a/Calendar/days/17.jpeg b/Calendar/days/17.jpeg deleted file mode 100644 index 2d59d88..0000000 Binary files a/Calendar/days/17.jpeg and /dev/null differ diff --git a/Calendar/days/18.jpeg b/Calendar/days/18.jpeg deleted file mode 100644 index fa5141d..0000000 Binary files a/Calendar/days/18.jpeg and /dev/null differ diff --git a/Calendar/days/19.jpeg b/Calendar/days/19.jpeg deleted file mode 100644 index d27906d..0000000 Binary files a/Calendar/days/19.jpeg and /dev/null differ diff --git a/Calendar/days/2.jpeg b/Calendar/days/2.jpeg deleted file mode 100644 index 31b3bb3..0000000 Binary files a/Calendar/days/2.jpeg and /dev/null differ diff --git a/Calendar/days/20.jpeg b/Calendar/days/20.jpeg deleted file mode 100644 index 73c74f2..0000000 Binary files a/Calendar/days/20.jpeg and /dev/null differ diff --git a/Calendar/days/21.jpeg b/Calendar/days/21.jpeg deleted file mode 100644 index d901e0d..0000000 Binary files a/Calendar/days/21.jpeg and /dev/null differ diff --git a/Calendar/days/22.jpeg b/Calendar/days/22.jpeg deleted file mode 100644 index f0c19a1..0000000 Binary files a/Calendar/days/22.jpeg and /dev/null differ diff --git a/Calendar/days/23.jpeg b/Calendar/days/23.jpeg deleted file mode 100644 index 49c4f38..0000000 Binary files a/Calendar/days/23.jpeg and /dev/null differ diff --git a/Calendar/days/24.jpeg b/Calendar/days/24.jpeg deleted file mode 100644 index 62cd2c9..0000000 Binary files a/Calendar/days/24.jpeg and /dev/null differ diff --git a/Calendar/days/25.jpeg b/Calendar/days/25.jpeg deleted file mode 100644 index 41a4ea9..0000000 Binary files a/Calendar/days/25.jpeg and /dev/null differ diff --git a/Calendar/days/26.jpeg b/Calendar/days/26.jpeg deleted file mode 100644 index c0454a3..0000000 Binary files a/Calendar/days/26.jpeg and /dev/null differ diff --git a/Calendar/days/27.jpeg b/Calendar/days/27.jpeg deleted file mode 100644 index bf1f44c..0000000 Binary files a/Calendar/days/27.jpeg and /dev/null differ diff --git a/Calendar/days/28.jpeg b/Calendar/days/28.jpeg deleted file mode 100644 index 9795ecf..0000000 Binary files a/Calendar/days/28.jpeg and /dev/null differ diff --git a/Calendar/days/29.jpeg b/Calendar/days/29.jpeg deleted file mode 100644 index 9e5e350..0000000 Binary files a/Calendar/days/29.jpeg and /dev/null differ diff --git a/Calendar/days/3.jpeg b/Calendar/days/3.jpeg deleted file mode 100644 index 3c69a2d..0000000 Binary files a/Calendar/days/3.jpeg and /dev/null differ diff --git a/Calendar/days/30.jpeg b/Calendar/days/30.jpeg deleted file mode 100644 index d0daebb..0000000 Binary files a/Calendar/days/30.jpeg and /dev/null differ diff --git a/Calendar/days/31.jpeg b/Calendar/days/31.jpeg deleted file mode 100644 index 9a8ce2f..0000000 Binary files a/Calendar/days/31.jpeg and /dev/null differ diff --git a/Calendar/days/4.jpeg b/Calendar/days/4.jpeg deleted file mode 100644 index 4b6a148..0000000 Binary files a/Calendar/days/4.jpeg and /dev/null differ diff --git a/Calendar/days/5.jpeg b/Calendar/days/5.jpeg deleted file mode 100644 index fcf7d07..0000000 Binary files a/Calendar/days/5.jpeg and /dev/null differ diff --git a/Calendar/days/6.jpeg b/Calendar/days/6.jpeg deleted file mode 100644 index c46c03d..0000000 Binary files a/Calendar/days/6.jpeg and /dev/null differ diff --git a/Calendar/days/7.jpeg b/Calendar/days/7.jpeg deleted file mode 100644 index af18d7a..0000000 Binary files a/Calendar/days/7.jpeg and /dev/null differ diff --git a/Calendar/days/8.jpeg b/Calendar/days/8.jpeg deleted file mode 100644 index 7c3fae2..0000000 Binary files a/Calendar/days/8.jpeg and /dev/null differ diff --git a/Calendar/days/9.jpeg b/Calendar/days/9.jpeg deleted file mode 100644 index b37f7c5..0000000 Binary files a/Calendar/days/9.jpeg and /dev/null differ diff --git a/Calendar/translations/de/months/April.jpeg b/Calendar/translations/de/months/April.jpeg deleted file mode 100644 index 322f869..0000000 Binary files a/Calendar/translations/de/months/April.jpeg and /dev/null differ diff --git a/Calendar/translations/de/months/August.jpeg b/Calendar/translations/de/months/August.jpeg deleted file mode 100644 index f8ac9e6..0000000 Binary files a/Calendar/translations/de/months/August.jpeg and /dev/null differ diff --git a/Calendar/translations/de/months/December.jpeg b/Calendar/translations/de/months/December.jpeg deleted file mode 100644 index 9a32068..0000000 Binary files a/Calendar/translations/de/months/December.jpeg and /dev/null differ diff --git a/Calendar/translations/de/months/February.jpeg b/Calendar/translations/de/months/February.jpeg deleted file mode 100644 index 3e1bc37..0000000 Binary files a/Calendar/translations/de/months/February.jpeg and /dev/null differ diff --git a/Calendar/translations/de/months/January.jpeg b/Calendar/translations/de/months/January.jpeg deleted file mode 100644 index a5b5758..0000000 Binary files a/Calendar/translations/de/months/January.jpeg and /dev/null differ diff --git a/Calendar/translations/de/months/July.jpeg b/Calendar/translations/de/months/July.jpeg deleted file mode 100644 index 8dab4cc..0000000 Binary files a/Calendar/translations/de/months/July.jpeg and /dev/null differ diff --git a/Calendar/translations/de/months/June.jpeg b/Calendar/translations/de/months/June.jpeg deleted file mode 100644 index 7318e35..0000000 Binary files a/Calendar/translations/de/months/June.jpeg and /dev/null differ diff --git a/Calendar/translations/de/months/March.jpeg b/Calendar/translations/de/months/March.jpeg deleted file mode 100644 index 4b82715..0000000 Binary files a/Calendar/translations/de/months/March.jpeg and /dev/null differ diff --git a/Calendar/translations/de/months/May.jpeg b/Calendar/translations/de/months/May.jpeg deleted file mode 100644 index ca97b11..0000000 Binary files a/Calendar/translations/de/months/May.jpeg and /dev/null differ diff --git a/Calendar/translations/de/months/November.jpeg b/Calendar/translations/de/months/November.jpeg deleted file mode 100644 index 9ad2d5d..0000000 Binary files a/Calendar/translations/de/months/November.jpeg and /dev/null differ diff --git a/Calendar/translations/de/months/October.jpeg b/Calendar/translations/de/months/October.jpeg deleted file mode 100644 index 3d20137..0000000 Binary files a/Calendar/translations/de/months/October.jpeg and /dev/null differ diff --git a/Calendar/translations/de/months/September.jpeg b/Calendar/translations/de/months/September.jpeg deleted file mode 100644 index 9e472ef..0000000 Binary files a/Calendar/translations/de/months/September.jpeg and /dev/null differ diff --git a/Calendar/translations/en/months/April.jpeg b/Calendar/translations/en/months/April.jpeg deleted file mode 100644 index 322f869..0000000 Binary files a/Calendar/translations/en/months/April.jpeg and /dev/null differ diff --git a/Calendar/translations/en/months/August.jpeg b/Calendar/translations/en/months/August.jpeg deleted file mode 100644 index f8ac9e6..0000000 Binary files a/Calendar/translations/en/months/August.jpeg and /dev/null differ diff --git a/Calendar/translations/en/months/December.jpeg b/Calendar/translations/en/months/December.jpeg deleted file mode 100644 index 3411f5a..0000000 Binary files a/Calendar/translations/en/months/December.jpeg and /dev/null differ diff --git a/Calendar/translations/en/months/February.jpeg b/Calendar/translations/en/months/February.jpeg deleted file mode 100644 index 31423a6..0000000 Binary files a/Calendar/translations/en/months/February.jpeg and /dev/null differ diff --git a/Calendar/translations/en/months/January.jpeg b/Calendar/translations/en/months/January.jpeg deleted file mode 100644 index 72f82b9..0000000 Binary files a/Calendar/translations/en/months/January.jpeg and /dev/null differ diff --git a/Calendar/translations/en/months/July.jpeg b/Calendar/translations/en/months/July.jpeg deleted file mode 100644 index 2b95662..0000000 Binary files a/Calendar/translations/en/months/July.jpeg and /dev/null differ diff --git a/Calendar/translations/en/months/June.jpeg b/Calendar/translations/en/months/June.jpeg deleted file mode 100644 index 47b85ea..0000000 Binary files a/Calendar/translations/en/months/June.jpeg and /dev/null differ diff --git a/Calendar/translations/en/months/March.jpeg b/Calendar/translations/en/months/March.jpeg deleted file mode 100644 index c70d65b..0000000 Binary files a/Calendar/translations/en/months/March.jpeg and /dev/null differ diff --git a/Calendar/translations/en/months/May.jpeg b/Calendar/translations/en/months/May.jpeg deleted file mode 100644 index bd587ba..0000000 Binary files a/Calendar/translations/en/months/May.jpeg and /dev/null differ diff --git a/Calendar/translations/en/months/November.jpeg b/Calendar/translations/en/months/November.jpeg deleted file mode 100644 index 9ad2d5d..0000000 Binary files a/Calendar/translations/en/months/November.jpeg and /dev/null differ diff --git a/Calendar/translations/en/months/October.jpeg b/Calendar/translations/en/months/October.jpeg deleted file mode 100644 index 8f6253a..0000000 Binary files a/Calendar/translations/en/months/October.jpeg and /dev/null differ diff --git a/Calendar/translations/en/months/September.jpeg b/Calendar/translations/en/months/September.jpeg deleted file mode 100644 index 9e472ef..0000000 Binary files a/Calendar/translations/en/months/September.jpeg and /dev/null differ