diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index fb710a7..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.directory b/.directory deleted file mode 100644 index f89d008..0000000 --- a/.directory +++ /dev/null @@ -1,6 +0,0 @@ -[Dolphin] -Timestamp=2019,1,23,16,14,48 -Version=4 - -[Settings] -HiddenFilesShown=true diff --git a/.gitignore b/.gitignore index 554f38c..87cd60f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ *.secret test/* +.DS_Store +.directory diff --git a/notiframe/.directory b/notiframe/.directory deleted file mode 100644 index fab0efe..0000000 --- a/notiframe/.directory +++ /dev/null @@ -1,5 +0,0 @@ -[Dolphin] -PreviewsShown=false -Timestamp=2019,1,23,16,24,39 -Version=4 -ViewMode=1 diff --git a/notiframe/NotiFrame.py b/notiframe/NotiFrame.py index 4ddadec..c2def83 100644 --- a/notiframe/NotiFrame.py +++ b/notiframe/NotiFrame.py @@ -4,6 +4,7 @@ import time import widgets.widget as widget import argparse import os +import toml try: import drivers.epd7in5b testMode = False @@ -24,14 +25,35 @@ if not testMode: epd = epd7in5b.EPD() epd.init() -width = 640 -height = 384 -cwidth = int(round(width/3)) -cheight = int(round(height/3)) +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 -image_yellow = Image.new('1', (width, height), 255) # 255: clear the frame +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(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) -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) #str1 = open("text.txt", "r").read() @@ -44,9 +66,18 @@ draw_black = ImageDraw.Draw(image_black) def initWidgets(): widgetList = [] - widgetList.append(widget.ImageWidget(cwidth, cheight, (0, 0), (3, 3), "mono", "fill", os.path.join(mydir, '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")) + 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)) diff --git a/notiframe/config.toml b/notiframe/config.toml new file mode 100644 index 0000000..0a8c057 --- /dev/null +++ b/notiframe/config.toml @@ -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" diff --git a/notiframe/test/card_image.bmp b/notiframe/test/card_image.bmp index 18d5b86..931fa42 100644 Binary files a/notiframe/test/card_image.bmp and b/notiframe/test/card_image.bmp differ diff --git a/notiframe/test/imgBlack.bmp b/notiframe/test/imgBlack.bmp index 5b18f26..afb7a94 100644 Binary files a/notiframe/test/imgBlack.bmp and b/notiframe/test/imgBlack.bmp differ diff --git a/notiframe/test/mask.bmp b/notiframe/test/mask.bmp index d922119..fbe8a88 100644 Binary files a/notiframe/test/mask.bmp and b/notiframe/test/mask.bmp differ diff --git a/notiframe/widgets/widget.py b/notiframe/widgets/widget.py index 5251753..7a3d465 100644 --- a/notiframe/widgets/widget.py +++ b/notiframe/widgets/widget.py @@ -175,6 +175,7 @@ class ImageWidget(): self.draw_mask_black = ImageDraw.Draw(self.mask_black) self.bwMode = bwMode self.scaleMode = scaleMode + print(img) self.image = Image.open(img) self.updateWidget() @@ -222,9 +223,9 @@ class ImageWidget(): def bwImg(self, img): self.autoThresholdLimit(img) - if self.bwMode is "mono": + if self.bwMode == "mono": return img.convert('L').point(self.threshold, '1') - if self.bwMode is "dither": + if self.bwMode == "dither": return img.convert(mode='1') def pasteImg(self, img): @@ -243,11 +244,11 @@ class ImageWidget(): def updateWidget(self): if self.image is not None: - if self.scaleMode is "fill": + if self.scaleMode == "fill": rsImg = self.fillImg(self.image) - if self.scaleMode is "resize": + if self.scaleMode == "resize": rsImg = self.resizeImg(self.image) - if self.scaleMode is "none": + if self.scaleMode == "none": rsImg = self.image newImg = self.bwImg(rsImg) self.pasteImg(newImg)