pygtk - Python GTK+: create custom signals? -


is possible create new signals in python gtk+ ?

i'd skeleton code example, please.

an excerpt:

creating own signals

the other thing want use when subclassing gobject define custom signals. can create own signals can emitted users of class can connect them.

when signal emitted set of closures executed. closure abstraction of callback concept. closure callback (a function pointer), user data (it last parameter callback) , function cleanup issues, not discussed in document.

for sake of article don't need know difference between callback , closure both terms used. advised not totally correct.

as said before, when signal emitted, set of closures executed. 1 of them same 1 instances of class , hence name: class closure, , other ones custom user callbacks. note not signals need have class closure because optional.

from, http://www.pygtk.org/articles/subclassing-gobject/sub-classing-gobject-in-python.htm, hope helps. there example code on site , here , snippet:

import pygtk pygtk.require('2.0') import gobject  class car(gobject.gobject):     __gproperties__ = {         'fuel' : (gobject.type_float, 'fuel of car',                   'amount of fuel remains in tank',                   0, 60, 50, gobject.param_readwrite)         }      __gsignals__ = {         'engine-started' : (gobject.signal_run_last, gobject.type_none,                             (gobject.type_float,))         }      def __init__(self):         gobject.gobject.__init__(self)         self.fuel = 50      def do_get_property(self, property):         if property.name == 'fuel':             return self.fuel         else:             raise attributeerror, 'unknown property %s' % property.name      def do_set_property(self, property, value):         if property.name == 'fuel':             self.fuel = value         else:             raise attributeerror, 'unknown property %s' % property.name      def do_engine_started(self, remaining_fuel):         print '***** beginning of class closure *****'         print 'the engine ready , still have %f of fuel' % self.fuel         print '***** end of class closure *****'      def start(self):         self.emit('engine-started', self.get_property('fuel'))  gobject.type_register(car) 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -