CellRendererAccel

A CellRendererAccel is used to render a keyboard accelerator into a cell. The object is editable if required and allows a user to change the accelerator by entering a new combination.

Note

See the CellRenderer page for additional methods available.

Constructor

The CellRendererAccel can be constructed using the following:

cellrendereraccel = Gtk.CellRendererAccel()

Properties

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

cellrendereraccel.set_property("item", value)

The property items available for use with the CellRendererAccel are:

  • "editable" - when specified as True, the accelerator value can be edited by the user.

Signals

The commonly used signals of a CellRendererAccel are:

"accel-cleared" (cellrendereraccel, path_string)
"accel-edited" (cellrendereraccel, path_string, accel_key, accel_mods, hardware_keycode)

The "accel-cleared" signals is emitted when the user presses the Backspace key. On the other hand, "accel-edited" is seen when the user changes the accelerator by entering another key combination.

Example

Below is an example of an CellRendererAccel:

#!/usr/bin/env python3

from gi.repository import Gtk

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

        self.liststore = Gtk.ListStore(str, str)
        self.liststore.append(["New", "<Primary>n"])
        self.liststore.append(["Open", "<Primary>o"])
        self.liststore.append(["Save", "<Primary>s"])

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

        cellrenderertext = Gtk.CellRendererText()

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

        cellrendereraccel = Gtk.CellRendererAccel()
        cellrendereraccel.set_property("editable", True)
        cellrendereraccel.connect("accel-edited", self.on_accel_edited)
        cellrendereraccel.connect("accel-cleared", self.on_accel_cleared)

        treeviewcolumn = Gtk.TreeViewColumn("Accelerator")
        treeview.append_column(treeviewcolumn)
        treeviewcolumn.pack_start(cellrendereraccel, True)
        treeviewcolumn.add_attribute(cellrendereraccel, "text", 1)

    def on_accel_edited(self, cellrendereraccel, path, key, mods, hwcode):
        accelerator = Gtk.accelerator_name(key, mods)
        self.liststore[path][1] = accelerator

    def on_accel_cleared(self, cellrendereraccel, path):
        self.liststore[path][1] = "None"

window = CellRendererAccel()
window.show_all()

Gtk.main()

Download: CellRendererAccel