diff --git a/inkycal/main.py b/inkycal/main.py index d290743..a68b620 100644 --- a/inkycal/main.py +++ b/inkycal/main.py @@ -232,14 +232,17 @@ class Inkycal: self.info = f"{runtime.format('D MMM @ HH:mm')} " for number in range(1, self._module_number): + + print(f'Generating image {number}') + name = eval(f"self.module_{number}.name") - generate_im = f'black,colour=self.module_{number}.generate_image()' - save_black = f'black.save("{self.image_folder}/module{number}_black.png", "PNG")' - save_colour = f'colour.save("{self.image_folder}/module{number}_colour.png", "PNG")' - full_command = generate_im+'\n'+save_black+'\n'+save_colour + module = eval(f'self.module_{number}') try: - exec(full_command) + black,colour=module.generate_image() + black.save(f"{self.image_folder}/module{number}_black.png", "PNG") + colour.save(f"{self.image_folder}/module{number}_colour.png", "PNG") + print('OK!') self.info += f"module {number}: OK " except Exception as Error: diff --git a/inkycal/modules/inkycal_image.py b/inkycal/modules/inkycal_image.py index a5eb031..d5d483a 100644 --- a/inkycal/modules/inkycal_image.py +++ b/inkycal/modules/inkycal_image.py @@ -67,6 +67,7 @@ class Inkyimage(inkycal_module): self.rotation = self.config['rotation'] self.layout = self.config['layout'] + self.colours = self.config['colours'] # give an OK message print('{0} loaded'.format(self.name)) @@ -91,6 +92,8 @@ class Inkyimage(inkycal_module): im_height = self.height im_size = im_width, im_height logger.info('image size: {} x {} px'.format(im_width, im_height)) + logger.info('image path: {}'.format(self.image_path)) + logger.info('colors: {}'.format(self.colours)) # Try to open the image if it exists and is an image file try: @@ -109,13 +112,14 @@ class Inkyimage(inkycal_module): logger.debug(('image-height:', self.image.height)) # Create an image for black pixels and one for coloured pixels + im_black = Image.new('RGB', size = im_size, color = 'white') im_colour = Image.new('RGB', size = im_size, color = 'white') # do the required operations self._remove_alpha() self._to_layout() - black, colour = self._map_colours() + black, colour = self._map_colours(self.colours) # paste the images on the canvas im_black.paste(black, (self.x, self.y)) @@ -125,6 +129,9 @@ class Inkyimage(inkycal_module): im_black.save(images+self.name+'.png', 'PNG') im_colour.save(images+self.name+'_colour.png', 'PNG') + # return images + return black, colour + def _rotate(self, angle=None): """Rotate the image to a given angle angle must be one of :[0, 90, 180, 270, 360, 'auto'] @@ -134,9 +141,9 @@ class Inkyimage(inkycal_module): angle = self.rotation # Check if angle is supported - if angle not in self._allowed_rotation: - print('invalid angle provided, setting to fallback: 0 deg') - angle = 0 + # if angle not in self._allowed_rotation: + # print('invalid angle provided, setting to fallback: 0 deg') + # angle = 0 # Autoflip the image if angle == 'auto' if angle == 'auto': @@ -182,11 +189,11 @@ class Inkyimage(inkycal_module): im = self.image if mode == None: mode = self.layout - if mode not in self._allowed_layout: - print('{} is not supported. Should be one of {}'.format( - mode, self._allowed_layout)) - print('setting layout to fallback: centre') - mode = 'center' + # if mode not in self._allowed_layout: + # print('{} is not supported. Should be one of {}'.format( + # mode, self._allowed_layout)) + # print('setting layout to fallback: centre') + # mode = 'center' # If mode is center, just center the image if mode == 'center': diff --git a/inkycal/tests/inkycal_image_test.py b/inkycal/tests/inkycal_image_test.py new file mode 100644 index 0000000..0a99797 --- /dev/null +++ b/inkycal/tests/inkycal_image_test.py @@ -0,0 +1,36 @@ +import unittest +from inkycal.modules import Inkyimage as Module + +tests = [ +{ + "position": 1, + "name": "Inkyimage", + "config": { + "size": [528,880], + "path": "https://cdn.britannica.com/s:700x500/84/73184-004-E5A450B5/Sunflower-field-Fargo-North-Dakota.jpg", + "rotation": "0", + "layout": "fill", + "padding_x": 0, + "padding_y": 0, + "fontsize": 12, + "language": "en", + "colours": "bwr" + } +}, +] + +class module_test(unittest.TestCase): + def test_get_config(self): + print('getting data for web-ui...', end = "") + Module.get_config() + print('OK') + + def test_generate_image(self): + for test in tests: + print(f'test {tests.index(test)+1} generating image..') + module = Module(test) + module.generate_image() + print('OK') + +if __name__ == '__main__': + unittest.main()