Added option for info-section
When info-section is set in the web-ui, a small section at the bottom of the display will show the time of last update.
This commit is contained in:
		| @@ -16,7 +16,7 @@ class Layout: | |||||||
|   """Page layout handling""" |   """Page layout handling""" | ||||||
|  |  | ||||||
|   def __init__(self, model=None, width=None, height=None, |   def __init__(self, model=None, width=None, height=None, | ||||||
|                supports_colour=False): |                supports_colour=False, use_info_section=True): | ||||||
|     """Initialize parameters for specified epaper model |     """Initialize parameters for specified epaper model | ||||||
|     Use model parameter to specify display OR |     Use model parameter to specify display OR | ||||||
|     Crate a custom display with given width and height""" |     Crate a custom display with given width and height""" | ||||||
| @@ -35,20 +35,30 @@ class Layout: | |||||||
|         } |         } | ||||||
|  |  | ||||||
|       self.display_height, self.display_width = display_dimensions[model] |       self.display_height, self.display_width = display_dimensions[model] | ||||||
|       self.display_size = display_dimensions[model] |  | ||||||
|  |       # if 'colour' was found in the display name, set supports_colour to True | ||||||
|       if 'colour' in model: |       if 'colour' in model: | ||||||
|         self.supports_colour = True |         self.supports_colour = True | ||||||
|       else: |       else: | ||||||
|         self.supports_colour = False |         self.supports_colour = False | ||||||
|  |  | ||||||
|  |     # If a custom width and height was specified, use those values instead | ||||||
|     elif width and height: |     elif width and height: | ||||||
|       self.display_height = width |       self.display_height = width | ||||||
|       self.display_width = height |       self.display_width = height | ||||||
|       self.supports_colour = supports_colour |       self.supports_colour = supports_colour | ||||||
|  |  | ||||||
|     else: |     else: | ||||||
|       print("Can't create a layout without given sizes") |       raise Exception("Can't create a layout without given sizes") | ||||||
|       raise |  | ||||||
|  |     # If the info section should be used, reduce the canvas size to 95% | ||||||
|  |     if not isinstance(use_info_section, bool): | ||||||
|  |       raise ValueError('use_info_section should be a boolean (True/False)') | ||||||
|  |  | ||||||
|  |     if use_info_section == True: | ||||||
|  |       self.display_height = int(self.display_height*0.95) | ||||||
|  |  | ||||||
|  |     self.display_size = self.display_width, self.display_height | ||||||
|  |  | ||||||
|     self.top_section_width = self.display_width |     self.top_section_width = self.display_width | ||||||
|     self.middle_section_width = self.display_width |     self.middle_section_width = self.display_width | ||||||
|   | |||||||
| @@ -31,7 +31,8 @@ class Settings: | |||||||
|   ] |   ] | ||||||
|  |  | ||||||
|   def __init__(self, settings_file_path): |   def __init__(self, settings_file_path): | ||||||
|     """Load settings from path (folder or settings.json file)""" |     """Load settings from path (folder or settings.json file) | ||||||
|  |     Set show_info_section to False to hide the info section""" | ||||||
|     try: |     try: | ||||||
|       if settings_file_path.endswith('settings.json'): |       if settings_file_path.endswith('settings.json'): | ||||||
|         folder = settings_file_path.split('/settings.json')[0] |         folder = settings_file_path.split('/settings.json')[0] | ||||||
| @@ -60,7 +61,11 @@ class Settings: | |||||||
|     self._validate() |     self._validate() | ||||||
|  |  | ||||||
|     # Get the height-percentages of the modules |     # Get the height-percentages of the modules | ||||||
|     self.Layout = Layout(model=self.model) |     if self.info_section == True: | ||||||
|  |       self.Layout = Layout(model=self.model, use_info_section = True) | ||||||
|  |     else: | ||||||
|  |       self.Layout = Layout(model=self.model, use_info_section = False) | ||||||
|  |  | ||||||
|     all_heights = [_['height'] for _ in self._settings['panels']] |     all_heights = [_['height'] for _ in self._settings['panels']] | ||||||
|     num_modules = len(self.active_modules()) |     num_modules = len(self.active_modules()) | ||||||
|  |  | ||||||
| @@ -105,7 +110,7 @@ class Settings: | |||||||
|     settings = self._settings |     settings = self._settings | ||||||
|  |  | ||||||
|     required =  ['language', 'units', 'hours', 'model', 'calibration_hours', |     required =  ['language', 'units', 'hours', 'model', 'calibration_hours', | ||||||
|                   'display_orientation'] |                   'display_orientation', 'info_section'] | ||||||
|  |  | ||||||
|     # Check if all required settings exist |     # Check if all required settings exist | ||||||
|     for param in required: |     for param in required: | ||||||
| @@ -121,6 +126,7 @@ class Settings: | |||||||
|     self.update_interval = settings['update_interval'] |     self.update_interval = settings['update_interval'] | ||||||
|     self.calibration_hours = settings['calibration_hours'] |     self.calibration_hours = settings['calibration_hours'] | ||||||
|     self.display_orientation = settings['display_orientation'] |     self.display_orientation = settings['display_orientation'] | ||||||
|  |     self.info_section = settings['info_section'] | ||||||
|  |  | ||||||
|     # Validate the parameters |     # Validate the parameters | ||||||
|     if (not isinstance(self.language, str) or self.language not in |     if (not isinstance(self.language, str) or self.language not in | ||||||
| @@ -157,6 +163,10 @@ class Settings: | |||||||
|       print('display orientation not supported, switching to fallback, normal') |       print('display orientation not supported, switching to fallback, normal') | ||||||
|       self.display_orientation = 'normal' |       self.display_orientation = 'normal' | ||||||
|  |  | ||||||
|  |     if (not isinstance(self.info_section, bool)): | ||||||
|  |       print('info_section must be True/False. Switching to fallback: False') | ||||||
|  |       self.info_section = False | ||||||
|  |  | ||||||
|     print('Settings file OK!') |     print('Settings file OK!') | ||||||
|  |  | ||||||
|   def active_modules(self): |   def active_modules(self): | ||||||
|   | |||||||
| @@ -24,7 +24,7 @@ logger = logging.getLogger('inkycal') | |||||||
| logger.setLevel(level=logging.ERROR) | logger.setLevel(level=logging.ERROR) | ||||||
|  |  | ||||||
| class Inkycal: | class Inkycal: | ||||||
|   """Main class""" |   """Inkycal main class""" | ||||||
|  |  | ||||||
|   def __init__(self, settings_path, render=True): |   def __init__(self, settings_path, render=True): | ||||||
|     """initialise class |     """initialise class | ||||||
| @@ -91,8 +91,7 @@ class Inkycal: | |||||||
|     # Give an OK message |     # Give an OK message | ||||||
|     print('loaded inkycal') |     print('loaded inkycal') | ||||||
|  |  | ||||||
|  |   def countdown(self, interval_mins=None): | ||||||
|   def countdown(self, interval_mins=None ): |  | ||||||
|     """Returns the remaining time in seconds until next display update""" |     """Returns the remaining time in seconds until next display update""" | ||||||
|  |  | ||||||
|     # Validate update interval |     # Validate update interval | ||||||
| @@ -129,7 +128,9 @@ class Inkycal: | |||||||
|     return remaining_time |     return remaining_time | ||||||
|  |  | ||||||
|   def test(self): |   def test(self): | ||||||
|     """Inkycal test run""" |     """Inkycal test run. | ||||||
|  |     Generates images for each module, one by one and prints OK if no | ||||||
|  |     problems were found.""" | ||||||
|     print('You are running inkycal v{}'.format(self._release)) |     print('You are running inkycal v{}'.format(self._release)) | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -165,6 +166,12 @@ class Inkycal: | |||||||
|     # Count the number of times without any errors |     # Count the number of times without any errors | ||||||
|     counter = 1 |     counter = 1 | ||||||
|  |  | ||||||
|  |     # Calculate the max. fontsize for info-section | ||||||
|  |     if self.Settings.info_section == True: | ||||||
|  |       info_section_height = round(self.Settings.Layout.display_height* (1/95) ) | ||||||
|  |       self.font = auto_fontsize(ImageFont.truetype( | ||||||
|  |         fonts['NotoSans-SemiCondensed']), info_section_height) | ||||||
|  |  | ||||||
|     while True: |     while True: | ||||||
|       print('Generating images for all modules...') |       print('Generating images for all modules...') | ||||||
|       for module in self.active_modules: |       for module in self.active_modules: | ||||||
| @@ -212,7 +219,7 @@ class Inkycal: | |||||||
|  |  | ||||||
|       print('\ninkycal has been running without any errors for', end = ' ') |       print('\ninkycal has been running without any errors for', end = ' ') | ||||||
|       print('{} display updates'.format(counter)) |       print('{} display updates'.format(counter)) | ||||||
|       print('That was {}'.format(runtime.humanize())) |       print('Programm started {}'.format(runtime.humanize())) | ||||||
|  |  | ||||||
|       counter += 1 |       counter += 1 | ||||||
|  |  | ||||||
| @@ -256,7 +263,9 @@ class Inkycal: | |||||||
|  |  | ||||||
|     # Create an empty canvas with the size of the display |     # Create an empty canvas with the size of the display | ||||||
|     width, height = self.Settings.Layout.display_size |     width, height = self.Settings.Layout.display_size | ||||||
|     height, width = width, height |      | ||||||
|  |     if self.Settings.info_section == True: | ||||||
|  |       height = round(height * ((1/95)*100) ) | ||||||
|  |  | ||||||
|     im_black = Image.new('RGB', (width, height), color = 'white') |     im_black = Image.new('RGB', (width, height), color = 'white') | ||||||
|     im_colour = Image.new('RGB', (width ,height), color = 'white') |     im_colour = Image.new('RGB', (width ,height), color = 'white') | ||||||
| @@ -319,6 +328,16 @@ class Inkycal: | |||||||
|         # Shift the y-axis cursor at the beginning of next section |         # Shift the y-axis cursor at the beginning of next section | ||||||
|         im2_cursor += section_size[1] |         im2_cursor += section_size[1] | ||||||
|  |  | ||||||
|  |     # Show an info section if specified by the settings file | ||||||
|  |     now = arrow.now() | ||||||
|  |     stamp = 'last update: {}'.format(now.format('D MMM @ HH:mm', locale = | ||||||
|  |                                                 self.Settings.language)) | ||||||
|  |     if self.Settings.info_section == True: | ||||||
|  |       write(im_black, (0, im1_cursor), (width, height-im1_cursor), | ||||||
|  |             stamp, font = self.font) | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     # optimize the image by mapping colours to pure black and white | ||||||
|     if self.optimize == True: |     if self.optimize == True: | ||||||
|       self._optimize_im(im_black).save(images+'canvas.png', 'PNG') |       self._optimize_im(im_black).save(images+'canvas.png', 'PNG') | ||||||
|       self._optimize_im(im_colour).save(images+'canvas_colour.png', 'PNG') |       self._optimize_im(im_colour).save(images+'canvas_colour.png', 'PNG') | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user