*********** wx.VListBox *********** Inheritance diagram for `wx.VListBox`: | .. inheritance-diagram:: 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 <#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. .. seealso:: `wx.SimpleHtmlListBox `_, `wx.HtmlListBox `_ Derived From ^^^^^^^^^^^^^ * `wx.VScrolledWindow `_ * `wx.Panel `_ * `wx.Window `_ * `wx.EvtHandler `_ * `wx.Object `_ Known Subclasses ^^^^^^^^^^^^^^^^ `wx.HtmlListBox `_, `wx.SimpleHtmlListBox `_ Methods Summary ^^^^^^^^^^^^^^^ * `__init__ <#__init__>`_ * `Clear <#Clear>`_ * `DeselectAll <#DeselectAll>`_ * `GetFirstSelected <#GetFirstSelected>`_ * `GetItemCount <#GetItemCount>`_ * `GetMargins <#GetMargins>`_ * `GetNextSelected <#GetNextSelected>`_ * `GetSelectedCount <#GetSelectedCount>`_ * `GetSelection <#GetSelection>`_ * `GetSelectionBackground <#GetSelectionBackground>`_ * `HasMultipleSelection <#HasMultipleSelection>`_ * `IsCurrent <#IsCurrent>`_ * `IsSelected <#IsSelected>`_ * `OnDrawBackground <#OnDrawBackground>`_ * `OnDrawSeparator <#OnDrawSeparator>`_ * `Select <#Select>`_ * `SelectAll <#SelectAll>`_ * `SelectRange <#SelectRange>`_ * `SetItemCount <#SetItemCount>`_ * `SetMargins <#SetMargins>`_ * `SetMarginsXY <#SetMarginsXY>`_ * `SetSelection <#SetSelection>`_ * `SetSelectionBackground <#SetSelectionBackground>`_ * `Toggle <#Toggle>`_ Properties Summary ^^^^^^^^^^^^^^^^^^ * `FirstSelected <#FirstSelected>`_ * `ItemCount <#ItemCount>`_ * `Margins <#Margins>`_ * `SelectedCount <#SelectedCount>`_ * `Selection <#Selection>`_ * `SelectionBackground <#SelectionBackground>`_ Class API ========= Methods ^^^^^^^ .. method:: __init__(parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, name=wx.VListBoxNameStr) Default constructor. **Parameters:** * `parent` (`wx.Window `_) * `id` (int) * `pos` (`wx.Point `_) * `size` (`wx.Size `_) * `style` (long) * `name` (string) | **Returns:** `wx.VListBox `_ -------- .. method:: Clear() Deletes all items from the control. -------- .. method:: 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. .. seealso:: `SelectAll <#SelectAll>`_, `Select <#Select>`_ -------- .. method:: 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. -------- .. method:: GetItemCount() Get the number of items in the control. | **Returns:** `long` .. seealso:: `SetItemCount <#SetItemCount>`_ -------- .. method:: 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 `_ .. seealso:: `SetMargins <#SetMargins>`_ -------- .. method:: 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. .. seealso:: `GetFirstSelected <#GetFirstSelected>`_ -------- .. method:: 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` .. seealso:: `IsSelected <#IsSelected>`_, `GetFirstSelected <#GetFirstSelected>`_, `GetNextSelected <#GetNextSelected>`_ -------- .. method:: GetSelection() Get the currently selected item or ``wx.NOT_FOUND`` if there is no selection. | **Returns:** `int` -------- .. method:: GetSelectionBackground() Returns the background colour used for the selected cells. By default the standard system colour is used. | **Returns:** `wx.Colour `_ .. seealso:: `wx.SystemSettings.GetColour `_, `SetSelectionBackground <#SetSelectionBackground>`_ -------- .. method:: 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` -------- .. method:: 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 <#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` -------- .. method:: IsSelected(item) Returns ``True`` if this item is selected, ``False`` otherwise. **Parameters:** * `item` (long) | **Returns:** `bool` -------- .. method:: 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 -------- .. method:: 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 -------- .. method:: 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 <#SetSelection>`_ for the single selection ones. -------- .. method:: 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. .. seealso:: `DeselectAll <#DeselectAll>`_, `Select <#Select>`_ -------- .. method:: 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. .. seealso:: `SelectAll <#SelectAll>`_, `Select <#Select>`_ -------- .. method:: 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) -------- .. method:: 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:** * `pt` (`wx.Point `_) -------- .. method:: 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) -------- .. method:: 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) -------- .. method:: 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:** * `col` (`wx.Colour `_) .. seealso:: `GetSelectionBackground <#GetSelectionBackground>`_ -------- .. method:: 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. .. seealso:: `Select <#Select>`_ -------- Properties ^^^^^^^^^^ .. attribute:: FirstSelected See `GetFirstSelected <#GetFirstSelected>`_ .. attribute:: ItemCount See `GetItemCount <#GetItemCount>`_ and `SetItemCount <#SetItemCount>`_ .. attribute:: Margins See `GetMargins <#GetMargins>`_ and `SetMargins <#SetMargins>`_ .. attribute:: SelectedCount See `GetSelectedCount <#GetSelectedCount>`_ .. attribute:: Selection See `GetSelection <#GetSelection>`_ and `SetSelection <#SetSelection>`_ .. attribute:: SelectionBackground See `GetSelectionBackground <#GetSelectionBackground>`_ and `SetSelectionBackground <#SetSelectionBackground>`_