wx.VListBox¶
wx.VListBox is a ListBox-like control with the following two main differences from a regular wx.ListBox: it can have an arbitrarily huge number of items because it doesn’t store them itself but uses the OnDrawItem
callback to draw them (so it is a virtual listbox) and its items can have variable height as determined by OnMeasureItem
(so it is also a listbox with the lines of variable height).
Also, as a consequence of its virtual nature, it doesn’t have any methods to append or insert items in it as it isn’t necessary to do it: you just have to call SetItemCount
to tell the control how many items it should display. Of course, this also means that you will never use this class directly because it has pure virtual functions, but will need to derive your own class from it (for example, wx.html.HtmlListBox).
However it emits the same events as wx.ListBox and the same event macros may be used with it. Since wx.VListBox does not store its items itself, the events will only contain the index, not any contents such as the string of an item.
See also
Class Hierarchy¶
Known Subclasses¶
Methods Summary¶
Default constructor, you must call |
|
Deletes all items from the control. |
|
Creates the control. |
|
Deselects all the items in the listbox. |
|
Returns the index of the first selected item in the listbox or |
|
Get the number of items in the control. |
|
Returns the rectangle occupied by this item in physical coordinates. |
|
Returns the margins used by the control. |
|
Returns the index of the next selected item or |
|
Returns the number of the items currently selected. |
|
Get the currently selected item or |
|
Returns the background colour used for the selected cells. |
|
Returns |
|
Returns |
|
Returns |
|
This method is used to draw the item’s background and, maybe, a border around it. |
|
The derived class must implement this function to actually draw the item with the given index on the provided DC. |
|
This method may be used to draw separators between the lines. |
|
The derived class must implement this method to return the height of the specified item (in pixels). |
|
Selects or deselects the specified item which must be valid (i.e. not equal to |
|
Selects all the items in the listbox. |
|
Selects all items in the specified range which may be given in any order. |
|
Set the number of items to be shown in the control. |
|
Set the margins: horizontal margin is the distance between the window border and the item contents while vertical margin is half of the distance between items. |
|
Set the selection to the specified item, if it is -1 the selection is unset. |
|
Sets the colour to be used for the selected cells background. |
|
Toggles the state of the specified item, i.e. selects it if it was unselected and deselects it if it was selected. |
Properties Summary¶
See |
|
See |
|
See |
|
See |
|
Class API¶
- class wx.VListBox(VScrolledWindow)¶
Possible constructors:
VListBox() -> None VListBox(parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=0, name=VListBoxNameStr) -> None
VListBox is a ListBox-like control with the following two main differences from a regular ListBox: it can have an arbitrarily huge number of items because it doesn’t store them itself but uses the OnDrawItem() callback to draw them (so it is a virtual listbox) and its items can have variable height as determined by OnMeasureItem() (so it is also a listbox with the lines of variable height).
Methods¶
- __init__(self, *args, **kw)¶
-
__init__ (self)
Default constructor, you must call
Create
later.- Return type:
None
__init__ (self, parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=0, name=VListBoxNameStr)
Normal constructor which calls
Create
internally.- Parameters:
- Return type:
None
- Clear(self)¶
Deletes all items from the control.
- Return type:
None
- Create(self, parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=0, name=VListBoxNameStr)¶
Creates the control.
To finish creating it you also should call
SetItemCount
to let it know about the number of items it contains.The only special style which may be used with wx.VListBox is
LB_MULTIPLE
which indicates that the listbox should support multiple selection.
- DeselectAll(self)¶
Deselects all the items in the listbox.
This method is only valid for multi selection listboxes.
- Return type:
bool
- Returns:
True
if any items were changed, i.e. if there had been any selected items before, orFalse
if all the items were already deselected.
- static GetClassDefaultAttributes(variant=WINDOW_VARIANT_NORMAL)¶
- Parameters:
variant (WindowVariant)
- Return type:
- GetFirstSelected(self)¶
Returns the index of the first selected item in the listbox or
NOT_FOUND
if no items are currently selected.cookie is an opaque parameter which should be passed to the subsequent calls to
GetNextSelected
. It is needed in order to allow parallel iterations over the selected items.Here is a typical example of using these functions:
item, cookie = vlbox.GetFirstSelected() while item != wx.NOT_FOUND: # ... process item ... item, cookie = vlbox.GetNextSelected(cookie)
This method is only valid for multi selection listboxes.
- Return type:
Tuple[int, int]
- GetItemCount(self)¶
Get the number of items in the control.
- Return type:
int
See also
- GetItemRect(self, item)¶
Returns the rectangle occupied by this item in physical coordinates.
If the item is not currently visible, returns an empty rectangle.
- Parameters:
item (int)
- Return type:
Added in version 2.9.0.
- GetMargins(self)¶
Returns the margins used by the control.
The
x
field of the returned point is the horizontal margin and they
field is the vertical one.- Return type:
See also
- GetNextSelected(self, cookie)¶
Returns the index of the next selected item or
NOT_FOUND
if there are no more.This method is only valid for multi selection listboxes.
- Parameters:
cookie (long)
- Return type:
Tuple[int, int]
See also
- GetSelectedCount(self)¶
Returns the number of the items currently selected.
It is valid for both single and multi selection controls. In the former case it may only return 0 or 1 however.
- Return type:
int
See also
- GetSelection(self)¶
Get the currently selected item or
NOT_FOUND
if there is no selection.- Return type:
int
- GetSelectionBackground(self)¶
Returns the background colour used for the selected cells.
By default the standard system colour is used.
- Return type:
- HasMultipleSelection(self)¶
Returns
True
if the listbox was created withLB_MULTIPLE
style and so supports multiple selection orFalse
if it is a single selection listbox.- Return type:
bool
- IsCurrent(self, item)¶
Returns
True
if this item is the current one,False
otherwise.The current item is always the same as selected one for the single selection listbox and in this case this method is equivalent to
IsSelected
but they are different for multi selection listboxes where many items may be selected but only one (at most) is current.- Parameters:
item (int)
- Return type:
bool
- IsSelected(self, item)¶
Returns
True
if this item is selected,False
otherwise.- Parameters:
item (int)
- Return type:
bool
- OnDrawBackground(self, dc, rect, n)¶
This method is used to draw the item’s background and, maybe, a border around it.
The base class version implements a reasonable default behaviour which consists in drawing the selected item with the standard background colour and drawing a border around the item if it is either selected or current.
Todo
Change this function signature to non-const.
- OnDrawItem(self, dc, rect, n)¶
The derived class must implement this function to actually draw the item with the given index on the provided DC.
- Parameters:
- Return type:
None
Todo
Change this function signature to non-const.
- OnDrawSeparator(self, dc, rect, n)¶
This method may be used to draw separators between the lines.
The rectangle passed to it may be modified, typically to deflate it a bit before passing to
OnDrawItem
.The base class version of this method doesn’t do anything.
- Parameters:
- Return type:
None
Todo
Change this function signature to non-const.
- OnMeasureItem(self, n)¶
The derived class must implement this method to return the height of the specified item (in pixels).
- Parameters:
n (int)
- Return type:
int
- Select(self, item, select=True)¶
Selects or deselects the specified item which must be valid (i.e. not equal to
NOT_FOUND
).This function is only valid for the multiple selection listboxes, use
SetSelection
for the single selection ones.- Parameters:
item (int)
select (bool)
- Return type:
bool
- Returns:
True
if the items selection status has changed orFalse
otherwise.
- SelectAll(self)¶
Selects all the items in the listbox.
This method is only valid for multi selection listboxes.
- Return type:
bool
- Returns:
True
if any items were changed, i.e. if there had been any unselected items before, orFalse
if all the items were already selected.
See also
- SelectRange(self, from_, to_)¶
Selects all items in the specified range which may be given in any order.
This method is only valid for multi selection listboxes.
- Parameters:
from_ (int)
to_ (int)
- Return type:
bool
- Returns:
True
if the items selection status has changed orFalse
otherwise.
- SetItemCount(self, count)¶
Set the number of items to be shown in the control.
This is just a synonym for
wx.VScrolledWindow.SetRowCount
.- Parameters:
count (int)
- Return type:
None
- SetMargins(self, *args, **kw)¶
Set the margins: horizontal margin is the distance between the window border and the item contents while vertical margin is half of the distance between items.
By default both margins are 0.
SetMargins (self, pt)
- Parameters:
pt (wx.Point)
- Return type:
None
SetMargins (self, x, y)
- Parameters:
x (int)
y (int)
- Return type:
None
- SetSelection(self, selection)¶
Set the selection to the specified item, if it is -1 the selection is unset.
The selected item will be automatically scrolled into view if it isn’t currently visible.
This method may be used both with single and multiple selection listboxes.
- Parameters:
selection (int)
- Return type:
None
- SetSelectionBackground(self, col)¶
Sets the colour to be used for the selected cells background.
The background of the standard cells may be changed by simply calling
wx.Window.SetBackgroundColour
.- Parameters:
col (wx.Colour)
- Return type:
None
Note
Using a non-default background colour may result in control having an appearance different from the similar native controls and should be avoided in general.
See also
- Toggle(self, item)¶
Toggles the state of the specified item, i.e. selects it if it was unselected and deselects it if it was selected.
This method is only valid for multi selection listboxes.
- Parameters:
item (int)
- Return type:
None
See also
Properties¶
- ItemCount¶
See
GetItemCount
andSetItemCount
- Margins¶
See
GetMargins
andSetMargins
- SelectedCount¶
See
GetSelectedCount
- Selection¶
See
GetSelection
andSetSelection
- SelectionBackground¶