From 2269bcf3fa75f0817f27550d6558d6ad68202a3b Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 21 May 2019 14:52:38 +0200 Subject: [PATCH] Implemented dynamic crypto list in all designs --- Calendar/AgendaListPanel.py | 17 +++++++++++++++-- Calendar/CryptoListDesign.py | 15 ++++++++++----- Calendar/DayListPanel.py | 13 ++++++++----- Calendar/DayViewPanel.py | 3 ++- Calendar/MonthOvPanel.py | 4 +++- Calendar/MonthViewPanel.py | 14 ++++++++++++-- 6 files changed, 50 insertions(+), 16 deletions(-) diff --git a/Calendar/AgendaListPanel.py b/Calendar/AgendaListPanel.py index 4bbceb5..b222d45 100644 --- a/Calendar/AgendaListPanel.py +++ b/Calendar/AgendaListPanel.py @@ -5,12 +5,13 @@ 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 = line_thickness infolist_size = (1, 0.24) -infolist_padding = 2 +infolist_padding = 0 class AgendaListPanel (PanelDesign): '''Lists upcoming events in chronological order and groups them by days''' @@ -44,7 +45,19 @@ class AgendaListPanel (PanelDesign): pass def add_crypto (self, crypto): - pass + 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__() diff --git a/Calendar/CryptoListDesign.py b/Calendar/CryptoListDesign.py index 7a94ba6..949e8a4 100644 --- a/Calendar/CryptoListDesign.py +++ b/Calendar/CryptoListDesign.py @@ -11,14 +11,14 @@ class CryptoListDesign (DesignEntity): super(CryptoListDesign, self).__init__(size) self.crypto = crypto self.text_size = text_size + self.matrix = self.__get_matrix__() def __finish_image__ (self): - matrix = self.__get_matrix__() col_spacing = 10 - if len(matrix) > 0: - col_spacing = (self.size[0] / len(matrix[0])) * 0.5 - - table_design = TableDesign(self.size, matrix=matrix, col_spacing=col_spacing, fontsize = self.text_size, mask=False, truncate_rows=True) + 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) @@ -29,3 +29,8 @@ class CryptoListDesign (DesignEntity): 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 diff --git a/Calendar/DayListPanel.py b/Calendar/DayListPanel.py index 7fbb213..e271208 100644 --- a/Calendar/DayListPanel.py +++ b/Calendar/DayListPanel.py @@ -10,6 +10,7 @@ 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) @@ -48,6 +49,7 @@ 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): @@ -74,8 +76,12 @@ class DayListPanel (PanelDesign): pos = (0, ypos) design = CryptoListDesign(size, crypto) - design.pos = pos + 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__() @@ -98,9 +104,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"] or ["crypto"]: - self.dayrow_count -= infoarea_replacedrowscount - def __get_following_days__(self): following_days = [] for i in range(self.dayrow_count): @@ -114,7 +117,7 @@ class DayListPanel (PanelDesign): 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) diff --git a/Calendar/DayViewPanel.py b/Calendar/DayViewPanel.py index 512d3a1..a35447c 100644 --- a/Calendar/DayViewPanel.py +++ b/Calendar/DayViewPanel.py @@ -77,7 +77,8 @@ class DayViewPanel (PanelDesign): pos = (0, self.size[1] - size[1]) crypto = CryptoListDesign(size, crypto) - crypto.pos = pos + acutal_height = crypto.get_estimated_height() + crypto.pos = (pos[0], pos[1] + (height - acutal_height)) self.draw_design(crypto) diff --git a/Calendar/MonthOvPanel.py b/Calendar/MonthOvPanel.py index f5be56c..b377a32 100644 --- a/Calendar/MonthOvPanel.py +++ b/Calendar/MonthOvPanel.py @@ -95,8 +95,10 @@ class MonthOvPanel (PanelDesign): 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) - info_list.pos = (int(month_pos[0]), month_pos[1] + month_height + self.weather_header_height) + 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): diff --git a/Calendar/MonthViewPanel.py b/Calendar/MonthViewPanel.py index c3bc3a7..4fbab24 100644 --- a/Calendar/MonthViewPanel.py +++ b/Calendar/MonthViewPanel.py @@ -8,6 +8,7 @@ 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 @@ -32,7 +33,7 @@ class MonthViewPanel (PanelDesign): def __init_sizes__(self): self.weather_height = 0 self.info_height = 0 - if general_settings["info-area"] in ["events", "rss"]: + if general_settings["info-area"] in ["events", "rss", "crypto"]: self.info_height = info_height if general_settings["weather-info"]: self.weather_height = weather_height @@ -78,7 +79,16 @@ class MonthViewPanel (PanelDesign): pass def add_crypto (self, crypto): - pass + 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__()