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.
See also
wx.ControlWithItems, wx.ItemContainerImmutable
wx.Choice, wx.ComboBox, wx.ControlWithItems, wx.ListBox, wx.adv.OwnerDrawnComboBox, wx.html.SimpleHtmlListBox
Appends item into the control. |
|
Alias for |
|
Removes all items from the control. |
|
Deletes an item from the control. |
|
Returns the client object associated with the given item and transfers its ownership to the caller. |
|
Returns a pointer to the client data associated with the given item (if any). |
|
Alias for |
|
Alias for |
|
Returns |
|
Returns |
|
Returns |
|
Inserts item into the control. |
|
Replaces the current control contents with the given items. |
|
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 |
|
Alias for |
|
Alias for |
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.
Append
(self, *args, **kw)¶Append (self, item)
Appends item into the control.
item (string) – String to add.
int
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.
item (string) – String to add.
clientData (ClientData) – Pointer to client data to associate with the new item.
int
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.
items (list of strings) – Array of strings to insert.
int
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.
n (int) – The zero-based item index.
See also
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
.
n (int) – The zero-based item index.
ClientData
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.
n (int) – The zero-based position of the item.
ClientData
A pointer to the client data, or None
if not present.
GetClientObject
(self, n)¶Alias for GetClientData
GetItems
(self)¶Alias for GetStrings
HasClientData
(self)¶Returns True
, if either untyped data ( void*
) or object data (wxClientData) is associated with the items of the control.
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.
bool
HasClientUntypedData
(self)¶Returns True
, if untyped data ( void*
) is associated with the items of the control.
bool
Insert
(self, *args, **kw)¶Insert (self, item, pos)
Inserts item into the control.
item (string) – String to add.
pos (int) – Position to insert item before, zero based.
int
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.
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.
int
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.
items (list of strings) – Array of strings to insert.
pos (int) – Position to insert the items before, zero based.
int
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.
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.
n (int) – The zero-based item index.
data (ClientData) – The client data to associate with the item.
SetClientObject
(self, n, data)¶Alias for SetClientData