Gtk.CellRendererSpin


Gtk.CellRendererSpin — Renders a spin button in a cell

Object Hierarchy:

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

See also:

Gtk.CellRendererText, Gtk.SpinButton


Functions:

  • new () -> Gtk.CellRenderer

Description:

Gtk.CellRendererSpin renders text in a cell like Gtk.CellRendererText from which it is derived. But while Gtk.CellRendererText offers a simple entry to edit the text, Gtk.CellRendererSpin offers a Gtk.SpinButton widget. Of course, that means that the text has to be parseable as a floating point number.

The range of the spinbutton is taken from the adjustment property of the cell renderer, which can be set explicitly or mapped to a column in the tree model, like all properties of cell renders. Gtk.CellRendererSpin also has properties for the Gtk.CellRendererSpin::climb-rate and the number of Gtk.CellRendererSpin::digits to display. Other GtkSpinButton properties can be set in a handler for the Gtk.CellRenderer::editing-started signal.

The Gtk.CellRendererSpin cell renderer was added in GTK+ 2.10.


Function Details:

new()

new () -> Gtk.CellRenderer

Creates a new Gtk.CellRendererSpin.

  • Returns: a new Gtk.CellRendererSpin

  • Since: 2.10


Example:

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

class CellRendererSpin(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_title("CellRendererSpin")
        self.set_default_size(150, -1)
        self.connect("destroy", Gtk.main_quit)

        self.liststore = Gtk.ListStore(str, int)
        self.liststore.append(["Oranges", 5])
        self.liststore.append(["Bananas", 2])
        self.liststore.append(["Apples", 3])

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

        cellrenderertext = Gtk.CellRendererText()

        adjustment = Gtk.Adjustment(0, 0, 10, 1, 1, 0)
        cellrendererspin = Gtk.CellRendererSpin()
        cellrendererspin.set_property("editable", True)
        cellrendererspin.set_property("adjustment", adjustment)
        cellrendererspin.connect("edited", self.on_cell_edited)

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

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

    def on_cell_edited(self, cellrendererspin, treepath, value):
        self.liststore[treepath][1] = int(value)

window = CellRendererSpin()
window.show_all()

Gtk.main()

results matching ""

    No results matching ""