Added support for toml config file

redesign
Josef Dabrowski 7 years ago
parent 1dcb98172e
commit c7284b6149

BIN
.DS_Store vendored

Binary file not shown.

@ -1,6 +0,0 @@
[Dolphin]
Timestamp=2019,1,23,16,14,48
Version=4
[Settings]
HiddenFilesShown=true

2
.gitignore vendored

@ -2,3 +2,5 @@
*.secret *.secret
test/* test/*
.DS_Store
.directory

@ -1,5 +0,0 @@
[Dolphin]
PreviewsShown=false
Timestamp=2019,1,23,16,24,39
Version=4
ViewMode=1

@ -4,6 +4,7 @@ import time
import widgets.widget as widget import widgets.widget as widget
import argparse import argparse
import os import os
import toml
try: try:
import drivers.epd7in5b import drivers.epd7in5b
testMode = False testMode = False
@ -24,14 +25,35 @@ if not testMode:
epd = epd7in5b.EPD() epd = epd7in5b.EPD()
epd.init() epd.init()
width = 640 def convert(input):
height = 384 if isinstance(input, dict):
cwidth = int(round(width/3)) return dict((convert(key), convert(value)) for key, value in input.iteritems())
cheight = int(round(height/3)) 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:'}
]}
image_yellow = Image.new('1', (width, height), 255) # 255: clear the frame #print(toml.dumps(config))
print(config)
print(config2)
cwidth = int(round(config['resWidth']/config['cellsWidth']))
cheight = int(round(config['resHeight']/config['cellsHeight']))
image_yellow = Image.new('1', (config['resWidth'], config['resHeight']), 255) # 255: clear the frame
draw_yellow = ImageDraw.Draw(image_yellow) draw_yellow = ImageDraw.Draw(image_yellow)
image_black = Image.new('1', (width, height), 255) # 255: clear the frame image_black = Image.new('1', (config['resWidth'], config['resHeight']), 255) # 255: clear the frame
draw_black = ImageDraw.Draw(image_black) draw_black = ImageDraw.Draw(image_black)
#str1 = open("text.txt", "r").read() #str1 = open("text.txt", "r").read()
@ -44,9 +66,18 @@ draw_black = ImageDraw.Draw(image_black)
def initWidgets(): def initWidgets():
widgetList = [] widgetList = []
widgetList.append(widget.ImageWidget(cwidth, cheight, (0, 0), (3, 3), "mono", "fill", os.path.join(mydir, 'widgets/resources/images/forest.jpg'))) for widg_conf in config['widgets']:
widgetList.append(widget.TrelloWidget(cwidth, cheight, (0, 0), (1, 3), "Organisation", "Plans")) if widg_conf['type'] == 'image':
widgetList.append(widget.TrelloWidget(cwidth, cheight, (1, 0), (2, 3), "E-paper", "Done")) 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.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), (1, 3), str2))
#widgetList.append(widget.TextWidget(cwidth, cheight, (0, 0), (2, 3), str1)) #widgetList.append(widget.TextWidget(cwidth, cheight, (0, 0), (2, 3), str1))

@ -0,0 +1,40 @@
cellsHeight = 3
resHeight = 384
resWidth = 640
cellsWidth = 3
[[widgets]]
width = 3
posX = 0
posY = 0
scaleMode = "fill"
bwStyle = "mono"
type = "image"
filename = "forest.jpg"
height = 3
[[widgets]]
list = "Plans"
height = 3
width = 1
board = "Organisation"
posX = 0
posY = 0
type = "trello"
[[widgets]]
list = "To Do:"
height = 2
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"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

@ -175,6 +175,7 @@ class ImageWidget():
self.draw_mask_black = ImageDraw.Draw(self.mask_black) self.draw_mask_black = ImageDraw.Draw(self.mask_black)
self.bwMode = bwMode self.bwMode = bwMode
self.scaleMode = scaleMode self.scaleMode = scaleMode
print(img)
self.image = Image.open(img) self.image = Image.open(img)
self.updateWidget() self.updateWidget()
@ -222,9 +223,9 @@ class ImageWidget():
def bwImg(self, img): def bwImg(self, img):
self.autoThresholdLimit(img) self.autoThresholdLimit(img)
if self.bwMode is "mono": if self.bwMode == "mono":
return img.convert('L').point(self.threshold, '1') return img.convert('L').point(self.threshold, '1')
if self.bwMode is "dither": if self.bwMode == "dither":
return img.convert(mode='1') return img.convert(mode='1')
def pasteImg(self, img): def pasteImg(self, img):
@ -243,11 +244,11 @@ class ImageWidget():
def updateWidget(self): def updateWidget(self):
if self.image is not None: if self.image is not None:
if self.scaleMode is "fill": if self.scaleMode == "fill":
rsImg = self.fillImg(self.image) rsImg = self.fillImg(self.image)
if self.scaleMode is "resize": if self.scaleMode == "resize":
rsImg = self.resizeImg(self.image) rsImg = self.resizeImg(self.image)
if self.scaleMode is "none": if self.scaleMode == "none":
rsImg = self.image rsImg = self.image
newImg = self.bwImg(rsImg) newImg = self.bwImg(rsImg)
self.pasteImg(newImg) self.pasteImg(newImg)

Loading…
Cancel
Save