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 # Get the height-percentages of the modules
self.Layout = Layout(model=self.model) self.Layout = Layout(model=self.model)
all_heights = [_['height'] for _ in self._settings['panels']] all_heights = [_['height'] for _ in self._settings['panels']]
num_modules = len(self.active_modules())
# If no height is provided, use default values
if len(set(all_heights)) == 1 and None in all_heights:
self.Layout.create_sections()
# 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], # check if height have (or have not) been provided for all modules
middle_section=heights[1], if len(all_heights) == num_modules:
bottom_section=heights[2])
# 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 # If only some heights were defined, raise an error
else: else:
@ -81,7 +97,7 @@ class Settings:
print("Please leave height empty for all modules") print("Please leave height empty for all modules")
print("OR specify the height for all sections") print("OR specify the height for all sections")
raise Exception('Module height is not specified in all modules!') raise Exception('Module height is not specified in all modules!')
def _validate(self): def _validate(self):
"""Validate the basic config""" """Validate the basic config"""