Tree (hwx.gui)#

class Tree(headers=None, **kwds)#

Bases: Widget

Hierarchical list of items.

Attribute Table#

Name

Type

children

property

header

property

numCols

property

selectionMode

property

Method Table#

Name

Description

add (self, parent=None, text=None, icon=None, **kwds)

Adds a TreeItem to the Tree.

addColumn (self, label, width=-1)

Adds one or more columns to the tree, width pixes wide.

addWidget (self, widget, col, item)

Add any widget to a tree item.

clear (self)

Removes all items from the tree.

collapseAll (self)

Collapses all items.

enableEdit (self, col=None, edit=True)

Makes all tree items or specific tree column to be editable.

ensureItemVisible (self, item)

Scrolls view so this item is visible.

expandAll (self, expanded=True)

Expands (or collapses) all items.

fitColumns (self)

Fit the columns in the tree.

get (self)

Returns the current selected item.

getChildren (self, parent=None)

Overloaded Widget method for ‘children’ property.

getSelected (self)

Returns a list of the selected items.

hideColumn (self, column)

onSelectionChange (self)

remove (self, item)

Removes the specified item from the tree.

removeColumn (self, indices)

Removes columns based on their initial indices.

setColumnWidth (self, column, width)

Set the width of a particular column in a tree.

setSelected (self, items, selected=True, clear=True)

Selects the specified items.

showColumn (self, column)

sort (self, column, ascending)

Example

from hwx import gui

def buildContextMenu(menu, col):
if exTree.getSelected():
   def delete():
      for item in exTree.getSelected():
      exTree.remove(item)
   menu.insertItem('Remove', icon='glyphDeleteStrip-16.png', command=delete)
else:
   def add():
      exTree.add(text=['New-Item_1', "New-item_2"])
   menu.insertItem('Add', icon='glyphPlusStrip-16.png', command=add)

# Create a Tree object, and add different types of data.
# Right click to see to context menu options.
exTree = gui.Tree(headers=["Name", "Value"], onContextMenu=buildContextMenu)
exTree.add(text=['Name', 'Base'])

item1 = exTree.add(text=["Material"])
choices = [("a", "A"), ("b", "B"), ("c", "C")]
combobox = gui.ComboBox(values=choices)
exTree.addWidget(combobox, 1, item1)

item2 = exTree.add(text=["Design Space"])
checkBox = gui.CheckBox()
exTree.addWidget(checkBox, 1, item2)

dialog = gui.Dialog(caption="Tree", children=exTree)
show(dialog)
property selectionMode#

The selection mode. Valid choices are:

  • “single”

  • “extended”

  • “multi”

  • “contiguous”

  • “none”

property children#

Returns all the children of a tree

clear()#

Removes all items from the tree.

add(parent=None, text=None, icon=None, **kwds)#

Adds a TreeItem to the Tree.

Parameters:
  • parent (TreeItem) – A TreeItem to define hierarchy.

  • text (str|list[str]) – Text or List of text that gets displayed in column.

  • icon (str|list[str]) – Absolute path of the icon or a list of icons.

Returns:

the added TreeItem.

Return type:

TreeItem

remove(item)#

Removes the specified item from the tree.

Parameters:

item (TreeItem) – Item to be removed.

get()#

Returns the current selected item.

getSelected()#

Returns a list of the selected items.

setSelected(items, selected=True, clear=True)#

Selects the specified items.

Parameters:
  • items (list[TreeItem]) – list of TreeItems to be selected.

  • selected (bool) – Determines if items will be selected or not.

  • clear (bool) – Determines if al previously selected items will be cleared or not.

expandAll(expanded=True)#

Expands (or collapses) all items.

Parameters:

expanded (bool) – Determines whether to expand or not.

collapseAll()#

Collapses all items.

ensureItemVisible(item)#

Scrolls view so this item is visible.

Parameters:

item (TreeItem) – TreeItem to make visible.

getChildren(parent=None)#

Overloaded Widget method for ‘children’ property.

addColumn(label, width=-1)#

Adds one or more columns to the tree, width pixes wide.

All columns apart from the first one are inserted to the right of the existing ones. If width is negative, the new column’s width is set to maximum.

Parameters:
  • label (str|list[str]) – Name of the column.

  • width (int|list[int]) – How wide each column is in pixels.

Returns:

The indices of the new columns.

Return type:

list[int]

removeColumn(indices)#

Removes columns based on their initial indices.

Parameters:

indices (int|list[int]) –

enableEdit(col=None, edit=True)#

Makes all tree items or specific tree column to be editable.

Parameters:
  • col (int) – Column index needs to be make editable.

  • edit (bool) – If True, column is editable else not.

addWidget(widget, col, item)#

Add any widget to a tree item.

Parameters:
  • widget (gui.Widget) – Widget needs to be inserted.

  • col (int) – Column index of TreeItem in which widget needs to be inserted.

  • item (TreeItem) – TreeItem in which widget needs to be inserted.

fitColumns()#

Fit the columns in the tree.

setColumnWidth(column, width)#

Set the width of a particular column in a tree.

Parameters:
  • column (int) – Column index of tree.

  • width (int) – Width of the column.

property header#

Column labels of the tree.

property numCols: int#

The number of columns in the tree.