Skip to content

Commit 94def95

Browse files
author
PolygonalTree
committed
add error if the rois is empty when start is clicked
1 parent 684f975 commit 94def95

File tree

4 files changed

+50
-42
lines changed

4 files changed

+50
-42
lines changed

DesktopApp/desktopApp.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import urllib.request as urllib
22
import urllib.parse as parse
3-
import sys, time, subprocess, paramiko
3+
import sys, time, subprocess
44
import view, socket, webbrowser
55
import threading
66
from PySide import QtCore, QtGui
@@ -73,7 +73,7 @@ class ControlMainWindow(QtGui.QMainWindow):
7373

7474
autosave = AutoSaveData()
7575

76-
def __init__(self, parent=None):
76+
def __init__(self, localIp,parent=None):
7777
super(ControlMainWindow, self).__init__(parent)
7878
self.ui = view.Ui_MainWindow()
7979
self.ui.setupUi(self)
@@ -167,13 +167,17 @@ def askPiId(device, port):
167167
piId=f.read()
168168
return piId
169169

170-
171-
172-
173-
174-
if __name__ == "__main__":
170+
171+
def main():
175172
localIp = socket.gethostbyname(str(socket.gethostname())).split('.')
176173
app = QtGui.QApplication(sys.argv)
177-
mySW = ControlMainWindow()
174+
mySW = ControlMainWindow(localIp)
178175
mySW.show()
179176
sys.exit(app.exec_())
177+
178+
179+
180+
if __name__ == "__main__":
181+
main()
182+
183+

server.py

+21-23
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import bottle
21
from bottle import *
32

43
import db
54
from subprocess import Popen, PIPE, call
6-
import os, signal, time, json
5+
from os import path, kill
6+
from signal import SIGTERM
7+
import json
78

8-
basedir=os.path.dirname(__file__)
9+
basedir=path.dirname(__file__)
910

1011
app = Bottle()
1112

12-
outputfile = os.path.join(basedir,"output.txt")
13+
outputfile = path.join(basedir,"output.txt")
1314

1415

1516
class RoiData():
@@ -20,18 +21,17 @@ def __init__(self):
2021

2122
@app.route('/static/<filepath:path>')
2223
def server_static(filepath):
23-
return static_file(filepath, root=os.path.join(basedir,"static"))
24+
return static_file(filepath, root=path.join(basedir,"static"))
2425

2526
@app.route('/')
2627
def index():
27-
print(os.path.dirname(__file__))
2828
mid= checkMachineId()
2929
_,status = checkPid()
3030
df = subprocess.Popen(["df", "./"], stdout=subprocess.PIPE)
3131
output = df.communicate()[0]
3232
device, size, used, available, percent, mountpoint = \
3333
output.split(b"\n")[1].split()
34-
return template(os.path.join(basedir+"/views","index.tpl"), machineId=mid, status=status, freeSpace = percent)
34+
return template(path.join(basedir+"/views","index.tpl"), machineId=mid, status=status, freeSpace = percent)
3535

3636
@app.route('/websocket')
3737
def handle_websocket():
@@ -74,9 +74,7 @@ def list_roi():
7474
@app.post('/changeMachineId')
7575
def changeMachineId():
7676
try:
77-
print("changing name")
7877
name = request.json
79-
print(name)
8078
changeMId(name['newName'])
8179
return(name['newName'])
8280
except:
@@ -89,27 +87,26 @@ def starStop():
8987
try:
9088
data = request.json
9189
t = data['time']
92-
print(t)
9390
#set time, given in miliseconds from javascript, used in seconds for date
9491
setTime = call(['date', '-s', '@'+str(t)[:-3]])
9592
except:
9693
print ("no data")
9794
pid, isAlreadyRunning = checkPid()
9895

9996
if isAlreadyRunning:
100-
os.kill(pid,signal.SIGTERM)
97+
kill(pid,SIGTERM)
10198
else:
10299
db.writeMask(data)
103100
#f = open('mask.msk','wb')
104101
#pickle.dump(data['roi'], f)
105102
#f.close()
106-
pySolo = Popen(["python2",os.path.join(basedir,"pvg_standalone.py"),
107-
"-c", os.path.join(basedir,"pysolo_video.cfg"),
103+
pySolo = Popen(["python2",path.join(basedir,"pvg_standalone.py"),
104+
"-c", path.join(basedir,"pysolo_video.cfg"),
108105
"-i","0",
109106
"-k", "mask.msk",
110107
"-t", str(data['trackingType']),
111108
"-o", outputfile,
112-
"--showmask",
109+
"--showmask",#useful?
113110
"--trackonly"])
114111

115112
#pySolo = Popen(["python2", "pvg.py"])# -c pysolo_video.cfg -i 0 -k mask.msk -t 0 -o output.txt", shell=True)
@@ -123,11 +120,12 @@ def state():
123120
def refresh():
124121
pid, isAlreadyRunning = checkPid()
125122
if isAlreadyRunning:
126-
#add a call to a function to update snapshot
123+
#add a call to a function to update snapshot when trackingType
124+
#for now, do nothing
127125
pass
128126
else:
129-
pySolo = call(["python2",os.path.join(basedir,"pvg_standalone.py"),
130-
"-c", os.path.join(basedir,"pysolo_video.cfg"),
127+
pySolo = call(["python2",path.join(basedir,"pvg_standalone.py"),
128+
"-c", path.join(basedir,"pysolo_video.cfg"),
131129
"-i","0",
132130
"--snapshot",])
133131
redirect("/")
@@ -140,8 +138,8 @@ def downloadData(machineID):
140138
pid, isAlreadyRunning = checkPid()
141139
mid = checkMachineId()
142140
if mid == machineID:
143-
#Add a "last downloaded" and "free space available"
144-
return static_file(outputfile, root='')
141+
#TODO:Add a "last downloaded"
142+
return static_file(outputfile, root='/', download=outputfile)
145143
else:
146144
redirect("/")
147145

@@ -185,7 +183,7 @@ def poweroff(machineID):
185183

186184
def checkPid():
187185
proc = Popen(["pgrep", "-f",
188-
"python2 "+os.path.join(basedir,"pvg_standalone.py")]
186+
"python2 "+path.join(basedir,"pvg_standalone.py")]
189187
, stdout=PIPE)
190188
try:
191189
pid=int(proc.stdout.readline())
@@ -197,13 +195,13 @@ def checkPid():
197195
return pid, started
198196

199197
def changeMId(name):
200-
f = open(os.path.join(basedir,'machineId'),'w')
198+
f = open(path.join(basedir,'machineId'),'w')
201199
piId = f.write(name)
202200
f.close()
203201
return True
204202

205203
def checkMachineId():
206-
f = open(os.path.join(basedir,'machineId'),'r')
204+
f = open(path.join(basedir,'machineId'),'r')
207205
piId = f.read().rstrip()
208206
f.close()
209207
return piId
@@ -217,7 +215,7 @@ def readData():
217215
lastData = lines[-1]
218216
splitedData = lastData.split('\t')
219217
jsonData = json.dumps(splitedData)
220-
print (jsonData)
218+
#print (jsonData)
221219
return jsonData
222220

223221
"""The main program"""

static/js/main.js

+15-9
Original file line numberDiff line numberDiff line change
@@ -300,15 +300,21 @@ function ev_start(){
300300
var tracking = $('input[name=optionTrack]:checked').val();
301301
var d = new Date();
302302
var t = d.getTime();
303-
var data = JSON.stringify({time:t,trackingType:tracking,roi:RoiObj});
304-
var oReq = new XMLHttpRequest();
305-
oReq.open("put", "/started", false);
306-
oReq.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
307-
oReq.send(data);
308-
console.log("start");
309-
console.log(t);
310-
console.log(data);
311-
location.reload();
303+
if (RoiObj.rois.length<1){
304+
alert("There is no ROI selected. You can't start tracking.");
305+
}else if (typeof tracking == 'undefined'){
306+
alert("There is no tracking type selected. You can't start tracking.");
307+
}else{
308+
var data = JSON.stringify({time:t,trackingType:tracking,roi:RoiObj});
309+
var oReq = new XMLHttpRequest();
310+
oReq.open("put", "/started", false);
311+
oReq.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
312+
oReq.send(data);
313+
console.log("start");
314+
console.log(t);
315+
console.log(data);
316+
location.reload();
317+
}
312318

313319
}
314320
/// Stop

views/index.tpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@
113113
<div class="track-select">
114114
<div class="input-group"><label>
115115
<input type="radio" name="optionTrack" id="optionTrack0" value="0">
116-
Position</label>
116+
Virtual Beam</label>
117117

118118
</div>
119119
<div class="input-group ">
120120
<input type="radio" name="optionTrack" id="optionTrack1" value="1">
121-
<label>Distance</label>
121+
<label>Distance Walked</label>
122122
</div>
123123
<div class="input-group">
124124
<input type="radio" name="optionTrack" id="optionTrack2" value="2">

0 commit comments

Comments
 (0)