parent
7cc109111f
commit
2a2ad18a03
@ -1,16 +1,17 @@
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
import numpy
|
import numpy
|
||||||
|
|
||||||
module_name = 'inkycal_agenda'
|
image1_path = "/home/pi/Desktop/cal.png"
|
||||||
|
image2_path = "/home/pi/Desktop/cal2.png"
|
||||||
|
output_file = "/home/pi/Desktop/merged.png"
|
||||||
|
|
||||||
|
def merge(image1, image2, out_filename):
|
||||||
def merge(module_name, out_filename):
|
|
||||||
"""Merge black pixels from image2 into image 1
|
"""Merge black pixels from image2 into image 1
|
||||||
module_name = name of the module generating the image
|
module_name = name of the module generating the image
|
||||||
out_filename = what name to give to the finished file
|
out_filename = what name to give to the finished file
|
||||||
"""
|
"""
|
||||||
|
|
||||||
im1_name, im2_name = module_name+'.png', module_name+'_colour.png'
|
im1_name, im2_name = image1_path, image2_path
|
||||||
im1 = Image.open(im1_name).convert('RGBA')
|
im1 = Image.open(im1_name).convert('RGBA')
|
||||||
im2 = Image.open(im2_name).convert('RGBA')
|
im2 = Image.open(im2_name).convert('RGBA')
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ def merge(module_name, out_filename):
|
|||||||
im1.paste(im2, (0,0), im2)
|
im1.paste(im2, (0,0), im2)
|
||||||
im1.save(out_filename+'.png', 'PNG')
|
im1.save(out_filename+'.png', 'PNG')
|
||||||
|
|
||||||
merge(module_name, module_name+'2')
|
merge(image1_path, image2_path, output_file)
|
||||||
|
|
||||||
|
|
||||||
print('Done')
|
print('Done')
|
||||||
|
@ -103,35 +103,41 @@ class Calendar(inkycal_module):
|
|||||||
im_colour = Image.new('RGB', size = im_size, color = 'white')
|
im_colour = Image.new('RGB', size = im_size, color = 'white')
|
||||||
|
|
||||||
# Allocate space for month-names, weekdays etc.
|
# Allocate space for month-names, weekdays etc.
|
||||||
month_name_height = int(self.height*0.1)
|
month_name_height = int(im_height * 0.1)
|
||||||
weekdays_height = int(self.height*0.05)
|
weekdays_height = int(im_height * 0.05)
|
||||||
|
logger.debug((f"month_name_height: {month_name_height}"))
|
||||||
|
logger.debug((f"weekdays_height: {weekdays_height}"))
|
||||||
|
|
||||||
|
|
||||||
if self.show_events == True:
|
if self.show_events == True:
|
||||||
calendar_height = int(self.height*0.6)
|
logger.debug("Allocating space for events")
|
||||||
events_height = int(self.height*0.25)
|
calendar_height = int(im_height * 0.6)
|
||||||
logger.debug('calendar-section size: {0} x {1} px'.format(
|
events_height = int(im_height * 0.25)
|
||||||
im_width, calendar_height))
|
logger.debug(f'calendar-section size: {im_width} x {calendar_height} px')
|
||||||
logger.debug('events-section size: {0} x {1} px'.format(
|
logger.debug(f'events-section size: {im_width} x {events_height} px')
|
||||||
im_width, events_height))
|
|
||||||
else:
|
else:
|
||||||
calendar_height = self.height - month_name_height - weekday_height
|
logger.debug("Not allocating space for events")
|
||||||
logger.debug('calendar-section size: {0} x {1} px'.format(
|
calendar_height = im_height - month_name_height - weekday_height
|
||||||
im_width, calendar_height))
|
logger.debug(f'calendar-section size: {im_width} x {calendar_height} px')
|
||||||
|
|
||||||
# Create grid and calculate icon sizes
|
# Create a 7x6 grid and calculate icon sizes
|
||||||
calendar_rows, calendar_cols = 6, 7
|
calendar_rows, calendar_cols = 6, 7
|
||||||
icon_width = im_width // calendar_cols
|
icon_width = im_width // calendar_cols
|
||||||
icon_height = calendar_height // calendar_rows
|
icon_height = calendar_height // calendar_rows
|
||||||
|
logger.debug(f"icon_size: {icon_width}x{icon_height}px")
|
||||||
|
|
||||||
# Calculate spacings for calendar area
|
# Calculate spacings for calendar area
|
||||||
x_spacing_calendar = int((im_width % calendar_cols) / 2)
|
x_spacing_calendar = int((im_width % calendar_cols) / 2)
|
||||||
y_spacing_calendar = int((im_height % calendar_rows) / 2)
|
y_spacing_calendar = int((im_height % calendar_rows) / 2)
|
||||||
|
|
||||||
|
logger.debug((f"x_spacing_calendar: {x_spacing_calendar}"))
|
||||||
|
logger.debug((f"y_spacing_calendar :{y_spacing_calendar}"))
|
||||||
|
|
||||||
# Calculate positions for days of month
|
# Calculate positions for days of month
|
||||||
grid_start_y = (month_name_height + weekdays_height + y_spacing_calendar)
|
grid_start_y = (month_name_height + weekdays_height + y_spacing_calendar)
|
||||||
grid_start_x = x_spacing_calendar
|
grid_start_x = x_spacing_calendar
|
||||||
|
|
||||||
grid = [(grid_start_x + icon_width*x, grid_start_y + icon_height*y)
|
grid_coordinates = [(grid_start_x + icon_width*x, grid_start_y + icon_height*y)
|
||||||
for y in range(calendar_rows) for x in range(calendar_cols)]
|
for y in range(calendar_rows) for x in range(calendar_cols)]
|
||||||
|
|
||||||
weekday_pos = [(grid_start_x + icon_width*_, month_name_height) for _ in
|
weekday_pos = [(grid_start_x + icon_width*_, month_name_height) for _ in
|
||||||
@ -148,12 +154,8 @@ class Calendar(inkycal_module):
|
|||||||
weekstart = now.shift(days = - now.isoweekday())
|
weekstart = now.shift(days = - now.isoweekday())
|
||||||
|
|
||||||
# Write the name of current month
|
# Write the name of current month
|
||||||
write(
|
write(im_black, (0,0),(im_width, month_name_height),
|
||||||
im_black,
|
str(now.format('MMMM',locale=self.language)), font = self.font,
|
||||||
(x_spacing_calendar,0),
|
|
||||||
(self.width, month_name_height),
|
|
||||||
str(now.format('MMMM',locale=self.language)),
|
|
||||||
font = self.font,
|
|
||||||
autofit = True)
|
autofit = True)
|
||||||
|
|
||||||
# Set up weeknames in local language and add to main section
|
# Set up weeknames in local language and add to main section
|
||||||
@ -174,21 +176,27 @@ class Calendar(inkycal_module):
|
|||||||
# Create a calendar template and flatten (remove nestings)
|
# Create a calendar template and flatten (remove nestings)
|
||||||
flatten = lambda z: [x for y in z for x in y]
|
flatten = lambda z: [x for y in z for x in y]
|
||||||
calendar_flat = flatten(cal.monthcalendar(now.year, now.month))
|
calendar_flat = flatten(cal.monthcalendar(now.year, now.month))
|
||||||
|
#logger.debug(f" calendar_flat: {calendar_flat}")
|
||||||
|
|
||||||
|
# Map days of month to co-ordinates of grid -> 3: (row2_x,col3_y)
|
||||||
|
grid = {}
|
||||||
|
for i in calendar_flat:
|
||||||
|
if i != 0:
|
||||||
|
grid[i] = grid_coordinates[calendar_flat.index(i)]
|
||||||
|
#logger.debug(f"grid:{grid}")
|
||||||
|
|
||||||
|
# remove zeros from calendar since they are not required
|
||||||
|
calendar_flat = [num for num in calendar_flat if num != 0]
|
||||||
|
|
||||||
# Add the numbers on the correct positions
|
# Add the numbers on the correct positions
|
||||||
for i in range(len(calendar_flat)):
|
for number in calendar_flat:
|
||||||
if calendar_flat[i] not in (0, int(now.day)):
|
if number != int(now.day):
|
||||||
write(
|
write(im_black, grid[number], (icon_width, icon_height),
|
||||||
im_black,
|
str(number), font = self.num_font, fill_height = 0.5)
|
||||||
grid[i],
|
|
||||||
(icon_width,icon_height),
|
|
||||||
str(calendar_flat[i]),
|
|
||||||
font = self.num_font, fill_height = 0.5
|
|
||||||
)
|
|
||||||
|
|
||||||
# Draw a red/black circle with the current day of month in white
|
# Draw a red/black circle with the current day of month in white
|
||||||
icon = Image.new('RGBA', (icon_width, icon_height))
|
icon = Image.new('RGBA', (icon_width, icon_height))
|
||||||
current_day_pos = grid[calendar_flat.index(now.day)]
|
current_day_pos = grid[int(now.day)]
|
||||||
x_circle,y_circle = int(icon_width/2), int(icon_height/2)
|
x_circle,y_circle = int(icon_width/2), int(icon_height/2)
|
||||||
radius = int(icon_width * 0.2)
|
radius = int(icon_width * 0.2)
|
||||||
ImageDraw.Draw(icon).ellipse(
|
ImageDraw.Draw(icon).ellipse(
|
||||||
@ -211,9 +219,13 @@ class Calendar(inkycal_module):
|
|||||||
line_spacing)
|
line_spacing)
|
||||||
|
|
||||||
# generate list of coordinates for each line
|
# generate list of coordinates for each line
|
||||||
event_lines = [(0, grid[-1][1] + int(events_height/max_event_lines*_))
|
events_offset = im_height - events_height
|
||||||
|
event_lines = [(0, events_offset + int(events_height/max_event_lines*_))
|
||||||
for _ in range(max_event_lines)]
|
for _ in range(max_event_lines)]
|
||||||
|
|
||||||
|
#logger.debug(f"event_lines {event_lines}")
|
||||||
|
|
||||||
|
|
||||||
# timeline for filtering events within this month
|
# timeline for filtering events within this month
|
||||||
month_start = arrow.get(now.floor('month'))
|
month_start = arrow.get(now.floor('month'))
|
||||||
month_end = arrow.get(now.ceil('month'))
|
month_end = arrow.get(now.ceil('month'))
|
||||||
@ -244,7 +256,7 @@ class Calendar(inkycal_module):
|
|||||||
for days in days_with_events:
|
for days in days_with_events:
|
||||||
draw_border(
|
draw_border(
|
||||||
im_colour,
|
im_colour,
|
||||||
grid[calendar_flat.index(days)],
|
grid[days],
|
||||||
(icon_width, icon_height),
|
(icon_width, icon_height),
|
||||||
radius = 6,
|
radius = 6,
|
||||||
thickness= 1,
|
thickness= 1,
|
||||||
|
Loading…
Reference in New Issue
Block a user