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:
parent
e18df47162
commit
7b029f532e
@ -16,7 +16,7 @@ class Layout:
|
||||
"""Page layout handling"""
|
||||
|
||||
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
|
||||
Use model parameter to specify display OR
|
||||
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_size = display_dimensions[model]
|
||||
|
||||
# if 'colour' was found in the display name, set supports_colour to True
|
||||
if 'colour' in model:
|
||||
self.supports_colour = True
|
||||
else:
|
||||
self.supports_colour = False
|
||||
|
||||
# If a custom width and height was specified, use those values instead
|
||||
elif width and height:
|
||||
self.display_height = width
|
||||
self.display_width = height
|
||||
self.supports_colour = supports_colour
|
||||
|
||||
else:
|
||||
print("Can't create a layout without given sizes")
|
||||
raise
|
||||
raise Exception("Can't create a layout without given sizes")
|
||||
|
||||
# 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.middle_section_width = self.display_width
|
||||
|
@ -31,7 +31,8 @@ class Settings:
|
||||
]
|
||||
|
||||
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:
|
||||
if settings_file_path.endswith('settings.json'):
|
||||
folder = settings_file_path.split('/settings.json')[0]
|
||||
@ -60,7 +61,11 @@ class Settings:
|
||||
self._validate()
|
||||
|
||||
# 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']]
|
||||
num_modules = len(self.active_modules())
|
||||
|
||||
@ -105,7 +110,7 @@ class Settings:
|
||||
settings = self._settings
|
||||
|
||||
required = ['language', 'units', 'hours', 'model', 'calibration_hours',
|
||||
'display_orientation']
|
||||
'display_orientation', 'info_section']
|
||||
|
||||
# Check if all required settings exist
|
||||
for param in required:
|
||||
@ -121,6 +126,7 @@ class Settings:
|
||||
self.update_interval = settings['update_interval']
|
||||
self.calibration_hours = settings['calibration_hours']
|
||||
self.display_orientation = settings['display_orientation']
|
||||
self.info_section = settings['info_section']
|
||||
|
||||
# Validate the parameters
|
||||
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')
|
||||
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!')
|
||||
|
||||
def active_modules(self):
|
||||
|
@ -24,7 +24,7 @@ logger = logging.getLogger('inkycal')
|
||||
logger.setLevel(level=logging.ERROR)
|
||||
|
||||
class Inkycal:
|
||||
"""Main class"""
|
||||
"""Inkycal main class"""
|
||||
|
||||
def __init__(self, settings_path, render=True):
|
||||
"""initialise class
|
||||
@ -91,8 +91,7 @@ class Inkycal:
|
||||
# Give an OK message
|
||||
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"""
|
||||
|
||||
# Validate update interval
|
||||
@ -129,7 +128,9 @@ class Inkycal:
|
||||
return remaining_time
|
||||
|
||||
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))
|
||||
|
||||
|
||||
@ -165,6 +166,12 @@ class Inkycal:
|
||||
# Count the number of times without any errors
|
||||
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:
|
||||
print('Generating images for all modules...')
|
||||
for module in self.active_modules:
|
||||
@ -212,7 +219,7 @@ class Inkycal:
|
||||
|
||||
print('\ninkycal has been running without any errors for', end = ' ')
|
||||
print('{} display updates'.format(counter))
|
||||
print('That was {}'.format(runtime.humanize()))
|
||||
print('Programm started {}'.format(runtime.humanize()))
|
||||
|
||||
counter += 1
|
||||
|
||||
@ -256,7 +263,9 @@ class Inkycal:
|
||||
|
||||
# Create an empty canvas with the size of the display
|
||||
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_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
|
||||
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:
|
||||
self._optimize_im(im_black).save(images+'canvas.png', 'PNG')
|
||||
self._optimize_im(im_colour).save(images+'canvas_colour.png', 'PNG')
|
||||
|
Loading…
Reference in New Issue
Block a user