| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  | #!/usr/bin/python3 | 
					
						
							|  |  |  | # -*- coding: utf-8 -*- | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | Calendar module for Inky-Calendar Project | 
					
						
							|  |  |  | Copyright by aceisace | 
					
						
							|  |  |  | """
 | 
					
						
							| 
									
										
										
										
											2020-05-23 01:45:40 +02:00
										 |  |  | from inkycal.modules.template import inkycal_module | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  | from inkycal.custom import * | 
					
						
							| 
									
										
										
										
											2020-05-23 01:45:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  | import calendar as cal | 
					
						
							|  |  |  | import arrow | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-23 01:45:40 +02:00
										 |  |  | filename = os.path.basename(__file__).split('.py')[0] | 
					
						
							|  |  |  | logger = logging.getLogger(filename) | 
					
						
							| 
									
										
										
										
											2020-05-26 19:10:20 +02:00
										 |  |  | logger.setLevel(level=logging.ERROR) | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 19:10:20 +02:00
										 |  |  | class Calendar(inkycal_module): | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  |   """Calendar class
 | 
					
						
							|  |  |  |   Create monthly calendar and show events from given icalendars | 
					
						
							|  |  |  |   """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def __init__(self, section_size, section_config): | 
					
						
							|  |  |  |     """Initialize inkycal_calendar module""" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-23 01:45:40 +02:00
										 |  |  |     super().__init__(section_size, section_config) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Module specific parameters | 
					
						
							|  |  |  |     required = ['week_starts_on'] | 
					
						
							|  |  |  |     for param in required: | 
					
						
							|  |  |  |       if not param in section_config: | 
					
						
							|  |  |  |         raise Exception('config is missing {}'.format(param)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # module name | 
					
						
							| 
									
										
										
										
											2020-05-29 03:59:44 +02:00
										 |  |  |     self.name = self.__class__.__name__ | 
					
						
							| 
									
										
										
										
											2020-05-23 01:45:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # module specific parameters | 
					
						
							| 
									
										
										
										
											2020-05-21 01:00:37 +02:00
										 |  |  |     self.num_font = ImageFont.truetype( | 
					
						
							|  |  |  |       fonts['NotoSans-SemiCondensed'], size = self.fontsize) | 
					
						
							| 
									
										
										
										
											2020-05-23 01:45:40 +02:00
										 |  |  |     self.weekstart = self.config['week_starts_on'] | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  |     self.show_events = True | 
					
						
							| 
									
										
										
										
											2020-05-29 03:59:44 +02:00
										 |  |  |     self.date_format = 'D MMM' | 
					
						
							|  |  |  |     self.time_format = "HH:mm" | 
					
						
							| 
									
										
										
										
											2020-06-19 19:40:50 +02:00
										 |  |  |     self.language = self.config['language'] | 
					
						
							| 
									
										
										
										
											2020-05-26 19:10:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  |     self.timezone = get_system_tz() | 
					
						
							| 
									
										
										
										
											2020-05-23 01:45:40 +02:00
										 |  |  |     self.ical_urls = self.config['ical_urls'] | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  |     self.ical_files = [] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-23 01:45:40 +02:00
										 |  |  |     # give an OK message | 
					
						
							|  |  |  |     print('{0} loaded'.format(self.name)) | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def generate_image(self): | 
					
						
							|  |  |  |     """Generate image for this module""" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Define new image size with respect to padding | 
					
						
							| 
									
										
										
										
											2020-05-23 01:45:40 +02:00
										 |  |  |     im_width = int(self.width - (self.width * 2 * self.margin_x)) | 
					
						
							|  |  |  |     im_height = int(self.height - (self.height * 2 * self.margin_y)) | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  |     im_size = im_width, im_height | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-23 01:45:40 +02:00
										 |  |  |     logger.info('Image size: {0}'.format(im_size)) | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Create an image for black pixels and one for coloured pixels | 
					
						
							| 
									
										
										
										
											2020-05-21 01:00:37 +02:00
										 |  |  |     im_black = Image.new('RGB', size = im_size, color = 'white') | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  |     im_colour = Image.new('RGB', size = im_size, color = 'white') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Allocate space for month-names, weekdays etc. | 
					
						
							|  |  |  |     month_name_height = int(self.height*0.1) | 
					
						
							|  |  |  |     weekdays_height = int(self.height*0.05) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if self.show_events == True: | 
					
						
							|  |  |  |       calendar_height = int(self.height*0.6) | 
					
						
							|  |  |  |       events_height = int(self.height*0.25) | 
					
						
							| 
									
										
										
										
											2020-05-23 01:45:40 +02:00
										 |  |  |       logger.debug('calendar-section size: {0} x {1} px'.format( | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  |         im_width, calendar_height)) | 
					
						
							| 
									
										
										
										
											2020-05-23 01:45:40 +02:00
										 |  |  |       logger.debug('events-section size: {0} x {1} px'.format( | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  |         im_width, events_height)) | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |       calendar_height = self.height - month_name_height - weekday_height | 
					
						
							| 
									
										
										
										
											2020-05-23 01:45:40 +02:00
										 |  |  |       logger.debug('calendar-section size: {0} x {1} px'.format( | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  |         im_width, calendar_height)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create grid and calculate icon sizes | 
					
						
							| 
									
										
										
										
											2020-08-17 21:54:53 +03:00
										 |  |  |     now = arrow.now(tz = self.timezone) | 
					
						
							|  |  |  |     monthstart = now.span('month')[0].weekday() | 
					
						
							| 
									
										
										
										
											2020-08-17 22:58:01 +03:00
										 |  |  |     monthdays = now.ceil('month').day | 
					
						
							| 
									
										
										
										
											2020-08-17 21:54:53 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-17 22:58:01 +03:00
										 |  |  |     if monthstart > 4 and monthdays == 31: | 
					
						
							| 
									
										
										
										
											2020-08-17 21:54:53 +03:00
										 |  |  |         calendar_rows, calendar_cols = 7, 7 | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         calendar_rows, calendar_cols = 6, 7 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-21 01:00:37 +02:00
										 |  |  |     icon_width = im_width // calendar_cols | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  |     icon_height = calendar_height // calendar_rows | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Calculate spacings for calendar area | 
					
						
							| 
									
										
										
										
											2020-05-21 01:00:37 +02:00
										 |  |  |     x_spacing_calendar = int((im_width % calendar_cols) / 2) | 
					
						
							| 
									
										
										
										
											2020-05-18 18:31:23 +02:00
										 |  |  |     y_spacing_calendar = int((im_height % calendar_rows) / 2) | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Calculate positions for days of month | 
					
						
							|  |  |  |     grid_start_y = (month_name_height + weekdays_height + y_spacing_calendar) | 
					
						
							|  |  |  |     grid_start_x = x_spacing_calendar | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     grid = [(grid_start_x + icon_width*x, grid_start_y + icon_height*y) | 
					
						
							|  |  |  |             for y in range(calendar_rows) for x in range(calendar_cols)] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     weekday_pos = [(grid_start_x + icon_width*_, month_name_height) for _ in | 
					
						
							|  |  |  |                    range(calendar_cols)] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Set weekstart of calendar to specified weekstart | 
					
						
							|  |  |  |     if self.weekstart == "Monday": | 
					
						
							|  |  |  |       cal.setfirstweekday(cal.MONDAY) | 
					
						
							|  |  |  |       weekstart = now.shift(days = - now.weekday()) | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |       cal.setfirstweekday(cal.SUNDAY) | 
					
						
							|  |  |  |       weekstart = now.shift(days = - now.isoweekday()) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Write the name of current month | 
					
						
							|  |  |  |     write( | 
					
						
							|  |  |  |       im_black, | 
					
						
							|  |  |  |       (x_spacing_calendar,0), | 
					
						
							|  |  |  |       (self.width, month_name_height), | 
					
						
							|  |  |  |       str(now.format('MMMM',locale=self.language)), | 
					
						
							|  |  |  |       font = self.font, | 
					
						
							|  |  |  |       autofit = True) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Set up weeknames in local language and add to main section | 
					
						
							|  |  |  |     weekday_names = [weekstart.shift(days=+_).format('ddd',locale=self.language) | 
					
						
							|  |  |  |       for _ in range(7)] | 
					
						
							| 
									
										
										
										
											2020-05-23 01:45:40 +02:00
										 |  |  |     logger.debug('weekday names: {}'.format(weekday_names)) | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for _ in range(len(weekday_pos)): | 
					
						
							|  |  |  |       write( | 
					
						
							|  |  |  |         im_black, | 
					
						
							|  |  |  |         weekday_pos[_], | 
					
						
							|  |  |  |         (icon_width, weekdays_height), | 
					
						
							|  |  |  |         weekday_names[_], | 
					
						
							|  |  |  |         font = self.font, | 
					
						
							|  |  |  |         autofit = True | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Create a calendar template and flatten (remove nestings) | 
					
						
							|  |  |  |     flatten = lambda z: [x for y in z for x in y] | 
					
						
							|  |  |  |     calendar_flat = flatten(cal.monthcalendar(now.year, now.month)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Add the numbers on the correct positions | 
					
						
							|  |  |  |     for i in range(len(calendar_flat)): | 
					
						
							|  |  |  |       if calendar_flat[i] not in (0, int(now.day)): | 
					
						
							|  |  |  |         write( | 
					
						
							|  |  |  |           im_black, | 
					
						
							|  |  |  |           grid[i], | 
					
						
							|  |  |  |           (icon_width,icon_height), | 
					
						
							|  |  |  |           str(calendar_flat[i]), | 
					
						
							| 
									
										
										
										
											2020-05-21 01:00:37 +02:00
										 |  |  |           font = self.num_font, fill_height = 0.5 | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  |           ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Draw a red/black circle with the current day of month in white | 
					
						
							|  |  |  |     icon = Image.new('RGBA', (icon_width, icon_height)) | 
					
						
							|  |  |  |     current_day_pos = grid[calendar_flat.index(now.day)] | 
					
						
							|  |  |  |     x_circle,y_circle = int(icon_width/2), int(icon_height/2) | 
					
						
							| 
									
										
										
										
											2020-07-04 16:22:31 +02:00
										 |  |  |     radius = int(icon_width * 0.2) | 
					
						
							| 
									
										
										
										
											2020-05-21 01:00:37 +02:00
										 |  |  |     ImageDraw.Draw(icon).ellipse( | 
					
						
							|  |  |  |       (x_circle-radius, y_circle-radius, x_circle+radius, y_circle+radius), | 
					
						
							|  |  |  |       fill= 'black', outline=None) | 
					
						
							|  |  |  |     write(icon, (0,0), (icon_width, icon_height), str(now.day), | 
					
						
							|  |  |  |           font=self.num_font, fill_height = 0.5, colour='white') | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  |     im_colour.paste(icon, current_day_pos, icon) | 
					
						
							| 
									
										
										
										
											2020-05-26 19:10:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # If events should be loaded and shown... | 
					
						
							|  |  |  |     if self.show_events == True: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # import the ical-parser | 
					
						
							| 
									
										
										
										
											2020-05-26 19:10:20 +02:00
										 |  |  |       from inkycal.modules.ical_parser import iCalendar | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # find out how many lines can fit at max in the event section | 
					
						
							|  |  |  |       line_spacing = 0 | 
					
						
							|  |  |  |       max_event_lines = events_height // (self.font.getsize('hg')[1] + | 
					
						
							|  |  |  |                                           line_spacing) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # generate list of coordinates for each line | 
					
						
							|  |  |  |       event_lines = [(0, grid[-1][1] + int(events_height/max_event_lines*_)) | 
					
						
							|  |  |  |                      for _ in range(max_event_lines)] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # timeline for filtering events within this month | 
					
						
							|  |  |  |       month_start = arrow.get(now.floor('month')) | 
					
						
							|  |  |  |       month_end = arrow.get(now.ceil('month')) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # fetch events from given icalendars | 
					
						
							| 
									
										
										
										
											2020-05-26 19:10:20 +02:00
										 |  |  |       self.ical = iCalendar() | 
					
						
							|  |  |  |       parser = self.ical | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  |       if self.ical_urls: | 
					
						
							|  |  |  |         parser.load_url(self.ical_urls) | 
					
						
							|  |  |  |       if self.ical_files: | 
					
						
							|  |  |  |         parser.load_from_file(self.ical_files) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Filter events for full month (even past ones) for drawing event icons | 
					
						
							| 
									
										
										
										
											2020-05-30 00:45:53 +02:00
										 |  |  |       month_events = parser.get_events(month_start, month_end, self.timezone) | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  |       parser.sort() | 
					
						
							| 
									
										
										
										
											2020-05-21 01:00:37 +02:00
										 |  |  |       self.month_events = month_events | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # find out on which days of this month events are taking place | 
					
						
							|  |  |  |       days_with_events = [int(events['begin'].format('D')) for events in | 
					
						
							|  |  |  |                           month_events] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # remove duplicates (more than one event in a single day) | 
					
						
							|  |  |  |       list(set(days_with_events)).sort() | 
					
						
							| 
									
										
										
										
											2020-05-21 01:00:37 +02:00
										 |  |  |       self._days_with_events = days_with_events | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # Draw a border with specified parameters around days with events | 
					
						
							|  |  |  |       for days in days_with_events: | 
					
						
							|  |  |  |         draw_border( | 
					
						
							|  |  |  |           im_colour, | 
					
						
							|  |  |  |           grid[calendar_flat.index(days)], | 
					
						
							|  |  |  |           (icon_width, icon_height), | 
					
						
							| 
									
										
										
										
											2020-05-21 01:00:37 +02:00
										 |  |  |           radius = 6, | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  |           thickness= 1, | 
					
						
							| 
									
										
										
										
											2020-07-04 16:22:31 +02:00
										 |  |  |           shrinkage = (0.4, 0.2) | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  |           ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Filter upcoming events until 4 weeks in the future | 
					
						
							|  |  |  |       parser.clear_events() | 
					
						
							| 
									
										
										
										
											2020-05-30 00:45:53 +02:00
										 |  |  |       upcoming_events = parser.get_events(now, now.shift(weeks=4), | 
					
						
							|  |  |  |                                           self.timezone) | 
					
						
							| 
									
										
										
										
											2020-05-21 01:00:37 +02:00
										 |  |  |       self._upcoming_events = upcoming_events | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # delete events which won't be able to fit (more events than lines) | 
					
						
							| 
									
										
										
										
											2020-05-29 03:59:44 +02:00
										 |  |  |       upcoming_events[:max_event_lines] | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Check if any events were found in the given timerange | 
					
						
							|  |  |  |       if upcoming_events: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Find out how much space (width) the date format requires | 
					
						
							|  |  |  |         lang = self.language | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         date_width = int(max([self.font.getsize( | 
					
						
							| 
									
										
										
										
											2020-05-18 18:31:23 +02:00
										 |  |  |           events['begin'].format(self.date_format,locale=lang))[0] | 
					
						
							|  |  |  |           for events in upcoming_events]) * 1.1) | 
					
						
							| 
									
										
										
										
											2020-05-26 19:10:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-18 18:31:23 +02:00
										 |  |  |         time_width = int(max([self.font.getsize( | 
					
						
							|  |  |  |           events['begin'].format(self.time_format, locale=lang))[0] | 
					
						
							|  |  |  |           for events in upcoming_events]) * 1.1) | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         line_height = self.font.getsize('hg')[1] + line_spacing | 
					
						
							| 
									
										
										
										
											2020-05-26 19:10:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-18 18:31:23 +02:00
										 |  |  |         event_width_s = im_width - date_width - time_width | 
					
						
							|  |  |  |         event_width_l = im_width - date_width | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # Display upcoming events below calendar | 
					
						
							|  |  |  |         tomorrow = now.shift(days=1).floor('day') | 
					
						
							|  |  |  |         in_two_days = now.shift(days=2).floor('day') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cursor = 0 | 
					
						
							|  |  |  |         for event in upcoming_events: | 
					
						
							| 
									
										
										
										
											2020-05-18 18:31:23 +02:00
										 |  |  |           name = event['title'] | 
					
						
							|  |  |  |           date = event['begin'].format(self.date_format, locale=lang) | 
					
						
							|  |  |  |           time = event['begin'].format(self.time_format, locale=lang) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  |           if now < event['end']: | 
					
						
							|  |  |  |             write(im_colour, event_lines[cursor], (date_width, line_height), | 
					
						
							|  |  |  |                   date, font=self.font, alignment = 'left') | 
					
						
							| 
									
										
										
										
											2020-05-18 18:31:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             # Check if event is all day | 
					
						
							|  |  |  |             if parser.all_day(event) == True: | 
					
						
							|  |  |  |               write(im_black, (date_width, event_lines[cursor][1]), | 
					
						
							|  |  |  |                   (event_width_l, line_height), name, font=self.font, | 
					
						
							|  |  |  |                   alignment = 'left') | 
					
						
							|  |  |  |             else: | 
					
						
							| 
									
										
										
										
											2020-06-19 19:40:50 +02:00
										 |  |  |               write(im_black, (date_width, event_lines[cursor][1]), | 
					
						
							|  |  |  |                   (time_width, line_height), time, font=self.font, | 
					
						
							| 
									
										
										
										
											2020-05-18 18:31:23 +02:00
										 |  |  |                   alignment = 'left') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               write(im_black, (date_width+time_width,event_lines[cursor][1]), | 
					
						
							|  |  |  |                   (event_width_s, line_height), name, font=self.font, | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  |                   alignment = 'left') | 
					
						
							|  |  |  |             cursor += 1 | 
					
						
							|  |  |  |       else: | 
					
						
							| 
									
										
										
										
											2020-05-18 18:31:23 +02:00
										 |  |  |         symbol = '- ' | 
					
						
							|  |  |  |         while self.font.getsize(symbol)[0] < im_width*0.9: | 
					
						
							|  |  |  |           symbol += ' -' | 
					
						
							|  |  |  |         write(im_black, event_lines[0], | 
					
						
							|  |  |  |               (im_width, self.font.getsize(symbol)[1]), symbol, | 
					
						
							|  |  |  |               font = self.font) | 
					
						
							| 
									
										
										
										
											2020-05-18 03:46:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Save image of black and colour channel in image-folder | 
					
						
							|  |  |  |     im_black.save(images+self.name+'.png') | 
					
						
							|  |  |  |     im_colour.save(images+self.name+'_colour.png') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == '__main__': | 
					
						
							| 
									
										
										
										
											2020-05-23 01:45:40 +02:00
										 |  |  |   print('running {0} in standalone mode'.format(filename)) |