Controlling visibility

There are a number of methods that allow you to manage which items are visible within the display. An object may be not visible either because it has been scrolled off the visible part of its containing frame or because it is part of a child list that is collapsed. You can determine whether an item is visible on the screen with the IsVisible(item) method which returns True if the item is visible, and False if it is not. You can force an item to become visible by using the method Ensure-Visible(item). This method forces the item to become visible by expanding the item's parent (and its parent, and so on) if needed, and then scrolling the tree to put the item in the visible part of the control. If you only need to do the scrolling portion, use the method ScrollTo(item) to manage the task.

Iterate through the visible items in the tree starting with the method Get-FirstVisibleItem(). This method returns the wx.TreeItemId of the topmost item in the visible portion of the display. To iterate through the display, use the method GetNextVisible(item) passing it the previously used item returned from GetFirstVisibleItem() or GetNextVisible(). This method returns the wx.Tree-ItemId of the item following the one passed to the method (meaning the next lowest row in the display) regardless of nesting or depth. To move upward in the list, use the method GetPreviousVisible(item). If the item is not visible, then an invalid item is returned.

There are a few other methods that affect the visible display of items in the tree. The tree control has a property that sets the number of pixels that are indented by the control at each new level. Get the current value of that property with GetIndent(), and set it with SetIndent(indent), where indent is the integer value of the number of pixels to indent new levels.

Get information about the tree item at a specific point using the method Hit-Test(point), where point is a wx.Point of a location in the tree control. The return value is a tuple (item, flags) where item is the wx.TreeItemId of the item at that point, or None. If there is no item at that point, then an invalid item will be returned which can be tested by calling its IsOk() method. The flags portion of the result is a bitmask with several possible values giving extra information about the location being tested. Table 15.5 contains a complete list of flags.

There are a couple of methods that allow you to deal with the actual boundaries of the items on the screen. The method GetBoundingRect(item, text-Only=False) returns a wx.Rect instance corresponding to the bounding rectangle of the text item on the screen. The item parameter is the wx.TreeItemId of the item in question. If the textOnly parameter is True then the rectangle only includes the area covered by the item's display text. If the parameter is False,

Table 15.5 Valid hit test flags for the tree control

Hit Test Flag

Description

wx.TREE_HITTEST_ABOVE

The point is above the tree's client area and not part of any item.

wx.TREE_HITTEST_BELOW

The point is below the tree's client area and is not part of any item.

wx.TREE_HITTEST_NOWHERE

The point is within the tree's client area, but is still not part of any item.

wx.TREE_HITTEST_ONITEMBUTTON

The point is on the expand/contract icon button which is part of the item.

wx.TREE_HITTEST_ONITEMICON

The point is on the image portion of the item.

wx.TREE_HITTEST_ONITEMINDENT

The point is in the indent area to the left of the display text of the item.

wx.TREE_HITTEST_ONITEMLABEL

The point is in the display text of the item.

wx.TREE_HITTEST_ONITEMRIGHT

The point is to the right of the display text of the item.

wx.TREE_HITTEST_ONITEMSTATEICON

The point is in the state icon for the item.

wx.TREE_HITTEST_TOLEFT

The point is to the left of the tree's client area and is not part of any item.

wx.TREE_HITTEST_TORIGHT

The point is to the right of the tree's client area and is not part of any item.

then the rectangle also includes the image displayed with the rectangle. In neither case does the rectangle include the blank area from the edge of the tree control to the beginning of a nested display item. If the item is not currently visible, then the method returns None.

Was this article helpful?

+2 0

Post a comment