plectrum.selection

class plectrum.selection.Selection(items=None, on_selection_changed=None)[source]

Bases: object

Represent a selection of items.

__init__(items=None, on_selection_changed=None)[source]

Initialise with initial items.

on_selection_changed should be an optional callable to call, with no arguments, whenever the selection changes.

Note

No selection changed notification should be issued for initial items.

add(item)[source]

Add item to selection.

item must be keyable.

Issue selection changed notification if item newly added.

If item already in selection, raise no error and issue no selection changed notification.

remove(item)[source]

Remove item from selection.

Raise KeyError if item not in selection.

Issue selection changed notification if item removed.

clear()[source]

Remove all items from selection.

Issue a single selection changed notification if items were removed.

toggle(item)[source]

Toggle inclusion of item in selection.

If item present in selection, remove it. Otherwise add it.