redesign
Josef Dabrowski 6 years ago
parent 4fc0329d3f
commit 81e40142f7

@ -0,0 +1,5 @@
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.pythonPath": "/usr/bin/python2"
}

@ -1,113 +0,0 @@
from PIL import Image, ImageDraw, ImageFont, ImageOps
import re
import time
import widgets.widget as widget
import argparse
import os
import toml
try:
import drivers.epd7in5b
testMode = False
except:
testMode = True
mydir = os.path.dirname(os.path.abspath(__file__))
parser = argparse.ArgumentParser(description="NotiFrame display")
parser.add_argument('-t', '--test', help='enable test mode', action='store_true')
args = parser.parse_args()
if args.test:
testMode = True
print("RUNNING IN TESTMODE: "+str(testMode))
if not testMode:
epd = epd7in5b.EPD()
epd.init()
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
uni_config = toml.load(os.path.join(mydir, 'config.toml'))
config = convert(uni_config)
config2 = {'resWidth': 640, 'resHeight': 384, 'cellsWidth': 3, 'cellsHeight': 3, 'widgets': [
{'type': 'image', 'posX': 0, 'posY': 0, 'width': 3, 'height': 3, 'bwStyle': 'mono', 'scaleMode': 'fill', 'filename': 'forest.jpg'},
{'type': 'trello', 'posX': 0, 'posY': 0, 'width': 1, 'height': 3, 'board': 'Organisation', 'list': 'Plans'},
{'type': 'trello', 'posX': 1, 'posY': 0, 'width': 2, 'height': 3, 'board': 'E-paper', 'list': 'To Do:'}
]}
#print(toml.dumps(config))
#print(config)
#print(config2)
cwidth = int(round(int(config['resWidth'])/int(config['cellsWidth'])))
cheight = int(round(int(config['resHeight'])/int(config['cellsHeight'])))
image_yellow = Image.new('1', (config['resWidth'], config['resHeight']), 255) # 255: clear the frame
draw_yellow = ImageDraw.Draw(image_yellow)
image_black = Image.new('1', (config['resWidth'], config['resHeight']), 255) # 255: clear the frame
draw_black = ImageDraw.Draw(image_black)
#str1 = open("text.txt", "r").read()
#str2 = open("text.txt", "r").read()
#str3 = open("text.txt", "r").read()
#strList = []
#strList.append(str1)
#strList.append(str2)
#strList.append(str3)
def initWidgets():
widgetList = []
for widg_conf in config['widgets']:
if widg_conf['type'] == 'image':
widgetList.append(widget.ImageWidget(cwidth, cheight, (widg_conf['posX'], widg_conf['posY']),
(widg_conf['width'], widg_conf['height']), widg_conf['bwStyle'], widg_conf['scaleMode'],
os.path.join(mydir, os.path.join('widgets/resources/images/', widg_conf['filename']))))
if widg_conf['type'] == 'trello':
widgetList.append(widget.TrelloWidget(cwidth, cheight, (widg_conf['posX'], widg_conf['posY']),
(widg_conf['width'], widg_conf['height']), widg_conf['board'], widg_conf['list']))
#widgetList.append(widget.ImageWidget(cwidth, cheight, (0, 0), (3, 3), "mono", "fill", os.path.join(mydir, os.path.join('widgets/resources/images/', 'forest.jpg'))))
#widgetList.append(widget.TrelloWidget(cwidth, cheight, (0, 0), (1, 3), "Organisation", "Plans"))
#widgetList.append(widget.TrelloWidget(cwidth, cheight, (1, 0), (2, 3), "E-paper", "Done"))
#widgetList.append(widget.ImageWidget(cwidth, cheight, (1, 2), (2, 1), "mono", "fill", "forest.jpg"))
#widgetList.append(widget.TextWidget(cwidth, cheight, (0, 0), (1, 3), str2))
#widgetList.append(widget.TextWidget(cwidth, cheight, (0, 0), (2, 3), str1))
#widgetList.append(widget.ImageWidget(cwidth, cheight, (1, 0), (1, 3), "mono", "fill", "g.jpg"))
return widgetList
def drawWidget(w):
coordX = w.cellX*cwidth
coordY = w.cellY*cheight
image_black.paste(im=w.image_black, mask=w.mask_black, box=(coordX, coordY))
image_yellow.paste(w.image_yellow, (coordX, coordY))
def render(index):
if index is not 0:
for widg in widgetList:
widg.updateWidget()
draw_black.rectangle(xy=((0,0), image_black.size), fill=255)
draw_yellow.rectangle(xy=((0,0), image_yellow.size), fill=255)
for widg in widgetList:
drawWidget(widg)
if not testMode:
epd.display_frame(epd.get_frame_buffer(image_black),epd.get_frame_buffer(image_yellow))
else:
image_black.save(os.path.join(mydir, 'test/imgBlack.bmp'))
image_yellow.save(os.path.join(mydir, 'test/imgYellow.bmp'))
widgetList = initWidgets()
i = 0
while(True):
print("RENDERING "+str(i))
render(i)
i = (i + 1)
#time.sleep(10)

@ -0,0 +1,54 @@
from PIL import Image, ImageDraw, ImageFont, ImageOps
import re
import time
#import widgets.widget as widget
import argparse
import os
import toml
import requests
from io import BytesIO
try:
import drivers.epd7in5b
testMode = False
except:
testMode = True
canvas_url_black = 'http://0.0.0.0:5000/display'
mydir = os.path.dirname(os.path.abspath(__file__))
parser = argparse.ArgumentParser(description="NotiFrame display")
parser.add_argument('-t', '--test', help='enable test mode', action='store_true')
args = parser.parse_args()
if args.test:
testMode = True
print("RUNNING IN TESTMODE: "+str(testMode))
if not testMode:
epd = drivers.epd7in5b.EPD()
epd.init()
def render(index):
while(True):
print("requesting display image")
try:
blk = requests.get(canvas_url_black)
#ylw = requests.get(urlylw)
image_black = Image.open(BytesIO(blk.content))
image_yellow = None
#image_yellow = Image.open(BytesIO(ylw.content))
#draw_black.rectangle(xy=((0,0), image_black.size), fill=255)
#draw_yellow.rectangle(xy=((0,0), image_yellow.size), fill=255)
if not testMode:
epd.display_frame(epd.get_frame_buffer(image_black.rotate(180)),epd.get_frame_buffer(image_yellow.rotate(180)))
else:
image_black.save(os.path.join(mydir, 'test/imgBlackDisplayClient.bmp'))
#image_yellow.save(os.path.join(mydir, 'test/imgYellow.bmp'))
except:
print("failed to load display image")
i =+ 1
time.sleep(20)
i = 0
render(i)

@ -25,7 +25,7 @@
#
import epdif
import Image
from PIL import Image
import RPi.GPIO as GPIO
# Display resolution
@ -142,7 +142,7 @@ class EPD:
self.digital_write(self.reset_pin, GPIO.LOW) # module reset
self.delay_ms(200)
self.digital_write(self.reset_pin, GPIO.HIGH)
self.delay_ms(200)
self.delay_ms(200)
def get_frame_buffer(self, image):
buf = [0xFF] * (self.width * self.height / 8)
@ -175,7 +175,7 @@ class EPD:
temp3 = 0x00 #black
else:
temp3 = 0x03 #white
temp3 = (temp3 << 4) & 0xFF
temp1 = (temp1 << 1) & 0xFF
temp2 = (temp2 << 1) & 0xFF
@ -201,4 +201,3 @@ class EPD:
self.send_data(0xa5)
### END OF FILE ###

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

@ -0,0 +1,239 @@
from flask import Flask, render_template, request, redirect, url_for, send_file
import toml
import os
from PIL import Image, ImageDraw, ImageFont, ImageOps
import re
import time
import widgets.widget as widget
import argparse
app = Flask(__name__)
mydir = os.path.dirname(os.path.abspath(__file__))
# print(mydir)
###mydir = os.path.join(mydir, '../')
# print(mydir)
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
####################################################
####################################################
####################################################
uni_config = toml.load(os.path.join(mydir, 'config.toml'))
config = convert(uni_config)
config2 = {'resWidth': 640, 'resHeight': 384, 'cellsWidth': 3, 'cellsHeight': 3, 'widgets': [
{'type': 'image', 'posX': 0, 'posY': 0, 'width': 3, 'height': 3, 'bwStyle': 'mono', 'scaleMode': 'fill', 'filename': 'forest.jpg'},
{'type': 'trello', 'posX': 0, 'posY': 0, 'width': 1, 'height': 3, 'board': 'Organisation', 'list': 'Plans'},
{'type': 'trello', 'posX': 1, 'posY': 0, 'width': 2, 'height': 3, 'board': 'E-paper', 'list': 'To Do:'}
]}
cwidth = int(round(int(config['resWidth'])/int(config['cellsWidth'])))
cheight = int(round(int(config['resHeight'])/int(config['cellsHeight'])))
image_yellow = Image.new('1', (config['resWidth'], config['resHeight']), 255) # 255: clear the frame
draw_yellow = ImageDraw.Draw(image_yellow)
image_black = Image.new('1', (config['resWidth'], config['resHeight']), 255) # 255: clear the frame
draw_black = ImageDraw.Draw(image_black)
####################################################
####################################################
####################################################
# HOMEPAGE
@app.route('/home', methods=['GET', 'POST'])
def home(): # Toml config passed to html page via two dicts.
# Form data passed back to webserver as JSON.
config = read_config()
widgLists, sysList = prep_dict_for_web(config)
if request.method == 'POST':
jsonData = request.get_json()
print(jsonData)
jsonData = convert(jsonData)
# update system variables
for key in sysList:
print("%" + jsonData[key] + "$")
if jsonData[key]:
if isInt(jsonData[key]):
#print(request.form[key] + " is int")
sysList[key] = int(jsonData[key])
else:
sysList[key] = jsonData[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 jsonData[key + str(i)]:
if isInt(jsonData[key + str(i)]):
#print(request.form[key+str(i)] + " is int")
widgLists[i][key] = int(jsonData[key + str(i)])
else:
widgLists[i][key] = jsonData[key + str(i)]
update_config(widgLists, sysList)
widgTypes = widgetTypes()
return render_template('home.html', title='Overview', widgLists=widgLists, sysList=sysList, widgTypes=widgTypes)
@app.route('/newWidget', methods=['GET', 'POST'])
def newWidget(): #
#if request.method == 'GET':
widgType = request.args['type']
conf_defaults = pull_default_conf(widgType)
#import pdb; pdb.set_trace()
if request.method == 'POST':
#widgType = request.form['ty']
jsonData = request.get_json()
print(jsonData)
jsonData = convert(jsonData)
return render_template('newWidget.html', title='Overview', conf_defaults=conf_defaults)
@app.route('/display', methods=['GET', 'POST'])
def display():
location = 'test/imgBlack.bmp'
updateWidgets()
return send_file(location)
def pull_default_conf(widgType=None):
uni_config = toml.load(os.path.join(mydir, 'config.toml'))
config = convert(uni_config)
conf_dict = {
'trello': {
'board': {'default': '', 'datatype': 'text'},
'list': {'default': '', 'datatype': 'text'},
'width': {'default': 1, 'datatype': 'number', 'min': 1, 'max': config['cellsWidth']},
'height': {'default': 1, 'datatype': 'number', 'min': 1, 'max': config['cellsHeight']},
'posX': {'default': 0, 'datatype': 'number', 'min': 0, 'max': config['cellsWidth']-1},
'posY': {'default': 0, 'datatype': 'number', 'min': 0, 'max': config['cellsHeight']-1}
},
'text': {
'text': {'default': 'abcdefghijklmnopqrstuvwxyz', 'datatype': 'text'},
'width': {'default': 1, 'datatype': 'number', 'min': 1, 'max': config['cellsWidth']},
'height': {'default': 1, 'datatype': 'number', 'min': 1, 'max': config['cellsHeight']},
'posX': {'default': 0, 'datatype': 'number', 'min': 0, 'max': config['cellsWidth']-1},
'posY': {'default': 0, 'datatype': 'number', 'min': 0, 'max': config['cellsHeight']-1}
},
'image': {
'file': {'default': 'img.jpg', 'datatype': 'text'},
'bwMode': {'default': 'mono', 'datatype': 'text'},
'scaleMode': {'default': 'fill', 'datatype': 'text'},
'width': {'default': 1, 'datatype': 'number', 'min': 1, 'max': config['cellsWidth']},
'height': {'default': 1, 'datatype': 'number', 'min': 1, 'max': config['cellsHeight']},
'posX': {'default': 0, 'datatype': 'number', 'min': 0, 'max': config['cellsWidth']-1},
'posY': {'default': 0, 'datatype': 'number', 'min': 0, 'max': config['cellsHeight']-1}
}
}
if widgType != None:
conf_dict = conf_dict.get(widgType)
return conf_dict
def widgetTypes():
dflt_conf = pull_default_conf()
widgTypes = []
for key in dflt_conf.keys():
widgTypes.append(key)
return widgTypes
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))
####################################################
####################################################
####################################################
def initWidgets():
widgetList = []
for widg_conf in config['widgets']:
if widg_conf['type'] == 'image':
widgetList.append(widget.ImageWidget(cwidth, cheight, (widg_conf['posX'], widg_conf['posY']),
(widg_conf['width'], widg_conf['height']), widg_conf['bwStyle'], widg_conf['scaleMode'],
os.path.join(mydir, os.path.join('widgets/resources/images/', widg_conf['filename']))))
if widg_conf['type'] == 'trello':
widgetList.append(widget.TrelloWidget(cwidth, cheight, (widg_conf['posX'], widg_conf['posY']),
(widg_conf['width'], widg_conf['height']), widg_conf['board'], widg_conf['list']))
return widgetList
def drawWidget(w):
coordX = w.cellX*cwidth
coordY = w.cellY*cheight
image_black.paste(im=w.image_black, mask=w.mask_black, box=(coordX, coordY))
image_yellow.paste(w.image_yellow, (coordX, coordY))
def updateWidgets():
for widg in widgetList:
print(" updating trello widget")
widg.updateWidget()
print("")
draw_black.rectangle(xy=((0,0), image_black.size), fill=255)
draw_yellow.rectangle(xy=((0,0), image_yellow.size), fill=255)
for widg in widgetList:
drawWidget(widg)
image_black.save(os.path.join(mydir, 'test/imgBlack.bmp'))
image_yellow.save(os.path.join(mydir, 'test/imgYellow.bmp'))
widgetList = initWidgets()
####################################################
####################################################
####################################################
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')

@ -22,20 +22,11 @@ posY = 0
type = "trello"
[[widgets]]
list = "To Do:"
height = 2
list = "Active:"
height = 3
width = 2
board = "E-paper"
posX = 1
posY = 0
type = "trello"
[[widgets]]
list = "Tasks"
height = 1
width = 2
board = "Organisation"
posX = 1
posY = 2
type = "trello"

@ -8,6 +8,8 @@
<body>
<div>
<!-- EDIT EXISTING CONFIG -->
<h2>EDIT EXISTING CONFIG</h2>
<form action="/home" class='form' method="post">
{% for n in range(widgLists| length) %}
<h4>Widget {{n}}</h4>
@ -27,9 +29,22 @@
<input type="submit" value="Submit">
</form>
<!-- ADD NEW WIDGET -->
<h2>ADD NEW WIDGET</h2>
<form action="/newWidget" class="form" method="get">
<h4>New Widget</h4>
Type: <select id="type" name="type">
{% for type in widgTypes %}
<option value="{{type}}">{{type}}</option>
{% endfor %}
</select>
<input type="submit" value="Submit">
</form>
</div>
<script>
/**
@ -80,5 +95,6 @@
form.addEventListener('submit', handleFormSubmit);
</script>
</body>
</html>

@ -0,0 +1,87 @@
<!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">
<!-- jquery, popper.js, bootstrap4 beta -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</head>
<body>
<div>
<!-- SPECIFY NEW CONFIG DETAILS -->
<h2>SPECIFY NEW CONFIG DETAILS</h2>
<form action="/newWidget" class='form' method="post">
{% for key, value in conf_defaults.iteritems() %}
{{key}}:
{% if value['datatype'] == 'text' %}
<input type="text" name="{{key}}" value="{{value['default']}}">
{% endif %}
{% if value['datatype'] == 'number' %}
<input type="number" name="{{key}}" value="{{value['default']}}" min="{{value['min']}}" max="{{value['max']}}">
{% endif %}
<br>
<br>
{% endfor %}
<input type="submit" value="Submit">
</form>
</div>
<script>
/**
* Retrieves input data from a form and returns it as a JSON object.
* @param {HTMLFormControlsCollection} elements the form elements
* @return {Object} form data as an object literal
*/
const isValidElement = element => {
return element.name && element.value;
};
const formToJSON = elements => [].reduce.call(elements, (data, element) => {
if (isValidElement(element)) {
data[element.name] = element.value;
}
return data;
}, {});
const handleFormSubmit = event => {
// Stop the form from submitting since were handling that with AJAX.
event.preventDefault();
// Call our function to get the form data.
const data = formToJSON(form.elements);
/**
// Demo only: print the form data onscreen as a formatted JSON object.
const dataContainer = document.getElementsByClassName('results__display')[0];
// Use `JSON.stringify()` to make the output valid, human-readable JSON.
dataContainer.textContent = JSON.stringify(data, null, " ");
// ...this is where wed actually do something with the form data...
**/
var textContent = JSON.stringify(data, null, " ");
var request = new XMLHttpRequest();
request.open('POST', '/newWidget', true);
request.setRequestHeader('Content-Type', 'application/json');
request.send(textContent);
};
/*
* This is where things actually get started. We find the form element using
* its class name, then attach the `handleFormSubmit()` function to the
* `submit` event.
*/
const form = document.getElementsByClassName('form')[0];
form.addEventListener('submit', handleFormSubmit);
</script>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Before

Width:  |  Height:  |  Size: 240 KiB

After

Width:  |  Height:  |  Size: 240 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

@ -1,109 +0,0 @@
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(): # Toml config passed to html page via two dicts.
# Form data passed back to webserver as JSON.
config = read_config()
widgLists, sysList = prep_dict_for_web(config)
if request.method == 'POST':
jsonData = request.get_json()
print(jsonData)
jsonData = convert(jsonData)
# update system variables
for key in sysList:
print("%" + jsonData[key] + "$")
if jsonData[key]:
if isInt(jsonData[key]):
#print(request.form[key] + " is int")
sysList[key] = int(jsonData[key])
else:
sysList[key] = jsonData[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 jsonData[key + str(i)]:
if isInt(jsonData[key + str(i)]):
#print(request.form[key+str(i)] + " is int")
widgLists[i][key] = int(jsonData[key + str(i)])
else:
widgLists[i][key] = jsonData[key + str(i)]
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: 1.3 MiB

After

Width:  |  Height:  |  Size: 1.3 MiB

Before

Width:  |  Height:  |  Size: 891 KiB

After

Width:  |  Height:  |  Size: 891 KiB

Before

Width:  |  Height:  |  Size: 759 KiB

After

Width:  |  Height:  |  Size: 759 KiB

@ -6,10 +6,22 @@ import os
import requests
from requests_oauthlib import OAuth1Session
import re
import toml
import time
mydir = os.path.dirname(os.path.abspath(__file__))
t = time.time()
def timer():
global t
newT = time.time()
print("Time " + str(newT-t))
t = newT
def textBox(text, font, position, limits, colour, draw_black):
print(" textbox")
timer()
str = ""
limit = [0, 0]
limit[0] = limits[0] - position[0]
@ -54,6 +66,8 @@ def putImage(imagepath, maskpath, position, colour):
draw_yellow.bitmap((0, 0), black_invert, 255)
def roundRect(draw, topLeft, bottomRight, arcsize, type):
print(" roundrect")
timer()
a = 180
arcStart = topLeft
arcEnd = (arcStart[0] + arcsize, arcStart[1] + arcsize)
@ -111,7 +125,15 @@ def roundRect(draw, topLeft, bottomRight, arcsize, type):
draw.line((lineStart, lastLineEnd))
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
class TextWidget():
@ -263,6 +285,8 @@ class TrelloWidget():
self.boardName = boardName
self.listName = listName
self.width = dim[0]
self.height = dim[1]
self.wt = cwidth * dim[0]
@ -284,10 +308,23 @@ class TrelloWidget():
self.font2 = ImageFont.truetype(fontpath, 13)
self.font3 = ImageFont.truetype(fontpath, 10)
uni_config = toml.load(os.path.join(os.path.join(mydir, '..'), 'config.toml'))
config = convert(uni_config)
self.conf_dict = {
'type': {'default': 'trello'},
'board': {'default': ''},
'list': {'default': ''},
'width': {'default': 1, 'min': 1, 'max': config['cellsWidth']},
'height': {'default': 1, 'min': 1, 'max': config['cellsHeight']},
'posX': {'default': 0, 'min': 0, 'max': config['cellsWidth']-1},
'posY': {'default': 0, 'min': 0, 'max': config['cellsHeight']-1}
}
self.updateWidget()
def initTrelloClient(self):
print("CONNECTING TO TRELLO")
timer()
self.trello_key = 'a3d8f7c04c266e5c9571f6b7747aa353'
self.trello_secret = 'd4ac9968d997aa3e5a0ebf129a627b03701520de6ff19834c81d6d9c56fe7e9b'
try:
@ -359,13 +396,25 @@ class TrelloWidget():
return access_token, resource_owner_key, resource_owner_secret
def updateWidget(self):
print(" init trello client")
timer()
self.initTrelloClient()
print(" generating canvas")
timer()
self.image_black = Image.new('1', (self.wt, self.ht), 255)
self.mask_black = Image.new('1', (self.wt, self.ht), 255)
print(" cards from board")
timer()
card_list = self.cardsFromBoard(self.boardName, self.listName)
print(" print cards")
timer()
self.printCards(card_list)
print(" saving images")
timer()
self.image_black.save(os.path.join(mydir, '../test/card_image.bmp'))
self.mask_black.save(os.path.join(mydir, '../test/mask.bmp'))
print(" done")
timer()
#self.draw_black.rectangle((0, 0, self.wt, self.ht), fill=255) #inclusive/exclusive dimensions?
#self.draw_yellow.rectangle((0, 0, self.wt, self.ht), fill=255)
#textBox(content, self.font, (0,0), (self.wt, self.ht), "black", self.draw_black)
@ -378,6 +427,8 @@ class TrelloWidget():
self.lastY = 0
def makeCard(self, card):
print(" making card")
timer()
# calculate card dimensions for an image to draw the card on
# then draw the card on the widget canvas
# card dimensions: wt/width, ht/height (cards as large as one cell)
@ -394,7 +445,8 @@ class TrelloWidget():
self.drawText(card.name, self.font1, card_draw, card_image, card_wt, offset, padding)
self.cardLastY += 4
self.drawText(card.description, self.font3, card_draw, card_image, card_wt, offset, padding)
if card.description != "":
self.drawText(card.description, self.font3, card_draw, card_image, card_wt, offset, padding)
card_ht = self.cardLastY+padding
@ -414,23 +466,42 @@ class TrelloWidget():
def drawText(self, text, font, draw, ima, card_wt, offset, padding):
#self.cardLastY += 4
sizex, sizey = textBox(text, font, (offset+padding, self.cardLastY),
(card_wt-(offset+padding), ima.size[1]), "black", draw)
(card_wt-(offset+padding), ima.size[1]), "black", draw)
# find predicted height of textbox and set lastY to it
self.cardLastY += sizey
def cardsFromBoard(self, boardName, listName):
cards = []
all_boards = self.client.list_boards()
print(" 1")
timer()
for board in all_boards:
print(" 2")
timer()
if board.name == boardName:
slctd_board = board
slctd_board.list_lists()
all_lists_in_board = slctd_board.all_lists()
for lst in all_lists_in_board:
print(" 3")
timer()
if lst.name == listName:
card_list = lst.list_cards()
for crd in card_list:
print(" 4")
timer()
cards.append(self.makeCard(crd))
return cards
class surfWidget():
# this widget displays an image
def __init__(self, cwidth, cheight, xy=(0, 0), dim=(1, 1)):
self.name = ""
Loading…
Cancel
Save