Thanks Edward and Thomas.

Btw, do we need to put Leo's Qt Widget hierarchy Code
<https://groups.google.com/g/leo-editor/c/bKb4e3WiY4E/m/E2zLEQUYCAAJ> to
the doc? I believe it is very useful.

I let AI add some nice `|` or `-`, it works, but it remove Edward's useful
'if 1, else' part 🤭

```python
# Clear the console
g.cls()

# Global total counter for the number of objects processed
total = 0

# Function to get the name of a widget
def w_name(w):
    name = w.objectName() or 'no name'
    return f"<{name}>:{w.__class__.__name__}"

# Function to print information about a widget
def dump(tag, w, level=0, is_last=True, prefix=""):
    global total
    total += 1
    connector = "└── " if is_last else "├── "
    indent = prefix + connector
    print(f"{id(w):<14} lvl {level:2}: {indent}{tag}:{w_name(w)}")
    prefix += "    " if is_last else "│   "
    return prefix

# Function to recursively dump children of a widget
def dump_children(w, level=0, prefix=""):
    wanted_classes = (
        'DynamicWindow', 'Frame', 'Layout',
        'Splitter', 'Stacked', 'Text', 'Widget'
    )
    children = [child for child in w.children()
                if any(cls in child.__class__.__name__ for cls in
wanted_classes)]
    for i, child in enumerate(children):
        is_last = (i == len(children) - 1)
        new_prefix = dump(f"child {i}", child, level + 1, is_last, prefix)
        dump_children(child, level + 1, new_prefix)

# Function to perform a full dump starting from a widget
def full_dump(tag, w):
    print(f"\nFull dump of {w_name(w)} at {id(w)}...\n")
    dump(tag, w, level=0, is_last=True)
    dump_children(w, level=0)


full_dump('c.frame.top.parent()', c.frame.top.parent())
print(f"\ntotal objects: {total}")
```

*Here is the output:*

```
6176345456     lvl  0: └──
c.frame.top.parent():<qt_tabwidget_stackedwidget>:QStackedWidget
6176345616     lvl  1: ├── child 0:<no name>:QStackedLayout
5375113840     lvl  1: └── child 1:<MainWindow>:DynamicWindow
6176345776     lvl  2:     ├── child 0:<_layout>:QLayout
5375113360     lvl  2:     └── child 1:<centralwidget>:QWidget
5375113040     lvl  3:         ├── child 0:<main_splitter>:QSplitter
5375106960     lvl  4:         │   ├── child 0:<bodyFrame>:QFrame
5375107120     lvl  5:         │   │   ├── child 0:<innerBodyFrame>:QFrame
5375107280     lvl  6:         │   │   │   ├── child
0:<bodyStackedWidget>:QStackedWidget
6176346256     lvl  7:         │   │   │   │   ├── child 0:<no
name>:QStackedLayout
5375105840     lvl  7:         │   │   │   │   └── child
1:<bodyPage2>:QWidget
5375105680     lvl  8:         │   │   │   │       ├── child
0:<bodyVLayout>:QVBoxLayout
5375105200     lvl  8:         │   │   │   │       └── child 1:<no
name>:LeoLineTextWidget
5375103760     lvl  9:         │   │   │   │           ├── child 0:<no
name>:QHBoxLayout
5375106320     lvl  9:         │   │   │   │           └── child
1:<richTextEdit>:LeoQTextBrowser
5375103440     lvl 10:         │   │   │   │               ├── child
0:<qt_scrollarea_viewport>:QWidget
6176346416     lvl 10:         │   │   │   │               ├── child
1:<qt_scrollarea_hcontainer>:QWidget
6176346896     lvl 11:         │   │   │   │               │   └── child
0:<no name>:QBoxLayout
6176346736     lvl 10:         │   │   │   │               └── child
2:<qt_scrollarea_vcontainer>:QWidget
6176346896     lvl 11:         │   │   │   │                   └── child
0:<no name>:QBoxLayout
5375105520     lvl  6:         │   │   │   └── child
1:<bodyInnerGrid>:QGridLayout
5375105360     lvl  5:         │   │   └── child 1:<bodyGrid>:QGridLayout
5375112880     lvl  4:         │   ├── child
1:<secondary_splitter>:QSplitter
5375114800     lvl  5:         │   │   ├── child 0:<logFrame>:QFrame
5375111760     lvl  6:         │   │   │   ├── child
0:<logInnerFrame>:QFrame
5375111920     lvl  7:         │   │   │   │   ├── child
0:<logTabWidget>:QTabWidget
6176346736     lvl  8:         │   │   │   │   │   └── child
0:<qt_tabwidget_stackedwidget>:QStackedWidget
6175371216     lvl  9:         │   │   │   │   │       ├── child
0:<LeoQuickSearchWidget>:LeoQuickSearchWidget
6175371376     lvl 10:         │   │   │   │   │       │   ├── child
0:<verticalLayout_2>:QVBoxLayout
6175371536     lvl 11:         │   │   │   │   │       │   │   └── child
0:<verticalLayout>:QGridLayout
6175372016     lvl 10:         │   │   │   │   │       │   └── child
1:<listWidget>:QListWidget
6176346576     lvl 11:         │   │   │   │   │       │       ├── child
0:<qt_scrollarea_viewport>:QWidget
6176347216     lvl 11:         │   │   │   │   │       │       ├── child
1:<qt_scrollarea_hcontainer>:QWidget
6176347696     lvl 12:         │   │   │   │   │       │       │   └──
child 0:<no name>:QBoxLayout
6176347056     lvl 11:         │   │   │   │   │       │       └── child
2:<qt_scrollarea_vcontainer>:QWidget
6176348016     lvl 12:         │   │   │   │   │       │           └──
child 0:<no name>:QBoxLayout
6175361616     lvl  9:         │   │   │   │   │       ├── child
1:<LeoTagWidget>:LeoTagWidget
6175361136     lvl 10:         │   │   │   │   │       │   ├── child
0:<nodetags-verticalLayout_2>:QVBoxLayout
6175370256     lvl 11:         │   │   │   │   │       │   │   └── child
0:<nodetags-verticalLayout>:QVBoxLayout
6175369456     lvl 12:         │   │   │   │   │       │   │       ├──
child 0:<nodetags-horizontalLayout>:QHBoxLayout
6175369936     lvl 12:         │   │   │   │   │       │   │       └──
child 1:<nodetags-horizontalLayout2>:QHBoxLayout
6175370736     lvl 10:         │   │   │   │   │       │   └── child
1:<nodetags-listWidget>:QListWidget
6176347056     lvl 11:         │   │   │   │   │       │       ├── child
0:<qt_scrollarea_viewport>:QWidget
6176346576     lvl 11:         │   │   │   │   │       │       ├── child
1:<qt_scrollarea_hcontainer>:QWidget
6176348016     lvl 12:         │   │   │   │   │       │       │   └──
child 0:<no name>:QBoxLayout
6176347216     lvl 11:         │   │   │   │   │       │       └── child
2:<qt_scrollarea_vcontainer>:QWidget
6176347536     lvl 12:         │   │   │   │   │       │           └──
child 0:<no name>:QBoxLayout
6176346896     lvl  9:         │   │   │   │   │       ├── child 2:<no
name>:QStackedLayout
5375110000     lvl  9:         │   │   │   │   │       ├── child
3:<spellTab>:QWidget
5375110160     lvl 10:         │   │   │   │   │       │   ├── child
0:<spellVLayout>:QVBoxLayout
5375110320     lvl 10:         │   │   │   │   │       │   └── child
1:<spellFrame>:QFrame
5375110480     lvl 11:         │   │   │   │   │       │       ├── child
0:<spellVLayout>:QVBoxLayout
5375110640     lvl 12:         │   │   │   │   │       │       │   └──
child 0:<spellGrid>:QGridLayout
5375107600     lvl 11:         │   │   │   │   │       │       └── child
1:<leo_spell_listBox>:QListWidget
6176346576     lvl 12:         │   │   │   │   │       │           ├──
child 0:<qt_scrollarea_viewport>:QWidget
6176347216     lvl 12:         │   │   │   │   │       │           ├──
child 1:<qt_scrollarea_hcontainer>:QWidget
6176347696     lvl 13:         │   │   │   │   │       │           │   └──
child 0:<no name>:QBoxLayout
6176347056     lvl 12:         │   │   │   │   │       │           └──
child 2:<qt_scrollarea_vcontainer>:QWidget
6176347696     lvl 13:         │   │   │   │   │       │               └──
child 0:<no name>:QBoxLayout
6176090352     lvl  9:         │   │   │   │   │       ├── child 4:<no
name>:LeoQTextBrowser
6176348016     lvl 10:         │   │   │   │   │       │   ├── child
0:<qt_scrollarea_viewport>:QWidget
6176347856     lvl 10:         │   │   │   │   │       │   ├── child
1:<qt_scrollarea_hcontainer>:QWidget
6176347216     lvl 11:         │   │   │   │   │       │   │   └── child
0:<no name>:QBoxLayout
6176346576     lvl 10:         │   │   │   │   │       │   └── child
2:<qt_scrollarea_vcontainer>:QWidget
6176347216     lvl 11:         │   │   │   │   │       │       └── child
0:<no name>:QBoxLayout
5374261072     lvl  9:         │   │   │   │   │       └── child
5:<log-widget>:LeoQTextBrowser
6176348016     lvl 10:         │   │   │   │   │           ├── child
0:<qt_scrollarea_viewport>:QWidget
6176347856     lvl 10:         │   │   │   │   │           ├── child
1:<qt_scrollarea_hcontainer>:QWidget
6176346576     lvl 11:         │   │   │   │   │           │   └── child
0:<no name>:QBoxLayout
6176347696     lvl 10:         │   │   │   │   │           └── child
2:<qt_scrollarea_vcontainer>:QWidget
6176346576     lvl 11:         │   │   │   │   │               └── child
0:<no name>:QBoxLayout
5375111120     lvl  7:         │   │   │   │   └── child
1:<logInnerGrid>:QGridLayout
5375111280     lvl  6:         │   │   │   └── child 1:<logGrid>:QGridLayout
5375112240     lvl  5:         │   │   ├── child 1:<outlineFrame>:QFrame
5375112080     lvl  6:         │   │   │   ├── child
0:<outlineInnerFrame>:QFrame
5375111600     lvl  7:         │   │   │   │   ├── child
0:<treeWidget>:LeoQTreeWidget
6176346736     lvl  8:         │   │   │   │   │   ├── child
0:<qt_scrollarea_viewport>:QWidget
6176346896     lvl  8:         │   │   │   │   │   ├── child
1:<qt_scrollarea_hcontainer>:QWidget
6176348016     lvl  9:         │   │   │   │   │   │   └── child 0:<no
name>:QBoxLayout
6176346576     lvl  8:         │   │   │   │   │   └── child
2:<qt_scrollarea_vcontainer>:QWidget
6176348016     lvl  9:         │   │   │   │   │       └── child 0:<no
name>:QBoxLayout
4660528464     lvl  7:         │   │   │   │   └── child
1:<outlineInnerGrid>:QGridLayout
4660528624     lvl  6:         │   │   │   └── child
1:<outlineGrid>:QGridLayout
6176346256     lvl  5:         │   │   ├── child
2:<qt_splithandle_>:QSplitterHandle
6176346416     lvl  5:         │   │   └── child
3:<qt_splithandle_>:QSplitterHandle
6176346096     lvl  4:         │   ├── child
2:<qt_splithandle_>:QSplitterHandle
6176345936     lvl  4:         │   └── child
3:<qt_splithandle_>:QSplitterHandle
5375112560     lvl  3:         ├── child 1:<mainVLayout>:QVBoxLayout
5375103600     lvl  3:         └── child 2:<minibufferFrame>:QFrame
5375101680     lvl  4:             └── child
0:<minibufferHLayout>:QHBoxLayout

total objects: 90
```

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/CA%2BUQrQwirLFSNrPD3xothzBjoSWVFs4w70%2Bch4KheNr_53e3jg%40mail.gmail.com.

Reply via email to