Moved eV GUI stuff out of LabThings
This commit is contained in:
parent
3fef94dc95
commit
eeb15453d0
5 changed files with 169 additions and 33 deletions
41
openflexure_microscope/api/utilities/gui.py
Normal file
41
openflexure_microscope/api/utilities/gui.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import copy
|
||||
import logging
|
||||
from functools import wraps
|
||||
|
||||
|
||||
def expand_routes_from_dict(gui_description, extension_object):
|
||||
api_gui = copy.deepcopy(gui_description)
|
||||
if "forms" in gui_description and isinstance(api_gui["forms"], list):
|
||||
for form in api_gui["forms"]:
|
||||
if "route" in form and form["route"] in extension_object._rules.keys():
|
||||
form["route"] = extension_object._rules[form["route"]]["rule"]
|
||||
else:
|
||||
logging.warn(
|
||||
"No valid expandable route found for {}".format(form["route"])
|
||||
)
|
||||
return api_gui
|
||||
|
||||
|
||||
def expand_routes_from_func(func, extension_object):
|
||||
@wraps(func)
|
||||
def wrapped(*args, **kwargs):
|
||||
return expand_routes_from_dict(func(*args, **kwargs), extension_object)
|
||||
|
||||
return wrapped
|
||||
|
||||
|
||||
def expand_routes(gui_description, extension_object):
|
||||
# If given a function that generates a GUI dictionary
|
||||
if callable(gui_description):
|
||||
# Wrap in the route expander
|
||||
return expand_routes_from_func(gui_description, extension_object)
|
||||
# If given a dictionary directly
|
||||
elif isinstance(gui_description, dict):
|
||||
# Build a GUI generator function
|
||||
def gui_description_func():
|
||||
return gui_description
|
||||
|
||||
# Wrap in the route expander
|
||||
return expand_routes_from_func(gui_description_func, extension_object)
|
||||
else:
|
||||
raise RuntimeError("GUI description must be a function or a dictionary")
|
||||
Loading…
Add table
Add a link
Reference in a new issue