StringList#
Superclasses: Object
Implemented Interfaces: ListModel, Buildable
GtkStringList is a list model that wraps an array of strings.
The objects in the model are of type 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.
GtkStringList as GtkBuildable#
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
<object class="GtkStringList">
  <items>
    <item translatable="yes">Factory</item>
    <item translatable="yes">Home</item>
    <item translatable="yes">Subway</item>
  </items>
</object>
Constructors#
- class StringList
 - classmethod new(strings: list[str] | None = None) StringList#
 Creates a new
GtkStringListwith the givenstrings.- Parameters:
 strings – The strings to put in the model
Methods#
- class StringList
 - append(string: str) None#
 Appends
stringtoself.The
stringwill be copied. Seetakefor a way to avoid that.- Parameters:
 string – the string to insert
- get_string(position: int) str | None#
 Gets the string that is at
positioninself.If
selfdoes not containpositionitems,Noneis returned.This function returns the const char *. To get the object wrapping it, use
get_item().- Parameters:
 position – the position to get the string for
- remove(position: int) None#
 Removes the string at
positionfromself.positionmust be smaller than the current length of the list.- Parameters:
 position – the position of the string that is to be removed
- splice(position: int, n_removals: int, additions: list[str] | None = None) None#
 Changes
selfby removingn_removalsstrings and addingadditionsto it.This function is more efficient than
appendandremove, because it only emits the ::items-changed signal once for the change.This function copies the strings in
additions.The parameters
positionandn_removalsmust be correct (ie:position+n_removalsmust be less than or equal to the length of the list at the time this function is called).- Parameters:
 position – the position at which to make the change
n_removals – the number of strings to remove
additions – The strings to add