-
Notifications
You must be signed in to change notification settings - Fork 6
/
icons.py
47 lines (36 loc) · 1.18 KB
/
icons.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
from PIL import Image
from includes.epd import Epd
from includes.icon import Icon
from includes.text import Text
import spidev as SPI
import os, time
WHITE = 1
BLACK = 0
DISPLAY_TYPE = 'EPD_2X9'
ICON_SIZE = 100
def main():
bus, device = 0, 0
spi = SPI.SpiDev(bus, device)
display = Epd(spi, DISPLAY_TYPE)
print('--> Init and clear full screen %s' % display.size)
display.clearDisplayPart()
while True:
for file in os.listdir("./png-icons/%d/" % ICON_SIZE):
if file.endswith(".png"):
# display width and height
height, width = display.size
# canvas to draw to
image = Image.new('1', display.size, WHITE)
# add icon to canvas
icon = Icon(image, os.path.join(("./png-icons/%d/" % ICON_SIZE), file))
print("--> Prepare PNG: %s (size: %d x %d)" % (file, icon.width, icon.height))
# add text beside the icon
text = Text(width-128, height, file)
image.paste(text.image, (0, 128, 128, 296), mask=BLACK)
# send image to display
display.showImageFull(display.imageToPixelArray(image))
time.sleep(2)
display.clearDisplayPart()
# main
if "__main__" == __name__:
main()