Debugged inkycal_image
Still needs some work: - input parameter validation (rotation, layout, colours) - configuration of panel colors in Web UI Added suggestion for less dynamic calling of module.generate_image()
This commit is contained in:
parent
57cc49be21
commit
650e9bdb92
@ -232,14 +232,17 @@ class Inkycal:
|
|||||||
self.info = f"{runtime.format('D MMM @ HH:mm')} "
|
self.info = f"{runtime.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")
|
||||||
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")'
|
|
||||||
save_colour = f'colour.save("{self.image_folder}/module{number}_colour.png", "PNG")'
|
|
||||||
full_command = generate_im+'\n'+save_black+'\n'+save_colour
|
|
||||||
|
|
||||||
try:
|
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!')
|
print('OK!')
|
||||||
self.info += f"module {number}: OK "
|
self.info += f"module {number}: OK "
|
||||||
except Exception as Error:
|
except Exception as Error:
|
||||||
|
@ -67,6 +67,7 @@ class Inkyimage(inkycal_module):
|
|||||||
|
|
||||||
self.rotation = self.config['rotation']
|
self.rotation = self.config['rotation']
|
||||||
self.layout = self.config['layout']
|
self.layout = self.config['layout']
|
||||||
|
self.colours = self.config['colours']
|
||||||
|
|
||||||
# give an OK message
|
# give an OK message
|
||||||
print('{0} loaded'.format(self.name))
|
print('{0} loaded'.format(self.name))
|
||||||
@ -91,6 +92,8 @@ class Inkyimage(inkycal_module):
|
|||||||
im_height = self.height
|
im_height = self.height
|
||||||
im_size = im_width, im_height
|
im_size = im_width, im_height
|
||||||
logger.info('image size: {} x {} px'.format(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 to open the image if it exists and is an image file
|
||||||
try:
|
try:
|
||||||
@ -109,13 +112,14 @@ class Inkyimage(inkycal_module):
|
|||||||
logger.debug(('image-height:', self.image.height))
|
logger.debug(('image-height:', self.image.height))
|
||||||
|
|
||||||
# Create an image for black pixels and one for coloured pixels
|
# Create an image for black pixels and one for coloured pixels
|
||||||
|
|
||||||
im_black = Image.new('RGB', size = im_size, color = 'white')
|
im_black = Image.new('RGB', size = im_size, color = 'white')
|
||||||
im_colour = Image.new('RGB', size = im_size, color = 'white')
|
im_colour = Image.new('RGB', size = im_size, color = 'white')
|
||||||
|
|
||||||
# do the required operations
|
# do the required operations
|
||||||
self._remove_alpha()
|
self._remove_alpha()
|
||||||
self._to_layout()
|
self._to_layout()
|
||||||
black, colour = self._map_colours()
|
black, colour = self._map_colours(self.colours)
|
||||||
|
|
||||||
# paste the images on the canvas
|
# paste the images on the canvas
|
||||||
im_black.paste(black, (self.x, self.y))
|
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_black.save(images+self.name+'.png', 'PNG')
|
||||||
im_colour.save(images+self.name+'_colour.png', 'PNG')
|
im_colour.save(images+self.name+'_colour.png', 'PNG')
|
||||||
|
|
||||||
|
# return images
|
||||||
|
return black, colour
|
||||||
|
|
||||||
def _rotate(self, angle=None):
|
def _rotate(self, angle=None):
|
||||||
"""Rotate the image to a given angle
|
"""Rotate the image to a given angle
|
||||||
angle must be one of :[0, 90, 180, 270, 360, 'auto']
|
angle must be one of :[0, 90, 180, 270, 360, 'auto']
|
||||||
@ -134,9 +141,9 @@ class Inkyimage(inkycal_module):
|
|||||||
angle = self.rotation
|
angle = self.rotation
|
||||||
|
|
||||||
# Check if angle is supported
|
# Check if angle is supported
|
||||||
if angle not in self._allowed_rotation:
|
# if angle not in self._allowed_rotation:
|
||||||
print('invalid angle provided, setting to fallback: 0 deg')
|
# print('invalid angle provided, setting to fallback: 0 deg')
|
||||||
angle = 0
|
# angle = 0
|
||||||
|
|
||||||
# Autoflip the image if angle == 'auto'
|
# Autoflip the image if angle == 'auto'
|
||||||
if angle == 'auto':
|
if angle == 'auto':
|
||||||
@ -182,11 +189,11 @@ class Inkyimage(inkycal_module):
|
|||||||
im = self.image
|
im = self.image
|
||||||
if mode == None: mode = self.layout
|
if mode == None: mode = self.layout
|
||||||
|
|
||||||
if mode not in self._allowed_layout:
|
# if mode not in self._allowed_layout:
|
||||||
print('{} is not supported. Should be one of {}'.format(
|
# print('{} is not supported. Should be one of {}'.format(
|
||||||
mode, self._allowed_layout))
|
# mode, self._allowed_layout))
|
||||||
print('setting layout to fallback: centre')
|
# print('setting layout to fallback: centre')
|
||||||
mode = 'center'
|
# mode = 'center'
|
||||||
|
|
||||||
# If mode is center, just center the image
|
# If mode is center, just center the image
|
||||||
if mode == 'center':
|
if mode == 'center':
|
||||||
|
36
inkycal/tests/inkycal_image_test.py
Normal file
36
inkycal/tests/inkycal_image_test.py
Normal file
@ -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()
|
Loading…
Reference in New Issue
Block a user