-
Notifications
You must be signed in to change notification settings - Fork 0
/
clear_layout.py
41 lines (31 loc) · 1.51 KB
/
clear_layout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
This file is part of the PetalVault password manager distribution. See <https://github.com/F33RNI/PetalVault>.
Copyright (C) 2024 Fern Lane
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see <http://www.gnu.org/licenses/>.
"""
import logging
from typing import Any
from PyQt6.QtWidgets import QLayout
def clear_layout(layout: QLayout | Any) -> None:
"""Recursively removes all widgets and layouts from parent
Args:
layout (QLayout): parent layout
"""
logging.debug(f"Clearing layout: {layout}")
for i in reversed(range(layout.count())):
layout_item = layout.itemAt(i)
if layout_item.widget() is not None:
widget_to_remove = layout_item.widget()
logging.debug(f"Found child widget: {widget_to_remove}")
widget_to_remove.setParent(None)
layout.removeWidget(widget_to_remove)
elif layout_item.spacerItem() is None:
layout_to_remove = layout.itemAt(i)
logging.debug(f"Found child layout: {layout_to_remove}")
clear_layout(layout_to_remove)