2 Copyright 2008 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
21 from Element import Element
28 def __init__(self, block, n):
30 Make a new port from nested data.
31 @param block the parent element
32 @param n the nested odict
40 Element.__init__(self, block)
48 The port must be non-empty and type must a possible type.
50 try: assert(not self.is_empty())
51 except AssertionError: self._add_error_message('is empty.')
52 try: assert(self.get_type() in self.TYPES)
53 except AssertionError: self._add_error_message('Type "%s" is not a possible type.'%self.get_type())
57 return 'Source - %s(%s)'%(self.get_name(), self.get_key())
59 return 'Sink - %s(%s)'%(self.get_name(), self.get_key())
61 def is_port(self): return True
63 def get_color(self): return '#FFFFFF'
65 def get_name(self): return self._name
67 def get_key(self): return self._key
69 def is_sink(self): return self in self.get_parent().get_sinks()
71 def is_source(self): return self in self.get_parent().get_sources()
73 def get_type(self): return self.get_parent().resolve_dependencies(self._type)
75 def get_connections(self):
77 Get all connections that use this port.
78 @return a list of connection objects
80 connections = self.get_parent().get_parent().get_connections()
81 connections = filter(lambda c: c.get_source() is self or c.get_sink() is self, connections)
84 def is_connected(self):
86 Is this port connected?
87 @return true if at least one connection
89 return bool(self.get_connections())
93 Is this port full of connections?
94 Generally a sink can handle one connection and a source can handle many.
95 @return true if the port is full
97 if self.is_source(): return False
98 if self.is_sink(): return bool(self.get_connections())
103 An empty port has no connections.
104 @return true if empty
106 return not self.get_connections()