Changeset 8960

Show
Ignore:
Timestamp:
07/21/08 00:20:24
Author:
jblum
Message:

moved checks to grc_gnuradio, block tree window uses unique keys

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • grc/trunk/notes/todo.txt

    r8956 r8960  
    1414-log slider gui control 
    1515-variable resolution graph structure 
    16 -move checks from grc Block to grc_gnuradio specific 
    1716 
    1817############ Problems: #################### 
    1918-catch error on open non-existant files 
    20 -block tree window maps block by name 
    2119-variables dependent on variables that change 
    2220 
  • grc/trunk/src/grc/elements/Block.py

    r8956 r8960  
    6666                category = Utils.exists_or_else(n, 'category', '') 
    6767                params = Utils.listify(n, 'param') 
    68                 checks = Utils.listify(n, 'check') 
    6968                sources = Utils.listify(n, 'source') 
    7069                sinks = Utils.listify(n, 'sink') 
     
    102101                        #store the param 
    103102                        self._params[key] = param 
    104                 #store the checks 
    105                 self._checks = checks 
    106103                #create the source objects 
    107104                self._sources = odict() 
     
    158155                                for msg in c.get_error_messages(): 
    159156                                        self._add_error_message('%s: %s'%(c, msg)) 
    160                 for check in self._checks: 
    161                         check_res = self.resolve_dependencies(check) 
    162                         try: 
    163                                 check_eval = self.get_parent().evaluate(check_res) 
    164                                 try: assert(check_eval) 
    165                                 except AssertionError: self._add_error_message('Check "%s" failed.'%check) 
    166                         except: self._add_error_message('Check "%s" did not evaluate.'%check) 
    167157 
    168158        def __str__(self): return 'Block - %s - %s(%s)'%(self.get_id(), self.get_name(), self.get_key()) 
  • grc/trunk/src/grc/gui/BlockTreeWindow.py

    r8956 r8960  
    3333        def __init__(self, platform, get_flow_graph): 
    3434                """! 
    35                 SignalBlockSelectionWindow constructor. 
    36                 Show all possible signal blocks in this dialog
    37                 Each signal block is represented by a gtk label of its tag and an add button
    38                 The add button tells the flow graph to create the selected block. and add it to the flow graph
     35                BlockTreeWindow constructor. 
     36                Create a tree view of the possible blocks in the platform
     37                The tree view nodes will be category names, the leaves will be block names
     38                A mouse double click or button press action will trigger the add block event
    3939                @param platform the particular platform will all block prototypes 
    4040                @param get_flow_graph get the selected flow graph 
     
    4545                self.get_flow_graph = get_flow_graph 
    4646                #make the tree model for holding blocks 
    47                 self.treestore = gtk.TreeStore(gobject.TYPE_STRING
     47                self.treestore = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING
    4848                self.treeview = gtk.TreeView(self.treestore) 
    4949                self.treeview.set_enable_search(False) #disable pop up search box 
     
    6666                self.add_button.connect('clicked', self._handle_add_button) 
    6767                self.pack_start(self.add_button, False) 
    68                 #map names to keys 
    69                 self.names = dict() 
    7068                #map categories to iters 
    7169                self.categories = dict() 
     
    7472                #initialize 
    7573                self._handle_selection_change() 
    76                  
     74 
    7775        def add_block(self, block, category): 
    7876                """! 
     
    8280                @param category the category string 
    8381                """ 
    84                 if block.get_name() in self.names.keys(): 
    85                         print '%s has more than one block with name "%s".'%(self.platform, block.get_name()) 
    86                         print 'Although block names do not have to be unique, this gui requires that that are.' 
    87                         print 'Please rename the block to avoid problems.' 
    88                         return 
    8982                _BlockTree.add_block(self, block, category) 
    9083                new_iter = self.treestore.insert_before(self.categories[category], None) 
    9184                self.treestore.set_value(new_iter, 0, block.get_name()) 
    92                 self.names[block.get_name()] = block.get_key(
    93                  
     85                self.treestore.set_value(new_iter, 1, block.get_key()
     86 
    9487        def add_category(self, category): 
    9588                """! 
     
    129122                treestore, iter = selection.get_selected() 
    130123                if iter and not treestore.iter_has_child(iter): 
    131                         name = treestore.get_value(iter, 0) 
    132                         key = self.names[name] 
     124                        key = treestore.get_value(iter, 1) 
    133125                        self.get_flow_graph().add_new_block(key) 
    134126 
  • grc/trunk/src/grc_gnuradio/Block.py

    r8865 r8960  
    2626 
    2727class Block(_Block): 
    28          
     28 
    2929        ##for make source to keep track of indexes 
    3030        _source_count = 0 
    3131        ##for make sink to keep track of indexes 
    3232        _sink_count = 0 
    33                  
     33 
    3434        def __init__(self, flow_graph, n): 
    3535                """ 
     
    4141                self.self_flag = False 
    4242                #grab the data 
    43                 doc = Utils.exists_or_else(n, 'doc', '')        
     43                doc = Utils.exists_or_else(n, 'doc', '') 
    4444                imports = map(lambda i: i.strip(), Utils.listify(n, 'import')) 
    4545                make = n['make'] 
    46                 callbacks = Utils.listify(n, 'callback')                         
     46                checks = Utils.listify(n, 'check') 
     47                callbacks = Utils.listify(n, 'callback') 
    4748                #build the block 
    4849                _Block.__init__( 
    49                         self,                   
    50                         flow_graph=flow_graph,  
     50                        self, 
     51                        flow_graph=flow_graph, 
    5152                        n=n, 
    5253                ) 
     
    5455                self._imports = imports 
    5556                self._make = make 
    56                 self._callbacks = callbacks      
    57                  
     57                self._callbacks = callbacks 
     58                self._checks = checks 
     59 
    5860        def validate(self): 
     61                """! 
     62                Validate this block. 
     63                Call the base class validate. 
     64                Evaluate the checks: each check must evaluate to True. 
     65                Adjust the nports. 
     66                """ 
    5967                _Block.validate(self) 
     68                #evaluate the checks 
     69                for check in self._checks: 
     70                        check_res = self.resolve_dependencies(check) 
     71                        try: 
     72                                check_eval = self.get_parent().evaluate(check_res) 
     73                                try: assert check_eval 
     74                                except AssertionError: self._add_error_message('Check "%s" failed.'%check) 
     75                        except: self._add_error_message('Check "%s" did not evaluate.'%check) 
    6076                for ports, Port in ( 
    61                         (self._sources, self.get_parent().get_parent().Source),  
     77                        (self._sources, self.get_parent().get_parent().Source), 
    6278                        (self._sinks, self.get_parent().get_parent().Sink), 
    6379                ): 
     
    93109                                self.update() 
    94110                                continue 
    95                  
    96         def get_doc(self):  
     111 
     112        def get_doc(self): 
    97113                doc = self._doc.strip('\n').replace('\\\n', '') 
    98                 #merge custom doc with doxygen docs  
     114                #merge custom doc with doxygen docs 
    99115                return '\n'.join([doc, extract_docs.extract(self.get_key())]).strip('\n') 
    100          
    101         def get_imports(self):  
     116 
     117        def get_imports(self): 
    102118                """! 
    103119                Resolve all import statements. 
     
    108124                """ 
    109125                return filter(lambda i: i, sum(map(lambda i: self.resolve_dependencies(i).split('\n'), self._imports), [])) 
    110          
     126 
    111127        def get_make(self): return self.resolve_dependencies(self._make) 
    112          
     128 
    113129        def get_callbacks(self): 
    114130                """!