-
Notifications
You must be signed in to change notification settings - Fork 0
/
unicodewidget.py
executable file
·61 lines (47 loc) · 1.82 KB
/
unicodewidget.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
from rgbmatrix import RGBMatrix, RGBMatrixOptions
from widget import Widget
from PIL import Image, ImageDraw, ImageFont
import unicodedata
import re
class UnicodeWidget(Widget):
def __init__(self,x=0,y=0,color=(255,255,255),size=32,width=64,height=64):
super(UnicodeWidget,self).__init__(x,y,color,size,width,height)
self.font = ImageFont.truetype("TwitterColorEmoji-SVGinOT.ttf",self.size)
# self.font = ImageFont.truetype("NotoColorEmoji.ttf",109,0)
self.text = None
def update(self,t=None,description=None):
if description != None:
try:
t = unicodedata.lookup(description)
except KeyError:
print("symbol "+description+" not found")
t = None
# if re.search("[Tt]ree",description):
# self.color=(0,255,0)
# elif re.search("[sS]un",description):
# self.color=(255,255,0)
# elif re.search("[rR]ain",description):
# self.color=(64,64,255)
if t == None:
return
if (self.text != t):
self.image = Image.new("RGBA",(self.width,self.height))
draw = ImageDraw.Draw(self.image)
draw.text((self.x,self.y),t,font=self.font,fill=self.color)
self.text = t
self.changed = True
else:
self.changed = False
if __name__ == "__main__":
options = RGBMatrixOptions()
options.rows = 64
options.cols = 64
matrix = RGBMatrix(options = options)
while True:
u = UnicodeWidget(size=16,color=(255,0,0))
u.update(description=input("symbol:"))
if (u.changed):
im = Image.new("RGBA",(64,64))
im.alpha_composite(u.image)
matrix.SetImage(im.convert("RGB"))