SelectList

class qte.SelectList(iterable=None)

A SelectList is simple a list in which some items are marked as selected.

The following examples show usage:

>>> l = SelectList([1, 2, 3, 4, 5])
>>> l.select(3)
SelectList([1, 2, <3>, 4, 5])
>>> l.selection
(3,)
>>> l.select(6)
Traceback (most recent call last):
    ...
ValueError: 6
>>> l
SelectList([1, 2, <3>, 4, 5])
>>> l.clear()
>>> l.selection
()
>>> l.indexselect(0, 2)
SelectList([<1>, 2, <3>, 4, 5])
>>> l.indexselection
(0, 2)
>>> l.select(5, 3)
SelectList([<1>, 2, <3>, 4, <5>])
>>> l.selection
(1, 3, 5)

The following rules govern the processing of the selections:

  1. If options contains duplicates, the first matching value is selected when using select

    >>> l = SelectList([1, 2, 1])
    >>> l.select(1)
    SelectList([<1>, 2, 1])
    

    However, it is possible to explicitly select a value using indexselect().

    >>> l = SelectList([1, 2, 1])
    >>> l.indexselect(2)
    SelectList([1, 2, <1>])
    
  2. The selection lists are unordered.

    >>> l = SelectList([1, 2, 3, 4, 5])
    >>> _ = l.select(3)
    >>> _ = l.select(1)
    >>> l.selection
    (1, 3)
    
  3. If a selected value is changed in the SelectList, it is removed from the selection.

    >>> l = SelectList([1, 2, 3])
    >>> l.select(2)
    SelectList([1, <2>, 3])
    >>> l[1] = 4
    >>> l
    SelectList([1, 4, 3])
    

Members

Properties

SelectList.indexselection

Read only. Return a tuple of selected indexes.

SelectList.selection

Read only. Return a tuple of the selected values.

Methods

SelectList.clear()

Clear the selection.

SelectList.indexselect(*indexes)

Select indexes and return the SelectList.

>>> l = SelectList('abcdefg')
>>> l.indexselect(0, 3, 6)
SelectList([<'a'>, 'b', 'c', <'d'>, 'e', 'f', <'g'>])
SelectList.indexunselect(*indexes)

Remove indexes and return the SelectList.

If the selection does not contains indexes, then an IndexError is raised.

>>> l = SelectList('penguin')
>>> l.select('p', 'g')
SelectList([<'p'>, 'e', 'n', <'g'>, 'u', 'i', 'n'])
>>> l.indexunselect(3)
SelectList([<'p'>, 'e', 'n', 'g', 'u', 'i', 'n'])
>>> l.indexunselect(4)
Traceback (most recent call last):
    ...
IndexError: Item at position '4' is not selected
SelectList.select(*values)

Select values and return the SelectList.

>>> l = SelectList('abcdefg')
>>> l.select('a', 'd', 'f')
SelectList([<'a'>, 'b', 'c', <'d'>, 'e', <'f'>, 'g'])
SelectList.unselect(*values)

Remove values from the selection list and return the SelectList.

If the selection contains duplicate values, then the first found is removed. If no matching values are found, then a ValueError is raised.

>>> l = SelectList('penguin')
>>> l.indexselect(2, 6)
SelectList(['p', 'e', <'n'>, 'g', 'u', 'i', <'n'>])
>>> l.unselect('n')
SelectList(['p', 'e', 'n', 'g', 'u', 'i', <'n'>])
>>> l.unselect('p')
Traceback (most recent call last):
    ...
ValueError: 'p' is not selected

Project Versions

Table Of Contents

Previous topic

SafeWriter

Next topic

SortFilterProxyModel

This Page