Gtk.CellRendererToggle
Gtk.CellRendererToggle — Renders a toggle button in a cell
Object Hierarchy:
GObject
╰── GInitiallyUnowned
╰── Gtk.CellRenderer
╰── Gtk.CellRendererToggle
Functions:
- new
() -> Gtk.CellRenderer
- get_radio
(self) -> bool
- set_radio
(self, radio:bool)
- get_active
(self) -> bool
- set_active
(self, setting:bool)
- get_activatable
(self) -> bool
- set_activatable
(self, setting:bool)
Signals:
- “toggled”
(cell_renderer, path, user_data)
Description:
Gtk.CellRendererToggle
renders a toggle button in a cell. The button is drawn as a radio or a checkbutton, depending on the Gtk.CellRendererToggle::radio
property.
When activated, it emits the Gtk.CellRendererToggle::toggled signal
.
Function Details:
new()
new () -> Gtk.CellRenderer
Creates a new Gtk.CellRendererToggle
. Adjust renderingparameters using object properties. Object properties can be setglobally (with g_object_set()
). Also, with Gtk.TreeViewColumn
, youcan bind a property to a value in a Gtk.TreeModel
. For example, youcan bind the “active” property on the cell renderer to a boolean valuein the model, thus causing the check button to reflect the state ofthe model.
- Returns: the new cell renderer
get_radio()
get_radio (self) -> bool
Returns whether we’re rendering radio toggles rather than checkboxes.
- Returns:
True
if we’re rendering radio toggles rather than checkboxes
set_radio()
set_radio (self, radio:bool)
If radio
is True
, the cell renderer renders a radio toggle(i.e. a toggle in a group of mutually-exclusive toggles).If FALSE
, it renders a check toggle (a standalone boolean option).This can be set globally for the cell renderer, or changed justbefore rendering each cell in the model (for Gtk.TreeView
, you setup a per-row setting using Gtk.TreeView
Column to associate modelcolumns with cell renderer properties).
get_active()
get_active (self) -> bool
Returns whether the cell renderer is active. SeeGtk.CellRendererToggle:set_active()
.
- Returns:
True
if the cell renderer is active.
set_active()
set_active (self, setting:bool)
Activates or deactivates a cell renderer.
get_activatable()
get_activatable (self) -> bool
Returns whether the cell renderer is activatable. SeeGtk.CellRendererToggle:set_activatable()
.
Returns:
True
if the cell renderer is activatable.Since: 2.18
set_activatable()
set_activatable (self, setting:bool)
Makes the cell renderer activatable.
- Since: 2.18
Example:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class CellRendererToggle(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.connect("destroy", Gtk.main_quit)
self.liststore = Gtk.ListStore(str, bool)
self.liststore.append(["Ethernet", True])
self.liststore.append(["Wireless", True])
self.liststore.append(["Bluetooth", False])
self.liststore.append(["3g Mobile", True])
treeview = Gtk.TreeView()
treeview.set_model(self.liststore)
self.add(treeview)
cellrenderertext = Gtk.CellRendererText()
cellrenderertoggle = Gtk.CellRendererToggle()
cellrenderertoggle.connect("toggled", self.on_cell_toggled)
treeviewcolumn = Gtk.TreeViewColumn("Connection Type")
treeviewcolumn.pack_start(cellrenderertext, False)
treeviewcolumn.add_attribute(cellrenderertext, "text", 0)
treeview.append_column(treeviewcolumn)
treeviewcolumn = Gtk.TreeViewColumn("Status")
treeviewcolumn.pack_start(cellrenderertoggle, False)
treeviewcolumn.add_attribute(cellrenderertoggle, "active", 1)
treeview.append_column(treeviewcolumn)
def on_cell_toggled(self, cellrenderertoggle, treepath):
self.liststore[treepath][1] = not self.liststore[treepath][1]
window = CellRendererToggle()
window.show_all()
Gtk.main()