CellRendererSpinner

The CellRendererSpinner provides a Spinner widget within a TreeView, to indicate activity of a job.

Note

See the CellRenderer page for additional methods available.

Constructor

The CellRendererSpinner can be constructed using the following:

cellrendererspinner = Gtk.CellRendererSpinner()

Properties

The configuration of the CellRendererSpin is made using the property functions:

cellrendererspin.set_property("item", value)

The property items available for use with the CellRendererSpin are:

  • "active" - the active property configures whether the CellRendererSpinner is displayed in the cell or not.
  • "pulse" - the pulse value is set to indicate whether the animation is running. This would be updated twelve times in 750 milliseconds.
  • "size" - the size property can be specified to indicate the size of the Spinner widget. The value should be set to one of the following; Gtk.IconSize.INVALID, Gtk.IconSize.MENU, Gtk.IconSize.SMALL_TOOLBAR, Gtk.IconSize.LARGE_TOOLBAR, Gtk.IconSize.BUTTON, Gtk.IconSize.DND, or Gtk.IconSize.DIALOG.

Example

Below is an example of a CellRendererSpinner:

#!/usr/bin/env python3

from gi.repository import Gtk
from gi.repository import GObject

class CellRendererSpinner(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        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()

Download: CellRendererSpinner