Improved layout setup

It is now possible to use one, two or three modules and use the height defined by the settings file
This commit is contained in:
Ace 2020-06-13 16:14:49 +02:00
parent 90ec1a177d
commit f8834c4c21

View File

@ -61,19 +61,35 @@ class Settings:
# Get the height-percentages of the modules
self.Layout = Layout(model=self.model)
all_heights = [_['height'] for _ in self._settings['panels']]
# If no height is provided, use default values
if len(set(all_heights)) == 1 and None in all_heights:
self.Layout.create_sections()
num_modules = len(self.active_modules())
# if all heights are spcified, use given values
elif len(set(all_heights)) != 1 and not None in all_heights:
logger.info('Setting section height according to settings file')
heights = [_['height']/100 for _ in self._settings['panels']]
self.Layout.create_sections(top_section= heights[0],
middle_section=heights[1],
bottom_section=heights[2])
# check if height have (or have not) been provided for all modules
if len(all_heights) == num_modules:
# If no height is provided, use default values
if list(set(all_heights)) == [None]:
self.Layout.create_sections()
# if all heights are specified, use given values
else:
logger.info('Setting section height according to settings file')
to_decimal = lambda percentage: percentage/100
top_height = [to_decimal(_['height']) for _ in
self._settings['panels'] if _['location'] == 'top']
middle_height = [to_decimal(_['height']) for _ in
self._settings['panels'] if _['location'] == 'middle']
bottom_height = [to_decimal(_['height']) for _ in
self._settings['panels'] if _['location'] == 'bottom']
self.Layout.create_sections(
top_section = top_height[0] if top_height else 0,
middle_section = middle_height[0] if middle_height else 0,
bottom_section = bottom_height[0] if bottom_height else 0)
# If only some heights were defined, raise an error
else:
@ -81,7 +97,7 @@ class Settings:
print("Please leave height empty for all modules")
print("OR specify the height for all sections")
raise Exception('Module height is not specified in all modules!')
def _validate(self):
"""Validate the basic config"""