Skip to content

Gtk.BuilderListItemFactory

class — extends ListItemFactory

Creates widgets by instantiating GtkBuilder UI templates.

The templates must extend the class that the parent widget expects. For example, a factory provided to ListView.factory must have a template that extends ListItem.

Templates typically use Expression to obtain data from the items in the model.

Example:

  <interface>
    <template class="GtkListItem">
      <property name="child">
        <object class="GtkLabel">
          <property name="xalign">0</property>
          <binding name="label">
            <lookup name="name" type="SettingsKey">
              <lookup name="item">GtkListItem</lookup>
            </lookup>
          </binding>
        </object>
      </property>
    </template>
  </interface>

A common approach is to embed such templates as CDATA marked sections into a surrounding UI file. Note that if you use this approach, extracting translatable strings with xgettext will not work for strings inside the marked section.

Constructors

new_from_bytes

@classmethod
def new_from_bytes(cls, scope: BuilderScope | None, bytes: bytes) -> ListItemFactory

Creates a new GtkBuilderListItemFactory that instantiates widgets using bytes as the data to pass to GtkBuilder.

Parameters:

  • scope — A scope to use when instantiating
  • bytes — the GBytes containing the UI definition to instantiate

new_from_resource

@classmethod
def new_from_resource(cls, scope: BuilderScope | None, resource_path: str) -> ListItemFactory

Creates a new GtkBuilderListItemFactory that instantiates widgets using data read from the given resource_path to pass to GtkBuilder.

Parameters:

  • scope — A scope to use when instantiating
  • resource_path — valid path to a resource that contains the UI definition

Methods

get_bytes

def get_bytes(self) -> bytes

Gets the data used as the GtkBuilder UI template for constructing listitems.

get_resource

def get_resource(self) -> str | None

If the data references a resource, gets the path of that resource.

get_scope

def get_scope(self) -> BuilderScope | None

Gets the scope used when constructing listitems.

Properties

bytes

bytes: bytes  # read/write

GBytes containing the UI definition.

resource

resource: str  # read/write

Path of the resource containing the UI definition.

scope

scope: BuilderScope  # read/write

GtkBuilderScope to use when instantiating listitems