Removed redundant imports

This commit is contained in:
Joel Collins 2019-01-09 16:19:06 +00:00
parent 783cc05ac9
commit 1aad10c71b
6 changed files with 20 additions and 23 deletions

View file

@ -18,7 +18,7 @@ from flask import (
from flask.views import MethodView
from werkzeug.exceptions import default_exceptions
from openflexure_microscope.api.utilities import parse_payload, get_from_payload, gen, get_bool, list_routes
from openflexure_microscope.api.utilities import list_routes
from openflexure_microscope import Microscope, config
from openflexure_microscope.camera.pi import StreamingCamera

View file

@ -1,4 +1,4 @@
from openflexure_microscope.api.utilities import parse_payload, get_from_payload, gen, get_bool
from openflexure_microscope.api.utilities import gen
from openflexure_microscope.api.v1.views import MicroscopeView
from flask import Response, Blueprint, jsonify

View file

@ -1,4 +1,4 @@
from openflexure_microscope.api.utilities import parse_payload, get_from_payload, gen, get_bool
from openflexure_microscope.api.utilities import gen, get_bool, JsonPayload
from openflexure_microscope.api.v1.views import MicroscopeView
from flask import Response, Blueprint, jsonify, request, abort, url_for, redirect, send_file
@ -97,14 +97,13 @@ class ListAPI(MicroscopeView):
:<header Content-Type: application/json
:status 200: capture created
"""
state = parse_payload(request)
logging.info(state)
payload = JsonPayload(request)
filename = get_from_payload(state, 'filename', default=None)
keep_on_disk = bool(get_from_payload(state, 'keep_on_disk', default=True))
use_video_port = bool(get_from_payload(state, 'use_video_port', default=False))
filename = payload.param('filename')
keep_on_disk = payload.param('keep_on_disk', default=True, convert=bool)
use_video_port = payload.param('use_video_port', default=False, convert=bool)
resize = get_from_payload(state, 'size', default=None)
resize = payload.param('size', default=None)
if resize:
if ('width' in resize) and ('height' in resize):
resize = (int(resize['width']), int(resize['height'])) # Convert dict to tuple
@ -112,8 +111,8 @@ class ListAPI(MicroscopeView):
abort(400)
output = self.microscope.camera.new_image(
write_to_file=True,
keep_on_disk=keep_on_disk,
write_to_file=True,
keep_on_disk=keep_on_disk,
filename=filename)
self.microscope.camera.capture(

View file

@ -1,4 +1,3 @@
from openflexure_microscope.api.utilities import parse_payload, get_from_payload, gen, get_bool
from openflexure_microscope.api.v1.views import MicroscopeView
from flask import Response, Blueprint, jsonify, request, abort, url_for, redirect, send_file

View file

@ -1,4 +1,3 @@
from openflexure_microscope.api.utilities import parse_payload, get_from_payload, gen, get_bool
from openflexure_microscope.api.v1.views import MicroscopeViewPlugin
from flask import Response, Blueprint, jsonify

View file

@ -1,4 +1,4 @@
from openflexure_microscope.api.utilities import gen, axes_to_array, JsonResponse
from openflexure_microscope.api.utilities import gen, axes_to_array, JsonPayload
from openflexure_microscope.api.v1.views import MicroscopeView
from flask import Response, Blueprint, jsonify, request
@ -56,22 +56,22 @@ class PositionAPI(MicroscopeView):
"""
# Create response object
response = JsonResponse(request)
logging.debug(response.json)
payload = JsonPayload(request)
logging.debug(payload.json)
# Construct position array
position = [0, 0, 0]
# Handle absolute positioning (calculate a relative move from current position and target)
if response.param('absolute') is True:
target_position = axes_to_array(response.json, ['x', 'y', 'z'])
if payload.param('absolute') is True:
target_position = axes_to_array(payload.json, ['x', 'y', 'z'])
logging.debug("TARGET: {}".format(target_position))
position = [target_position[i] - self.microscope.stage.position[i] for i in range(3)]
logging.debug("DELTA: {}".format(position))
else:
# Get coordinates from payload
position = axes_to_array(response.json, ['x', 'y', 'z'], [0, 0, 0])
position = axes_to_array(payload.json, ['x', 'y', 'z'], [0, 0, 0])
logging.debug(position)
@ -128,13 +128,13 @@ class StageParamsAPI(MicroscopeView):
"""
# Get payload
response = JsonResponse(request)
logging.debug(response.json)
payload = JsonPayload(request)
logging.debug(payload.json)
# BACKLASH
if response.param('backlash'):
if payload.param('backlash'):
# Construct backlash array
backlash = axes_to_array(response.param('backlash'), ['x', 'y', 'z'], [0, 0, 0])
backlash = axes_to_array(payload.param('backlash'), ['x', 'y', 'z'], [0, 0, 0])
logging.debug("BACKLASH: {}".format(backlash))
# Apply backlash