2 Copyright 2008, 2009 Free Software Foundation, Inc.
3 This file is part of GNU Radio
5 GNU Radio Companion is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 GNU Radio Companion is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 from Element import Element
24 def __init__(self, block, n, dir):
26 Make a new port from nested data.
27 @param block the parent element
28 @param n the nested odict
29 @param dir the direction source or sink
32 Element.__init__(self, block)
34 self._name = n['name']
36 self._type = n['type']
42 The port must be non-empty and type must a possible type.
44 Element.validate(self)
45 try: assert self.get_type() in self.get_types()
46 except AssertionError: self.add_error_message('Type "%s" is not a possible type.'%self.get_type())
50 return 'Source - %s(%s)'%(self.get_name(), self.get_key())
52 return 'Sink - %s(%s)'%(self.get_name(), self.get_key())
56 Get a list of all possible port types.
57 @throw NotImplementedError
59 raise NotImplementedError
61 def is_port(self): return True
62 def get_color(self): return '#FFFFFF'
63 def get_name(self): return self._name
64 def get_key(self): return self._key
65 def is_sink(self): return self._dir == 'sink'
66 def is_source(self): return self._dir == 'source'
67 def get_type(self): return self.get_parent().resolve_dependencies(self._type)
69 def get_connections(self):
71 Get all connections that use this port.
72 @return a list of connection objects
74 connections = self.get_parent().get_parent().get_connections()
75 connections = filter(lambda c: c.get_source() is self or c.get_sink() is self, connections)
78 def get_enabled_connections(self):
80 Get all enabled connections that use this port.
81 @return a list of connection objects
83 return filter(lambda c: c.get_enabled(), self.get_connections())