Gtk.StringList

g GObject.GInterface GObject.GInterface Gio.ListModel Gio.ListModel GObject.GInterface->Gio.ListModel Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable GObject.Object GObject.Object Gtk.StringList Gtk.StringList GObject.Object->Gtk.StringList Gio.ListModel->Gtk.StringList Gtk.Buildable->Gtk.StringList

Subclasses:

None

Methods

Inherited:

GObject.Object (37), Gio.ListModel (4), Gtk.Buildable (1)

Structs:

GObject.ObjectClass (5)

class

new (strings)

append (string)

get_string (position)

remove (position)

splice (position, n_removals, additions)

take (string)

Virtual Methods

Inherited:

GObject.Object (7), Gio.ListModel (3), Gtk.Buildable (9)

Properties

Name

Type

Flags

Short Description

strings

[str]

w/co

Signals

Inherited:

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

Fields

Inherited:

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

Class Details

class Gtk.StringList(**kwargs)
Bases:

GObject.Object, Gio.ListModel, Gtk.Buildable

Abstract:

No

Structure:

Gtk.StringListClass

GtkStringList is a list model that wraps an array of strings.

The objects in the model are of type [class`Gtk`.StringObject] and have a “string” property that can be used inside expressions.

GtkStringList is well-suited for any place where you would typically use a char*[], but need a list model.

Gtk.StringList as Gtk.Buildable

The GtkStringList implementation of the GtkBuildable interface supports adding items directly using the <items> element and specifying <item> elements for each item. Each <item> element supports the regular translation attributes “translatable”, “context” and “comments”.

Here is a UI definition fragment specifying a GtkStringList

``xml <object class=”GtkStringList”>

<items>

<item translatable=”yes”>Factory</item> <item translatable=”yes”>Home</item> <item translatable=”yes”>Subway</item>

</items>

</object> ``

classmethod new(strings)[source]
Parameters:

strings ([str] or None) – The strings to put in the model

Returns:

a new GtkStringList

Return type:

Gtk.StringList

Creates a new GtkStringList with the given strings.

append(string)[source]
Parameters:

string (str) – the string to insert

Appends string to self.

The string will be copied. See [method`Gtk`.StringList.take] for a way to avoid that.

get_string(position)[source]
Parameters:

position (int) – the position to get the string for

Returns:

the string at the given position

Return type:

str or None

Gets the string that is at position in self.

If self does not contain position items, None is returned.

This function returns the const str *. To get the object wrapping it, use Gio.ListModel.get_item().

remove(position)[source]
Parameters:

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

Removes the string at position from self.

position must be smaller than the current length of the list.

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

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

  • additions ([str] or None) – The strings to add

Changes self by removing n_removals strings and adding additions to it.

This function is more efficient than [method`Gtk`.StringList.append] and [method`Gtk`.StringList.remove], because it only emits the ::items-changed signal once for the change.

This function copies the strings 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).

take(string)[source]
Parameters:

string (str) – the string to insert

Adds string to self at the end, and takes ownership of it.

This variant of [method`Gtk`.StringList.append] is convenient for formatting strings:

``c gtk_string_list_take (self, g_strdup_print (“%d dollars”, lots)); ``

Property Details

Gtk.StringList.props.strings
Name:

strings

Type:

[str]

Default Value:

[]

Flags:

WRITABLE, CONSTRUCT_ONLY

New in version 4.10.