|
|
|
|
@ -53,45 +53,71 @@ def putImage(imagepath, maskpath, position, colour):
|
|
|
|
|
black_invert = ImageOps.invert(image_black.convert('L'))
|
|
|
|
|
draw_yellow.bitmap((0, 0), black_invert, 255)
|
|
|
|
|
|
|
|
|
|
def roundRect(draw, topLeft, bottomRight, arcsize):
|
|
|
|
|
|
|
|
|
|
def roundRect(draw, topLeft, bottomRight, arcsize, type):
|
|
|
|
|
a = 180
|
|
|
|
|
arcStart = topLeft
|
|
|
|
|
arcEnd = (arcStart[0] + arcsize, arcStart[1] + arcsize)
|
|
|
|
|
lastLineEnd = (arcStart[0], arcStart[1]+arcsize/2)
|
|
|
|
|
lineStart = (arcStart[0]+arcsize/2, arcStart[1])
|
|
|
|
|
draw.arc((arcStart, arcEnd), a, a+90)
|
|
|
|
|
if type is 'outline':
|
|
|
|
|
draw.arc((arcStart, arcEnd), a, a+90)
|
|
|
|
|
elif type is 'fill':
|
|
|
|
|
draw.ellipse(xy=(arcStart, arcEnd), fill=0)
|
|
|
|
|
|
|
|
|
|
a = (a + 90) % 360
|
|
|
|
|
arcStart = (bottomRight[0]-arcsize, topLeft[1])
|
|
|
|
|
arcEnd = (arcStart[0] + arcsize, arcStart[1] + arcsize)
|
|
|
|
|
lineEnd = (arcStart[0]+arcsize/2, arcStart[1])
|
|
|
|
|
draw.line((lineStart, lineEnd))
|
|
|
|
|
if type is 'outline':
|
|
|
|
|
draw.line((lineStart, lineEnd))
|
|
|
|
|
elif type is 'fill':
|
|
|
|
|
box1corner1 = lineStart
|
|
|
|
|
lineStart = (arcEnd[0], arcEnd[1]-arcsize/2)
|
|
|
|
|
draw.arc((arcStart, arcEnd), a, a+90)
|
|
|
|
|
if type is 'outline':
|
|
|
|
|
draw.arc((arcStart, arcEnd), a, a+90)
|
|
|
|
|
elif type is 'fill':
|
|
|
|
|
draw.ellipse(xy=(arcStart, arcEnd), fill=0)
|
|
|
|
|
|
|
|
|
|
a = (a + 90) % 360
|
|
|
|
|
arcStart = (bottomRight[0]-arcsize, bottomRight[1]-arcsize)
|
|
|
|
|
arcEnd = (arcStart[0] + arcsize, arcStart[1] + arcsize)
|
|
|
|
|
lineEnd = (arcEnd[0], arcEnd[1]-arcsize/2)
|
|
|
|
|
draw.line((lineStart, lineEnd))
|
|
|
|
|
if type is 'outline':
|
|
|
|
|
draw.line((lineStart, lineEnd))
|
|
|
|
|
lineStart = (arcEnd[0]-arcsize/2, arcEnd[1])
|
|
|
|
|
draw.arc((arcStart, arcEnd), a, a+90)
|
|
|
|
|
if type is 'outline':
|
|
|
|
|
draw.arc((arcStart, arcEnd), a, a+90)
|
|
|
|
|
elif type is 'fill':
|
|
|
|
|
draw.ellipse(xy=(arcStart, arcEnd), fill=0)
|
|
|
|
|
box2corner1 = lastLineEnd
|
|
|
|
|
box2corner2 = lineEnd
|
|
|
|
|
|
|
|
|
|
a = (a + 90) % 360
|
|
|
|
|
arcStart = (topLeft[0], bottomRight[1]-arcsize)
|
|
|
|
|
arcEnd = (arcStart[0] + arcsize, arcStart[1] + arcsize)
|
|
|
|
|
lineEnd = (arcEnd[0]-arcsize/2, arcEnd[1])
|
|
|
|
|
draw.line((lineStart, lineEnd))
|
|
|
|
|
|
|
|
|
|
if type is 'outline':
|
|
|
|
|
draw.arc((arcStart, arcEnd), a, a+90)
|
|
|
|
|
elif type is 'fill':
|
|
|
|
|
box1corner2 = lineStart
|
|
|
|
|
draw.ellipse(xy=(arcStart, arcEnd), fill=0)
|
|
|
|
|
|
|
|
|
|
draw.rectangle(xy=(box1corner1, box1corner2), fill=0)
|
|
|
|
|
draw.rectangle(xy=(box2corner1, box2corner2), fill=0)
|
|
|
|
|
|
|
|
|
|
lineStart = (arcStart[0], arcStart[1]+arcsize/2)
|
|
|
|
|
draw.arc((arcStart, arcEnd), a, a+90)
|
|
|
|
|
|
|
|
|
|
draw.line((lineStart, lastLineEnd))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TextWidget():
|
|
|
|
|
# this example widget will have a set size: 3x1 cells (one column)
|
|
|
|
|
# an instance of this widget class can be created and pasted to canvas
|
|
|
|
|
def __init__(self, cwidth, cheight, xy=(0, 0), dim=(1, 1), str=""):
|
|
|
|
|
def __init__(self, cwidth, cheight, xy=(0, 0), dim=(1, 1), stringIn=""):
|
|
|
|
|
self.width = dim[0]
|
|
|
|
|
self.height = dim[1]
|
|
|
|
|
self.wt = cwidth * dim[0]
|
|
|
|
|
@ -104,8 +130,11 @@ class TextWidget():
|
|
|
|
|
self.image_black = Image.new(
|
|
|
|
|
'1', (self.wt, self.ht), 255) # 255: clear the frame
|
|
|
|
|
self.draw_black = ImageDraw.Draw(self.image_black)
|
|
|
|
|
self.mask_black = Image.new('1', (self.wt, self.ht), 255)
|
|
|
|
|
self.draw_mask_black = ImageDraw.Draw(self.mask_black)
|
|
|
|
|
self.font = ImageFont.truetype('DejaVuSans.ttf', 16)
|
|
|
|
|
self.updateWidget(str)
|
|
|
|
|
self.stringInput = stringIn
|
|
|
|
|
self.updateWidget()
|
|
|
|
|
|
|
|
|
|
def drawText(self, str):
|
|
|
|
|
# define parameters for text placement
|
|
|
|
|
@ -115,15 +144,15 @@ class TextWidget():
|
|
|
|
|
textBox(str, self.font, position, limit, "black", self.draw_black)
|
|
|
|
|
|
|
|
|
|
def saveImages(self):
|
|
|
|
|
print("saving widget images")
|
|
|
|
|
self.image_black.save("imgBlackWidget.bmp")
|
|
|
|
|
self.image_yellow.save("imgYellowWidget.bmp")
|
|
|
|
|
|
|
|
|
|
def updateWidget(self, str):
|
|
|
|
|
self.draw_black.rectangle((0, 0, self.wt, self.ht), fill=255)
|
|
|
|
|
self.draw_yellow.rectangle((0, 0, self.wt, self.ht), fill=255)
|
|
|
|
|
self.drawText(str)
|
|
|
|
|
self.saveImages()
|
|
|
|
|
def updateWidget(self):
|
|
|
|
|
if self.stringInput is not None:
|
|
|
|
|
self.draw_black.rectangle((0, 0, self.wt, self.ht), fill=255)
|
|
|
|
|
self.draw_yellow.rectangle((0, 0, self.wt, self.ht), fill=255)
|
|
|
|
|
self.drawText(self.stringInput)
|
|
|
|
|
self.saveImages()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ImageWidget():
|
|
|
|
|
@ -142,9 +171,12 @@ class ImageWidget():
|
|
|
|
|
self.image_black = Image.new(
|
|
|
|
|
'1', (self.wt, self.ht), 255) # 255: clear the frame
|
|
|
|
|
self.draw_black = ImageDraw.Draw(self.image_black)
|
|
|
|
|
self.mask_black = Image.new('1', (self.wt, self.ht), 255)
|
|
|
|
|
self.draw_mask_black = ImageDraw.Draw(self.mask_black)
|
|
|
|
|
self.bwMode = bwMode
|
|
|
|
|
self.scaleMode = scaleMode
|
|
|
|
|
self.updateWidget(Image.open(img))
|
|
|
|
|
self.image = Image.open(img)
|
|
|
|
|
self.updateWidget()
|
|
|
|
|
|
|
|
|
|
def resizeImg(self, img):
|
|
|
|
|
# scale image down until whole image fits inside the cell
|
|
|
|
|
@ -152,14 +184,11 @@ class ImageWidget():
|
|
|
|
|
cRatio = self.wt / self.ht # canvas ratio
|
|
|
|
|
if cRatio > iRatio: # height is limiting dimension
|
|
|
|
|
fixedImg = img.resize((int(self.ht * iRatio), self.ht))
|
|
|
|
|
print(" limited by height")
|
|
|
|
|
return fixedImg
|
|
|
|
|
if cRatio < iRatio: # width is limiting dimension
|
|
|
|
|
fixedImg = img.resize((self.wt, int(self.wt / iRatio)))
|
|
|
|
|
print(" limited by width")
|
|
|
|
|
return fixedImg
|
|
|
|
|
fixedImg = img
|
|
|
|
|
print(" ratios are equal, not limited")
|
|
|
|
|
return fixedImg
|
|
|
|
|
|
|
|
|
|
def fillImg(self, img):
|
|
|
|
|
@ -167,33 +196,22 @@ class ImageWidget():
|
|
|
|
|
iRatio = img.size[0] / img.size[1] # image ratio
|
|
|
|
|
cRatio = self.wt / self.ht # canvas ratio
|
|
|
|
|
if cRatio > iRatio:
|
|
|
|
|
print("new sizes as calcd in resize: " +
|
|
|
|
|
str(self.wt) + " " + str(self.wt / iRatio))
|
|
|
|
|
# width = wt, calc new height w/ ratio
|
|
|
|
|
fixedImg = img.resize((self.wt, int(self.wt / iRatio)))
|
|
|
|
|
offset = 0.5 * (fixedImg.size[1] - self.ht) # centre by height
|
|
|
|
|
cropped = fixedImg.crop((0, offset, self.wt, offset + self.ht - 1))
|
|
|
|
|
# cropped.load()
|
|
|
|
|
print("zoomed to fill height")
|
|
|
|
|
return cropped
|
|
|
|
|
if cRatio < iRatio:
|
|
|
|
|
# height = ht, calc new width w/ ratio
|
|
|
|
|
fixedImg = img.resize((int(self.ht * iRatio), self.ht))
|
|
|
|
|
offset = 0.5 * (fixedImg.size[0] - self.wt) # centre by width
|
|
|
|
|
cropped = fixedImg.crop((offset, 0, offset + self.wt, self.ht - 1))
|
|
|
|
|
# cropped.load()
|
|
|
|
|
print("zoomed to fill width")
|
|
|
|
|
return cropped
|
|
|
|
|
print("not zoomed")
|
|
|
|
|
return img.resize((self.wt, self.ht))
|
|
|
|
|
|
|
|
|
|
def autoThresholdLimit(self, img):
|
|
|
|
|
gscale = img.convert(mode="L")
|
|
|
|
|
gscale.save("greyscale.bmp")
|
|
|
|
|
extrema = gscale.getextrema()
|
|
|
|
|
print("EXTREMA: " + str(extrema))
|
|
|
|
|
limit = extrema[0] + 0.4 * (extrema[1] - extrema[0])
|
|
|
|
|
print(limit)
|
|
|
|
|
self.thresLim = limit
|
|
|
|
|
|
|
|
|
|
def threshold(self, val):
|
|
|
|
|
@ -220,26 +238,22 @@ class ImageWidget():
|
|
|
|
|
self.image_black.paste(img, (0, offset))
|
|
|
|
|
|
|
|
|
|
def saveImages(self):
|
|
|
|
|
print("saving widget images")
|
|
|
|
|
self.image_black.save("imgBlackWidget.bmp")
|
|
|
|
|
self.image_yellow.save("imgYellowWidget.bmp")
|
|
|
|
|
|
|
|
|
|
def updateWidget(self, img):
|
|
|
|
|
if self.scaleMode is "fill":
|
|
|
|
|
rsImg = self.fillImg(img)
|
|
|
|
|
if self.scaleMode is "resize":
|
|
|
|
|
rsImg = self.resizeImg(img)
|
|
|
|
|
if self.scaleMode is "none":
|
|
|
|
|
rsImg = img
|
|
|
|
|
rsImg.save("rsImg.bmp")
|
|
|
|
|
newImg = self.bwImg(rsImg)
|
|
|
|
|
newImg.save("bwImg.bmp")
|
|
|
|
|
print(" Dimensions are now: " +
|
|
|
|
|
str(newImg.size[0]) + "x" + str(newImg.size[1]))
|
|
|
|
|
print(" Dimensions of widget canvas: " +
|
|
|
|
|
str(self.wt) + "x" + str(self.ht))
|
|
|
|
|
self.pasteImg(newImg)
|
|
|
|
|
self.saveImages()
|
|
|
|
|
def updateWidget(self):
|
|
|
|
|
if self.image is not None:
|
|
|
|
|
if self.scaleMode is "fill":
|
|
|
|
|
rsImg = self.fillImg(self.image)
|
|
|
|
|
if self.scaleMode is "resize":
|
|
|
|
|
rsImg = self.resizeImg(self.image)
|
|
|
|
|
if self.scaleMode is "none":
|
|
|
|
|
rsImg = self.image
|
|
|
|
|
rsImg.save("rsImg.bmp")
|
|
|
|
|
newImg = self.bwImg(rsImg)
|
|
|
|
|
newImg.save("bwImg.bmp")
|
|
|
|
|
self.pasteImg(newImg)
|
|
|
|
|
self.saveImages()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TrelloWidget():
|
|
|
|
|
@ -250,8 +264,6 @@ class TrelloWidget():
|
|
|
|
|
self.boardName = boardName
|
|
|
|
|
self.listName = listName
|
|
|
|
|
|
|
|
|
|
self.initTrelloClient()
|
|
|
|
|
|
|
|
|
|
self.width = dim[0]
|
|
|
|
|
self.height = dim[1]
|
|
|
|
|
self.wt = cwidth * dim[0]
|
|
|
|
|
@ -264,6 +276,8 @@ class TrelloWidget():
|
|
|
|
|
self.image_black = Image.new(
|
|
|
|
|
'1', (self.wt, self.ht), 255) # 255: clear the frame
|
|
|
|
|
self.draw_black = ImageDraw.Draw(self.image_black)
|
|
|
|
|
self.mask_black = Image.new('1', (self.wt, self.ht), 255)
|
|
|
|
|
self.draw_mask_black = ImageDraw.Draw(self.mask_black)
|
|
|
|
|
self.lastY = 0
|
|
|
|
|
self.cardLastY = 0
|
|
|
|
|
self.font1 = ImageFont.truetype('DejaVuSans.ttf', 12)
|
|
|
|
|
@ -273,6 +287,7 @@ class TrelloWidget():
|
|
|
|
|
self.updateWidget()
|
|
|
|
|
|
|
|
|
|
def initTrelloClient(self):
|
|
|
|
|
print("CONNECTING TO TRELLO")
|
|
|
|
|
self.trello_key = 'a3d8f7c04c266e5c9571f6b7747aa353'
|
|
|
|
|
self.trello_secret = 'd4ac9968d997aa3e5a0ebf129a627b03701520de6ff19834c81d6d9c56fe7e9b'
|
|
|
|
|
try:
|
|
|
|
|
@ -344,45 +359,64 @@ class TrelloWidget():
|
|
|
|
|
return access_token, resource_owner_key, resource_owner_secret
|
|
|
|
|
|
|
|
|
|
def updateWidget(self):
|
|
|
|
|
self.initTrelloClient()
|
|
|
|
|
self.image_black = Image.new('1', (self.wt, self.ht), 255)
|
|
|
|
|
self.mask_black = Image.new('1', (self.wt, self.ht), 255)
|
|
|
|
|
card_list = self.cardsFromBoard(self.boardName, self.listName)
|
|
|
|
|
self.printCards(card_list)
|
|
|
|
|
self.image_black.save("card_image.bmp")
|
|
|
|
|
self.mask_black.save("mask.bmp")
|
|
|
|
|
#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)
|
|
|
|
|
|
|
|
|
|
def printCards(self, card_list):
|
|
|
|
|
for cardImg in card_list:
|
|
|
|
|
self.image_black.paste(cardImg, (0, self.lastY))
|
|
|
|
|
print(self.lastY)
|
|
|
|
|
self.lastY += cardImg.size[1]
|
|
|
|
|
self.image_black.paste(cardImg[0], (0, self.lastY))
|
|
|
|
|
self.mask_black.paste(cardImg[1], (0, self.lastY))
|
|
|
|
|
self.lastY += cardImg[0].size[1]
|
|
|
|
|
self.lastY = 0
|
|
|
|
|
|
|
|
|
|
def makeCard(self, card):
|
|
|
|
|
# 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)
|
|
|
|
|
arcsize = 25
|
|
|
|
|
padding = 3*arcsize/8
|
|
|
|
|
cardLastY = 0
|
|
|
|
|
card_wt = int(self.wt / self.width)
|
|
|
|
|
arcsize = 20 #23
|
|
|
|
|
offset = 10 #15
|
|
|
|
|
padding = 8
|
|
|
|
|
#padding = 5*arcsize/16 + offset
|
|
|
|
|
card_wt = int(self.wt)
|
|
|
|
|
card_ht = int(self.ht)*5
|
|
|
|
|
self.cardLastY = 0 + offset + padding
|
|
|
|
|
|
|
|
|
|
self.cardLastY = 0
|
|
|
|
|
card_image = Image.new('1', (card_wt, card_ht), 255)
|
|
|
|
|
card_draw = ImageDraw.Draw(card_image)
|
|
|
|
|
self.drawText(card.name, self.font1, card_draw, card_image, card_wt, padding)
|
|
|
|
|
self.drawText(card.description, self.font3, card_draw, card_image, card_wt, padding)
|
|
|
|
|
roundRect(card_draw, (2, 2), (card_wt-3, self.cardLastY+padding+4), arcsize)
|
|
|
|
|
card_image = card_image.crop((0, 0, card_wt, self.cardLastY+padding+4+1))
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
card_ht = self.cardLastY+padding
|
|
|
|
|
|
|
|
|
|
mask_image = Image.new('1', (card_wt, card_ht+1), 255)
|
|
|
|
|
mask_draw = ImageDraw.Draw(mask_image)
|
|
|
|
|
|
|
|
|
|
roundRect(card_draw, (offset, offset), (card_wt-offset, card_ht), arcsize, 'outline')
|
|
|
|
|
roundRect(mask_draw, (offset, offset), (card_wt-offset, card_ht), arcsize, 'fill')
|
|
|
|
|
|
|
|
|
|
card_image = card_image.crop((0, 0, card_wt, card_ht+1))
|
|
|
|
|
mask_image = ImageOps.invert(mask_image.convert('L'))
|
|
|
|
|
|
|
|
|
|
card_image.save("card_image.bmp")
|
|
|
|
|
self.cardLastY = 0
|
|
|
|
|
return card_image
|
|
|
|
|
return card_image, mask_image
|
|
|
|
|
|
|
|
|
|
def drawText(self, text, font, draw, ima, card_wt, padding):
|
|
|
|
|
sizex, sizey = textBox(text, font, (0+padding, self.cardLastY+ 2*padding/3 ),
|
|
|
|
|
(card_wt-padding, ima.size[1]), "black", draw)
|
|
|
|
|
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)
|
|
|
|
|
# find predicted height of textbox and set lastY to it
|
|
|
|
|
self.cardLastY += sizey + 4
|
|
|
|
|
self.cardLastY += sizey
|
|
|
|
|
|
|
|
|
|
def cardsFromBoard(self, boardName, listName):
|
|
|
|
|
cards = []
|
|
|
|
|
|