Gtk.SingleSelection

g GObject.GInterface GObject.GInterface Gio.ListModel Gio.ListModel GObject.GInterface->Gio.ListModel Gtk.SectionModel Gtk.SectionModel GObject.GInterface->Gtk.SectionModel Gtk.SelectionModel Gtk.SelectionModel GObject.GInterface->Gtk.SelectionModel GObject.Object GObject.Object Gtk.SingleSelection Gtk.SingleSelection GObject.Object->Gtk.SingleSelection Gio.ListModel->Gtk.SingleSelection Gtk.SectionModel->Gtk.SingleSelection Gtk.SelectionModel->Gtk.SingleSelection

Subclasses:

None

Methods

Inherited:

GObject.Object (37), Gio.ListModel (4), Gtk.SectionModel (2), Gtk.SelectionModel (11)

Structs:

GObject.ObjectClass (5)

class

new (model)

get_autoselect ()

get_can_unselect ()

get_model ()

get_selected ()

get_selected_item ()

set_autoselect (autoselect)

set_can_unselect (can_unselect)

set_model (model)

set_selected (position)

Virtual Methods

Inherited:

GObject.Object (7), Gio.ListModel (3), Gtk.SectionModel (1), Gtk.SelectionModel (9)

Properties

Name

Type

Flags

Short Description

autoselect

bool

r/w/en

can-unselect

bool

r/w/en

item-type

GObject.GType

r

model

Gio.ListModel

r/w/en

n-items

int

r

selected

int

r/w/en

selected-item

GObject.Object

r

Signals

Inherited:

GObject.Object (1), Gio.ListModel (1), Gtk.SectionModel (1), Gtk.SelectionModel (1)

Fields

Inherited:

GObject.Object (1), Gio.ListModel (1), Gtk.SectionModel (1), Gtk.SelectionModel (1)

Class Details

class Gtk.SingleSelection(**kwargs)
Bases:

GObject.Object, Gio.ListModel, Gtk.SectionModel, Gtk.SelectionModel

Abstract:

No

Structure:

Gtk.SingleSelectionClass

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 [signal`Gio`.ListModel::items-changed] emission, it stays selected. In particular, this means that changing the sort order of an underlying sort model will preserve the selection.

classmethod new(model)[source]
Parameters:

model (Gio.ListModel or None) – the GListModel to manage

Returns:

a new GtkSingleSelection

Return type:

Gtk.SingleSelection

Creates a new selection to handle model.

get_autoselect()[source]
Returns:

True if autoselect is enabled

Return type:

bool

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

get_can_unselect()[source]
Returns:

True to support unselecting

Return type:

bool

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

get_model()[source]
Returns:

The model being wrapped

Return type:

Gio.ListModel or None

Gets the model that self is wrapping.

get_selected()[source]
Returns:

The position of the selected item

Return type:

int

Gets the position of the selected item.

If no item is selected, Gtk.INVALID_LIST_POSITION is returned.

get_selected_item()[source]
Returns:

The selected item

Return type:

GObject.Object or None

Gets the selected item.

If no item is selected, None is returned.

set_autoselect(autoselect)[source]
Parameters:

autoselect (bool) – True to always select an item

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.

set_can_unselect(can_unselect)[source]
Parameters:

can_unselect (bool) – True to allow unselecting

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

Note that setting [property`Gtk`.SingleSelection:autoselect] will cause unselecting to not work, so it practically makes no sense to set both at the same time the same time.

set_model(model)[source]
Parameters:

model (Gio.ListModel or None) – A GListModel to wrap

Sets the model that self should wrap.

If model is None, self will be empty.

set_selected(position)[source]
Parameters:

position (int) – the item to select or Gtk.INVALID_LIST_POSITION

Selects the item at the given position.

If the list does not have an item at position or Gtk.INVALID_LIST_POSITION is given, the behavior depends on the value of the [property`Gtk`.SingleSelection: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.

Property Details

Gtk.SingleSelection.props.autoselect
Name:

autoselect

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

If the selection will always select an item.

Gtk.SingleSelection.props.can_unselect
Name:

can-unselect

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

If unselecting the selected item is allowed.

Gtk.SingleSelection.props.item_type
Name:

item-type

Type:

GObject.GType

Default Value:

<GType GObject>

Flags:

READABLE

The type of items. See [method`Gio`.ListModel.get_item_type].

New in version 4.8.

Gtk.SingleSelection.props.model
Name:

model

Type:

Gio.ListModel

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The model being managed.

Gtk.SingleSelection.props.n_items
Name:

n-items

Type:

int

Default Value:

0

Flags:

READABLE

The number of items. See [method`Gio`.ListModel.get_n_items].

New in version 4.8.

Gtk.SingleSelection.props.selected
Name:

selected

Type:

int

Default Value:

4294967295

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Position of the selected item.

Gtk.SingleSelection.props.selected_item
Name:

selected-item

Type:

GObject.Object

Default Value:

None

Flags:

READABLE

The selected item.