forked from stemplePI/ledBoard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tKinterGrid.py
82 lines (58 loc) · 1.78 KB
/
tKinterGrid.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import tkinter as tk
import threading
newKeys = []
heldKeys = []
keyLock = threading.Lock()
memGrid = [[0 for i in range(8)]for i in range(8)]
bttnGrid = [[]for i in range(8)]
def startup():
global bttnGrid, canvas
window = tk.Tk()
window.title("YS LED Board Emulator")
bttnGrid = [[0 for x in range(8)] for y in range(8)]
canvas = tk.Canvas(width=400, height=400, bg="blue")
for y in range(8):
for x in range(8):
bttnGrid[x][y] = canvas.create_rectangle(
x*50, (7-y)*50, x*50+50, (7-y)*50+50, fill='#000000', outline='#FFFFFF')
canvas.bind("<Button-1>", lambda a: bttnPress(a))
canvas.bind("<ButtonRelease-1>", lambda a: bttnRelease(a))
canvas.pack()
def block():
try:
tk.mainloop()
except KeyboardInterrupt:
setCol()
def drawGrid(grid):
for y, row in enumerate(grid):
for x, val in enumerate(row):
drawPixel(x, y, val)
stripShow()
def drawPixel(x, y, c):
memGrid[y][x] = c
def setCol(c=0, n=range(384)):
for x in range(8):
for y in range(8):
drawPixel(x, y, c)
stripShow()
def stripShow():
global canvas
for y, row in enumerate(memGrid):
for x, val in enumerate(row):
canvas.itemconfigure(bttnGrid[y][x], fill="#{:06x}".format(val))
def readKeys():
"""Returns newly pressed keys, as well as all keys being held
(List newKeys, List pressedKeys)"""
with keyLock:
global newKeys
locNewKeys = newKeys
newKeys = []
return(locNewKeys, heldKeys)
def bttnPress(a):
with keyLock:
newKeys.append((7-int(a.y/50), int(a.x/50)))
heldKeys.append((7-int(a.y/50), int(a.x/50)))
def bttnRelease(a):
with keyLock:
global heldKeys
heldKeys = []