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_gnuradio.Port
20 #Flow graph block port (source or sink).
22 from grc.elements.Port import Port as _Port
24 from grc.Constants import MAX_NUM_PORTS
29 TYPES = ['complex', 'float', 'int', 'short', 'byte']
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
38 vlen = Utils.exists_or_else(n, 'vlen', '1')
39 nports = Utils.exists_or_else(n, 'nports', '')
40 optional = Utils.exists_or_else(n, 'optional', '')
49 self._optional = bool(optional)
53 Get the vector length.
54 If the evaluation of vlen cannot be cast to an integer, return 1.
55 @return the vector length or 1
57 vlen = self.get_parent().resolve_dependencies(self._vlen)
58 try: return int(self.get_parent().get_parent().evaluate(vlen))
63 Get the number of ports.
64 If already blank, return a blank
65 If the evaluation of nports cannot be cast to an integer, return 1.
66 @return the number of ports or 1
68 nports = self.get_parent().resolve_dependencies(self._nports)
69 #return blank if nports is blank
70 if not nports: return ''
72 nports = int(self.get_parent().get_parent().evaluate(nports))
73 assert(0 < nports <= MAX_NUM_PORTS)
77 def get_optional(self): return bool(self._optional)
81 Get the color that represents this port's type.
82 Codes differ for ports where the vec length is 1 or greater than 1.
83 @return a hex color code.
86 if self.get_vlen() == 1:
94 return {#vlen is non 1
101 except: return _Port.get_color(self)
106 An empty port has no connections.
107 Not empty of optional is set.
108 @return true if empty
110 return not self.get_optional() and not self.get_connections()
114 def __init__(self, block, n):
117 n['key'] = str(block._source_count)
118 block._source_count = block._source_count + 1
119 Port.__init__(self, block, n)
122 self.get_parent()._source_count = self.get_parent()._source_count - 1
126 def __init__(self, block, n):
129 n['key'] = str(block._sink_count)
130 block._sink_count = block._sink_count + 1
131 Port.__init__(self, block, n)
134 self.get_parent()._sink_count = self.get_parent()._sink_count - 1