diff --git a/src/calng/scenes.py b/src/calng/scenes.py index a701f5acdb7bc809af55976541d7a6400104a34c..f9669225c268576626e886fe2cbb3b32559025c2 100644 --- a/src/calng/scenes.py +++ b/src/calng/scenes.py @@ -1,5 +1,6 @@ import enum +import karabo.native import karathon from karabo.common.scenemodel.api import ( CheckBoxModel, @@ -32,6 +33,9 @@ PADDING = 5 RECONFIGURABLE = 4 # TODO: look up proper enum NODE_TYPE_NODE = 1 +_type_to_display_model = { + "BOOL": CheckBoxModel +} _type_to_line_editable = { "BOOL": (CheckBoxModel, {"klass": "EditableCheckBox"}), "DOUBLE": (DoubleLineEditModel, {}), @@ -240,6 +244,10 @@ class MaybeEditableRow(HorizontalLayout): if "displayedName" in key_attr else key_path.split(".")[-1] ) + if "valueType" not in key_attr: + print(f"Key {key_path} on {device_id} had no valueType") + return + value_type = key_attr["valueType"] self.children.extend( [ LabelModel( @@ -247,7 +255,7 @@ class MaybeEditableRow(HorizontalLayout): width=label_width, height=height, ), - DisplayLabelModel( + _type_to_display_model.get(value_type, DisplayLabelModel)( keys=[f"{device_id}.{key_path}"], width=display_width, height=height, @@ -255,9 +263,6 @@ class MaybeEditableRow(HorizontalLayout): ] ) if key_attr["accessMode"] == RECONFIGURABLE: - if "valueType" not in key_attr: - return - value_type = key_attr["valueType"] if "options" in key_attr: self.children.append( ComboBoxModel( @@ -541,6 +546,37 @@ class AssemblerDeviceStatus(VerticalLayout): train_id, padding=0, ), + LabelModel( + text="Image downsampling", + width=14 * BASE_INC, + height=BASE_INC, + ), + HorizontalLayout( + LabelModel( + text="Factor", + width=7 * BASE_INC, + height=BASE_INC, + ), + ComboBoxModel( + keys=[f"{device_id}.downsamplingFactor"], + width=7 * BASE_INC, + height=BASE_INC, + ), + padding=0, + ), + HorizontalLayout( + LabelModel( + text="Function", + width=7 * BASE_INC, + height=BASE_INC, + ), + ComboBoxModel( + keys=[f"{device_id}.downsamplingFunction"], + width=7 * BASE_INC, + height=BASE_INC, + ), + padding=0, + ), DeviceSceneLinkModel( text="I'm actually a TrainMatcher", keys=[f"{device_id}.availableScenes"], @@ -557,7 +593,9 @@ class AssemblerDeviceStatus(VerticalLayout): def schema_to_hash(schema): - if isinstance(schema, karathon.Schema): + if isinstance(schema, (karathon.Hash, karabo.native.Hash)): + return schema + elif isinstance(schema, karathon.Schema): return schema.getParameterHash() else: return schema.hash @@ -589,7 +627,6 @@ def correction_device_overview_scene(device_id, schema): device_id, schema_hash, "constantParameters", - title="Parameters used for CalCat queries", ), DisplayCommandModel( keys=[f"{device_id}.loadMostRecentConstants"], @@ -603,7 +640,6 @@ def correction_device_overview_scene(device_id, schema): schema_hash, "corrections", max_depth=2, - title="Correction steps", ), ) @@ -627,13 +663,18 @@ def manager_device_overview_scene( manager_device_id, mds_hash, "managed.constantParameters", - title="Parameters used for CalCat queries", ), DisplayCommandModel( keys=[f"{manager_device_id}.managed.loadMostRecentConstants"], width=10 * BASE_INC, height=BASE_INC, ), + recursive_maybe_editable( + manager_device_id, + mds_hash, + "managed.preview", + max_depth=2, + ), ), recursive_maybe_editable( manager_device_id, @@ -700,12 +741,19 @@ def simple_assembler_overview(device_id, geometry_device_id): def recursive_maybe_editable( device_id, schema_hash, prefix, depth=1, max_depth=3, title=None ): - if title is None: - title = prefix.split(".")[-1] + schema_hash = schema_to_hash(schema_hash) # note: not just using sets because that loses ordering node_keys = [] value_keys = [] slot_keys = [] + attr = schema_hash.getAttributes(prefix) + + if title is None: + if "displayedName" in attr: + title = attr.get("displayedName") + else: + title = prefix.split(".")[-1] + for key in schema_hash.get(prefix).getKeys(): attrs = schema_hash.getAttributes(f"{prefix}.{key}") if attrs.get("nodeType") == NODE_TYPE_NODE: