-
Notifications
You must be signed in to change notification settings - Fork 0
/
screen-main.py
96 lines (84 loc) · 2.24 KB
/
screen-main.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
86
87
88
89
90
91
92
93
94
95
96
import time
from scrap.util import read_config, wait_till_done, ScrapException, UserInput, read_commands
from comm.serialcomm import SerialComm
from scrap.scrapinterface import ScrapInterface
from scrap.ui import UI
conf_dict = read_config("conf.txt")
# create ScrapInterface
scrap = ScrapInterface(conf_dict)
# create UI
ui = UI(conf_dict)
# start user input thread
userInput = UserInput()
userInput.start()
keepGoing = True
while keepGoing:
# wait a little
#time.sleep(0.05)
ui.performUI()
# make empty command list
parse_inputs = []
# read message; if None, received nothing
user_inp = userInput.returnMessage()
if user_inp != None:
parse_inputs.append(user_inp)
# read UI message
ui_inp = ui.returnMessage()
if ui_inp != None:
parse_inputs.append(ui_inp)
for parse_inp in parse_inputs:
try:
doneYet = False
isFromUI = False
# check if is from UI
print parse_inp
if isinstance(parse_inp,type("")):
if parse_inp.lower() == 'exit':
keepGoing = False
break
if parse_inp.lower() == 'read':
parse_inputs.extend(read_commands("test_print"))
continue
elif isinstance(parse_inp,tuple):
parse_inp = "s {0},{1}".format(parse_inp[0],parse_inp[1])
isFromUI = True
inp = parse_inp.strip()
if inp.lower() == 'r':
wait_till_done(scrap.reset())
doneYet = True
elif inp == 'u':
wait_till_done(scrap.pen_up())
doneYet = True
elif inp == 'U':
wait_till_done(scrap.pen_super_up())
doneYet = True
elif inp.lower() == 'd':
wait_till_done(scrap.pen_down())
doneYet = True
if not doneYet:
comm,coords = inp.split()
coords = coords.strip().split(",")
if len(coords) < 2:
raise ValueError("use a comma to seperate coords")
# do this if NOT from twitch
if not isFromUI:
if comm == 's':
wait_till_done(scrap.set_coords(coords))
pass
elif comm == 'sp':
wait_till_done(scrap.set_coords(coords,passive=True))
pass
# do this if from UI
else:
if comm == 's':
wait_till_done(scrap.set_coords(coords,passive=True))
pass
elif comm == 'r':
wait_till_done(scrap.reset())
pass
except ValueError,e:
print str(e)
except ScrapException,e:
print str(e)
scrap.stop()
time.sleep(0.25)