Gio.ListStore

g GObject.GInterface GObject.GInterface Gio.ListModel Gio.ListModel GObject.GInterface->Gio.ListModel GObject.Object GObject.Object Gio.ListStore Gio.ListStore GObject.Object->Gio.ListStore Gio.ListModel->Gio.ListStore

Subclasses:

None

Methods

Inherited:

GObject.Object (37), Gio.ListModel (4)

Structs:

GObject.ObjectClass (5)

class

new (item_type)

append (item)

find (item)

find_with_equal_func (item, equal_func)

find_with_equal_func_full (item, equal_func, *user_data)

insert (position, item)

insert_sorted (item, compare_func, *user_data)

remove (position)

remove_all ()

sort (compare_func, *user_data)

splice (position, n_removals, additions)

Virtual Methods

Inherited:

GObject.Object (7), Gio.ListModel (3)

Properties

Name

Type

Flags

Short Description

item-type

GObject.GType

r/w/co

n-items

int

r

Signals

Inherited:

GObject.Object (1), Gio.ListModel (1)

Fields

Inherited:

GObject.Object (1), Gio.ListModel (1)

Class Details

class Gio.ListStore(**kwargs)
Bases:

GObject.Object, Gio.ListModel

Abstract:

No

Structure:

Gio.ListStoreClass

Gio.ListStore is a simple implementation of Gio.ListModel that stores all items in memory.

It provides insertions, deletions, and lookups in logarithmic time with a fast path for the common case of iterating the list linearly.

classmethod new(item_type)[source]
Parameters:

item_type (GObject.GType) – the GObject.GType of items in the list

Returns:

a new Gio.ListStore

Return type:

Gio.ListStore

Creates a new Gio.ListStore with items of type item_type. item_type must be a subclass of GObject.Object.

New in version 2.44.

append(item)[source]
Parameters:

item (GObject.Object) – the new item

Appends item to self. item must be of type Gio.ListStore :item-type.

This function takes a ref on item.

Use Gio.ListStore.splice() to append multiple items at the same time efficiently.

New in version 2.44.

find(item)[source]
Parameters:

item (GObject.Object) – an item

Returns:

Whether self contains item. If it was found, position will be set to the position where item occurred for the first time.

position:

the first position of item, if it was found.

Return type:

(bool, position: int)

Looks up the given item in the list store by looping over the items until the first occurrence of item. If item was not found, then position will not be set, and this method will return False.

If you need to compare the two items with a custom comparison function, use Gio.ListStore.find_with_equal_func() with a custom GLib.EqualFunc instead.

New in version 2.64.

find_with_equal_func(item, equal_func)[source]
Parameters:
Returns:

Whether self contains item. If it was found, position will be set to the position where item occurred for the first time.

position:

the first position of item, if it was found.

Return type:

(bool, position: int)

Looks up the given item in the list store by looping over the items and comparing them with equal_func until the first occurrence of item which matches. If item was not found, then position will not be set, and this method will return False.

item is always passed as second parameter to equal_func.

Since GLib 2.76 it is possible to pass NULL for item.

New in version 2.64.

find_with_equal_func_full(item, equal_func, *user_data)[source]
Parameters:
Returns:

Whether self contains item. If it was found, position will be set to the position where item occurred for the first time.

position:

the first position of item, if it was found.

Return type:

(bool, position: int)

Like Gio.ListStore.find_with_equal_func() but with an additional user_data that is passed to equal_func.

item is always passed as second parameter to equal_func.

Since GLib 2.76 it is possible to pass NULL for item.

New in version 2.74.

insert(position, item)[source]
Parameters:
  • position (int) – the position at which to insert the new item

  • item (GObject.Object) – the new item

Inserts item into self at position. item must be of type Gio.ListStore :item-type or derived from it. position must be smaller than the length of the list, or equal to it to append.

This function takes a ref on item.

Use Gio.ListStore.splice() to insert multiple items at the same time efficiently.

New in version 2.44.

insert_sorted(item, compare_func, *user_data)[source]
Parameters:
Returns:

the position at which item was inserted

Return type:

int

Inserts item into self at a position to be determined by the compare_func.

The list must already be sorted before calling this function or the result is undefined. Usually you would approach this by only ever inserting items by way of this function.

This function takes a ref on item.

New in version 2.44.

remove(position)[source]
Parameters:

position (int) – the position of the item that is to be removed

Removes the item from self that is at position. position must be smaller than the current length of the list.

Use Gio.ListStore.splice() to remove multiple items at the same time efficiently.

New in version 2.44.

remove_all()[source]

Removes all items from self.

New in version 2.44.

sort(compare_func, *user_data)[source]
Parameters:

Sort the items in self according to compare_func.

New in version 2.46.

splice(position, n_removals, additions)[source]
Parameters:
  • position (int) – the position at which to make the change

  • n_removals (int) – the number of items to remove

  • additions ([GObject.Object]) – the items to add

Changes self by removing n_removals items and adding n_additions items to it. additions must contain n_additions items of type Gio.ListStore :item-type. None is not permitted.

This function is more efficient than Gio.ListStore.insert() and Gio.ListStore.remove(), because it only emits Gio.ListModel ::items-changed once for the change.

This function takes a ref on each item in additions.

The parameters position and n_removals must be correct (ie: position + n_removals must be less than or equal to the length of the list at the time this function is called).

New in version 2.44.

Property Details

Gio.ListStore.props.item_type
Name:

item-type

Type:

GObject.GType

Default Value:

<GType GObject>

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The type of items contained in this list store. Items must be subclasses of GObject.Object.

New in version 2.44.

Gio.ListStore.props.n_items
Name:

n-items

Type:

int

Default Value:

0

Flags:

READABLE

The number of items contained in this list store.

New in version 2.74.