6
# TODO: use gobject type system
14
class Pad(gobject.GObject):
16
'data-ready': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
19
def __init__(self, direction, type = TYPE_ANY, subtype = None):
20
super(Pad, self).__init__()
21
self.direction = direction
23
self.subtype = subtype
28
if pad.direction == self.direction:
29
print "pads with same direction (%s) can't be linked" % pad.direction
32
if pad.owner is None or self.owner is None:
33
print "both pads need to have an owner to be able to link them"
36
#TODO: add checks for types
37
#TODO: add checks for loops
42
if pad.direction == DIRECTION_OUT:
43
self.linked.connect('data-ready', self.owner.on_data_ready)
48
if self.linked is None:
50
self.linked.linked = None
54
if not self.linked is None:
55
self.linked.owner.run(self.linked)
58
self.emit('data-ready')
61
return self.owner.data(self)
63
class Element(object):
64
def __init__(self, name):
69
return self._pads.get(name)
71
def add_pad(self, name, pad):
72
if self._pads.get(name) is None:
73
self._pads[name] = pad
77
print "a pad with the name %s already exist. can't add another" % name
81
print "default run() does nothing. re-implement in your element class"
84
def data(self, pad=None):
85
print "default data() returns None. re-implement in your element class"
88
def on_data_ready(self, sender):
89
print "default data_ready() does nothing. re-implement in your element class"
94
class Source(Element):
95
def __init__(self, name, type, subtype = None):
96
super(Source, self).__init__(name)
97
self.add_pad('out', Pad(DIRECTION_OUT, type, subtype))
100
class Filter(Element):
101
def __init__(self, name, in_type, out_type, in_subtype = None, out_subtype = None):
102
super(Filter, self).__init__(name)
103
self.add_pad('in', Pad(DIRECTION_IN, in_type, in_subtype))
104
self.add_pad('out', Pad(DIRECTION_OUT, out_type, out_subtype))
106
class Output(Element):
108
super(Output, self).__init__("output")
109
self.add_pad('in', Pad(DIRECTION_IN, TYPE_INTERNAL, None))
111
def on_data_ready(self, sender):
112
print "FINISHED !!!!"