summaryrefslogtreecommitdiff
path: root/grc/python/Port.py
diff options
context:
space:
mode:
authorSebastian Koslowski <koslowski@kit.edu>2013-11-26 14:01:20 +0100
committerSebastian Koslowski <koslowski@kit.edu>2013-11-29 12:37:12 +0100
commitac2babe9d2a7992f5fcfc97d8606329e76c1666e (patch)
tree173edcab71c46f1ea728a58c05d670a931cf3baf /grc/python/Port.py
parent549b060f2d8f7636cd7f9053e93eb279e93c662a (diff)
grc: rewrite of nports code (WIP)
Diffstat (limited to 'grc/python/Port.py')
-rw-r--r--grc/python/Port.py48
1 files changed, 41 insertions, 7 deletions
diff --git a/grc/python/Port.py b/grc/python/Port.py
index 5f1247ce45..f664204e85 100644
--- a/grc/python/Port.py
+++ b/grc/python/Port.py
@@ -92,6 +92,7 @@ class Port(_Port, _GUIPort):
"""
self._n = n
if n['type'] == 'msg': n['key'] = 'msg'
+ if n['type'] == 'message': n['key'] = n['name']
if dir == 'source' and not n.find('key'):
n['key'] = str(block._source_count)
block._source_count += 1
@@ -109,6 +110,7 @@ class Port(_Port, _GUIPort):
self._nports = n.find('nports') or ''
self._vlen = n.find('vlen') or ''
self._optional = bool(n.find('optional'))
+ self._clones = [] # references to cloned ports (for nports > 1)
def get_types(self): return Constants.TYPE_TO_SIZEOF.keys()
@@ -183,8 +185,8 @@ class Port(_Port, _GUIPort):
the number of ports or 1
"""
nports = self.get_parent().resolve_dependencies(self._nports)
- #return blank if nports is blank
- if not nports: return ''
+ if not nports: # return blank if nports is blank
+ return ''
try:
return max(1, int(self.get_parent().get_parent().evaluate(nports)))
except:
@@ -215,9 +217,41 @@ class Port(_Port, _GUIPort):
return '#%.2x%.2x%.2x'%(r, g, b)
except: return _Port.get_color(self)
- def copy(self, new_key=None):
+ def get_clones(self):
+ """
+ Get clones of this master port
+ """
+ return self._clones
+
+ def add_clone(self):
+ """
+ Create a clone of this (master) port and store it internally
+ This clone will have the same key. The name get an index
+ If this is the first clone, this (master) port will get a 0 appended to its name
+
+ Returns:
+ the newly create clone
+ """
+ if not self._clones: # add index to master port name
+ self._name = self._n['name'] + '0'
+ if not self._key.isdigit():
+ self._n['key'] = self._name
+
+ # Prepare a copy of the odict for the clone
n = self._n.copy()
- #remove nports from the key so the copy cannot be a duplicator
- if n.has_key('nports'): n.pop('nports')
- if new_key: n['key'] = new_key
- return self.__class__(self.get_parent(), n, self._dir)
+ if 'nports' in n: n.pop('nports') # remove nports from the key so the copy cannot be a duplicator
+ n['name'] = self._n['name'] + str(len(self._clones) + 1)
+ n['key'] = '99999' if self._key.isdigit() else n['name']
+
+ port = self.__class__(self.get_parent(), n, self._dir)
+ self._clones.append(port)
+ return port
+
+ def remove_duplicate(self, port):
+ """
+ Remove a cloned port from the internal list
+ Remove to index 0 of the master port name if there are no more clones
+ """
+ self._clones.remove(port)
+ if not self._clones:
+ self._name = self._n['key'] = self._n['name']