Macro ExpandTreeItem/fr: Difference between revisions

From FreeCAD Documentation
(Created page with "{{Macro/fr|Icon=Macro ExpandTreeItem|Name=Macro ExpandTreeItem|Name/fr=Macro ExpandTreeItem|Description=Cette macro déroule les item sélectionnés.|Author=wmayer, UR_|Versio...")
(Created page with "Déroule/enroule les items sélectionnés")
Line 3: Line 3:
==Description==
==Description==


Déroule/enroule les items sélectionnés
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

Revision as of 18:26, 13 July 2018

File:Macro ExpandTreeItem Macro ExpandTreeItem

Description
Cette macro déroule les item sélectionnés.

Version macro : 00.00
Date dernière modification : 2018-07-11
Auteur: wmayer, UR_
Auteur
wmayer, UR_
Téléchargement
None
Liens
Version Macro
00.00
Dernière modification
2018-07-11
Version(s) FreeCAD
None
Raccourci clavier
None
Voir aussi
None

Description

Déroule/enroule les items sélectionnés

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

if there is no selection all trees are collapse True/False

Use

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

Script

The icon for the tool bar the .png and the .SVG

# -*- 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
# if there is no selection all trees are collapse True / False
#
__Title__    = "Macro ExpandTreeItem"
__Author__   = "wmayer, UR_"
__Version__  = "00.00"
__Date__     = "2018-07-11"

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()
    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?

Other languages: