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)¶ Bases:
wx._core.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:
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 theInsert()
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
alias of wx.lib.newevent.NewEvent.<locals>._Event
ListAddEvent
alias of wx.lib.newevent.NewEvent.<locals>._Event
ListRemoveEvent
alias of wx.lib.newevent.NewEvent.<locals>._Event
ListMoveEvent
alias of wx.lib.newevent.NewEvent.<locals>._Event
ListEditEvent
alias of wx.lib.newevent.NewEvent.<locals>._Event
ListDblClickEvent
alias of wx.lib.newevent.NewEvent.<locals>._Event
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 object - labels – 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
.
-
_selectedFG
= '#000000'¶ Default foreground colour for the currently selected item.
-
_defaultFG
= '#000000'¶ Default foreground colour for unselected items.
-
_selectedBG
= '#cdcdff'¶ Background colour for the currently selected item.
-
_defaultBG
= '#FFFFFF'¶ Background colour for the unselected items.
-
__init__
(parent, labels=None, clientData=None, tooltips=None, style=0)¶ Create an
EditableListBox
.Parameters: - parent –
wx
parent object - labels – 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
.
- parent –
-
VisibleItemCount
()¶ Returns the number of items in the list which are visible (i.e. which have not been hidden via a call to
ApplyFilter()
).
-
GetCount
()¶ Returns the number of items in the list.
-
Clear
()¶ Removes all items from the list.
-
ClearSelection
()¶ Ensures that no items are selected.
-
SetSelection
(n)¶ Selects the item at the given index.
-
GetSelection
()¶ 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)¶ 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)¶ 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)¶ Removes the item at the given index from the list.
-
IndexOf
(clientData)¶ Returns the index of the list item with the specified
clientData
.
-
GetLabels
()¶ Returns the labels of all items in the list.
-
GetData
()¶ Returns the data associated with every item in the list.
-
GetWidgets
()¶ Returns the widget associated with every item in the list.
-
SetItemLabel
(n, s)¶ 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)¶ Returns the label of the item at index
n
.Parameters: n – Index of the item.
-
SetItemWidget
(n, widget=None)¶ 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)¶ Returns the widget for the item at index
i
, orNone
, if the widget hasn’t been set.
-
SetItemTooltip
(n, tooltip=None)¶ Sets the tooltip associated with the item at index
n
.
-
GetItemTooltip
(n)¶ Returns the tooltip associated with the item at index
n
.
-
SetItemData
(n, data=None)¶ Sets the data associated with the item at index
n
.
-
GetItemData
(n)¶ Returns the data associated with the item at index
n
.
-
SetItemForegroundColour
(n, defaultColour=None, selectedColour=None)¶ Sets the foreground colour of the item at index
n
.
-
SetItemBackgroundColour
(n, defaultColour=None, selectedColour=None)¶ Sets the background colour of the item at index
n
.
-
SetItemFont
(n, font)¶ Sets the font for the item label at index
n
.
-
GetItemFont
(n)¶ Returns the font for the item label at index
n
.
-
Enable
(enable=True)¶ Enables/disables this
EditableListBox
and all of its children.
-
Disable
()¶ Equivalent to
Enable(False)
.
-
ApplyFilter
(filterStr=None, ignoreCase=False)¶ 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
.
-
_EditableListBox__addItem
(ev)¶ Called when the add item button is pushed.
Does nothing but post an
EVT_ELB_ADD_EVENT
- it is up to a registered handler to implement the functionality of adding an item to the list.
-
_EditableListBox__configTooltip
(listItem)¶ If the
ELB_TOOLTIP
style was enabled, this method configures mouse-over listeners on the widget representing the given list item, so the item displays the tool tip on mouse overs.If
ELB_TOOLTIP
is not enabled, a regular tooltip is configured.
-
_EditableListBox__configTooltipDown
(listItem)¶ If the
ELB_TOOLTIP_DOWN
style was enabled, this method configures mouse-down listeners on the given list item widget, so the item displays the tool tip on mouse down.This method is not called if
ELB_TOOLTIP_DOWN
is not enabled.
-
_EditableListBox__drawList
(ev=None)¶ ‘Draws’ the set of items in the list according to the current scrollbar thumb position.
-
_EditableListBox__fixIndex
(idx)¶ If the
ELB_REVERSE
style is active, this method will return an inverted version of the given index. Otherwise it returns the index value unchanged.
-
_EditableListBox__getSelection
(fix=False)¶ Returns a 3-tuple containing the (uncorrected) index, label, and associated client data of the currently selected list item, or (None, None, None) if no item is selected.
-
_EditableListBox__itemClicked
(ev=None, widget=None)¶ Called when an item in the list is clicked. Selects the item and posts an
EVT_ELB_SELECT_EVENT
.This method may be called programmatically, by explicitly passing in the target
widget
. This functionality is used by the__onKeyboard()
event.Parameters: - ev – A
wx.MouseEvent
. - widget – The widget on which to simulate a mouse click. Must be provided when called programmatically.
- ev – A
-
_EditableListBox__moveItem
(offset)¶ Called when the move up or move down buttons are pushed.
Moves the selected item by the specified offset and posts an
EVT_ELB_MOVE_EVENT
, unless it doesn’t make sense to do the move.
-
_EditableListBox__moveItemDown
(ev)¶ Called when the move down button is pushed. Calls the
__moveItem()
method.
-
_EditableListBox__moveItemUp
(ev)¶ Called when the move up button is pushed. Calls the
__moveItem()
method.
-
_EditableListBox__onDoubleClick
(ev, listItem)¶ Called when an item is double clicked. See the
ELB_EDITABLE
style.This method is only called if the
ELB_EDITABLE
style flag is not set.Posts a
ListDblClickEvent
.
-
_EditableListBox__onEdit
(ev, listItem)¶ Called when an item is double clicked.
This method is only called if the
ELB_EDITABLE
style flag is set.Creates and displays a
wx.TextCtrl
allowing the user to edit the item label. AListEditEvent
is posted every time the text changes.
-
_EditableListBox__onKeyboard
(ev)¶ Called when a key is pressed. On up/down arrow key presses, changes the selected item, and scrolls if necessary.
-
_EditableListBox__onMouseWheel
(ev=None, move=None)¶ Called when the mouse wheel is scrolled over the list. Scrolls through the list accordingly.
Parameters: - ev – A
wx.MouseEvent
- move – If called programmatically, a number indicating the direction in which to scroll.
- ev – A
-
_EditableListBox__onScrollButton
(ev)¶ Called when either of the scroll up/down buttons are clicked (if the
ELB_SCROLL_BUTTONS
style is active). Scrolls the list up/down, if possible.
-
_EditableListBox__removeItem
(ev)¶ Called when the remove item button is pushed.
Posts an
EVT_ELB_REMOVE_EVENT
and removes the selected item from the list.Event listeners may call
Veto()
on the event object to cancel the removal.
-
_EditableListBox__updateMoveButtons
()¶
-
_EditableListBox__updateScrollbar
(ev=None)¶ Updates the scrollbar parameters according to the number of items in the list, and the screen size of the list panel. If there is enough room to display all items in the list, the scroll bar is hidden.
-
__module__
= 'fsleyes_widgets.elistbox'¶
- parent –
-
class
fsleyes_widgets.elistbox.
_ListItem
(label, data, tooltip, labelWidget, container, defaultFGColour, selectedFGColour, defaultBGColour, selectedBGColour, extraWidget=None)¶ Bases:
object
Internal class used to represent items in the list.
Create a _ListItem object.
Parameters: - label (str) – The item label which will be displayed.
- data – User data associated with the item.
- tooltip (str) – A tooltip to be displayed when the mouse is moved over the item.
- labelWidget – The
wx
object which represents the list item. - container – The
wx
object used as a container for thewidget
. - defaultFGColour – Foreground colour to use when the item is not selected.
- selectedFGColour – Foreground colour to use when the item is selected.
- defaultBGColour – Background colour to use when the item is not selected.
- selectedBGColour – Background colour to use when the item is selected.
- extraWidget – A user-settable widget to be displayed alongside this item.
-
__init__
(label, data, tooltip, labelWidget, container, defaultFGColour, selectedFGColour, defaultBGColour, selectedBGColour, extraWidget=None)¶ Create a _ListItem object.
Parameters: - label (str) – The item label which will be displayed.
- data – User data associated with the item.
- tooltip (str) – A tooltip to be displayed when the mouse is moved over the item.
- labelWidget – The
wx
object which represents the list item. - container – The
wx
object used as a container for thewidget
. - defaultFGColour – Foreground colour to use when the item is not selected.
- selectedFGColour – Foreground colour to use when the item is selected.
- defaultBGColour – Background colour to use when the item is not selected.
- selectedBGColour – Background colour to use when the item is selected.
- extraWidget – A user-settable widget to be displayed alongside this item.
-
__dict__
= mappingproxy({'__module__': 'fsleyes_widgets.elistbox', '__doc__': 'Internal class used to represent items in the list.', '__init__': <function _ListItem.__init__>, '__dict__': <attribute '__dict__' of '_ListItem' objects>, '__weakref__': <attribute '__weakref__' of '_ListItem' objects>})¶
-
__module__
= 'fsleyes_widgets.elistbox'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
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
¶ alias of
wx.lib.newevent.NewEvent.<locals>._Event
-
fsleyes_widgets.elistbox.
ListAddEvent
¶ alias of
wx.lib.newevent.NewEvent.<locals>._Event
-
fsleyes_widgets.elistbox.
ListRemoveEvent
¶ alias of
wx.lib.newevent.NewEvent.<locals>._Event
-
fsleyes_widgets.elistbox.
Veto
(self)¶
-
fsleyes_widgets.elistbox.
GetVeto
(self)¶
-
fsleyes_widgets.elistbox.
ListMoveEvent
¶ alias of
wx.lib.newevent.NewEvent.<locals>._Event
-
fsleyes_widgets.elistbox.
ListEditEvent
¶ alias of
wx.lib.newevent.NewEvent.<locals>._Event
-
fsleyes_widgets.elistbox.
ListDblClickEvent
¶ alias of
wx.lib.newevent.NewEvent.<locals>._Event
-
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.