Fix non-render mode
improved printed messages simplified some code fixed printed time not updating correctly removed non-required logging from PIL
This commit is contained in:
		| @@ -56,10 +56,12 @@ logging.basicConfig( | |||||||
|         ] |         ] | ||||||
|   ) |   ) | ||||||
|  |  | ||||||
|  | # Show less logging for PIL module | ||||||
|  | logging.getLogger("PIL").setLevel(logging.WARNING) | ||||||
|  |  | ||||||
| filename = os.path.basename(__file__).split('.py')[0] | filename = os.path.basename(__file__).split('.py')[0] | ||||||
| logger = logging.getLogger(filename) | logger = logging.getLogger(filename) | ||||||
|  |  | ||||||
| # TODO: fix issue with non-render mode requiring SPI |  | ||||||
| # TODO: autostart -> supervisor? | # TODO: autostart -> supervisor? | ||||||
|  |  | ||||||
| class Inkycal: | class Inkycal: | ||||||
| @@ -77,7 +79,6 @@ class Inkycal: | |||||||
|       to improve rendering on E-Papers. Set this to False for 9.7" E-Paper. |       to improve rendering on E-Papers. Set this to False for 9.7" E-Paper. | ||||||
|   """ |   """ | ||||||
|  |  | ||||||
|  |  | ||||||
|   def __init__(self, settings_path=None, render=True): |   def __init__(self, settings_path=None, render=True): | ||||||
|     """Initialise Inkycal""" |     """Initialise Inkycal""" | ||||||
|  |  | ||||||
| @@ -114,13 +115,13 @@ class Inkycal: | |||||||
|     # Option to use epaper image optimisation, reduces colours |     # Option to use epaper image optimisation, reduces colours | ||||||
|     self.optimize = True |     self.optimize = True | ||||||
|  |  | ||||||
|  |     # Load drivers if image should be rendered | ||||||
|  |     if self.render == True: | ||||||
|  |  | ||||||
|       # Init Display class with model in settings file |       # Init Display class with model in settings file | ||||||
|       from inkycal.display import Display |       from inkycal.display import Display | ||||||
|       self.Display = Display(settings["model"]) |       self.Display = Display(settings["model"]) | ||||||
|  |  | ||||||
|     # Load drivers if image should be rendered |  | ||||||
|     if self.render == True: |  | ||||||
|  |  | ||||||
|       # check if colours can be rendered |       # check if colours can be rendered | ||||||
|       self.supports_colour = True if 'colour' in settings['model'] else False |       self.supports_colour = True if 'colour' in settings['model'] else False | ||||||
|  |  | ||||||
| @@ -208,16 +209,13 @@ class Inkycal: | |||||||
|  |  | ||||||
|     for number in range(1, self._module_number): |     for number in range(1, self._module_number): | ||||||
|       name = eval(f"self.module_{number}.name") |       name = eval(f"self.module_{number}.name") | ||||||
|       generate_im = f'black,colour=self.module_{number}.generate_image()' |       module = eval(f'self.module_{number}') | ||||||
|       save_black = f'black.save("{self.image_folder}/module{number}_black.png", "PNG")' |       print(f'generating image(s) for {name}...', end="") | ||||||
|       save_colour = f'colour.save("{self.image_folder}/module{number}_colour.png", "PNG")' |  | ||||||
|       full_command = generate_im+'\n'+save_black+'\n'+save_colour |  | ||||||
|       #print(full_command) |  | ||||||
|  |  | ||||||
|       print(f'generating image(s) for {name}...') |  | ||||||
|       try: |       try: | ||||||
|         exec(full_command) |         black,colour=module.generate_image() | ||||||
|         self.info += f"module {number}: OK  " |         black.save(f"{self.image_folder}/module{number}_black.png", "PNG") | ||||||
|  |         colour.save(f"{self.image_folder}/module{number}_colour.png", "PNG") | ||||||
|  |         print('OK!') | ||||||
|       except Exception as Error: |       except Exception as Error: | ||||||
|         errors.append(number) |         errors.append(number) | ||||||
|         self.info += f"module {number}: Error!  " |         self.info += f"module {number}: Error!  " | ||||||
| @@ -251,18 +249,18 @@ class Inkycal: | |||||||
|     print(f'Selected E-paper display: {self.settings["model"]}') |     print(f'Selected E-paper display: {self.settings["model"]}') | ||||||
|  |  | ||||||
|     while True: |     while True: | ||||||
|       print(f"Date: {runtime.format('D MMM YY')} | Time: {runtime.format('HH:mm')}") |       current_time = arrow.now(tz=get_system_tz()) | ||||||
|       print('Generating images for all modules...') |       print(f"Date: {current_time.format('D MMM YY')} | " | ||||||
|  |             f"Time: {current_time.format('HH:mm')}") | ||||||
|  |       print('Generating images for all modules...', end='') | ||||||
|  |  | ||||||
|       errors = [] # store module numbers in here |       errors = [] # store module numbers in here | ||||||
|  |  | ||||||
|       # short info for info-section |       # short info for info-section | ||||||
|       self.info = f"{arrow.now(tz=get_system_tz()).format('D MMM @ HH:mm')}  " |       self.info = f"{current_time.format('D MMM @ HH:mm')}  " | ||||||
|  |  | ||||||
|       for number in range(1, self._module_number): |       for number in range(1, self._module_number): | ||||||
|  |  | ||||||
|         print(f'Generating image {number}') |  | ||||||
|  |  | ||||||
|         name = eval(f"self.module_{number}.name") |         name = eval(f"self.module_{number}.name") | ||||||
|         module = eval(f'self.module_{number}') |         module = eval(f'self.module_{number}') | ||||||
|  |  | ||||||
| @@ -270,8 +268,6 @@ class Inkycal: | |||||||
|           black,colour=module.generate_image() |           black,colour=module.generate_image() | ||||||
|           black.save(f"{self.image_folder}/module{number}_black.png", "PNG") |           black.save(f"{self.image_folder}/module{number}_black.png", "PNG") | ||||||
|           colour.save(f"{self.image_folder}/module{number}_colour.png", "PNG") |           colour.save(f"{self.image_folder}/module{number}_colour.png", "PNG") | ||||||
|  |  | ||||||
|           print('OK!') |  | ||||||
|           self.info += f"module {number}: OK  " |           self.info += f"module {number}: OK  " | ||||||
|         except Exception as Error: |         except Exception as Error: | ||||||
|           errors.append(number) |           errors.append(number) | ||||||
| @@ -320,8 +316,7 @@ class Inkycal: | |||||||
|  |  | ||||||
|           Display.render(im_black) |           Display.render(im_black) | ||||||
|  |  | ||||||
|       print('\ninkycal has been running without any errors for ' |       print(f'\nNo Errors since {counter} display updates \n' | ||||||
|             f"{counter} display updates \n" |  | ||||||
|             f'Programm started {runtime.humanize()}') |             f'Programm started {runtime.humanize()}') | ||||||
|  |  | ||||||
|       sleep_time = self.countdown() |       sleep_time = self.countdown() | ||||||
| @@ -363,7 +358,7 @@ class Inkycal: | |||||||
|     """Assembles all sub-images to a single image""" |     """Assembles all sub-images to a single image""" | ||||||
|  |  | ||||||
|     # Create 2 blank images with the same resolution as the display |     # Create 2 blank images with the same resolution as the display | ||||||
|     width, height = self.Display.get_display_size(self.settings["model"]) |     width, height = Display.get_display_size(self.settings["model"]) | ||||||
|  |  | ||||||
|     # Since Inkycal runs in vertical mode, switch the height and width |     # Since Inkycal runs in vertical mode, switch the height and width | ||||||
|     width, height = height, width |     width, height = height, width | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user