Gtk.CellRendererCombo


Gtk.CellRendererCombo — Renders a combobox in a cell

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.CellRenderer
            ╰── Gtk.CellRendererText
                ╰── Gtk.CellRendererCombo

Functions:

  • new () -> Gtk.CellRenderer

Signals:

  • “changed” (combo, path_string, new_iter, user_data)

Description:

Gtk.CellRendererCombo renders text in a cell like GtkCellRendererText from which it is derived. But while Gtk.CellRendererText offers a simple entry to edit the text, Gtk.CellRendererCombo offers a GtkComboBox widget to edit the text. The values to display in the combo box are taken from the tree model specified in the Gtk.CellRendererCombo::model property.

The combo cell renderer takes care of adding a text cell renderer to the combo box and sets it to display the column specified by its Gtk.CellRendererCombo::text-column property. Further properties of the combo box can be set in a handler for the Gtk.CellRenderer::editing-started signal.

The Gtk.CellRendererCombo cell renderer was added in GTK+ 2.6.


Function Details:

new()

new () -> Gtk.CellRenderer

Creates a new Gtk.CellRendererCombo. Adjust how text is drawn using object properties. Object properties can be set globally (with g_object_set()). Also, with `Gtk.TreeViewColumn, you can bind a property to a value in aGtk.TreeModel. For example, you can bind the “text” property on the cell renderer to a string value in the model, thus rendering a different string in each row of theGtk.TreeView`.

  • Returns: the new cell renderer

  • Since: 2.6


Example:

#!/usr/bin/env python

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class CellRendererCombo(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_title("CellRendererCombo")
        self.set_default_size(200, 200)
        self.connect("destroy", Gtk.main_quit)

        self.liststoreAppliance = Gtk.ListStore(str, str)
        self.liststoreAppliance.append(["Dishwasher", "Bosch"])
        self.liststoreAppliance.append(["Refrigerator", "Samsung"])
        self.liststoreAppliance.append(["Cooker", "Hotpoint"])

        self.liststoreManufacturers = Gtk.ListStore(str)
        self.liststoreManufacturers.append(["Bosch"])
        self.liststoreManufacturers.append(["Whirlpool"])
        self.liststoreManufacturers.append(["Hotpoint"])
        self.liststoreManufacturers.append(["DeLonghi"])
        self.liststoreManufacturers.append(["Samsung"])

        treeview = Gtk.TreeView()
        treeview.set_model(self.liststoreAppliance)
        self.add(treeview)

        cellrenderertext = Gtk.CellRendererText()

        treeviewcolumn = Gtk.TreeViewColumn("Appliance")
        treeview.append_column(treeviewcolumn)
        treeviewcolumn.pack_start(cellrenderertext, False)
        treeviewcolumn.add_attribute(cellrenderertext, "text", 0)

        cellrenderercombo = Gtk.CellRendererCombo()
        cellrenderercombo.set_property("editable", True)
        cellrenderercombo.set_property("model", self.liststoreManufacturers)
        cellrenderercombo.set_property("text-column", 0)
        cellrenderercombo.connect("changed", self.on_combo_changed)

        treeviewcolumn = Gtk.TreeViewColumn("Manufacturer")
        treeview.append_column(treeviewcolumn)
        treeviewcolumn.pack_start(cellrenderercombo, False)
        treeviewcolumn.add_attribute(cellrenderercombo, "text", 1)

    def on_combo_changed(self, cellrenderercombo, treepath, treeiter):
        self.liststoreAppliance[treepath][1] = self.liststoreManufacturers[treeiter][0]

window = CellRendererCombo()
window.show_all()

Gtk.main()

results matching ""

    No results matching ""