]> git.gag.com Git - debian/gnuradio/commitdiff
Cleanup: port modify code, other misc cleanup.
authorjblum <jblum@221aa14e-8319-0410-a670-987f0aec2ac5>
Sun, 3 May 2009 09:05:21 +0000 (09:05 +0000)
committerjblum <jblum@221aa14e-8319-0410-a670-987f0aec2ac5>
Sun, 3 May 2009 09:05:21 +0000 (09:05 +0000)
Fix: flowgraph update removes deleted-selected elements.
Fix: do all selected elements when putting selected elements on-top.
Fix: simplified get_elements, was causing strange bug.

git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10947 221aa14e-8319-0410-a670-987f0aec2ac5

grc/src/platforms/base/FlowGraph.py
grc/src/platforms/gui/FlowGraph.py
grc/src/platforms/python/Block.py

index 747038bfbc446d0b97defcd4d834e9c3e7fa8541..6aeef2fa72ffdf9406ac3968622d853bc991e4c7 100644 (file)
@@ -31,8 +31,6 @@ class FlowGraph(Element):
                @param platform a platforms with blocks and contrcutors
                @return the flow graph object
                """
-               #hold connections and blocks
-               self._elements = list()
                #initialize
                Element.__init__(self, platform)
                #inital blank import
@@ -73,18 +71,14 @@ class FlowGraph(Element):
        def get_elements(self):
                """
                Get a list of all the elements.
-               Always ensure that the options block is in the list.
+               Always ensure that the options block is in the list (only once).
                @return the element list
                """
-               if self._options_block not in self._elements: self._elements.append(self._options_block)
-               #ensure uniqueness of the elements list
-               element_set = set()
-               element_list = list()
-               for element in self._elements:
-                       if element not in element_set: element_list.append(element)
-                       element_set.add(element)
-               #store cleaned up list
-               self._elements = element_list
+               options_block_count = self._elements.count(self._options_block)
+               if not options_block_count:
+                       self._elements.append(self._options_block)
+               for i in range(options_block_count-1):
+                       self._elements.remove(self._options_block)
                return self._elements
 
        def get_enabled_blocks(self):
@@ -142,9 +136,7 @@ class FlowGraph(Element):
                #remove block, remove all involved connections
                if element.is_block():
                        for port in element.get_ports():
-                               map(lambda c: self.remove_element(c), port.get_connections())
-               #remove a connection
-               elif element.is_connection(): pass
+                               map(self.remove_element, port.get_connections())
                self.get_elements().remove(element)
 
        def evaluate(self, expr):
@@ -161,7 +153,7 @@ class FlowGraph(Element):
                All connections and blocks must be valid.
                """
                for c in self.get_elements():
-                       try: assert(c.is_valid())
+                       try: assert c.is_valid()
                        except AssertionError: self._add_error_message('Element "%s" is not valid.'%c)
 
        ##############################################
@@ -195,7 +187,6 @@ class FlowGraph(Element):
                connections_n = fg_n.findall('connection')
                #create option block
                self._options_block = self.get_parent().get_new_block(self, 'options')
-               self._options_block.get_param('id').set_value('options')
                #build the blocks
                for block_n in blocks_n:
                        key = block_n.find('key')
index 31d90984de74a15c4e2cbc6bbe3dfac60e8a36a8..37157ac7cc93606a5a1dea7b143b98684a9a7706 100644 (file)
@@ -277,10 +277,16 @@ class FlowGraph(Element):
 
        def update(self):
                """
+               Removed deleted elements from the selected elements list.
                Update highlighting so only the selected is highlighted.
                Call update on all elements.
                """
                selected_elements = self.get_selected_elements()
+               #remove deleted elements
+               for selected in selected_elements:
+                       if selected not in self.get_elements():
+                               selected_elements.remove(selected)
+               #set highlight and update all
                for element in self.get_elements():
                        element.set_highlighted(element in selected_elements)
                        element.update()
@@ -299,7 +305,7 @@ class FlowGraph(Element):
                What is selected?
                At the given coordinate, return the elements found to be selected.
                If coor_m is unspecified, return a list of only the first element found to be selected:
-               Iterate though the elements backwardssince top elements are at the end of the list.
+               Iterate though the elements backwards since top elements are at the end of the list.
                If an element is selected, place it at the end of the list so that is is drawn last,
                and hence on top. Update the selected port information.
                @param coor the coordinate of the mouse click
@@ -317,11 +323,11 @@ class FlowGraph(Element):
                                if not coor_m: selected_port = selected_element
                                selected_element = selected_element.get_parent()
                        selected.add(selected_element)
+                       #place at the end of the list
+                       self.get_elements().remove(element)
+                       self.get_elements().append(element)
                        #single select mode, break
-                       if not coor_m:
-                               self.get_elements().remove(element)
-                               self.get_elements().append(element)
-                               break;
+                       if not coor_m: break
                #update selected ports
                self._old_selected_port = self._new_selected_port
                self._new_selected_port = selected_port
index 38a0ce492327cabac479167a779021969ba4c2ba..341e5fdc306c405ae351763cbc1d5aeda6ccb8b6 100644 (file)
@@ -110,19 +110,21 @@ class Block(_Block):
                @return true for change
                """
                changed = False
-               for ports in (self.get_sinks(), self.get_sources()):
-                       if ports and ports[0].get_nports():
-                               #find the param that controls port0
-                               for param in self.get_params():
-                                       if not param.is_enum() and param.get_key() in ports[0]._nports:
-                                               #try to increment the port controller by direction
-                                               try:
-                                                       value = param.evaluate()
-                                                       value = value + direction
-                                                       assert 0 < value
-                                                       param.set_value(value)
-                                                       changed = True
-                                               except: pass
+               #concat the nports string from the private nports settings of both port0
+               nports_str = \
+                       (self.get_sinks() and self.get_sinks()[0]._nports or '') + \
+                       (self.get_sources() and self.get_sources()[0]._nports or '')
+               #modify all params whose keys appear in the nports string
+               for param in self.get_params():
+                       if param.is_enum() or param.get_key() not in nports_str: continue
+                       #try to increment the port controller by direction
+                       try:
+                               value = param.evaluate()
+                               value = value + direction
+                               assert 0 < value
+                               param.set_value(value)
+                               changed = True
+                       except: pass
                return changed
 
        def get_doc(self):