fix tests, add border feature
This commit is contained in:
parent
b08cf00661
commit
60be01fbdb
@ -9,7 +9,7 @@ import time
|
|||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from PIL import ImageFont
|
from PIL import ImageFont, ImageDraw, Image
|
||||||
|
|
||||||
logs = logging.getLogger(__name__)
|
logs = logging.getLogger(__name__)
|
||||||
logs.setLevel(level=logging.INFO)
|
logs.setLevel(level=logging.INFO)
|
||||||
@ -299,17 +299,17 @@ def draw_border(image, xy, size, radius=5, thickness=1, shrinkage=(0.1, 0.1)):
|
|||||||
|
|
||||||
colour = 'black'
|
colour = 'black'
|
||||||
|
|
||||||
# size from function paramter
|
# size from function parameter
|
||||||
width, height = int(size[0] * (1 - shrinkage[0])), int(size[1] * (1 - shrinkage[1]))
|
width, height = int(size[0] * (1 - shrinkage[0])), int(size[1] * (1 - shrinkage[1]))
|
||||||
|
|
||||||
# shift cursor to move rectangle to center
|
# shift cursor to move rectangle to center
|
||||||
offset_x, offset_y = int((size[0] - width) / 2), int((size[1] - height) / 2)
|
offset_x, offset_y = int((size[0] - width) / 2), int((size[1] - height) / 2)
|
||||||
|
|
||||||
x, y, diameter = xy[0] + offset_x, xy[1] + offset_y, radius * 2
|
x, y, diameter = xy[0] + offset_x, xy[1] + offset_y, radius * 2
|
||||||
# lenght of rectangle size
|
# length of rectangle size
|
||||||
a, b = (width - diameter), (height - diameter)
|
a, b = (width - diameter), (height - diameter)
|
||||||
|
|
||||||
# Set coordinates for staright lines
|
# Set coordinates for straight lines
|
||||||
p1, p2 = (x + radius, y), (x + radius + a, y)
|
p1, p2 = (x + radius, y), (x + radius + a, y)
|
||||||
p3, p4 = (x + width, y + radius), (x + width, y + radius + b)
|
p3, p4 = (x + width, y + radius), (x + width, y + radius + b)
|
||||||
p5, p6 = (p2[0], y + height), (p1[0], y + height)
|
p5, p6 = (p2[0], y + height), (p1[0], y + height)
|
||||||
@ -333,3 +333,12 @@ def draw_border(image, xy, size, radius=5, thickness=1, shrinkage=(0.1, 0.1)):
|
|||||||
draw.arc((c3, c4), 270, 360, fill=colour, width=thickness)
|
draw.arc((c3, c4), 270, 360, fill=colour, width=thickness)
|
||||||
draw.arc((c5, c6), 0, 90, fill=colour, width=thickness)
|
draw.arc((c5, c6), 0, 90, fill=colour, width=thickness)
|
||||||
draw.arc((c7, c8), 90, 180, fill=colour, width=thickness)
|
draw.arc((c7, c8), 90, 180, fill=colour, width=thickness)
|
||||||
|
|
||||||
|
|
||||||
|
def draw_border_2(im: Image, xy: tuple, size: tuple, radius: int):
|
||||||
|
draw = ImageDraw.Draw(im)
|
||||||
|
|
||||||
|
x, y = xy
|
||||||
|
w, h = size
|
||||||
|
|
||||||
|
draw.rounded_rectangle(xy=(x, y, x + w, y + h), outline="black", radius=radius)
|
@ -104,6 +104,8 @@ class Inkycal:
|
|||||||
# Option to use epaper image optimisation, reduces colours
|
# Option to use epaper image optimisation, reduces colours
|
||||||
self.optimize = True
|
self.optimize = True
|
||||||
|
|
||||||
|
self.show_border = self.settings.get('border_around_modules', False)
|
||||||
|
|
||||||
# Load drivers if image should be rendered
|
# Load drivers if image should be rendered
|
||||||
if self.render:
|
if self.render:
|
||||||
# Init Display class with model in settings file
|
# Init Display class with model in settings file
|
||||||
@ -203,6 +205,8 @@ class Inkycal:
|
|||||||
print(f'generating image(s) for {name}...', end="")
|
print(f'generating image(s) for {name}...', end="")
|
||||||
try:
|
try:
|
||||||
black, colour = module.generate_image()
|
black, colour = module.generate_image()
|
||||||
|
if self.show_border:
|
||||||
|
draw_border_2(im=black, xy=(1, 1), size=(black.width - 2, black.height - 2), radius=5)
|
||||||
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!')
|
print('OK!')
|
||||||
@ -298,6 +302,8 @@ class Inkycal:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
black, colour = module.generate_image()
|
black, colour = module.generate_image()
|
||||||
|
if self.show_border:
|
||||||
|
draw_border_2(im=black, xy=(1, 1), size=(black.width - 2, black.height - 2), radius=5)
|
||||||
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")
|
||||||
self.info += f"module {number}: OK "
|
self.info += f"module {number}: OK "
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#!python3
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Inkycal iCalendar parsing module
|
Inkycal iCalendar parsing module
|
||||||
Copyright by aceinnolab
|
Copyright by aceinnolab
|
||||||
|
@ -15,29 +15,15 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class TextToDisplay(inkycal_module):
|
class TextToDisplay(inkycal_module):
|
||||||
"""TextToDisplay module
|
"""TextToDisplay module - Display text from a local file on the display
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name = "Text module - Display text from a local file on the display"
|
|
||||||
|
|
||||||
requires = {
|
|
||||||
"filepath": {
|
|
||||||
"label": "Please enter a filepath or URL pointing to a .txt file",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
"""Initialize inkycal_textfile_to_display module"""
|
"""Initialize inkycal_textfile_to_display module"""
|
||||||
|
|
||||||
super().__init__(config)
|
super().__init__(config)
|
||||||
|
|
||||||
config = config['config']
|
config = config['config']
|
||||||
|
|
||||||
# Check if all required parameters are present
|
|
||||||
for param in self.requires:
|
|
||||||
if param not in config:
|
|
||||||
raise Exception(f'config is missing {param}')
|
|
||||||
|
|
||||||
# required parameters
|
# required parameters
|
||||||
self.filepath = config["filepath"]
|
self.filepath = config["filepath"]
|
||||||
|
|
||||||
|
@ -27,7 +27,9 @@ class Config:
|
|||||||
# inkycal_todoist_test
|
# inkycal_todoist_test
|
||||||
TODOIST_API_KEY = get("TODOIST_API_KEY")
|
TODOIST_API_KEY = get("TODOIST_API_KEY")
|
||||||
|
|
||||||
TEMP_PATH = f"{basedir}/tmp"
|
TEMP_PATH = f"{basedir}/temp"
|
||||||
|
|
||||||
|
TEST_SETTINGS_PATH = f"{basedir}/settings.json"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,8 +16,6 @@ merge = Inkyimage.merge
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
temp_path = f"{Config.TEMP_PATH}/temp.txt"
|
|
||||||
|
|
||||||
dummy_data = [
|
dummy_data = [
|
||||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', ' Donec feugiat facilisis neque vel blandit.',
|
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', ' Donec feugiat facilisis neque vel blandit.',
|
||||||
'Integer viverra dolor risus.', ' Etiam neque tellus, sollicitudin at nisi a, mollis ornare enim.',
|
'Integer viverra dolor risus.', ' Etiam neque tellus, sollicitudin at nisi a, mollis ornare enim.',
|
||||||
@ -56,6 +54,8 @@ dummy_data = [
|
|||||||
'Duis facilisis sapien est, a elementum lorem maximus ut.'
|
'Duis facilisis sapien est, a elementum lorem maximus ut.'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
temp_path = f"{Config.TEMP_PATH}/temp.txt"
|
||||||
|
|
||||||
tests = [
|
tests = [
|
||||||
{
|
{
|
||||||
"position": 1,
|
"position": 1,
|
||||||
@ -74,7 +74,7 @@ tests = [
|
|||||||
"name": "TextToFile",
|
"name": "TextToFile",
|
||||||
"config": {
|
"config": {
|
||||||
"size": [500, 400],
|
"size": [500, 400],
|
||||||
"filepath": "https://de.wikipedia.org/wiki/Nationale_Rotkreuz-_und_Rothalbmond-Gesellschaft",
|
"filepath": "https://raw.githubusercontent.com/aceinnolab/Inkycal/main/setup.py",
|
||||||
"padding_x": 10,
|
"padding_x": 10,
|
||||||
"padding_y": 10,
|
"padding_y": 10,
|
||||||
"fontsize": 12,
|
"fontsize": 12,
|
||||||
@ -90,9 +90,8 @@ class TestTextToDisplay(unittest.TestCase):
|
|||||||
self.temp_path = temp_path
|
self.temp_path = temp_path
|
||||||
if not os.path.exists(Config.TEMP_PATH):
|
if not os.path.exists(Config.TEMP_PATH):
|
||||||
os.mkdir(Config.TEMP_PATH)
|
os.mkdir(Config.TEMP_PATH)
|
||||||
logger.info("could not find temporary file, creating now.")
|
with open(self.temp_path, encoding="utf-8", mode="w") as file:
|
||||||
with open(self.temp_path, encoding="utf-8", mode="w") as file:
|
file.writelines(dummy_data)
|
||||||
file.writelines(dummy_data)
|
|
||||||
|
|
||||||
def test_generate_image(self):
|
def test_generate_image(self):
|
||||||
for test in tests:
|
for test in tests:
|
||||||
|
@ -16,7 +16,7 @@ tests = [
|
|||||||
"name": "Webshot",
|
"name": "Webshot",
|
||||||
"config": {
|
"config": {
|
||||||
"size": [400, 100],
|
"size": [400, 100],
|
||||||
"url": "https://google.com",
|
"url": "https://www.catsuthecat.com/blogs/comics/the-one-about-regeneration",
|
||||||
"palette": "bwr",
|
"palette": "bwr",
|
||||||
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
||||||
}
|
}
|
||||||
@ -26,7 +26,7 @@ tests = [
|
|||||||
"name": "Webshot",
|
"name": "Webshot",
|
||||||
"config": {
|
"config": {
|
||||||
"size": [400, 200],
|
"size": [400, 200],
|
||||||
"url": "https://google.com",
|
"url": "https://www.catsuthecat.com/blogs/comics/the-one-about-crazy-friday-nights",
|
||||||
"palette": "bwy",
|
"palette": "bwy",
|
||||||
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ tests = [
|
|||||||
"name": "Webshot",
|
"name": "Webshot",
|
||||||
"config": {
|
"config": {
|
||||||
"size": [400, 300],
|
"size": [400, 300],
|
||||||
"url": "https://google.com",
|
"url": "https://www.catsuthecat.com/blogs/comics/the-one-about-teamwork",
|
||||||
"palette": "bw",
|
"palette": "bw",
|
||||||
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ tests = [
|
|||||||
"name": "Webshot",
|
"name": "Webshot",
|
||||||
"config": {
|
"config": {
|
||||||
"size": [400, 400],
|
"size": [400, 400],
|
||||||
"url": "https://google.com",
|
"url": "https://www.catsuthecat.com/blogs/comics/the-one-about-addictions-1",
|
||||||
"palette": "bwr",
|
"palette": "bwr",
|
||||||
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
"padding_x": 10, "padding_y": 10, "fontsize": 12, "language": "en"
|
||||||
}
|
}
|
||||||
|
28
tests/test_main.py
Normal file
28
tests/test_main.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
"""
|
||||||
|
Test main module
|
||||||
|
"""
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from inkycal import Inkycal
|
||||||
|
from tests import Config
|
||||||
|
|
||||||
|
|
||||||
|
class TestMain(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.settings_path = Config.TEST_SETTINGS_PATH
|
||||||
|
|
||||||
|
def test_init(self):
|
||||||
|
inkycal = Inkycal(self.settings_path, render=False)
|
||||||
|
assert inkycal.settings["model"] == "image_file"
|
||||||
|
assert inkycal.settings["update_interval"] == 5
|
||||||
|
assert inkycal.settings["orientation"] == 0
|
||||||
|
assert inkycal.settings["info_section"] == True
|
||||||
|
assert inkycal.settings["info_section_height"] == 70
|
||||||
|
assert inkycal.settings["border_around_modules"] == True
|
||||||
|
|
||||||
|
def test_run(self):
|
||||||
|
inkycal = Inkycal(self.settings_path, render=False)
|
||||||
|
inkycal.test()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user