Implemented dynamic crypto list in all designs

This commit is contained in:
Maximilian Giller 2019-05-21 14:52:38 +02:00
parent 0200116d88
commit 2269bcf3fa
6 changed files with 50 additions and 16 deletions

View file

@ -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__()

View file

@ -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
if len(self.matrix) > 0:
col_spacing = (self.size[0] / len(self.matrix[0])) * 0.5
table_design = TableDesign(self.size, matrix=matrix, col_spacing=col_spacing, fontsize = self.text_size, mask=False, truncate_rows=True)
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

View file

@ -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,9 +76,13 @@ 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__()
for i, date in enumerate(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)

View file

@ -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)

View file

@ -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):

View file

@ -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__()