Static type analysis
This commit is contained in:
parent
3aebb8bead
commit
7866ec0f47
63 changed files with 1825 additions and 2722 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import io
|
||||
import logging
|
||||
from typing import Dict, Optional, Tuple
|
||||
|
||||
from flask import send_file
|
||||
from labthings import Schema, fields, find_component
|
||||
|
|
@ -42,12 +43,14 @@ class CaptureAPI(ActionView):
|
|||
"""
|
||||
microscope = find_component("org.openflexure.microscope")
|
||||
|
||||
resize = args.get("resize", None)
|
||||
if resize:
|
||||
resize = (
|
||||
int(resize["width"]),
|
||||
int(resize["height"]),
|
||||
resize_dict: Optional[Dict[str, int]] = args.get("resize", None)
|
||||
if resize_dict:
|
||||
resize: Optional[Tuple[int, int]] = (
|
||||
int(resize_dict["width"]),
|
||||
int(resize_dict["height"]),
|
||||
) # Convert dict to tuple
|
||||
else:
|
||||
resize = None
|
||||
|
||||
# Explicitally acquire lock (prevents empty files being created if lock is unavailable)
|
||||
with microscope.camera.lock:
|
||||
|
|
@ -76,12 +79,14 @@ class RAMCaptureAPI(ActionView):
|
|||
"""
|
||||
microscope = find_component("org.openflexure.microscope")
|
||||
|
||||
resize = args.get("resize", None)
|
||||
if resize:
|
||||
resize = (
|
||||
int(resize["width"]),
|
||||
int(resize["height"]),
|
||||
resize_dict: Optional[Dict[str, int]] = args.get("resize", None)
|
||||
if resize_dict:
|
||||
resize: Optional[Tuple[int, int]] = (
|
||||
int(resize_dict["width"]),
|
||||
int(resize_dict["height"]),
|
||||
) # Convert dict to tuple
|
||||
else:
|
||||
resize = None
|
||||
|
||||
# Open a BytesIO stream to be destroyed once request has returned
|
||||
with microscope.camera.lock, io.BytesIO() as stream:
|
||||
|
|
@ -113,15 +118,18 @@ class GPUPreviewStartAPI(ActionView):
|
|||
"""
|
||||
microscope = find_component("org.openflexure.microscope")
|
||||
|
||||
window = args.get("window")
|
||||
logging.debug(window)
|
||||
# Get window argument from request
|
||||
window_arg = args.get("window")
|
||||
logging.debug(window_arg)
|
||||
|
||||
if len(window) != 4:
|
||||
fullscreen = True
|
||||
window = None
|
||||
else:
|
||||
# Default to no window
|
||||
fullscreen: bool = True
|
||||
window: Optional[Tuple[int, int, int, int]] = None
|
||||
|
||||
# If request argument is well formed, use that
|
||||
if len(window_arg) == 4:
|
||||
fullscreen = False
|
||||
window = [int(w) for w in window]
|
||||
window = (int(w) for w in window_arg)
|
||||
|
||||
microscope.camera.start_preview(fullscreen=fullscreen, window=window)
|
||||
return microscope.state
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import logging
|
||||
from typing import List, Tuple
|
||||
|
||||
from labthings import fields, find_component
|
||||
from labthings.views import ActionView
|
||||
|
|
@ -24,11 +25,11 @@ class MoveStageAPI(ActionView):
|
|||
|
||||
# Handle absolute positioning (calculate a relative move from current position and target)
|
||||
if (args.get("absolute")) and (microscope.stage): # Only if stage exists
|
||||
target_position = axes_to_array(args, ["x", "y", "z"])
|
||||
target_position: List[int] = axes_to_array(args, ["x", "y", "z"])
|
||||
logging.debug("TARGET: %s", (target_position))
|
||||
position = [
|
||||
position: Tuple[int, int, int] = (
|
||||
target_position[i] - microscope.stage.position[i] for i in range(3)
|
||||
]
|
||||
)
|
||||
logging.debug("DELTA: %s", (position))
|
||||
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import subprocess
|
|||
from labthings.views import ActionView
|
||||
|
||||
|
||||
def is_raspberrypi():
|
||||
def is_raspberrypi() -> bool:
|
||||
"""
|
||||
Checks if Raspberry Pi.
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue