Revert "modules refactoring + slight changes to folder structure"

This reverts commit 3fe9675bef.
This commit is contained in:
Ace
2020-05-12 19:30:45 +02:00
parent 3fe9675bef
commit c8786f6006
32 changed files with 17 additions and 1155 deletions

View File

@@ -1,4 +0,0 @@
from .parser import settings
print('loaded settings')
from .layout import layout
print('loaded layout')

View File

@@ -1,102 +0,0 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Layout module for Inky-Calendar software.
Copyright by aceisace
"""
import logging
class layout:
"""Page layout handling"""
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
def __init__(self, model=None, width=None, height=None,
supports_colour=False):
"""Initialize parameters for specified epaper model
Use model parameter to specify display OR
Crate a custom display with given width and height"""
self.background_colour = 'white'
self.text_colour = 'black'
if (model != None) and (width == None) and (height == None):
display_dimensions = {
'epd_7_in_5_v2_colour': (800, 400),
'epd_7_in_5_v2': (800, 400),
'epd_7_in_5_colour': (640, 384),
'epd_7_in_5': (640, 384),
'epd_5_in_83_colour': (600, 448),
'epd_5_in_83': (600, 448),
'epd_4_in_2_colour': (400, 300),
'epd_4_in_2': (400, 300),
}
self.display_height, self.display_width = display_dimensions[model]
if 'colour' in model:
self.three_colour_support = True
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
self.top_section_width = self.display_width
self.middle_section_width = self.display_width
self.bottom_section_width = self.display_width
self.create_sections()
def create_sections(self, top_section=0.10, middle_section=0.65,
bottom_section=0.25):
"""Allocate fixed percentage height for top and middle section
e.g. 0.2 = 20% (Leave empty for default values)
Set top/bottom_section to 0 to allocate more space for the middle section
"""
scale = lambda percentage: round(percentage * self.display_height)
if top_section == 0 or bottom_section == 0:
if top_section == 0:
self.top_section_height = 0
if bottom_section == 0:
self.bottom_section_height = 0
self.middle_section_height = scale(1 - top_section - bottom_section)
else:
if top_section + middle_section + bottom_section > 1.0:
print('All percentages should add up to max 100%, not more!')
raise
self.top_section_height = scale(top_section)
self.middle_section_height = scale(middle_section)
self.bottom_section_height = (self.display_height -
self.top_section_height - self.middle_section_height)
logging.debug('top-section size: {} x {} px'.format(
self.top_section_width, self.top_section_height))
logging.debug('middle-section size: {} x {} px'.format(
self.middle_section_width, self.middle_section_height))
logging.debug('bottom-section size: {} x {} px'.format(
self.bottom_section_width, self.bottom_section_height))
def get_section_size(self, section):
"""Enter top/middle/bottom to get the size of the section as a tuple:
(width, height)"""
if section not in ['top','middle','bottom']:
raise Exception('Invalid section: ', section)
else:
if section == 'top':
size = (self.top_section_width, self.top_section_height)
elif section == 'middle':
size = (self.middle_section_width, self.middle_section_height)
elif section == 'bottom':
size = (self.bottom_section_width, self.bottom_section_height)
return size

View File

@@ -1,137 +0,0 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Json settings parser. Currently in alpha!
Copyright by aceisace
"""
import json
from os import chdir #Ad-hoc
# TODO:
# Check of jsmin can/should be used to parse jsonc settings file
# Remove check of fixed settings file location. Ask user to specify path
# to settings file
from os import path
class settings:
"""Load and validate settings from the settings file"""
__supported_languages = ['en', 'de', 'ru', 'it', 'es', 'fr', 'el', 'sv', 'nl',
'pl', 'ua', 'nb', 'vi', 'zh_tw', 'zh-cn', 'ja', 'ko']
__supported_units = ['metric', 'imperial']
__supported_hours = [12, 24]
__supported_display_orientation = ['normal', 'upside_down']
__supported_models = [
'epd_7_in_5_v2_colour', 'epd_7_in_5_v2',
'epd_7_in_5_colour', 'epd_7_in_5',
'epd_5_in_83_colour','epd_5_in_83',
'epd_4_in_2_colour', 'epd_4_in_2'
]
def __init__(self, settings_file_path):
"""Load settings from path (folder or settings.json file)"""
try:
if settings_file_path.endswith('settings.json'):
folder = settings_file_path.split('/settings.json')[0]
else:
folder = settings_file_path
chdir(folder)
with open("settings.json") as file:
self.raw_settings = json.load(file)
except FileNotFoundError:
print('No settings file found in specified location')
try:
self.language = self.raw_settings['language']
if self.language not in self.__supported_languages or type(self.language) != str:
print('Unsupported language: {}!. Switching to english'.format(language))
self.language = 'en'
self.units = self.raw_settings['units']
if self.units not in self.__supported_units or type(self.units) != str:
print('Units ({}) not supported, using metric units.'.format(units))
self.units = 'metric'
self.hours = self.raw_settings['hours']
if self.hours not in self.__supported_hours or type(self.hours) != int:
print('Selected hours: {} not supported, using 24-hours'.format(hours))
self.hours = '24'
self.model = self.raw_settings['model']
if self.model not in self.__supported_models or type(self.model) != str:
print('Model: {} not supported. Please select a valid option'.format(model))
print('Switching to 7.5" ePaper black-white (v1) (fallback)')
self.model = 'epd_7_in_5'
self.calibration_hours = self.raw_settings['calibration_hours']
if not self.calibration_hours or type(self.calibration_hours) != list:
print('Invalid calibration hours: {}'.format(calibration_hours))
print('Using default option, 0am,12am,6pm')
self.calibration_hours = [0,12,18]
self.display_orientation = self.raw_settings['display_orientation']
if self.display_orientation not in self.__supported_display_orientation or type(
self.display_orientation) != str:
print('Invalid ({}) display orientation.'.format(display_orientation))
print('Switching to default orientation, normal-mode')
self.display_orientation = 'normal'
### Check if empty, If empty, set to none
for sections in self.raw_settings['panels']:
if sections['location'] == 'top':
self.top_section = sections['type']
self.top_section_config = sections['config']
elif sections['location'] == 'middle':
self.middle_section = sections['type']
self.middle_section_config = sections['config']
elif sections['location'] == 'bottom':
self.bottom_section = sections['type']
self.bottom_section_config = sections['config']
print('settings loaded')
except Exception as e:
print(e.reason)
def module_init(self, module_name):
"""Get all data from settings file by providing the module name"""
if module_name == self.top_section:
config = self.top_section_config
elif module_name == self.middle_section:
config = self.middle_section_config
elif module_name == self.bottom_section:
config = self.bottom_section_config
else:
print('Invalid module name!')
config = None
for module in self.raw_settings['panels']:
if module_name == module['type']:
location = module['location']
return config, location
def which_modules(self):
"""Returns a list of modules (from settings file) which should be loaded
on start"""
lst = [self.top_section, self.middle_section, self.bottom_section]
return lst
def main():
print('running settings parser as standalone...')
if __name__ == '__main__':
main()

View File

@@ -1,42 +0,0 @@
{
"language": "en",
"units": "metric",
"hours": 24,
"model": "epd_7_in_5_v2_colour",
"update_interval": 60,
"calibration_hours": [
0,
12,
18
],
"display_orientation": "normal",
"panels": [
{
"location": "top",
"type": "inkycal_weather",
"config": {
"api_key": "topsecret",
"location": "Stuttgart, DE"
}
},
{
"location": "middle",
"type": "inkycal_calendar",
"config": {
"week_starts_on": "Monday",
"ical_urls": [
"https://calendar.google.com/calendar/ical/en.usa%23holiday%40group.v.calendar.google.com/public/basic.ics"
]
}
},
{
"location": "bottom",
"type": "inkycal_rss",
"config": {
"rss_urls": [
"http://feeds.bbci.co.uk/news/world/rss.xml#"
]
}
}
]
}