summaryrefslogtreecommitdiff
path: root/grc/python
diff options
context:
space:
mode:
authorSebastian Koslowski <koslowski@kit.edu>2013-11-27 19:29:53 +0100
committerSebastian Koslowski <koslowski@kit.edu>2013-11-29 12:53:48 +0100
commit89597f955a55c075ea9069e41df6c6842ae28997 (patch)
tree5f1dcdc294cf923469dbd52e080aee8aa2acb013 /grc/python
parente57ebc85082e5d8c168e06394de55c478cfe9b5c (diff)
grc: doc fixes
Diffstat (limited to 'grc/python')
-rw-r--r--grc/python/Block.py9
-rw-r--r--grc/python/Port.py30
2 files changed, 23 insertions, 16 deletions
diff --git a/grc/python/Block.py b/grc/python/Block.py
index c8537b2caa..5dffcb3124 100644
--- a/grc/python/Block.py
+++ b/grc/python/Block.py
@@ -97,26 +97,27 @@ class Block(_Block, _GUIBlock):
"""
_Block.rewrite(self)
- #adjust nports
+ # adjust nports
for ports in (self.get_sources(), self.get_sinks()):
for i, master_port in enumerate(ports):
nports = master_port.get_nports() or 1
num_ports = 1 + len(master_port.get_clones())
- if not nports and num_ports == 1: # no/former master port? skip
+ if not nports and num_ports == 1: # not a master port and no left-over clones
continue
- # remove excess ports
+ # remove excess cloned ports
for port in master_port.get_clones()[nports-1:]:
# remove excess connections
for connection in port.get_connections():
self.get_parent().remove_element(connection)
master_port.remove_clone(port)
ports.remove(port)
- # add more ports
+ # add more cloned ports
for i in range(num_ports, nports):
port = master_port.add_clone()
ports.insert(ports.index(master_port) + i, port)
self.back_ofthe_bus(ports)
+ # renumber non-message/-msg ports
for i, port in enumerate(filter(lambda p: p.get_key().isdigit(), ports)):
port._key = str(i)
diff --git a/grc/python/Port.py b/grc/python/Port.py
index 056be97e72..b82995cf6f 100644
--- a/grc/python/Port.py
+++ b/grc/python/Port.py
@@ -219,41 +219,47 @@ class Port(_Port, _GUIPort):
def get_clones(self):
"""
- Get clones of this master port
+ Get the clones of this master port (nports > 1)
+
+ Returns:
+ a list of ports
"""
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
+ Create a clone of this (master) port and store a reference in self._clones.
+
+ The new port name (and key for message ports) will have index 1... appended.
+ If this is the first clone, this (master) port will get a 0 appended to its name (and key)
Returns:
- the newly create clone
+ the cloned port
"""
- if not self._clones: # add index to master port name
+ # add index to master port name if there are no clones yet
+ if not self._clones:
self._name = self._n['name'] + '0'
- if not self._key.isdigit():
+ if not self._key.isdigit(): # also update key for none stream ports
self._key = self._name
# Prepare a copy of the odict for the clone
n = self._n.copy()
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']
+ n['key'] = '99999' if self._key.isdigit() else n['name'] # dummy value 99999 will be fixed later
- port = self.__class__(self.get_parent(), n, self._dir)
+ port = self.__class__(self.get_parent(), n, self._dir) # clone
self._clones.append(port)
return port
def remove_clone(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
+ Remove a cloned port (from the list of clones only)
+ Remove the index 0 of the master port name (and key9 if there are no more clones left
"""
self._clones.remove(port)
+ # remove index from master port name if there are no more clones
if not self._clones:
self._name = self._n['name']
- if not self._key.isdigit():
+ if not self._key.isdigit(): # also update key for none stream ports
self._key = self._name