forked from IV2FI/DrawBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
53 lines (44 loc) · 1.44 KB
/
utils.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
from pynput.mouse import Controller, Button, Listener
from queue import Queue
import os
mouse = Controller()
queue = Queue()
clicked = 0
start = 0
def getPalette(app):
if app == 0:
app = "garticPhone"
elif app == 1:
app = "skribbl"
elif app == 2:
app = "paint"
else:
app = "gartic"
coordinatesFile = os.path.dirname(os.path.abspath(__file__)) + "\\colorPalettes\\" + app + "Coordinates.txt"
colorFiles = os.path.dirname(os.path.abspath(__file__)) + "\\colorPalettes\\" + app + "Colors.txt"
coordinates = [tuple(int(i) for i in t.strip('()').split(',')) for t in open(coordinatesFile).read().split()]
colors = [int(t) for t in open(colorFiles).read().split()]
return [colors, coordinates]
def getMouseCoordinatesOnce(x, y, button, pressed):
if not pressed:
return False
queue.put((x,y))
def getMouseCoordinatesTwice(x, y, button, pressed):
global clicked
global start
if pressed and button == Button.left:
clicked += 1
if clicked == 1 :
start = (x,y)
elif clicked == 2:
clicked = 0
queue.put([start, (x,y)])
return False
def getNextMouseClickPositionCoordinates():
listener = Listener(on_click=getMouseCoordinatesOnce)
listener.start()
return queue.get()
def getBounds():
listener = Listener(on_click=getMouseCoordinatesTwice)
listener.start()
return queue.get()