Responding to other user events from a tree control

In this section, we'll discuss the properties of the wx.TreeEvent class. Table 15.6 lists those properties.

Table 15.6 Properties of wx.TreeEvent

Property

Description

GetKeyCode()

Returns the integer key code of the key pressed. Only valid for the event type wx.evt_tree_key_down. This property will not tell you if any modifier keys were also pressed.

GetItem()

Returns the wx.TreeItemId of the item which is the subject of the event.

Responding to other user events 479

from a tree control

Table 15.6 Properties of wx.TreeEvent (continued)

Property

Description

GetKeyEventO

Only valid for wx.evt_tree_key_down events. Returns the underlying wx.KeyEvent being wrapped by the wx.TreeEvent. This key event will be able to tell you if modifier keys, such as shift or command, were pressed during the event.

GetLabel()

Returns the current text label of the item. Valid for the wx.EVT_TREE_BEGIN_LABEL_EDIT and wx.EVT_TREE_END_LABEL_EDIT.

GetPoint()

Returns a wx.Point of the mouse position for the event. Only valid for the drag events.

IsEditCancelledO

Only valid for a wx.evt_tree_end_label_edit action. Returns a Boolean— True if the current edit ended with a user cancel, and False otherwise.

SetToolTip(tooltip)

Only valid for the wx.evt_tree_item_gettooltip event. Allows you to set the tooltip for the item. This property only works on Windows systems.

Table 15.7 lists a few event types for the wx.TreeEvent that didn't fit into any of the previous sections, but that may be useful at some point.

Table 15.7 Other event types for the tree control

Event type

Description

wx.EVT_TREE_BEGIN_DRAG

This event is triggered when the user starts to drag a tree item with the left mouse button pressed. In order for the drag to actually do anything, the event handler must explictly call the event method Allow().

wx.EVT_TREE_BEGIN_RDRAG

This event is triggered when the user starts to drag a tree item with the right mouse button pressed (on Macintosh systems, this means a control-click). In order for the drag to actually do anything, the event handler must explictly call the event method Allow().

wx.EVT_TREE_ITEM_ACTIVATED

Triggered when an item is activated by a user double-click.

wx.EVT_TREE_ITEM_GETTOOLTIP

This event is sent when the mouse hovers over an item in the tree, and can be used to set a tooltip that is specific to that item. Simply set the label parameter in the event object and the system will take care of the rest.

wx.EVT_TREE_KEY_DOWN

This event is sent when a key is pressed while the tree control has the focus.

That's most of what you need to know about the tree control proper. We'll close off the chapter with a useful variant of the control that you can also use.

Was this article helpful?

0 0

Post a comment