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).
23 from grc.elements.Element import Element
30 def __init__(self, block, n):
32 Make a new port from nested data.
33 @param block the parent element
34 @param n the nested odict
42 Element.__init__(self, block)
50 The port must be non-empty and type must a possible type.
52 try: assert(not self.is_empty())
53 except AssertionError: self._add_error_message('is empty.')
54 try: assert(self.get_type() in self.TYPES)
55 except AssertionError: self._add_error_message('Type "%s" is not a possible type.'%self.get_type())
59 return 'Source - %s(%s)'%(self.get_name(), self.get_key())
61 return 'Sink - %s(%s)'%(self.get_name(), self.get_key())
63 def is_port(self): return True
65 def get_color(self): return '#FFFFFF'
67 def get_name(self): return self._name
69 def get_key(self): return self._key
71 def is_sink(self): return self in self.get_parent().get_sinks()
73 def is_source(self): return self in self.get_parent().get_sources()
75 def get_type(self): return self.get_parent().resolve_dependencies(self._type)
77 def get_connections(self):
79 Get all connections that use this port.
80 @return a list of connection objects
82 connections = self.get_parent().get_parent().get_connections()
83 connections = filter(lambda c: c.get_source() is self or c.get_sink() is self, connections)
86 def is_connected(self):
88 Is this port connected?
89 @return true if at least one connection
91 return bool(self.get_connections())
95 Is this port full of connections?
96 Generally a sink can handle one connection and a source can handle many.
97 @return true if the port is full
99 if self.is_source(): return False
100 if self.is_sink(): return bool(self.get_connections())
105 An empty port has no connections.
106 @return true if empty
108 return not self.get_connections()