Fixed default text padding (cutoff)
This commit is contained in:
parent
4d3c2cfbd7
commit
f417fdbe3e
13 changed files with 79 additions and 60 deletions
|
@ -1,15 +1,15 @@
|
|||
from DesignEntity import DesignEntity
|
||||
from Assets import defaultfontsize, colors
|
||||
from Assets import defaultfontsize, colors, defaultfont, path
|
||||
from datetime import datetime, date, timedelta
|
||||
from TableDesign import TableDesign
|
||||
from PIL import ImageDraw
|
||||
from PIL import ImageDraw, ImageFont
|
||||
from TextFormatter import date_summary_str, event_prefix_str
|
||||
|
||||
line_width = 1
|
||||
separator_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):
|
||||
super(AgendaListDesign, self).__init__(size)
|
||||
self.calendar = calendar
|
||||
self.line_spacing = line_spacing
|
||||
|
@ -25,7 +25,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
|
||||
|
@ -72,7 +72,7 @@ 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"]
|
||||
|
@ -87,4 +87,7 @@ class AgendaListDesign (DesignEntity):
|
|||
"color" : color,
|
||||
"background_color" : bg_color
|
||||
}
|
||||
return [default_cell, default_cell, cell, cell ]
|
||||
return [default_cell, default_cell, cell, cell ]
|
||||
|
||||
def __get_text_height__(self):
|
||||
return ImageFont.truetype(path + defaultfont, self.text_size).font.height
|
|
@ -10,7 +10,7 @@ agenda_ypadding = 5
|
|||
weatherheader_height = 0.113
|
||||
seperator_width = 3
|
||||
infolist_size = (1, 0.24)
|
||||
infolist_padding = 5
|
||||
infolist_padding = 2
|
||||
|
||||
class AgendaListPanel (PanelDesign):
|
||||
'''Lists upcoming events in chronological order and groups them by days'''
|
||||
|
|
|
@ -11,14 +11,17 @@ 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"]
|
||||
|
@ -64,9 +67,10 @@ 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)
|
||||
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
|
||||
|
||||
|
@ -77,10 +81,11 @@ class DayHeaderDesign (DesignEntity):
|
|||
|
||||
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")
|
||||
|
@ -105,8 +110,9 @@ 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")
|
||||
|
|
|
@ -6,16 +6,17 @@ 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"]
|
||||
|
||||
|
@ -49,7 +50,7 @@ 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)
|
||||
|
||||
|
@ -68,8 +69,8 @@ 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])
|
||||
|
@ -87,15 +88,15 @@ class DayRowDesign (DesignEntity):
|
|||
|
||||
def __draw_day_number__ (self):
|
||||
font_size = int(daynumber_fontsize * self.size[1])
|
||||
ypadding = daynumber_ypadding * self.size[1]
|
||||
size = (daynumber_y_size[0] * self.size[1], daynumber_y_size[1] * self.size[1])
|
||||
pos = (0, 0)
|
||||
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.pos = pos
|
||||
number.mask = False
|
||||
self.draw_design(number)
|
||||
|
||||
def __abs_co__ (self, coordinates):
|
||||
|
|
|
@ -8,7 +8,7 @@ from Dictionary import more_events
|
|||
class EventListDesign (DesignEntity):
|
||||
"""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__ = []
|
||||
|
|
|
@ -7,9 +7,10 @@ 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
|
||||
|
@ -81,10 +82,11 @@ 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")
|
||||
|
|
|
@ -6,9 +6,10 @@ from Assets import colors
|
|||
from settings import week_starts_on
|
||||
from BoxDesign import BoxDesign
|
||||
|
||||
daynumberboxsize = (0.143, 0.2) #(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
|
||||
|
@ -42,8 +43,8 @@ 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)):
|
||||
|
|
|
@ -14,18 +14,18 @@ from RssPostListDesign import RssPostListDesign
|
|||
from settings import general_settings
|
||||
|
||||
weatherheadersize = (1,0.113)
|
||||
monthtextsize = 40
|
||||
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)
|
||||
monthplace = (0, 0.12 - weatherheadersize[1])
|
||||
monthboxsize = (1, 0.085)
|
||||
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
|
||||
|
@ -77,17 +77,15 @@ 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_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)
|
||||
|
@ -117,15 +115,16 @@ class MonthOvPanel (PanelDesign):
|
|||
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)
|
||||
|
|
|
@ -14,7 +14,7 @@ class RssPostListDesign (DesignEntity):
|
|||
def __finish_image__ (self):
|
||||
self.__fill_post_matrix__()
|
||||
|
||||
table_design = TableDesign(self.size, line_spacing=5, col_spacing=3, 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):
|
||||
|
|
|
@ -7,6 +7,6 @@ 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"]):
|
||||
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"]):
|
||||
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)
|
|
@ -88,7 +88,8 @@ class TableDesign (TextDesign):
|
|||
width = font.getsize(self.matrix[r][c])[0] #get width of text in that row/col
|
||||
if self.wrap and self.max_col_size != None:
|
||||
content = wrap_text_with_font(content, self.max_col_size[c], font)
|
||||
height = font.getsize_multiline(content)[1] #get height of text in that col/row
|
||||
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
|
||||
|
@ -177,7 +178,8 @@ class TableDesign (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]
|
|
@ -3,7 +3,6 @@ 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):
|
||||
|
@ -49,7 +48,7 @@ class TextDesign (DesignEntity):
|
|||
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 +61,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__)
|
||||
|
|
|
@ -9,6 +9,7 @@ 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
|
||||
|
||||
|
@ -34,14 +35,14 @@ class WeatherColumnDesign (DesignEntity):
|
|||
numbers_list = [ [ forecast.short_description ],
|
||||
[ temperature ],
|
||||
[ humidity ],
|
||||
[ windspeed ] ]
|
||||
[ windspeed ]]
|
||||
|
||||
ypos = info_x_ypos * self.size[0]
|
||||
pos = (0, ypos)
|
||||
size = (self.size[0], self.size[1] - pos[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 = TableDesign(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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue