/
scriptrunner.py
201 lines (172 loc) · 6.17 KB
/
scriptrunner.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
194
195
196
197
198
199
200
201
__author__ = 'skaper'
# -*- coding: utf-8 -*-
from srunnerForm import Ui_ScriptRunner
from PyQt4 import QtGui
from PyQt4.QtCore import *
from configobj import ConfigObj
import sys, os, serial, time
hotKey=[]
dict={}
key = '!@#$%^&*()_+QWERTYUIOPASDFGHJKLZXCVBNM'
for elem in key:
hotKey.append(elem)
pathToScript = 'scripts/'
robotModel = 'Maya'
runinformation = ConfigObj('logs/run_runscrips.info')
runX = int(runinformation['run'])
runX+=1
timerunX = time.ctime()
runinformation['run'] = runX
runinformation['LastRun'] = timerunX
#Подключение arduino
try:
portLeft = serial.Serial('/dev/arduinoLeft', baudrate=115200, dsrdtr = 1, timeout=1)
except:
print 'Error 1.1: Port /dev/arduinoLeft not found'
try:
portRight = serial.Serial('/dev/arduinoRight', baudrate=115200, dsrdtr = 1, timeout=1)
except:
print 'Error 1.2: Port dev/arduinoRight not found'
try:
portHead = serial.Serial('/dev/arduinoHead', baudrate=115200, dsrdtr = 1, timeout=1)
except:
print 'Error 1.3: Port /dev/arduinoHeadMaya not found'
#time.sleep(3)
#if robotModel=='Maya':
# portHead.write('P1'+'\n')
def playMotionScript(path):
script = ConfigObj(str(path))
print path
headMotionCounterMax = int(script[str(0)])
print headMotionCounterMax
headMotionCounter = 1
while headMotionCounter < headMotionCounterMax:
sending = script[str(headMotionCounter)]
if sending[:1] == 'H':
portHead.write(sending[1:]+'\n')
if sending[:1]== 'R':
portRight.write(sending[1:]+'\n')
if sending[:1] == 'L':
portLeft.write(sending[1:]+'\n')
headMotionCounter +=1
#print headMotionCounter
time.sleep(.025)
class Editor(QtGui.QMainWindow):
def __init__(self):
super(Editor, self).__init__()
self.ui=Ui_ScriptRunner()
self.ui.setupUi(self)
self.loadingProgramm()
self.show()
self.ui.tableScripts.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
self.fillTable()
self.ui.tableScripts.itemPressed.connect(self.pressEtem)
'''
self.ui.ip.setText(str(get_ip_address('wlan2')))
self.ui.wifiHost.clicked.connect(self.wifiHostEvent)
self.ui.robotControl.clicked.connect(self.robotControlEvent)
self.ui.runDemo.clicked.connect(self.runDemoEvent)
self.ui.pushButton_6.clicked.connect(self.pushButton_6Ev)
'''
def fillTable(self):
allFiles = os.listdir(pathToScript)
files1 = filter(lambda x: x.endswith('.scr'), allFiles)
print files1
files = sorted(files1, key = lambda x: os.path.getctime(pathToScript+x))
print files
self.ui.tableScripts.setColumnCount(2)
self.ui.tableScripts.setRowCount(len(files))
for i, f in enumerate(files):
item = QtGui.QTableWidgetItem()
item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)
item.setText(f)
self.ui.tableScripts.setItem(i, 0, item)
#print os.path.getatime(pathToScript+f)
item = QtGui.QTableWidgetItem()
item.setText(hotKey[i])
self.ui.tableScripts.setItem(i, 1, item)
dict[hotKey[i]] = f
print dict
def loadingProgramm(self):
file = range(40)
numberOfLinesInFile = len(file)
progressWasCancelled = False
progress = QtGui.QProgressDialog(
"Parsing Log", "Stop", 0, numberOfLinesInFile, self)
labelLogo = QtGui.QLabel("")
labelLogo.setPixmap(QtGui.QPixmap("img/logorobotcontrol.png"))
progress.setLabel(labelLogo)
progress.setWindowModality(Qt.WindowModal)
progress.setMinimumDuration(0)
for lineNumber, line in enumerate(file):
progress.setValue(lineNumber)
if progress.wasCanceled():
progressWasCancelled = True
break
time.sleep(0.05)
progress.setValue(numberOfLinesInFile)
progress.deleteLater()
def runMotion(self, files, scriptName):
print len(files)
count = 0
while count <= len(files):
print '----------'
if files[count].startswith('delay-'):
print 'delay'
timedelay = files[count].split('-')
try:
delay = int(timedelay[1])
except:
delay = 0
time.sleep(delay)
else:
filenm = scriptName.split('.')[0]
print pathToScript+filenm+'/'+files[count]
playMotionScript(pathToScript+filenm+'/'+files[count])
print files[count]
count +=1
def runScript(self, file):
scriptList = ConfigObj(pathToScript+str(file))
counterMax = int(scriptList[str(0)])
counter = 1
motionFiles = []
while counter<=counterMax:
#print scriptList[str(counter)]
motionFiles.append(scriptList[str(counter)])
counter +=1
#print motionFiles
self.runMotion(motionFiles, file)
def keyPressEvent(self, event):
if type(event) == QtGui.QKeyEvent:
keyPress = event.text()
#keyPress = keyPress.text()
event.accept()
try:
nameFile = dict[str(keyPress)]
print nameFile
self.runScript(nameFile)
except:
print 'no'
else:
event.ignore()
def closeEvent(self, event):
reply = QtGui.QMessageBox.question(self, 'Message',
"Are you sure to quit?", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
event.accept()
runinformation[str(runX)] = timerunX + ' - ' + time.ctime()
runinformation.write()
if robotModel=='Maya':
portHead.write('P0'+'\n')
else:
event.ignore()
def keyUpdate(self):
pass
def pressEtem(self, item):
print item.text()
def main():
app = QtGui.QApplication(sys.argv)
ex = Editor()
sys.exit(app.exec_())
if __name__ == '__main__':
main()