2019-05-18 09:28:29 +02:00
|
|
|
from DesignEntity import DesignEntity
|
|
|
|
from TableDesign import TableDesign
|
|
|
|
from Assets import defaultfontsize
|
2019-05-19 00:22:24 +02:00
|
|
|
from GeckoCrypto import GeckoCrypto
|
|
|
|
from settings import crypto_coins
|
2019-05-18 09:28:29 +02:00
|
|
|
|
2019-05-19 22:20:26 +02:00
|
|
|
xpadding = 5
|
2019-05-18 09:28:29 +02:00
|
|
|
|
2019-07-13 08:05:35 +02:00
|
|
|
|
2019-05-18 09:28:29 +02:00
|
|
|
class CryptoListDesign (DesignEntity):
|
2019-07-13 08:05:35 +02:00
|
|
|
def __init__(self, size, crypto, text_size=defaultfontsize):
|
2019-05-18 09:28:29 +02:00
|
|
|
super(CryptoListDesign, self).__init__(size)
|
2019-05-19 00:22:24 +02:00
|
|
|
self.crypto = crypto
|
2019-05-18 09:28:29 +02:00
|
|
|
self.text_size = text_size
|
2019-05-21 14:52:38 +02:00
|
|
|
self.matrix = self.__get_matrix__()
|
2019-05-18 09:28:29 +02:00
|
|
|
|
2019-07-13 08:05:35 +02:00
|
|
|
def __finish_image__(self):
|
2019-05-19 22:06:02 +02:00
|
|
|
col_spacing = 10
|
2019-05-21 14:52:38 +02:00
|
|
|
if len(self.matrix) > 0:
|
|
|
|
col_spacing = (self.size[0] / len(self.matrix[0])) * 0.5
|
|
|
|
|
2019-07-13 08:05:35 +02:00
|
|
|
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)
|
2019-05-18 09:28:29 +02:00
|
|
|
self.draw_design(table_design)
|
|
|
|
|
2019-07-13 08:05:35 +02:00
|
|
|
def __get_matrix__(self):
|
2019-05-19 00:22:24 +02:00
|
|
|
matrix = []
|
|
|
|
coins = self.crypto.get_coins()
|
|
|
|
for coin in coins:
|
2019-07-13 08:05:35 +02:00
|
|
|
row = [coin.symbol.upper(), coin.name, coin.currency + " " +
|
|
|
|
str(coin.price), "% " + str(coin.day_change)]
|
2019-05-19 00:22:24 +02:00
|
|
|
matrix.append(row)
|
|
|
|
return matrix
|
2019-05-21 14:52:38 +02:00
|
|
|
|
|
|
|
def get_estimated_height(self):
|
|
|
|
line_height = self.text_size * 1.25
|
|
|
|
height = line_height * len(self.matrix)
|
|
|
|
return height
|