phoenix_title wx.ItemContainer

This class is an abstract base class for some wxWidgets controls which contain several items such as wx.ListBox, wx.CheckListBox, wx.ComboBox or wx.Choice.

It defines an interface which is implemented by all controls which have string subitems each of which may be selected.

wx.ItemContainer extends wx.ItemContainerImmutable interface with methods for adding/removing items.

It defines the methods for accessing the controls items and although each of the derived classes implements them differently, they still all conform to the same interface.

The items in a wx.ItemContainer have (non-empty) string labels and, optionally, client data associated with them. Client data may be of two different kinds: either simple untyped ( void ) pointers which are simply stored by the control but not used in any way by it, or typed pointers (wxClientData) which are owned by the control meaning that the typed client data (and only it) will be deleted when an item is deleted using Delete or the entire control is cleared using Clear, which also happens when it is destroyed.

Finally note that in the same control all items must have client data of the same type (typed or untyped), if any. This type is determined by the first call to Append (the version with client data pointer) or SetClientData.

Note that this is not a control, it’s a mixin interface that classes have to derive from in addition to wx.Control or wx.Window. Convenience class wx.ControlWithItems is provided for this purpose.


class_hierarchy Class Hierarchy

Inheritance diagram for class ItemContainer:

method_summary Methods Summary

Append

Appends item into the control.

AppendItems

Clear

Removes all items from the control.

Delete

Deletes an item from the control.

DetachClientObject

Returns the client object associated with the given item and transfers its ownership to the caller.

GetClientData

Returns a pointer to the client data associated with the given item (if any).

GetClientObject

Alias for GetClientData

GetItems

HasClientData

Returns True, if either untyped data ( void* ) or object data (wxClientData) is associated with the items of the control.

HasClientObjectData

Returns True, if object data is associated with the items of the control.

HasClientUntypedData

Returns True, if untyped data ( void* ) is associated with the items of the control.

Insert

Inserts item into the control.

Set

Replaces the current control contents with the given items.

SetClientData

Associates the given typed client data pointer with the given item: the data object will be deleted when the item is deleted (either explicitly by using Delete or implicitly when the control itself is destroyed).

SetClientObject

Alias for SetClientData

SetItems


property_summary Properties Summary

Items

See GetItems and SetItems


api Class API

class wx.ItemContainer(ItemContainerImmutable)

This class is an abstract base class for some wxWidgets controls which contain several items such as ListBox, CheckListBox, ComboBox or Choice.


Methods

Append(self, *args, **kw)

overload Overloaded Implementations:



Append (self, item)

Appends item into the control.

Parameters

item (string) – String to add.

Return type

int

Returns

The return value is the index of the newly inserted item. Note that this may be different from the last one if the control is sorted (e.g. has LB_SORT or CB_SORT style).



Append (self, item, clientData)

Appends item into the control.

Parameters
  • item (string) – String to add.

  • clientData (ClientData) – Pointer to client data to associate with the new item.

Return type

int

Returns

The return value is the index of the newly inserted item. Note that this may be different from the last one if the control is sorted (e.g. has LB_SORT or CB_SORT style).



Append (self, items)

Appends several items at once into the control.

Notice that calling this method is usually much faster than appending them one by one if you need to add a lot of items.

Parameters

items (list of strings) – Array of strings to insert.

Return type

int





AppendItems(self, items)


Clear(self)

Removes all items from the control.

Clear also deletes the client data of the existing items if it is owned by the control.



Delete(self, n)

Deletes an item from the control.

The client data associated with the item will be also deleted if it is owned by the control. Note that it is an error (signalled by an assert failure in debug builds) to remove an item with the index negative or greater or equal than the number of items in the control.

If there is a currently selected item below the item being deleted, i.e. if GetSelection returns a valid index greater than or equal to n, the selection is invalidated when this function is called. However if the selected item appears before the item being deleted, the selection is preserved unchanged.

Parameters

n (int) – The zero-based item index.

See also

Clear



DetachClientObject(self, n)

Returns the client object associated with the given item and transfers its ownership to the caller.

This method, unlike GetClientObject , expects the caller to delete the returned pointer. It also replaces the internally stored pointer with None, i.e. completely detaches the client object pointer from the control.

It’s an error to call this method unless HasClientObjectData returns True.

Parameters

n (int) – The zero-based item index.

Return type

ClientData

Returns

The associated client object pointer to be deleted by caller or None.

New in version 2.9.2.



GetClientData(self, n)

Returns a pointer to the client data associated with the given item (if any).

It is an error to call this function for a control which doesn’t have typed client data at all although it is wx.OK to call it even if the given item doesn’t have any client data associated with it (but other items do).

Notice that the returned pointer is still owned by the control and will be deleted by it, use DetachClientObject if you want to remove the pointer from the control.

Parameters

n (int) – The zero-based position of the item.

Return type

ClientData

Returns

A pointer to the client data, or None if not present.



GetClientObject(self, n)

Alias for GetClientData



GetItems(self)


HasClientData(self)

Returns True, if either untyped data ( void* ) or object data (wxClientData) is associated with the items of the control.

Return type

bool



HasClientObjectData(self)

Returns True, if object data is associated with the items of the control.

Object data pointers have the type ClientData* instead of void* and, importantly, are owned by the control, i.e. will be deleted by it, unlike their untyped counterparts.

Return type

bool



HasClientUntypedData(self)

Returns True, if untyped data ( void* ) is associated with the items of the control.

Return type

bool



Insert(self, *args, **kw)

overload Overloaded Implementations:



Insert (self, item, pos)

Inserts item into the control.

Parameters
  • item (string) – String to add.

  • pos (int) – Position to insert item before, zero based.

Return type

int

Returns

The return value is the index of the newly inserted item. If the insertion failed for some reason, -1 is returned.



Insert (self, item, pos, clientData)

Inserts item into the control.

Parameters
  • item (string) – String to add.

  • pos (int) – Position to insert item before, zero based.

  • clientData (ClientData) – Pointer to client data to associate with the new item.

Return type

int

Returns

The return value is the index of the newly inserted item. If the insertion failed for some reason, -1 is returned.



Insert (self, items, pos)

Inserts several items at once into the control.

Notice that calling this method is usually much faster than inserting them one by one if you need to insert a lot of items.

Parameters
  • items (list of strings) – Array of strings to insert.

  • pos (int) – Position to insert the items before, zero based.

Return type

int

Returns

The return value is the index of the last inserted item. If the insertion failed for some reason, -1 is returned.





Set(self, items)

Replaces the current control contents with the given items.

Notice that calling this method is usually much faster than appending them one by one if you need to add a lot of items.

Parameters

items (list of strings) – Array of strings to insert.



SetClientData(self, n, data)

Associates the given typed client data pointer with the given item: the data object will be deleted when the item is deleted (either explicitly by using Delete or implicitly when the control itself is destroyed).

Note that it is an error to call this function if any untyped client data pointers had been associated with the control items before.

Parameters
  • n (int) – The zero-based item index.

  • data (ClientData) – The client data to associate with the item.



SetClientObject(self, n, data)

Alias for SetClientData



SetItems(self, items)

Properties

Items

See GetItems and SetItems