fsleyes_widgets.elistbox

This module provides the EditableListBox class, an alternative to wx.gizmos.EditableListBox.

class fsleyes_widgets.elistbox.EditableListBox(parent, labels=None, clientData=None, tooltips=None, style=0, vgap=0)[source]

Bases: Panel

A panel which displays a list of items.

An EditableListBox contains a wx.Panel which in turn contains a collection of wx.StaticText widgets, which are laid out vertically, and display labels for each of the items in the list. Some rudimentary wrapper methods for modifying the list contents are provided by an EditableListBox object, with an interface similar to that of the wx.ListBox class.

In addition to displaying StaticText controls, the EditableListBox can also display arbitrary panels/controls associated with each label - see the Insert() and SetItemWidget`() methods.

Warning

If you are using an EditableListBox to display arbitrary controls/panels it is important to know that the EditableListBox assumes that all items are of the same size. Sizing/scrolling will not work properly if controls/panels for different list items are of different sizes.

The following style flags are available:

ELB_NO_SCROLL

If enabled, there will be no scrollbar.

ELB_NO_ADD

If enabled, there will be no add item button.

ELB_NO_REMOVE

If enabled, there will be no remove item button.

ELB_NO_MOVE

If enabled there will be no move item up or move item down buttons.

ELB_REVERSE

If enabled, the first item in the list (index 0) will be shown at the bottom, and the last item at the top.

ELB_TOOLTIP

If enabled, list items will be replaced with a tooltip on mouse-over.

ELB_EDITABLE

If enabled, double clicking a list item will allow the user to edit the item value.

ELB_NO_LABELS

If enabled, item labels are not shown - this is intended for lists which are to consist solely of widgets (see the extraWidget parameter to the Insert() method).

ELB_WIDGET_RIGHT

If enabled, item widgets are shown to the right of the item label.

ELB_TOOLTIP_DOWN

If enabled, when the left mouse button is clicked and held down on a list item, the item label is replaced with its tooltip while the mouse is held down.

ELB_SCROLL_BUTTONS

If enabled, and ELB_NO_SCROLL is not enabled, up/down buttons are added above/below the list, which allow the user to scroll up/down.

An EditableListBox generates the following events:

ListSelectEvent

Event emitted when an item is selected.

ListAddEvent

Event emitted when the 'add item' button is pushed.

ListRemoveEvent

Event emitted when the 'remove item' button is pushed.

ListMoveEvent

Event emitted when one of the 'move up'/'move down' buttons is pushed.

ListEditEvent

Event emitted when a list item is edited by the user (see the ELB_EDITABLE style).

ListDblClickEvent

Event emitted when a list item is double-clicked onthe user (see the ELB_EDITABLE style).

Note

The EditableListBox is an alternative to the wx.gizmos.EditableListBox. The latter is buggy under OS X, and getting tooltips working with the wx.ListBox is an absolute pain in the behind. So I felt the need to replicate its functionality. This implementation supports single selection only.

Create an EditableListBox.

Parameters:
VisibleItemCount()[source]

Returns the number of items in the list which are visible (i.e. which have not been hidden via a call to ApplyFilter()).

GetCount()[source]

Returns the number of items in the list.

Clear()[source]

Removes all items from the list.

ClearSelection()[source]

Ensures that no items are selected.

SetSelection(n)[source]

Selects the item at the given index.

GetSelection()[source]

Returns the index of the selected item, or wx.NOT_FOUND if no item is selected.

Insert(label, pos, clientData=None, tooltip=None, extraWidget=None)[source]

Insert an item into the list.

Parameters:
  • label – The label to be displayed.

  • pos – Index at which the item is to be inserted.

  • clientData – Data associated with the item.

  • tooltip – Tooltip to be shown, if the ELB_TOOLTIP style is active.

  • extraWidget – A widget to be displayed alongside the label.

Append(label, clientData=None, tooltip=None, extraWidget=None)[source]

Appends an item to the end of the list.

Parameters:
  • label – The label to be displayed

  • clientData – Data associated with the item

  • tooltip – Tooltip to be shown, if the ELB_TOOLTIP style is active.

  • extraWidget – A widget to be displayed alonside the item.

Delete(n)[source]

Removes the item at the given index from the list.

IndexOf(clientData)[source]

Returns the index of the list item with the specified clientData.

GetLabels()[source]

Returns the labels of all items in the list.

GetData()[source]

Returns the data associated with every item in the list.

GetWidgets()[source]

Returns the widget associated with every item in the list.

SetItemLabel(n, s)[source]

Sets the label of the item at index n to the string s.

Parameters:
  • n – Index of the item.

  • s – New label for the item.

GetItemLabel(n)[source]

Returns the label of the item at index n.

Parameters:

n – Index of the item.

SetItemWidget(n, widget=None)[source]

Sets the widget to be displayed alongside the item at index n.

If widget is set to None, any existing widget associated with the item is destroyed.

GetItemWidget(i)[source]

Returns the widget for the item at index i, or None, if the widget hasn’t been set.

SetItemTooltip(n, tooltip=None)[source]

Sets the tooltip associated with the item at index n.

GetItemTooltip(n)[source]

Returns the tooltip associated with the item at index n.

SetItemData(n, data=None)[source]

Sets the data associated with the item at index n.

GetItemData(n)[source]

Returns the data associated with the item at index n.

SetItemForegroundColour(n, defaultColour=None, selectedColour=None)[source]

Sets the foreground colour of the item at index n.

SetItemBackgroundColour(n, defaultColour=None, selectedColour=None)[source]

Sets the background colour of the item at index n.

SetItemFont(n, font)[source]

Sets the font for the item label at index n.

GetItemFont(n)[source]

Returns the font for the item label at index n.

Enable(enable=True)[source]

Enables/disables this EditableListBox and all of its children.

Disable()[source]

Equivalent to Enable(False).

ApplyFilter(filterStr=None, ignoreCase=False)[source]

Hides any items for which the label does not contain the given filterStr.

To clear the filter (and hence show all items), pass in filterStr=None.

MoveItem(offset, event=False)[source]

Move the currently selected item the specified offset.

Called when the move up or move down buttons are pushed.

Moves the selected item by the specified offset unless it doesn’t make sense to do the move.

If the item is moved, and event is True, posts a EVT_ELB_MOVE_EVENT,

fsleyes_widgets.elistbox.EVT_ELB_SELECT_EVENT = <wx.core.PyEventBinder object>

Identifier for the ListSelectEvent event.

fsleyes_widgets.elistbox.EVT_ELB_ADD_EVENT = <wx.core.PyEventBinder object>

Identifier for the ListAddEvent event.

fsleyes_widgets.elistbox.EVT_ELB_REMOVE_EVENT = <wx.core.PyEventBinder object>

Identifier for the ListRemoveEvent event.

fsleyes_widgets.elistbox.EVT_ELB_MOVE_EVENT = <wx.core.PyEventBinder object>

Identifier for the ListMoveEvent event.

fsleyes_widgets.elistbox.EVT_ELB_EDIT_EVENT = <wx.core.PyEventBinder object>

Identifier for the ListEditEvent event.

fsleyes_widgets.elistbox.ListSelectEvent

Event emitted when an item is selected. A ListSelectEvent has the following attributes (all are set to None if no item was selected):

  • idx: Index of selected item

  • label: Label of selected item

  • data: Client data associated with selected item

fsleyes_widgets.elistbox.ListAddEvent

Event emitted when the ‘add item’ button is pushed. It is up to a listener of this event to actually add a new item to the list. A ListAddEvent has the following attributes (all are set to None if no item was selected):

  • idx: Index of selected item

  • label: Label of selected item

  • data: Client data associated with selected item

fsleyes_widgets.elistbox.ListRemoveEvent

Event emitted when the ‘remove item’ button is pushed. A ListRemoveEvent has the following attributes:

  • idx: Index of removed item

  • label: Label of removed item

  • data: Client data associated with removed item

An event handler can call ListRemoveEvent.Veto() to cancel the item removal.

fsleyes_widgets.elistbox.Veto(self)[source]
fsleyes_widgets.elistbox.GetVeto(self)[source]
fsleyes_widgets.elistbox.ListMoveEvent

Event emitted when one of the ‘move up’/’move down’ buttons is pushed. A ListMoveEvent has the following attributes:

  • oldIdx: Index of item before move

  • newIdx: Index of item after move

  • label: Label of moved item

  • data: Client data associated with moved item

fsleyes_widgets.elistbox.ListEditEvent

Event emitted when a list item is edited by the user (see the ELB_EDITABLE style). A ListEditEvent has the following attributes:

  • idx: Index of edited item

  • label: New label of edited item

  • data: Client data associated with edited item.

fsleyes_widgets.elistbox.ListDblClickEvent

Event emitted when a list item is double-clicked onthe user (see the ELB_EDITABLE style). A ListDblClickEvent has the following attributes:

  • idx: Index of clicked item

  • label: Label of clicked item

  • data: Client data associated with clicked item.

fsleyes_widgets.elistbox.ELB_NO_SCROLL = 1

If enabled, there will be no scrollbar.

fsleyes_widgets.elistbox.ELB_NO_ADD = 2

If enabled, there will be no add item button.

fsleyes_widgets.elistbox.ELB_NO_REMOVE = 4

If enabled, there will be no remove item button.

fsleyes_widgets.elistbox.ELB_NO_MOVE = 8

If enabled there will be no move item up or move item down buttons.

fsleyes_widgets.elistbox.ELB_REVERSE = 16

If enabled, the first item in the list (index 0) will be shown at the bottom, and the last item at the top.

fsleyes_widgets.elistbox.ELB_TOOLTIP = 32

If enabled, list items will be replaced with a tooltip on mouse-over. If disabled, a regular tooltip is shown.

fsleyes_widgets.elistbox.ELB_EDITABLE = 64

If enabled, double clicking a list item will allow the user to edit the item value.

If this style is disabled, the EVT_ELB_DBLCLICK_EVENT will not be generated.

fsleyes_widgets.elistbox.ELB_NO_LABELS = 128

If enabled, item labels are not shown - this is intended for lists which are to consist solely of widgets (see the extraWidget parameter to the Insert() method). This style flag will negate the ELB_EDITABLE flag.

fsleyes_widgets.elistbox.ELB_WIDGET_RIGHT = 256

If enabled, item widgets are shown to the right of the item label. Otherwise (by default) item widgets are shown to the left.

fsleyes_widgets.elistbox.ELB_TOOLTIP_DOWN = 512

If enabled, when the left mouse button is clicked and held down on a list item, the item label is replaced with its tooltip while the mouse is held down. This style is ignored if the ELB_TOOLTIP style is active.

fsleyes_widgets.elistbox.ELB_SCROLL_BUTTONS = 1024

If enabled, and ELB_NO_SCROLL is not enabled, up/down buttons are added above/below the list, which allow the user to scroll up/down.