Ked som kedysi robil property grid, tak som potreboval vlozit do
TreeView tlacidlo a odchytavat click. Teda nieco podobne ako chcete vy.
Spravil som si vlastny renderer. Prikladam ho v prilohe. Urcite ho
nebudete chciet pouzit 1:1, ale ako priklad hadam postaci
David Hrachovy wrote:
Zdravim, tohle je muj prvni dotaz na teto konferenci, tak doufam, ze
bude stat za to:)
Mam treeview. V nem zobrazuji nejake zbozi z liststore. V jednom
sloupci zobrazuji pixbuf. Po jednom kliknuti na nejaky cell z toho
sloupce bych potreboval, aby se zavolala moje funkce f().
Konkretne: tukanim na obrazek pluska se zvysi pocet polozek ve skladu.
Zkousel jsem to pres signaly row-activated, cursor-changed, ale vzdycky
musim kliknout 2x:(
Rad uvitam primo ukazky kodu ci jine reseni.
Kdyz tak tu hodim i kod pro predstavu.
--
____________________________
Ing. Jan Janech
Katedra softverovych technologii
Fakulta riadenia a informatiky
Zilinska Univerzita
import gtk
import gobject
import pango
class CellRendererButton(gtk.GenericCellRenderer):
__gproperties__ = {
"text": (gobject.TYPE_STRING, None, "Text",
"Displayed text", gobject.PARAM_READWRITE),
}
__gsignals__ = {
'click' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
(gobject.TYPE_STRING, )),
}
def __init__(self):
self.__gobject_init__()
self.text = ""
self.width = 30
self.set_property('mode', gtk.CELL_RENDERER_MODE_EDITABLE)
def do_set_property(self, pspec, value):
setattr(self, pspec.name, value)
def do_get_property(self, pspec):
return getattr(self, pspec.name)
def on_render(self, window, widget, background_area, cell_area, expose_area, flags):
tid = 0
if flags & gtk.CELL_RENDERER_SELECTED:
tid = 3
layout = widget.create_pango_layout(self.text)
layout.set_font_description(widget.style.font_desc)
w, h = layout.get_size()
x = cell_area.x + 3
y = int(cell_area.y + (cell_area.height - h / pango.SCALE) / 2)
window.draw_layout(widget.style.text_gc[tid], x, y, layout)
if flags & gtk.CELL_RENDERER_SELECTED:
widget.style.paint_box(window, gtk.STATE_NORMAL, gtk.SHADOW_OUT, None, widget, "button",
cell_area.x + cell_area.width - self.width, cell_area.y, self.width, cell_area.height)
layout = widget.create_pango_layout("...")
layout.set_font_description(widget.style.font_desc)
w, h = layout.get_size()
x = int(cell_area.x + cell_area.width - self.width + (self.width - w / pango.SCALE) / 2)
y = int(cell_area.y + (cell_area.height - h / pango.SCALE) / 2)
window.draw_layout(widget.style.text_gc[0], x, y, layout)
def on_get_size(self, widget, cell_area=None):
if cell_area is None:
return (0, 0, self.width, 18)
else:
return (cell_area.x, cell_area.y, cell_area.width, cell_area.height)
def on_start_editing(self, event, widget, path, background_area, cell_area, flags):
x = cell_area.x + cell_area.width - self.width
if event is not None and event.type == gtk.gdk.BUTTON_PRESS and \
x < event.x < cell_area.x + cell_area.width and \
cell_area.y < event.y < cell_area.y + cell_area.height:
self.emit("click", path)
gobject.type_register(CellRendererButton)
_______________________________________________
Python mailing list
[email protected]
http://www.py.cz/mailman/listinfo/python