-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcore-mobility-studio.py
executable file
·193 lines (151 loc) · 4.81 KB
/
core-mobility-studio.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/python3
# core-mobility-studio
# Written by Lars Baumgaertner (c) 2017-2021
#
# requirements: tkinter, idle, appjar
#
# Installation on Ubuntu:
# $ apt-get install python-tk idle python-pip
# $ pip install appjar
# import the library
import subprocess
import subprocess
import shlex
from appJar import gui
from coreposlib import *
import os
script_path = os.path.abspath(os.path.dirname(__file__))
play_process = None
def check_process():
global play_process
if play_process != None:
app.setStatusbar("Status: running", 2)
play_process.poll()
if play_process.returncode != None:
change_state("normal", "")
play_process = None
else:
app.setStatusbar("Status: stopped", 2)
def get_filename():
f = app.getEntry("Filename")
if f == "":
app.errorBox("Error", "Please enter filename.")
return f
def get_delay():
d_entry = app.getEntry("Delay")
if d_entry == "":
return ""
try:
d = float(d_entry)
return " -d " + d_entry
except ValueError:
app.warningBox(
"Delay in seconds", "Please enter only valid float numbers. Ignoring value for now!")
return ""
cur_step = 0
total_steps = 0
def get_total_number_of_steps():
f = get_filename()
if f != "":
s_list = get_session()
if len(s_list) != 1:
print("Error: Need excatly one running session!\n")
sys.exit()
node_map = get_nodes(s_list[0])
scenario = load_posfile(f, node_map, s_list[0])
return len(scenario["step_list"])
def press_file(btn):
global cur_step
filepath = app.saveBox(
fileTypes=[("Position Files", "*.pos"), ("All Files", "*.*")])
print(filepath)
app.setEntry("Filename", filepath)
cur_step = 0
update_steps()
press_step_move("|<")
def update_steps():
global total_steps
total_steps = get_total_number_of_steps()
app.setStatusbar("Steps: " + str(cur_step) + "/" + str(total_steps), 1)
def press_record(btn):
print("pressed: ", btn)
filepath = get_filename()
if filepath != "":
cmd = script_path + "/core-record.py -f " + filepath
print(cmd)
subprocess.getstatusoutput(cmd)
update_steps()
print("done recording step")
def change_state(newstate, except_btn):
btns = ["Playback", "Loop", "Record Step", "|<", "<", ">", ">|"]
for i in btns:
if i != except_btn:
app.setButtonState(i, newstate)
def press_playback(btn):
global play_process
print("pressed: ", btn)
filepath = get_filename()
if play_process != None:
play_process.kill()
play_process = None
change_state("normal", btn)
else:
if filepath != "":
cmd = script_path + "/core-automator.py -f " + filepath + get_delay()
print(cmd)
args = shlex.split(cmd)
play_process = subprocess.Popen(args)
change_state("disabled", btn)
def press_loop(btn):
global play_process
print("pressed: ", btn)
if play_process != None:
play_process.kill()
play_process = None
change_state("normal", btn)
else:
filepath = get_filename()
if filepath != "":
cmd = script_path + "/core-automator.py -l -f " + filepath + get_delay()
args = shlex.split(cmd)
play_process = subprocess.Popen(args)
change_state("disabled", btn)
def press_step_move(btn):
global cur_step, total_steps
# print "pressed: ", btn , total_steps
if btn == "|<":
cur_step = 0
elif btn == ">|":
cur_step = total_steps - 1
elif btn == "<":
if cur_step > 0:
cur_step -= 1
elif btn == ">":
if cur_step < (total_steps - 1):
cur_step += 1
filepath = get_filename()
if filepath != "":
cmd = script_path + "/core-automator.py -f " + \
filepath + " -s " + str(cur_step)
subprocess.getstatusoutput(cmd)
app.setStatusbar("Steps: " + str(cur_step+1) +
"/" + str(total_steps), 1)
# top slice - CREATE the GUI
app = gui("CORE Mobility Studio")
### fillings go here ###
app.addLabelEntry("Filename", 1, 0)
app.addButton("Select File", press_file, 1, 1)
app.addHorizontalSeparator(2, 0, 2)
app.addLabelEntry("Delay", 3, 0)
app.addHorizontalSeparator(4, 0, 2)
app.addButtons(["Playback", "Loop"], [press_playback, press_loop], 5, 0, 2)
app.addButtons(["|<", "<", ">", ">|"], [press_step_move,
press_step_move, press_step_move, press_step_move], 6, 0, 2)
app.addHorizontalSeparator(7, 0, 2)
app.addButton("Record Step", press_record, 8, 0, 2)
app.addStatusbar(fields=3)
# background jobs
app.setPollTime(500)
app.registerEvent(check_process)
# bottom slice - START the GUI
app.go()