Macro ExpandTreeItem: Difference between revisions

From FreeCAD Documentation
(Vertical {{Macro}}; fixed icon)
(Marked this version for translation)
 
(6 intermediate revisions by 5 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
<translate>
<translate>

<!--T:1-->
<!--T:1-->
{{Macro
{{Macro
|Name=Macro ExpandTreeItem
|Name=Macro ExpandTreeItem
|Icon=Macro_ExpandTreeItem.svg
|Description=This macro expands selected tree and all sub trees in the tree view.
|Description=This macro expands selected tree and all sub trees in the tree view.<br/>If there is no selection, all trees are expanded.
|Author=wmayer, UR_
|Author=wmayer, UR_
|Version=00.00
|Version=00.02
|Date=2018-07-11
|Date=2019-07-25
|FCVersion=All
|Download=[https://www.freecadweb.org/wiki/images/9/94/Macro_ExpandTreeItem.svg ToolBar Icon]
}}
}}


Line 16: Line 20:


<!--T:4-->
<!--T:4-->
if selected tree is already expanded this tree and all sub trees are collapsed
if selected tree is already expanded, this tree and all sub trees are collapsed.


<!--T:5-->
<!--T:5-->
if there is no selection all trees are collapse True/False
if there is no selection, all trees are expanded.


<!--T:12-->
<!--T:12-->
[[File:Collapsed00.gif]]
[[File:Collapsed00.gif]]


==Use== <!--T:6-->
==Usage== <!--T:6-->


<!--T:7-->
<!--T:7-->
Line 31: Line 35:
==Script== <!--T:8-->
==Script== <!--T:8-->


<!--T:9-->
<!--T:13-->
The icon for the tool bar the .png [[File:Macro ExpandTreeItem.png]] and the .SVG [[File:Macro ExpandTreeItem.svg]]
ToolBar Icon .PNG [[File:Macro ExpandTreeItem.png]] and the .SVG [[File:Macro ExpandTreeItem.svg]]

</translate>
</translate>
'''Macro_ExpandTreeItem.FCMacro'''


{{MacroCode|code=
'''Macro_ExpandTreeItem.FCMacro
'''
{{Code|code=
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#
#
# Expands selected tree and all sub trees in the tree view.
# Expands selected tree and all sub trees in the tree view.
# if selected tree is already expanded this tree and all sub trees are collapsed
# if selected tree is already expanded this tree and all sub trees are collapsed True/False
# if there is no selection all trees are collapse True / False
# if there is no selection all trees are expanded
#
#
__Title__ = "Macro ExpandTreeItem"
__Title__ = "Macro ExpandTreeItem"
__Author__ = "wmayer, UR_"
__Author__ = "wmayer, UR_"
__Version__ = "00.00"
__Version__ = "00.02"
__Date__ = "2018-07-11"
__Date__ = "2019-07-25"


import PySide
import PySide
Line 76: Line 80:
Gui.Selection.addSelection(obj)
Gui.Selection.addSelection(obj)
items = tree.selectedItems()
items = tree.selectedItems()
for item in items:
toggleAll(tree, item, False)
except Exception:
except Exception:
None
None
Line 86: Line 92:
toggleAll(tree, item, False)
toggleAll(tree, item, False)
# print ("expanding")
# print ("expanding")

}}
}}
<translate>
<translate>

==Link== <!--T:10-->
==Link== <!--T:10-->



Latest revision as of 17:47, 5 December 2021

Other languages:

Macro ExpandTreeItem

Description
This macro expands selected tree and all sub trees in the tree view.
If there is no selection, all trees are expanded.

Macro version: 00.02
Last modified: 2019-07-25
FreeCAD version: All
Download: ToolBar Icon
Author: wmayer, UR_
Author
wmayer, UR_
Download
ToolBar Icon
Links
Macro Version
00.02
Date last modified
2019-07-25
FreeCAD Version(s)
All
Default shortcut
None
See also
None

Description

Expands selected tree and all sub trees in the tree view.

if selected tree is already expanded, this tree and all sub trees are collapsed.

if there is no selection, all trees are expanded.

Usage

Copy the macro in your macro directory, create your tool bar and launch.

Script

ToolBar Icon .PNG and the .SVG

Macro_ExpandTreeItem.FCMacro

# -*- coding: utf-8 -*-
#
# Expands selected tree and all sub trees in the tree view.
# if selected tree is already expanded this tree and all sub trees are collapsed True/False
# if there is no selection all trees are expanded
#
__Title__    = "Macro ExpandTreeItem"
__Author__   = "wmayer, UR_"
__Version__  = "00.02"
__Date__     = "2019-07-25"

import PySide
from PySide import QtGui ,QtCore
from PySide.QtGui import *
from PySide.QtCore import *

def toggleAll(tree, item, collapse):
    if collapse == False:
        tree.expandItem(item)
    elif collapse == True:  
        tree.collapseItem(item)

    for i in range(item.childCount()):
        toggleAll(tree, item.child(i), collapse)

mw = Gui.getMainWindow()
trees = mw.findChildren(QtGui.QTreeWidget)

for tree in trees:
    items = tree.selectedItems()

    try:
        if items == []:
            #tree.selectAll()                          # select all object
            for obj in FreeCAD.ActiveDocument.Objects: # select obj.OutList
                if len(obj.OutList) != 0:
                    Gui.Selection.addSelection(obj)
                    items = tree.selectedItems()
            for item in items:
                toggleAll(tree, item, False)
    except Exception:
        None

    for item in items:
            if item.isExpanded() == True:
                toggleAll(tree, item, True)
        #            print ("collapsing")
            else:
                toggleAll(tree, item, False)
        #            print ("expanding")

Link

Objektbaum mit einem Klick komplett aufklappen?