Gtk.CellRendererSpinner


Gtk.CellRendererSpinner — Renders a spinning animation in a cell

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.CellRenderer
            ╰── Gtk.CellRendererSpinner

See also:

Gtk.Spinner, Gtk.CellRendererProgress


Functions:

  • new () -> Gtk.CellRenderer

Description:

Gtk.CellRendererSpinner renders a spinning animation in a cell, very similar to Gtk.Spinner. It can often be used as an alternative to a Gtk.CellRendererProgress for displaying indefinite activity, instead of actual progress.

To start the animation in a cell, set the Gtk.CellRendererSpinner::active property to True and increment the Gtk.CellRendererSpinner::pulse property at regular intervals. The usual way to set the cell renderer properties for each cell is to bind them to columns in your tree model using e.g. Gtk.TreeViewColumn::add_attribute().


Function Details:

new()

new () -> Gtk.CellRenderer

Returns a new cell renderer which will show a spinner to indicateactivity.

  • Returns: a new Gtk.CellRenderer

  • Since: 2.20


Example:

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

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

        self.liststore = Gtk.ListStore(str, bool, int)
        self.liststore.append(["Copying files", True,  0])
        self.liststore.append(["Downloading access logs", False, 0])
        self.liststore.append(["Connecting to server", True, 0])

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

        cellrenderertext = Gtk.CellRendererText()
        self.cellrendererspinner = Gtk.CellRendererSpinner()

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

        treeviewcolumn = Gtk.TreeViewColumn("Status")
        treeview.append_column(treeviewcolumn)
        treeviewcolumn.pack_start(self.cellrendererspinner, False)
        treeviewcolumn.add_attribute(self.cellrendererspinner, "active", 1)

    def on_spinner_pulse(self):
        for item in self.liststore:
            if item[1]:
                if item[2] == 12:
                    item[2] = 0
                else:
                    item[2] += 1

        self.cellrendererspinner.set_property("pulse", item[2])

        return True

window = CellRendererSpinner()
window.show_all()

GObject.timeout_add(100, window.on_spinner_pulse)

Gtk.main()

results matching ""

    No results matching ""