-
Notifications
You must be signed in to change notification settings - Fork 0
/
paint.py
85 lines (69 loc) · 2.49 KB
/
paint.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
83
84
85
from tkinter import colorchooser,Tk
from drawer import color_symbol
from colored import fg,bg,attr
from console import console
from drawer import canvas
import colorama
import mouse
import time
# ------- create canvas -------
console.set_title("painting") # set console title
console.run_moveable_thread() # run thread that prohibits clicking on the console
win = canvas(64,34) # creating canvas
# ------- create main view -------
def reload():
win.fill(" ",False)
for x in range(62):
win.set(x+1,31,"—",False)
win.set(x+1,0,"_",False)
for y in range(30):
win.set(0,y+1,"|",False)
win.set(63,y+1,"|",False)
for y in range(29):
for x in range(62):
win.set(x+1,y+1," ",False)
for i in btns:
win.set(i[1],i[2],i[0][0],False)
win.write(i[1]+1,i[2],i[0][1:][:-1],False)
win.set(i[1]+len(i[0])-1,i[2],i[0][-1],False)
win.update()
# ------- create buttons -------
btns = []
def btn(text,x,y,cb):
btns.append(["["+text.upper()+"]",x,y+32,cb,False])
btn("CLEAR",1,1,reload)
color = "white"
def choose_color():
global color
Tk().withdraw()
color = colorchooser.askcolor(title="Choose color")[1]
btn("CHOOSE COLOR",10,1,choose_color)
# ------- main loop -------
reload()
run = True
while run:
if win.changed:
win.update()
if console.is_focus():
pos = win.get_mouse_position()
pos = (round(pos[0]),round(pos[1]))
if mouse.is_pressed("left"):
if pos[0] > 1 and pos[1] > 0 and pos[0] < 63 and pos[1] < 31:
win.set(pos[0],pos[1],color_symbol(color))
for i in btns:
if pos[0] >= i[1] and pos[0] <= i[1]+len(i[0]) \
and pos[1] == i[2]+1 and not i[4]:
win.set(i[1],i[2],fg("black")+bg("white")+i[0][0],False)
win.write(i[1]+1,i[2],i[0][1:][:-1],False)
win.set(i[1]+len(i[0])-1,i[2],i[0][-1]+attr("reset"),False)
i[4] = True
elif mouse.is_pressed("right"):
win.set(pos[0],pos[1]," ")
else:
for i in btns:
if i[4]:
win.set(i[1],i[2],i[0][0],False)
win.write(i[1]+1,i[2],i[0][1:][:-1],False)
win.set(i[1]+len(i[0])-1,i[2],i[0][-1],False)
i[4] = False
i[3]()