Ian,
Below is the source to a very simple example script I wrote to help me
better understand how signals in Urwid work. I thought I'd share, in
case someone else was having as hard a time figuring out how to use
signals as I was.
On an unrelated note, can you include __slots__ in all Urwid classes?
The program I'm writing with Urwid is eating up an excessive amount of
ram, and one of the tips I found for reducing python's memory
footprint is to use a __slots__ attribute which replaces the
memory-inefficient __dict__ with a tuple. :) Unfortunately it doesn't
work if one of the base classes doesn't use the __slots__ attribute
either. :(
Dominic
____code below______
#!/usr/bin/env python
import urwid
class sigsender(object):
__metaclass__ = urwid.MetaSignals
signals = ['sig']
def __init__(self):
urwid.Signals.connect(self, 'sig', self.cb)
def con(self, kin):
if kin is self:
pass
elif type(kin) is list:
map(self.con, kin)
elif 'sig' in kin.signals:
urwid.Signals.connect(self, 'sig', kin.cb)
def emit(self, extra=False):
print '\nemitting from %s' % self.__class__.__name__
if extra:
urwid.Signals.emit(self, 'sig', self)
else:
urwid.Signals.emit(self, 'sig')
def cb(self, rts=None):
if not rts:
print '%s recieved signal! printing!' % self.__class__.__name__
else:
print 'Oooh! %s received signal from %s! Lets mail them
back!' % (self.__class__.__name__, rts.__class__.__name__)
rts.thingy('OMGHI2U %s. Love, %s' %
(rts.__class__.__name__, self.__class__.__name__))
def thingy(self, response):
print 'Wow! %s got something back! It says: %s' %
(self.__class__.__name__, response)
class one(sigsender): pass
class two(sigsender): pass
class three(sigsender): pass
class four(sigsender): pass
a = one()
b = two()
c = three()
d = four()
a.emit()
b.emit()
c.emit()
d.emit()
print '\n\n'
a.con([a,b,c,d])
b.con([a,b,c,d])
c.con([a,b,c,d])
d.con([a,b,c,d])
a.emit()
b.emit()
c.emit()
d.emit()
a.emit(True)
b.emit(True)
c.emit(True)
d.emit(True)
_______________________________________________
Urwid mailing list
[email protected]
http://lists.excess.org/mailman/listinfo/urwid