wx.VListBox

Inheritance diagram for wx.VListBox:



Description

wx.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 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, such as wx.HtmlListBox, from it.

However it emits the same events as wx.ListBox and the same event macros may be used with it.

Class API

Methods

__init__(parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, name=wx.VListBoxNameStr)

Default constructor.

Parameters:


Returns:

wx.VListBox


Clear()
Deletes all items from the control.

DeselectAll()

Deselects all the items in the listbox.

Returns True if any items were changed, i.e. if there had been any selected items before, or False if all the items were already deselected.


Returns:

bool

Note

This method is only valid for multi selection listboxes.

See also

SelectAll, Select


GetFirstSelected()

Returns the index of the first selected item in the listbox or wx.NOT_FOUND if no items are currently selected.

Here is a typical example of using these functions:

item, cookie = vListBox.GetFirstSelected()

while item != wx.NOT_FOUND:

    # ... process item ...
    item = vListBox.GetNextSelected(cookie)

Returns:

(item, cookie)

Note

This method is only valid for multi selection listboxes.


GetItemCount()

Get the number of items in the control.


Returns:

long

See also

SetItemCount


GetMargins()

Returns the margins used by the control. The x field of the returned point is the horizontal margin and the y field is the vertical one.


Returns:

wx.Point

See also

SetMargins


GetNextSelected(cookie)

Returns the index of the next selected item or wx.NOT_FOUND if there are no more.

Parameters:

  • cookie (long): 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.

Returns:

int

Note

This method is only valid for multi selection listboxes.

See also

GetFirstSelected


GetSelectedCount()

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.


Returns:

long


GetSelection()

Get the currently selected item or wx.NOT_FOUND if there is no selection.


Returns:

int


GetSelectionBackground()

Returns the background colour used for the selected cells. By default the standard system colour is used.


Returns:

wx.Colour


HasMultipleSelection()

Returns True if the listbox was created with wx.LB_MULTIPLE style and so supports multiple selection or False if it is a single selection listbox.


Returns:

bool


IsCurrent(item)

Returns True if this item is the current one, False otherwise.

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 (long)

Returns:

bool


IsSelected(item)

Returns True if this item is selected, False otherwise.

Parameters:

  • item (long)

Returns:

bool


OnDrawBackground(dc, rect, n)

This method is used to draw the items 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.

Parameters:

  • dc (wx.DC): The device context to use for drawing
  • rect (wx.Rect): The bounding rectangle for the item
  • n (long): The index of the item

OnDrawSeparator(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:

  • dc (wx.DC): The device context to use for drawing
  • rect (wx.Rect): The bounding rectangle for the item
  • n (long): The index of the item

Select(item, select=True)

Selects or deselects the specified item which must be valid (i.e. not equal to wx.NOT_FOUND).

Return True if the items selection status has changed or False otherwise.

Parameters:

  • item (long): The item index
  • select (bool): whether to select or deselect the item.

Returns:

bool

Note

This function is only valid for the multiple selection listboxes, use SetSelection for the single selection ones.


SelectAll()

Selects all the items in the listbox.

Returns True if any items were changed, i.e. if there had been any unselected items before, or False if all the items were already selected.


Returns:

bool

Note

This method is only valid for multi selection listboxes.

See also

DeselectAll, Select


SelectRange(from, to)

Selects all items in the specified range which may be given in any order.

Return True if the items selection status has changed or False otherwise.

Parameters:

  • from (long)
  • to (long)

Returns:

bool

Note

This method is only valid for multi selection listboxes.

See also

SelectAll, Select


SetItemCount(count)

Set the number of items to be shown in the control.

This is just a synonym for wx.VScrolledWindow.SetLineCount.

Parameters:

  • count (long)

SetMargins(pt)

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.

Parameters:


SetMarginsXY(x, y)

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.

Parameters:

  • x (int)
  • y (int)

SetSelection(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)

SetSelectionBackground(col)

Sets the colour to be used for the selected cells background. The background of the standard cells may be changed by simply calling SetBackgroundColour.

Parameters:


Toggle(item)

Toggles the state of the specified item, i.e. selects it if it was unselected and deselects it if it was selected.

Parameters:

  • item (long)

Note

This method is only valid for multi selection listboxes.

See also

Select


Properties

FirstSelected
See GetFirstSelected
ItemCount
See GetItemCount and SetItemCount
Margins
See GetMargins and SetMargins
SelectedCount
See GetSelectedCount
Selection
See GetSelection and SetSelection
SelectionBackground
See GetSelectionBackground and SetSelectionBackground