[pygtk] [SOLVED] custom CellRenderer and custom signals - how?
Don Question
donquestion at rocketmail.com
Thu Mar 4 23:32:59 WST 2010
Thanks to a post in #pygtk at irc.gimp.org i got it solved. I want to share this for others
with maybe similar problems:
#--------------------------------------------------------------------------
import gtk
import gobject
class CellRendererPixbufXt(gtk.CellRendererPixbuf):
__gproperties__ = { 'active-state' :
(gobject.TYPE_STRING, 'pixmap/active widget state',
'stock-icon name representing active widget state',
None, gobject.PARAM_READWRITE) }
__gsignals__ = { 'clicked' :
(gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()) , }
def __init__( self ):
gtk.CellRendererPixbuf.__init__( self )
self.set_property( 'mode', gtk.CELL_RENDERER_MODE_ACTIVATABLE )
def do_get_property( self, property ):
if property.name == 'active-state':
return self.active_state
else:
raise AttributeError, 'unknown property %s' % property.name
def do_set_property( self, property, value ):
if property.name == 'active-state':
self.active_state = value
else:
raise AttributeError, 'unknown property %s' % property.name
def do_activate( self, event, widget, path, background_area, cell_area, flags ):
print( "do_activate" )
if event.type == gtk.gdk.BUTTON_PRESS:
self.emit('clicked')
def do_clicked(self):
print "do_clicked"
gobject.type_register(CellRendererPixbufXt)
#--------------------------------------------------------------------------
see also:
http://userpage.chemie.fu-berlin.de/~chrbecke/gobject-tutorial/
http://www.pygtk.org/pygtk2tutorial/sec-EventHandling.html
More information about the pygtk
mailing list