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:
		| @@ -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()) | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     # 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 no height is provided, use default values | ||||||
|     if len(set(all_heights)) == 1 and None in all_heights: |       if list(set(all_heights)) == [None]: | ||||||
|         self.Layout.create_sections() |         self.Layout.create_sections() | ||||||
|  |  | ||||||
|     # if all heights are spcified, use given values |       # if all heights are specified, use given values | ||||||
|     elif len(set(all_heights)) != 1 and not None in all_heights: |       else: | ||||||
|         logger.info('Setting section height according to settings file') |         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], |         to_decimal = lambda percentage: percentage/100 | ||||||
|                                   middle_section=heights[1], |  | ||||||
|                                   bottom_section=heights[2]) |         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: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user