Moved stream to new view model
This commit is contained in:
parent
f106c2ecba
commit
5fb200eefe
1 changed files with 18 additions and 28 deletions
|
|
@ -60,44 +60,34 @@ def index():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
##### TESTING CLASS STUFFS ######
|
##### Basic microscope view ######
|
||||||
class MicroscopeView(MethodView):
|
class MicroscopeView(MethodView):
|
||||||
|
|
||||||
def __init__(self, microscope_obj):
|
def __init__(self, microscope):
|
||||||
self.microscope_obj = microscope_obj
|
|
||||||
|
|
||||||
|
|
||||||
class TestAPI(MicroscopeView):
|
|
||||||
|
|
||||||
def get(self):
|
|
||||||
"""
|
"""
|
||||||
Get method for my cool new MethodView
|
Create a generic MethodView with a globally available
|
||||||
|
microscope object passed as an argument.
|
||||||
"""
|
"""
|
||||||
return jsonify(self.microscope_obj.state)
|
self.microscope = microscope
|
||||||
|
|
||||||
def post(self):
|
|
||||||
"""
|
|
||||||
Post method for my cool new MethodView
|
|
||||||
"""
|
|
||||||
return jsonify(request.get_json())
|
|
||||||
|
|
||||||
app.add_url_rule('/test', view_func=TestAPI.as_view('test', microscope_obj=microscope))
|
|
||||||
|
|
||||||
# Define API routes
|
# Define API routes
|
||||||
|
|
||||||
# Basic routes
|
# Basic views
|
||||||
|
|
||||||
@app.route(uri('/stream'))
|
class StreamAPI(MicroscopeView):
|
||||||
def stream():
|
def get(self):
|
||||||
"""Video streaming route. Put this in the src attribute of an img tag."""
|
"""
|
||||||
global microscope
|
Video streaming route. Put this in the src attribute of an img tag.
|
||||||
|
"""
|
||||||
|
# Restart stream worker thread
|
||||||
|
microscope.camera.start_worker()
|
||||||
|
|
||||||
# Restart stream worker thread
|
return Response(
|
||||||
microscope.camera.start_worker()
|
gen(self.microscope.camera),
|
||||||
|
mimetype='multipart/x-mixed-replace; boundary=frame')
|
||||||
|
|
||||||
|
app.add_url_rule(uri('/stream'), view_func=StreamAPI.as_view('stream', microscope=microscope))
|
||||||
|
|
||||||
return Response(
|
|
||||||
gen(microscope.camera),
|
|
||||||
mimetype='multipart/x-mixed-replace; boundary=frame')
|
|
||||||
|
|
||||||
@app.route(uri('/state'))
|
@app.route(uri('/state'))
|
||||||
def state():
|
def state():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue