commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 49/101: grc: refactor: some more bus ports


From: git
Subject: [Commit-gnuradio] [gnuradio] 49/101: grc: refactor: some more bus ports stuff
Date: Thu, 16 Mar 2017 14:58:05 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch python3
in repository gnuradio.

commit 89b09aaf80b8210c2ea4b3da712bfcfbb571a60a
Author: Sebastian Koslowski <address@hidden>
Date:   Wed Jul 20 13:45:06 2016 +0200

    grc: refactor: some more bus ports stuff
---
 grc/core/Block.py        | 55 +++++++++++++++++++-----------------------------
 grc/core/Connection.py   | 24 ++++++++++-----------
 grc/core/FlowGraph.py    |  2 +-
 grc/core/Port.py         |  6 +-----
 grc/gui/ActionHandler.py |  6 ++----
 5 files changed, 37 insertions(+), 56 deletions(-)

diff --git a/grc/core/Block.py b/grc/core/Block.py
index d3fe4d8..10deec8 100644
--- a/grc/core/Block.py
+++ b/grc/core/Block.py
@@ -600,18 +600,13 @@ class Block(Element):
     ##############################################
 
     def get_bus_structure(self, direction):
-        bus_structure = self.resolve_dependencies(
-            self._bus_structure_source if direction == 'source' else
-            self._bus_structure_sink)
-
+        bus_structure = 
self.resolve_dependencies(self._bus_structure[direction])
         if not bus_structure:
-            return ''  # TODO: Don't like empty strings. should change this to 
None eventually
-
+            return
         try:
-            clean_bus_structure = self.parent.evaluate(bus_structure)
-            return clean_bus_structure
+            return self.parent_flowgraph.evaluate(bus_structure)
         except:
-            return ''
+            return
 
     @staticmethod
     def back_ofthe_bus(portlist):
@@ -625,16 +620,16 @@ class Block(Element):
     def _import_bus_stuff(self, n):
         bus_sinks = n.get('bus_sink', [])
         if len(bus_sinks) > 0 and not self._bussify_sink:
-            self.bussify({'name': 'bus', 'type': 'bus'}, 'sink')
+            self.bussify('sink')
         elif len(bus_sinks) > 0:
-            self.bussify({'name': 'bus', 'type': 'bus'}, 'sink')
-            self.bussify({'name': 'bus', 'type': 'bus'}, 'sink')
+            self.bussify('sink')
+            self.bussify('sink')
         bus_sources = n.get('bus_source', [])
         if len(bus_sources) > 0 and not self._bussify_source:
-            self.bussify({'name': 'bus', 'type': 'bus'}, 'source')
+            self.bussify('source')
         elif len(bus_sources) > 0:
-            self.bussify({'name': 'bus', 'type': 'bus'}, 'source')
-            self.bussify({'name': 'bus', 'type': 'bus'}, 'source')
+            self.bussify('source')
+            self.bussify('source')
 
     def form_bus_structure(self, direc):
         ports = self.sources if direc == 'source' else self.sinks
@@ -657,12 +652,7 @@ class Block(Element):
         self.current_bus_structure[direc] = struct
         return struct
 
-    def bussify(self, n, direc):
-        if direc == 'source':
-            get_p_gui = self.get_sources_gui
-        else:
-            get_p_gui = self.get_sinks_gui
-
+    def bussify(self, direc):
         ports = self.sources if direc == 'source' else self.sinks
 
         for elt in ports:
@@ -670,33 +660,32 @@ class Block(Element):
                 self.parent.remove_element(connect)
 
         if ports and all('bus' != p.get_type() for p in ports):
-            struct = self.form_bus_structure(direc)
-            self.current_bus_structure[direc] = struct
+            struct = self.current_bus_structure[direc] = 
self.form_bus_structure(direc)
+            n = {'type': 'bus'}
             if ports[0].get_nports():
                 n['nports'] = '1'
 
-            for i in range(len(struct)):
-                n['key'] = str(len(ports))
-                n = dict(n)
-                port = self.parent_platform.get_new_port(self, 
direction=direc, **n)
+            for i, structlet in enumerate(struct):
+                name = 'bus{}#{}'.format(i, len(structlet))
+                port = self.parent_platform.get_new_port(
+                    self, direction=direc, key=str(len(ports)), name=name, **n)
                 ports.append(port)
         elif any('bus' == p.get_type() for p in ports):
+            get_p_gui = self.get_sources_gui if direc == 'source' else 
self.get_sinks_gui
             for elt in get_p_gui():
                 ports.remove(elt)
             self.current_bus_structure[direc] = ''
 
     def _init_bus_ports(self, n):
-        self.back_ofthe_bus(self.sources)
-        self.back_ofthe_bus(self.sinks)
         self.current_bus_structure = {'source': '', 'sink': ''}
-        self._bus_structure_source = n.get('bus_structure_source', '')
-        self._bus_structure_sink = n.get('bus_structure_sink', '')
+        self._bus_structure = {'source': n.get('bus_structure_source', ''),
+                               'sink': n.get('bus_structure_sink', '')}
         self._bussify_sink = n.get('bus_sink')
         self._bussify_source = n.get('bus_source')
         if self._bussify_sink:
-            self.bussify({'name': 'bus', 'type': 'bus'}, 'sink')
+            self.bussify('sink')
         if self._bussify_source:
-            self.bussify({'name': 'bus', 'type': 'bus'}, 'source')
+            self.bussify('source')
 
 
 class EPyBlock(Block):
diff --git a/grc/core/Connection.py b/grc/core/Connection.py
index 7820603..aec7a21 100644
--- a/grc/core/Connection.py
+++ b/grc/core/Connection.py
@@ -56,7 +56,10 @@ class Connection(Element):
             if connection.source_port is source and connection.sink_port is 
sink:
                 raise LookupError('This connection between source and sink is 
not unique.')
 
-        self._make_bus_connect()
+        if self.is_bus():
+            self._make_bus_connect()
+        else:
+            self.parent_flowgraph.connect(source, sink)
 
     @staticmethod
     def _get_sink_source(porta, portb):
@@ -82,7 +85,7 @@ class Connection(Element):
         return self.source_port.get_type() == self.sink_port.get_type() == 
'msg'
 
     def is_bus(self):
-        return self.source_port.get_type() == self.sink_port.get_type() == 
'bus'
+        return self.source_port.get_type() == 'bus'
 
     def validate(self):
         """
@@ -159,18 +162,13 @@ class Connection(Element):
     def _make_bus_connect(self):
         source, sink = self.source_port, self.sink_port
 
-        if (source.get_type() == 'bus') != (sink.get_type() == 'bus'):
+        if source.get_type() == sink.get_type() == 'bus':
             raise ValueError('busses must get with busses')
 
-        if not len(source.get_associated_ports()) == 
len(sink.get_associated_ports()):
+        sources = source.get_associated_ports()
+        sinks = sink.get_associated_ports()
+        if len(sources) != len(sinks):
             raise ValueError('port connections must have same cardinality')
 
-        if source.get_type() == 'bus':
-            sources = source.get_associated_ports()
-            sinks = sink.get_associated_ports()
-
-            for i in range(len(sources)):
-                try:
-                    self.parent_flowgraph.connect(sources[i], sinks[i])
-                except:
-                    pass
+        for ports in zip(sources, sinks):
+            self.parent_flowgraph.connect(*ports)
diff --git a/grc/core/FlowGraph.py b/grc/core/FlowGraph.py
index c626f7b..83ab53a 100644
--- a/grc/core/FlowGraph.py
+++ b/grc/core/FlowGraph.py
@@ -495,7 +495,7 @@ class FlowGraph(Element):
 
         for blk in self.blocks:
             doit(blk, blk.sources, blk.get_sources_gui(), 'source')
-            doit(blk, blk.sinks, blk.get_sinks_gui(), 'sinks')
+            doit(blk, blk.sinks, blk.get_sinks_gui(), 'sink')
 
 
 def _update_old_message_port_keys(source_key, sink_key, source_block, 
sink_block):
diff --git a/grc/core/Port.py b/grc/core/Port.py
index f12eb07..da8751b 100644
--- a/grc/core/Port.py
+++ b/grc/core/Port.py
@@ -303,11 +303,7 @@ class Port(Element):
                 self.key = self._name
 
     def get_name(self):
-        number = ''
-        if self.get_type() == 'bus':
-            busses = [a for a in self.parent.get_ports_gui() if a._dir == 
self._dir]
-            number = str(busses.index(self)) + '#' + 
str(len(self.get_associated_ports()))
-        return self._name + number
+        return self._name
 
     @lazy_property
     def is_sink(self):
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index 938f887..237dd6c 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -612,17 +612,15 @@ class ActionHandler:
                 if b._grc_source:
                     main.new_page(b._grc_source, show=True)
         elif action == Actions.BUSSIFY_SOURCES:
-            n = {'name':'bus', 'type':'bus'}
             for b in flow_graph.selected_blocks():
-                b.bussify(n, 'source')
+                b.bussify('source')
             flow_graph._old_selected_port = None
             flow_graph._new_selected_port = None
             Actions.ELEMENT_CREATE()
 
         elif action == Actions.BUSSIFY_SINKS:
-            n = {'name':'bus', 'type':'bus'}
             for b in flow_graph.selected_blocks():
-                b.bussify(n, 'sink')
+                b.bussify('sink')
             flow_graph._old_selected_port = None
             flow_graph._new_selected_port = None
             Actions.ELEMENT_CREATE()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]