summaryrefslogtreecommitdiff
path: root/grc/base/Port.py
diff options
context:
space:
mode:
Diffstat (limited to 'grc/base/Port.py')
-rw-r--r--grc/base/Port.py173
1 files changed, 86 insertions, 87 deletions
diff --git a/grc/base/Port.py b/grc/base/Port.py
index 1b2acb0582..b7de5301f1 100644
--- a/grc/base/Port.py
+++ b/grc/base/Port.py
@@ -21,97 +21,96 @@ from Element import Element
class Port(Element):
- def __init__(self, block, n, dir):
- """
- Make a new port from nested data.
-
- Args:
- block: the parent element
- n: the nested odict
- dir: the direction source or sink
- """
- #build the port
- Element.__init__(self, block)
- #grab the data
- self._name = n['name']
- self._key = n['key']
- self._type = n['type']
- self._dir = dir
+ def __init__(self, block, n, dir):
+ """
+ Make a new port from nested data.
+
+ Args:
+ block: the parent element
+ n: the nested odict
+ dir: the direction source or sink
+ """
+ #build the port
+ Element.__init__(self, block)
+ #grab the data
+ self._name = n['name']
+ self._key = n['key']
+ self._type = n['type']
+ self._dir = dir
-
- def validate(self):
- """
- Validate the port.
- The port must be non-empty and type must a possible type.
- """
- Element.validate(self)
- if self.get_type() not in self.get_types():
- self.add_error_message('Type "%s" is not a possible type.'%self.get_type())
+ def validate(self):
+ """
+ Validate the port.
+ The port must be non-empty and type must a possible type.
+ """
+ Element.validate(self)
+ if self.get_type() not in self.get_types():
+ self.add_error_message('Type "%s" is not a possible type.'%self.get_type())
- def __str__(self):
- if self.is_source():
- return 'Source - %s(%s)'%(self.get_name(), self.get_key())
- if self.is_sink():
- return 'Sink - %s(%s)'%(self.get_name(), self.get_key())
+ def __str__(self):
+ if self.is_source():
+ return 'Source - %s(%s)'%(self.get_name(), self.get_key())
+ if self.is_sink():
+ return 'Sink - %s(%s)'%(self.get_name(), self.get_key())
- def get_types(self):
- """
- Get a list of all possible port types.
- @throw NotImplementedError
- """
- raise NotImplementedError
+ def get_types(self):
+ """
+ Get a list of all possible port types.
+ @throw NotImplementedError
+ """
+ raise NotImplementedError
- def is_port(self): return True
- def get_color(self): return '#FFFFFF'
- def get_name(self):
- number = ''
- if self.get_type() == 'bus':
- busses = filter(lambda a: a._dir == self._dir, self.get_parent().get_ports_gui());
-
- number = str(busses.index(self)) + '#' + str(len(self.get_associated_ports()));
- return self._name + number
+ def is_port(self): return True
+ def get_color(self): return '#FFFFFF'
+ def get_name(self):
+ number = ''
+ if self.get_type() == 'bus':
+ busses = filter(lambda a: a._dir == self._dir, self.get_parent().get_ports_gui());
+
+ number = str(busses.index(self)) + '#' + str(len(self.get_associated_ports()));
+ return self._name + number
- def get_key(self): return self._key
- def is_sink(self): return self._dir == 'sink'
- def is_source(self): return self._dir == 'source'
- def get_type(self): return self.get_parent().resolve_dependencies(self._type)
+ def get_key(self): return self._key
+ def is_sink(self): return self._dir == 'sink'
+ def is_source(self): return self._dir == 'source'
+ def get_type(self): return self.get_parent().resolve_dependencies(self._type)
- def get_connections(self):
- """
- Get all connections that use this port.
-
- Returns:
- a list of connection objects
- """
- connections = self.get_parent().get_parent().get_connections()
- connections = filter(lambda c: c.get_source() is self or c.get_sink() is self, connections)
- return connections
+ def get_connections(self):
+ """
+ Get all connections that use this port.
+
+ Returns:
+ a list of connection objects
+ """
+ connections = self.get_parent().get_parent().get_connections()
+ connections = filter(lambda c: c.get_source() is self or c.get_sink() is self, connections)
+ return connections
- def get_enabled_connections(self):
- """
- Get all enabled connections that use this port.
-
- Returns:
- a list of connection objects
- """
- return filter(lambda c: c.get_enabled(), self.get_connections())
-
- def get_associated_ports(self):
- if not self.get_type() == 'bus':
- return [self];
- else:
- if self.is_source():
- get_p = self.get_parent().get_sources;
- bus_structure = self.get_parent().current_bus_structure['source'];
- direc = 'source'
- else:
- get_p = self.get_parent().get_sinks;
- bus_structure = self.get_parent().current_bus_structure['sink'];
- direc = 'sink'
-
- ports = [i for i in get_p() if not i.get_type() == 'bus'];
- if bus_structure:
- busses = [i for i in get_p() if i.get_type() == 'bus'];
- bus_index = busses.index(self);
- ports = filter(lambda a: ports.index(a) in bus_structure[bus_index], ports);
- return ports;
+ def get_enabled_connections(self):
+ """
+ Get all enabled connections that use this port.
+
+ Returns:
+ a list of connection objects
+ """
+ return filter(lambda c: c.get_enabled(), self.get_connections())
+
+ def get_associated_ports(self):
+ if not self.get_type() == 'bus':
+ return [self];
+ else:
+ if self.is_source():
+ get_p = self.get_parent().get_sources;
+ bus_structure = self.get_parent().current_bus_structure['source'];
+ direc = 'source'
+ else:
+ get_p = self.get_parent().get_sinks;
+ bus_structure = self.get_parent().current_bus_structure['sink'];
+ direc = 'sink'
+
+ ports = [i for i in get_p() if not i.get_type() == 'bus'];
+ if bus_structure:
+ busses = [i for i in get_p() if i.get_type() == 'bus'];
+ bus_index = busses.index(self);
+ ports = filter(lambda a: ports.index(a) in bus_structure[bus_index], ports);
+ return ports;