|
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 7.1 KiB |
|
Before Width: | Height: | Size: 240 KiB After Width: | Height: | Size: 240 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 7.1 KiB |
@ -0,0 +1,33 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link href="/style.css" rel="stylesheet" type="text/css" media="all">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
|
||||||
|
<form action="/home" method="post">
|
||||||
|
{% for n in range(widgLists| length) %}
|
||||||
|
<h4>Widget {{n}}</h4>
|
||||||
|
{% for key, value in widgLists[n].iteritems() %}
|
||||||
|
{{key}}: <input type="text" name="{{key}}{{n}}" value="{{value}}">
|
||||||
|
<br>
|
||||||
|
{% endfor %}
|
||||||
|
<br>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
<h4>System Settings</h4>
|
||||||
|
{% for key, value in sysList.iteritems() %}
|
||||||
|
{{key}}: <input type="text" name="{{key}}" value="{{value}}">
|
||||||
|
<br>
|
||||||
|
{% endfor %}
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<input type="submit" value="Submit">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -0,0 +1,97 @@
|
|||||||
|
from flask import Flask, render_template, request, redirect, url_for
|
||||||
|
import toml
|
||||||
|
import os
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
mydir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
#print(mydir)
|
||||||
|
mydir = os.path.join(mydir, '../')
|
||||||
|
#print(mydir)
|
||||||
|
|
||||||
|
essentials = {'type': None, 'height': None, 'width': None, 'posX': None, 'posY': None}
|
||||||
|
trello_options = {'board': None, 'list': None}
|
||||||
|
image_options = {'filename': None, 'scaleMode': None, 'bwStyle': None}
|
||||||
|
|
||||||
|
def convert(input):
|
||||||
|
if isinstance(input, dict):
|
||||||
|
return dict((convert(key), convert(value)) for key, value in input.iteritems())
|
||||||
|
elif isinstance(input, list):
|
||||||
|
return [convert(element) for element in input]
|
||||||
|
elif isinstance(input, unicode):
|
||||||
|
return input.encode('utf-8')
|
||||||
|
else:
|
||||||
|
return input
|
||||||
|
|
||||||
|
#HOMEPAGE
|
||||||
|
@app.route('/home', methods=['GET', 'POST'])
|
||||||
|
def home():
|
||||||
|
config = read_config()
|
||||||
|
widgLists, sysList = prep_dict_for_web(config)
|
||||||
|
if request.method == 'POST':
|
||||||
|
#update system variables
|
||||||
|
for key in sysList:
|
||||||
|
if request.form[key]:
|
||||||
|
if isInt(request.form[key]):
|
||||||
|
#print(request.form[key] + " is int")
|
||||||
|
sysList[key] = int(request.form[key])
|
||||||
|
else:
|
||||||
|
sysList[key] = request.form[key]
|
||||||
|
#update widget variables
|
||||||
|
#for i in range(len(widgLists)):
|
||||||
|
# for key in widgLists[i]:
|
||||||
|
# if request.form[key+str(i)]:
|
||||||
|
# widgLists[i][key] = request.form[key+str(i)]
|
||||||
|
for i in range(len(widgLists)):
|
||||||
|
for key in widgLists[i]:
|
||||||
|
#print(request.form[key+str(i)])
|
||||||
|
if isInt(request.form[key+str(i)]):
|
||||||
|
#print(request.form[key+str(i)] + " is int")
|
||||||
|
widgLists[i][key] = int(request.form[key+str(i)])
|
||||||
|
else:
|
||||||
|
widgLists[i][key] = request.form[key+str(i)]
|
||||||
|
|
||||||
|
#print(widgLists)
|
||||||
|
#print(sysList)
|
||||||
|
|
||||||
|
update_config(widgLists, sysList)
|
||||||
|
|
||||||
|
return render_template('home.html', title='Overview', widgLists=widgLists, sysList=sysList)
|
||||||
|
|
||||||
|
def isInt(s):
|
||||||
|
try:
|
||||||
|
int(s)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def prep_dict_for_web(config):
|
||||||
|
widgLists = config['widgets'] #list of dicts
|
||||||
|
sysList = {} #dict
|
||||||
|
for key in config:
|
||||||
|
if key != 'widgets':
|
||||||
|
sysList[key] = config[key]
|
||||||
|
return widgLists, sysList
|
||||||
|
|
||||||
|
def read_config():
|
||||||
|
uni_config = toml.load(os.path.join(mydir, 'config.toml'))
|
||||||
|
config = convert(uni_config)
|
||||||
|
#print(config)
|
||||||
|
#config = {'widgets': [
|
||||||
|
#{'width': 3, 'posX': 0, 'posY': 0, 'scaleMode': 'fill', 'bwStyle': 'mono', 'type': 'image', 'filename': 'forest.jpg', 'height': 3},
|
||||||
|
#{'list': 'Plans', 'height': 3, 'width': 1, 'board': 'Organisation', 'posX': 0, 'posY': 0, 'type': 'trello'},
|
||||||
|
#{'list': 'To Do:', 'height': 3, 'width': 2, 'board': 'E-paper', 'posX': 1, 'posY': 0, 'type': 'trello'}
|
||||||
|
#], 'cellsHeight': 3, 'resHeight': 384, 'resWidth': 640, 'cellsWidth': 3}
|
||||||
|
return config
|
||||||
|
|
||||||
|
def update_config(widgLists, sysList):
|
||||||
|
config = {'widgets': widgLists}
|
||||||
|
for key in sysList:
|
||||||
|
config[key] = sysList[key]
|
||||||
|
convert(config)
|
||||||
|
path = os.path.join(mydir, 'config.toml')
|
||||||
|
with open(path, "w+") as config_file:
|
||||||
|
config_file.write(toml.dumps(config))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(debug=True,host='0.0.0.0')
|
||||||
|
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 94 KiB |
|
Before Width: | Height: | Size: 93 KiB After Width: | Height: | Size: 93 KiB |
|
Before Width: | Height: | Size: 2.0 MiB After Width: | Height: | Size: 2.0 MiB |
|
Before Width: | Height: | Size: 350 KiB After Width: | Height: | Size: 350 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 891 KiB After Width: | Height: | Size: 891 KiB |