From 3de68767ad54ab78c01e8249af75369b80295613 Mon Sep 17 00:00:00 2001
From: David Hammer <dhammer@mailbox.org>
Date: Thu, 18 Nov 2021 11:04:04 +0100
Subject: [PATCH] Using *args for child nodes to clean up indentation

---
 src/calng/scenes.py | 267 ++++++++++++++++++++------------------------
 1 file changed, 118 insertions(+), 149 deletions(-)

diff --git a/src/calng/scenes.py b/src/calng/scenes.py
index 12f3136e..1373e022 100644
--- a/src/calng/scenes.py
+++ b/src/calng/scenes.py
@@ -125,11 +125,10 @@ class Space:
 
 
 class HorizontalLayout:
-    def __init__(self, children=None, padding=PADDING):
-        if children is None:
-            self.children = []
-        else:
-            self.children = children
+    def __init__(self, *arg_children, children=None, padding=PADDING):
+        self.children = list(arg_children)
+        if children is not None:
+            self.children.extend(children)
         self.padding = padding
 
     def render(self, x, y, align=Align.TOP):
@@ -165,11 +164,10 @@ class HorizontalLayout:
 
 
 class VerticalLayout:
-    def __init__(self, children=None, padding=PADDING):
-        if children is None:
-            self.children = []
-        else:
-            self.children = children
+    def __init__(self, *arg_children, children=None, padding=PADDING):
+        self.children = list(arg_children)
+        if children is not None:
+            self.children.extend(children)
         self.padding = padding
 
     def render(self, x, y):
@@ -243,7 +241,7 @@ class MaybeEditableRow(HorizontalLayout):
             else:
                 self.children.append(
                     LabelModel(
-                        text=f"Not yet supported: editing {key_path} of type {value_type}",
+                        text=f"Not implemented: editing {value_type} ({key_path})",
                         width=edit_width,
                         height=height,
                     )
@@ -261,23 +259,21 @@ class FoundConstantsColumn(VerticalLayout):
         self.children.extend(
             [
                 HorizontalLayout(
-                    children=[
-                        LabelModel(
-                            text=constant_name,
-                            width=6 * NARROW_INC,
-                            height=NARROW_INC,
-                        ),
-                        ColorBoolModel(
-                            width=NARROW_INC,
-                            height=NARROW_INC,
-                            keys=[f"{device_id}.{prefix}.{constant_name}.found"],
-                        ),
-                        DisplayLabelModel(
-                            keys=[f"{device_id}.{prefix}.{constant_name}.validFrom"],
-                            width=8 * BASE_INC,
-                            height=BASE_INC,
-                        ),
-                    ],
+                    LabelModel(
+                        text=constant_name,
+                        width=6 * NARROW_INC,
+                        height=NARROW_INC,
+                    ),
+                    ColorBoolModel(
+                        width=NARROW_INC,
+                        height=NARROW_INC,
+                        keys=[f"{device_id}.{prefix}.{constant_name}.found"],
+                    ),
+                    DisplayLabelModel(
+                        keys=[f"{device_id}.{prefix}.{constant_name}.validFrom"],
+                        width=8 * BASE_INC,
+                        height=BASE_INC,
+                    ),
                     padding=0,
                 )
                 for constant_name in schema_hash.get(prefix).getKeys()
@@ -340,14 +336,13 @@ class ManagerDeviceStatus(VerticalLayout):
             [
                 name,
                 HorizontalLayout(
-                    children=[
-                        state,
-                        restart_button,
-                    ],
+                    state,
+                    restart_button,
                     padding=0,
                 ),
                 HorizontalLayout(
-                    children=[instantiate_button, apply_button],
+                    instantiate_button,
+                    apply_button,
                     padding=0,
                 ),
                 DeviceSceneLinkModel(
@@ -405,17 +400,13 @@ class CorrectionDeviceStatus(VerticalLayout):
             [
                 name,
                 HorizontalLayout(
-                    children=[
-                        state,
-                        tid,
-                    ],
+                    state,
+                    tid,
                     padding=0,
                 ),
                 HorizontalLayout(
-                    children=[
-                        rate,
-                        processing_time,
-                    ],
+                    rate,
+                    processing_time,
                     padding=0,
                 ),
                 status_log,
@@ -466,20 +457,18 @@ class CompactDeviceLinkList(VerticalLayout):
         self.children.extend(
             [
                 HorizontalLayout(
-                    children=[
-                        DeviceSceneLinkModel(
-                            text=device_id.split("/")[-1],
-                            keys=[f"{device_id}.availableScenes"],
-                            width=7 * BASE_INC,
-                            height=BASE_INC,
-                        ),
-                        DisplayStateColorModel(
-                            show_string=True,
-                            keys=[f"{device_id}.state"],
-                            width=7 * BASE_INC,
-                            height=BASE_INC,
-                        ),
-                    ],
+                    DeviceSceneLinkModel(
+                        text=device_id.split("/")[-1],
+                        keys=[f"{device_id}.availableScenes"],
+                        width=7 * BASE_INC,
+                        height=BASE_INC,
+                    ),
+                    DisplayStateColorModel(
+                        show_string=True,
+                        keys=[f"{device_id}.state"],
+                        width=7 * BASE_INC,
+                        height=BASE_INC,
+                    ),
                     padding=0,
                 )
                 for device_id in device_ids
@@ -517,32 +506,28 @@ def correction_device_overview_scene(device_id, schema):
     schema_hash = schema_to_hash(schema)
 
     return HorizontalLayout(
-        children=[
-            CorrectionDeviceStatus(device_id),
-            VerticalLayout(
-                children=[
-                    recursive_maybe_editable(
-                        device_id,
-                        schema_hash,
-                        "constantParameters",
-                        title="Parameters used for CalCat queries",
-                    ),
-                    DisplayCommandModel(
-                        keys=[f"{device_id}.loadMostRecentConstants"],
-                        width=10 * BASE_INC,
-                        height=BASE_INC,
-                    ),
-                ]
-            ),
-            FoundConstantsColumn(device_id, schema_hash),
+        CorrectionDeviceStatus(device_id),
+        VerticalLayout(
             recursive_maybe_editable(
                 device_id,
                 schema_hash,
-                "corrections",
-                max_depth=2,
-                title="Correction steps",
+                "constantParameters",
+                title="Parameters used for CalCat queries",
             ),
-        ]
+            DisplayCommandModel(
+                keys=[f"{device_id}.loadMostRecentConstants"],
+                width=10 * BASE_INC,
+                height=BASE_INC,
+            ),
+        ),
+        FoundConstantsColumn(device_id, schema_hash),
+        recursive_maybe_editable(
+            device_id,
+            schema_hash,
+            "corrections",
+            max_depth=2,
+            title="Correction steps",
+        ),
     )
 
 
@@ -558,56 +543,44 @@ def manager_device_overview_scene(
     cds_hash = schema_to_hash(correction_device_schema)
 
     return VerticalLayout(
-        children=[
-            HorizontalLayout(
+        HorizontalLayout(
+            ManagerDeviceStatus(manager_device_id),
+            VerticalLayout(
+                recursive_maybe_editable(
+                    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.corrections",
+                max_depth=2,
+            ),
+        ),
+        HorizontalLayout(
+            titled("Correction devices", width=8 * NARROW_INC)(boxed(VerticalLayout))(
                 children=[
-                    ManagerDeviceStatus(manager_device_id),
-                    VerticalLayout(
-                        children=[
-                            recursive_maybe_editable(
-                                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.corrections",
-                        max_depth=2,
-                    ),
+                    CompactCorrectionDeviceOverview(device_id, cds_hash)
+                    for device_id in sorted(correction_device_ids)
                 ],
+                padding=0,
             ),
-            HorizontalLayout(
-                children=[
-                    titled("Correction devices", width=8 * NARROW_INC)(
-                        boxed(VerticalLayout)
-                    )(
-                        children=[
-                            CompactCorrectionDeviceOverview(device_id, cds_hash)
-                            for device_id in sorted(correction_device_ids)
-                        ],
-                        padding=0,
-                    ),
-                    CompactDeviceLinkList(
-                        sorted(
-                            set(domain_device_ids)
-                            - set(correction_device_ids)
-                            - {manager_device_id}
-                        )
-                    ),
-                ]
+            CompactDeviceLinkList(
+                sorted(
+                    set(domain_device_ids)
+                    - set(correction_device_ids)
+                    - {manager_device_id}
+                )
             ),
-        ]
+        ),
     )
 
 
@@ -633,7 +606,6 @@ def recursive_maybe_editable(
         else:
             value_keys.append(key)
     res = titled(title)(boxed(VerticalLayout))(
-        padding=0,
         children=[
             MaybeEditableRow(device_id, schema_hash, f"{prefix}.{key}")
             for key in value_keys
@@ -646,38 +618,35 @@ def recursive_maybe_editable(
             )
             for key in slot_keys
         ],
+        padding=0,
     )
     if depth < max_depth:
-        res.children.extend(
-            [
-                VerticalLayout(
-                    children=[
-                        recursive_maybe_editable(
-                            device_id,
-                            schema_hash,
-                            f"{prefix}.{key}",
-                            depth=depth + 1,
-                            max_depth=max_depth,
-                        )
-                        for key in node_keys
-                    ],
-                )
-            ]
+        res.children.append(
+            VerticalLayout(
+                children=[
+                    recursive_maybe_editable(
+                        device_id,
+                        schema_hash,
+                        f"{prefix}.{key}",
+                        depth=depth + 1,
+                        max_depth=max_depth,
+                    )
+                    for key in node_keys
+                ]
+            )
         )
     else:
         res.children.extend(
             [
                 VerticalLayout(
-                    children=[
-                        DeviceSceneLinkModel(
-                            text=key,
-                            keys=[f"{device_id}.availableScenes"],
-                            target=f"browse_schema:{prefix}.{key}",
-                            target_window=SceneTargetWindow.Dialog,
-                            width=5 * BASE_INC,
-                            height=BASE_INC,
-                        ),
-                    ]
+                    DeviceSceneLinkModel(
+                        text=key,
+                        keys=[f"{device_id}.availableScenes"],
+                        target=f"browse_schema:{prefix}.{key}",
+                        target_window=SceneTargetWindow.Dialog,
+                        width=5 * BASE_INC,
+                        height=BASE_INC,
+                    ),
                 )
                 for key in node_keys
             ]
-- 
GitLab