From c56c84aa10de325f1f1da7eba18fde3cc1be77e5 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Thu, 2 Mar 2023 18:29:35 +0100 Subject: [PATCH] added function to generate Device from globals() --- slic/core/device/auto.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 slic/core/device/auto.py diff --git a/slic/core/device/auto.py b/slic/core/device/auto.py new file mode 100644 index 00000000..22cd2ee8 --- /dev/null +++ b/slic/core/device/auto.py @@ -0,0 +1,23 @@ +from ..adjustable import Adjustable +from .device import Device +from .simpledevice import SimpleDevice + + +def auto(globals_dict, ID, **kwargs): + """ + Return a new SimpleDevice with the Adjustables/Devices extracted from globals_dict + globals_dict is expected to be the result of globals() from within ipython + Thus, the intended usage is: + overview = auto(globals(), "Overview") + """ + res = {} + for k, v in globals_dict.items(): + if k.startswith("_"): + continue + if not isinstance(v, (Adjustable, Device)): + continue + res[k] = v + return SimpleDevice(ID, **kwargs, **res) + + +