Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For one, you could create a custom subclass of <code>GObject</code>, which provides some <a href="http://www.pygtk.org/articles/subclassing-gobject/sub-classing-gobject-in-python.htm#d0e570" rel="nofollow">custom signals</a>. The following example is a slightly adapted version of the one given in the linked article:</p> <pre><code>import pygtk pygtk.require('2.0') import gobject class Car(gobject.GObject): __gsignals__ = { 'engine-started': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), 'engine-stopped': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), } def __init__(self): gobject.GObject.__init__(self) self._state = 0 def start(self): if not self._state: self._state = 1 self.emit('engine-started') def stop(self): if self._state: self._state = 0 self.emit('engine-stopped') gobject.type_register(Car) def kill_switch(c): def callback(*unused, **ignored): c.stop() return callback def on_start(*unused, **ignored): print "Started..." def on_stop(*unused, **ignored): print "Stopped..." some_car = Car() some_car.connect('engine-started', on_start) some_car.connect('engine-started', kill_switch(some_car)) some_car.connect('engine-stopped', on_stop) some_car.start() </code></pre> <p>Another approach would be to take advantage of one of the many event/signalling packages already on PyPI, for example:</p> <ul> <li><a href="http://pypi.python.org/pypi/zope.event" rel="nofollow">Zope Event</a></li> <li><a href="http://pypi.python.org/pypi/Louie" rel="nofollow">Louie</a></li> <li><a href="http://pydispatcher.sourceforge.net/" rel="nofollow">PyDispatcher</a></li> <li><a href="http://pypi.python.org/pypi/darts.util.events" rel="nofollow">Darts Events</a></li> <li><a href="http://pypi.python.org/pypi/Trellis" rel="nofollow">Trellis</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload