sugar-toolkit-gtk3/examples/cellrenderericon.py
Gonzalo Odiard 49365e132c New invoker, TreeViewInvoker
This new invoker is able to handle all the palettes on a treeview,
removing the need of one invoker per cell renderer (CellRendererInvoker).
This simplifies the code and makes it more efficient.
Also removes the logic from the CellRendererIcon, which
should only care about drawing itself. [1]

Is important to note than in Gtk3 a CellRenderer is not a GtkWidget
then can't know when the mouse is over it or have the usual events
used by other invokers, making the implementation CellRendererInvoker
very complicate.

This commit also removes the invoker of CellRendererIcon.

The ScrollingDetector logic is simplified too,
because now there are only one invoker instead of one by renderer
and the example code updated.

[1] https://developer.gnome.org/gtk3/stable/GtkCellRenderer.html
2015-05-14 12:04:07 -03:00

38 lines
841 B
Python

from gi.repository import Gtk
from sugar3.graphics import style
from sugar3.graphics.icon import CellRendererIcon
import common
test = common.Test()
test.show()
model = Gtk.ListStore(str)
for icon in ['one', 'two', 'three']:
model.append([icon])
treeview = Gtk.TreeView()
treeview.set_model(model)
test.pack_start(treeview, True, True, 0)
treeview.show()
col = Gtk.TreeViewColumn()
treeview.append_column(col)
cell_icon = CellRendererIcon()
cell_icon.props.width = style.GRID_CELL_SIZE
cell_icon.props.height = style.GRID_CELL_SIZE
cell_icon.props.size = style.SMALL_ICON_SIZE
cell_icon.props.icon_name = 'emblem-favorite'
col.pack_start(cell_icon, expand=False)
cell_text = Gtk.CellRendererText()
col.pack_start(cell_text, expand=True)
col.add_attribute(cell_text, 'text', 0)
if __name__ == '__main__':
common.main(test)