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 awx.Panel
which in turn contains a collection ofwx.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 anEditableListBox
object, with an interface similar to that of thewx.ListBox
class.In addition to displaying
StaticText
controls, theEditableListBox
can also display arbitrary panels/controls associated with each label - see theInsert()
andSetItemWidget`()
methods.Warning
If you are using an
EditableListBox
to display arbitrary controls/panels it is important to know that theEditableListBox
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:
If enabled, there will be no scrollbar.
If enabled, there will be no add item button.
If enabled, there will be no remove item button.
If enabled there will be no move item up or move item down buttons.
If enabled, the first item in the list (index 0) will be shown at the bottom, and the last item at the top.
If enabled, list items will be replaced with a tooltip on mouse-over.
If enabled, double clicking a list item will allow the user to edit the item value.
If enabled, item labels are not shown - this is intended for lists which are to consist solely of widgets (see the
extraWidget
parameter to theInsert()
method).If enabled, item widgets are shown to the right of the item label.
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.
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:Event emitted when an item is selected.
Event emitted when the 'add item' button is pushed.
Event emitted when the 'remove item' button is pushed.
Event emitted when one of the 'move up'/'move down' buttons is pushed.
Event emitted when a list item is edited by the user (see the
ELB_EDITABLE
style).Event emitted when a list item is double-clicked onthe user (see the
ELB_EDITABLE
style).Note
The
EditableListBox
is an alternative to thewx.gizmos.EditableListBox
. The latter is buggy under OS X, and getting tooltips working with thewx.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:
parent –
wx
parent objectlabels – List of strings, the items in the list
clientData – List of data associated with the list items.
tooltips – List of strings, tooltips for each item.
style – Style bitmask - accepts
ELB_NO_SCROLL
,ELB_NO_ADD
,ELB_NO_REMOVE
,ELB_NO_MOVE
,ELB_REVERSE
,ELB_TOOLTIP
,ELB_EDITABLE
,ELB_NO_LABEL
,ELB_WIDGET_RIGHT
,ELB_TOOLTIP_DOWN
, andELB_SCROLL_BUTTONS
.vgap – Vertical gap in pixels between each item. Ignored if
ELB_NO_LABEL
is set.
- 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()
).
- 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.
- SetItemLabel(n, s)[source]
Sets the label of the item at index
n
to the strings
.- 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 toNone
, any existing widget associated with the item is destroyed.
- GetItemWidget(i)[source]
Returns the widget for the item at index
i
, orNone
, if the widget hasn’t been set.
- 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
.
- 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 aEVT_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 toNone
if no item was selected):idx
: Index of selected itemlabel
: Label of selected itemdata
: 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 toNone
if no item was selected):idx
: Index of selected itemlabel
: Label of selected itemdata
: 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 itemlabel
: Label of removed itemdata
: Client data associated with removed item
An event handler can call
ListRemoveEvent.Veto()
to cancel the item removal.
- 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 movenewIdx
: Index of item after movelabel
: Label of moved itemdata
: 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). AListEditEvent
has the following attributes:idx
: Index of edited itemlabel
: New label of edited itemdata
: 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). AListDblClickEvent
has the following attributes:idx
: Index of clicked itemlabel
: Label of clicked itemdata
: 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 theInsert()
method). This style flag will negate theELB_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.