SingleSelection#

class SingleSelection(**properties: Any)#

Superclasses: Object

Implemented Interfaces: ListModel, SectionModel, SelectionModel

GtkSingleSelection is a GtkSelectionModel that allows selecting a single item.

Note that the selection is persistent – if the selected item is removed and re-added in the same items_changed emission, it stays selected. In particular, this means that changing the sort order of an underlying sort model will preserve the selection.

Constructors#

class SingleSelection
classmethod new(model: ListModel | None = None) SingleSelection#

Creates a new selection to handle model.

Parameters:

model – the GListModel to manage

Methods#

class SingleSelection
get_autoselect() bool#

Checks if autoselect has been enabled or disabled via set_autoselect().

get_can_unselect() bool#

If True, unselect_item() is supported and allows unselecting the selected item.

get_model() ListModel | None#

Gets the model that self is wrapping.

get_selected() int#

Gets the position of the selected item.

If no item is selected, INVALID_LIST_POSITION is returned.

get_selected_item() Object | None#

Gets the selected item.

If no item is selected, None is returned.

set_autoselect(autoselect: bool) None#

Enables or disables autoselect.

If autoselect is True, self will enforce that an item is always selected. It will select a new item when the currently selected item is deleted and it will disallow unselecting the current item.

Parameters:

autoselectTrue to always select an item

set_can_unselect(can_unselect: bool) None#

If True, unselecting the current item via unselect_item() is supported.

Note that setting autoselect will cause unselecting to not work, so it practically makes no sense to set both at the same time.

Parameters:

can_unselectTrue to allow unselecting

set_model(model: ListModel | None = None) None#

Sets the model that self should wrap.

If model is None, self will be empty.

Parameters:

model – A GListModel to wrap

set_selected(position: int) None#

Selects the item at the given position.

If the list does not have an item at position or INVALID_LIST_POSITION is given, the behavior depends on the value of the autoselect property: If it is set, no change will occur and the old item will stay selected. If it is unset, the selection will be unset and no item will be selected. This also applies if can_unselect is set to False.

Parameters:

position – the item to select or INVALID_LIST_POSITION

Properties#

class SingleSelection
props.autoselect: bool#

The type of the None singleton.

props.can_unselect: bool#

The type of the None singleton.

props.item_type: type#

The type of the None singleton.

Added in version 4.8.

props.model: ListModel#

The type of the None singleton.

props.n_items: int#

The type of the None singleton.

Added in version 4.8.

props.selected: int#

The type of the None singleton.

props.selected_item: Object#

The type of the None singleton.