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
19 ##@package grc.elements.Port
20 #Flow graph block port (source or sink).
24 from grc.elements.Element import Element
31 def __init__(self, block, n):
33 Make a new port from nested data.
34 @param block the parent element
35 @param n the nested odict
43 Element.__init__(self, block)
51 The port must be non-empty and type must a possible type.
53 try: assert(not self.is_empty())
54 except AssertionError: self._add_error_message('is empty.')
55 try: assert(self.get_type() in self.TYPES)
56 except AssertionError: self._add_error_message('Type "%s" is not a possible type.'%self.get_type())
60 return 'Source - %s(%s)'%(self.get_name(), self.get_key())
62 return 'Sink - %s(%s)'%(self.get_name(), self.get_key())
64 def is_port(self): return True
66 def get_color(self): return '#FFFFFF'
68 def get_name(self): return self._name
70 def get_key(self): return self._key
72 def is_sink(self): return self in self.get_parent().get_sinks()
74 def is_source(self): return self in self.get_parent().get_sources()
76 def get_type(self): return self.get_parent().resolve_dependencies(self._type)
78 def get_connections(self):
80 Get all connections that use this port.
81 @return a list of connection objects
83 connections = self.get_parent().get_parent().get_connections()
84 connections = filter(lambda c: c.get_source() is self or c.get_sink() is self, connections)
87 def is_connected(self):
89 Is this port connected?
90 @return true if at least one connection
92 return bool(self.get_connections())
96 Is this port full of connections?
97 Generally a sink can handle one connection and a source can handle many.
98 @return true if the port is full
100 if self.is_source(): return False
101 if self.is_sink(): return bool(self.get_connections())
106 An empty port has no connections.
107 @return true if empty
109 return not self.get_connections()