commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r10947 - in gnuradio/trunk/grc/src/platforms: base gui


From: jblum
Subject: [Commit-gnuradio] r10947 - in gnuradio/trunk/grc/src/platforms: base gui python
Date: Sun, 3 May 2009 03:05:22 -0600 (MDT)

Author: jblum
Date: 2009-05-03 03:05:21 -0600 (Sun, 03 May 2009)
New Revision: 10947

Modified:
   gnuradio/trunk/grc/src/platforms/base/FlowGraph.py
   gnuradio/trunk/grc/src/platforms/gui/FlowGraph.py
   gnuradio/trunk/grc/src/platforms/python/Block.py
Log:
Cleanup: port modify code, other misc cleanup.
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.



Modified: gnuradio/trunk/grc/src/platforms/base/FlowGraph.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/base/FlowGraph.py  2009-05-02 07:55:12 UTC 
(rev 10946)
+++ gnuradio/trunk/grc/src/platforms/base/FlowGraph.py  2009-05-03 09:05:21 UTC 
(rev 10947)
@@ -31,8 +31,6 @@
                @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 @@
        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 @@
                #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 @@
                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 @@
                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')

Modified: gnuradio/trunk/grc/src/platforms/gui/FlowGraph.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/gui/FlowGraph.py   2009-05-02 07:55:12 UTC 
(rev 10946)
+++ gnuradio/trunk/grc/src/platforms/gui/FlowGraph.py   2009-05-03 09:05:21 UTC 
(rev 10947)
@@ -277,10 +277,16 @@
 
        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 @@
                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 @@
                                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

Modified: gnuradio/trunk/grc/src/platforms/python/Block.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/python/Block.py    2009-05-02 07:55:12 UTC 
(rev 10946)
+++ gnuradio/trunk/grc/src/platforms/python/Block.py    2009-05-03 09:05:21 UTC 
(rev 10947)
@@ -110,19 +110,21 @@
                @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):





reply via email to

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