commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r7907 - in grc/branches/grc_reloaded/src/grc: elements


From: jblum
Subject: [Commit-gnuradio] r7907 - in grc/branches/grc_reloaded/src/grc: elements platforms/gnuradio_python platforms/gnuradio_python/blocks/misc platforms/gnuradio_python/data
Date: Fri, 29 Feb 2008 20:19:35 -0700 (MST)

Author: jblum
Date: 2008-02-29 20:19:35 -0700 (Fri, 29 Feb 2008)
New Revision: 7907

Added:
   
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/misc/import.xml
Modified:
   grc/branches/grc_reloaded/src/grc/elements/Param.py
   grc/branches/grc_reloaded/src/grc/elements/Port.py
   grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/FlowGraph.py
   grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Generator.py
   grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Param.py
   
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/block_tree.xml
   grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/no_gui.tmpl
   grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/wx_gui.tmpl
Log:
added import block

Modified: grc/branches/grc_reloaded/src/grc/elements/Param.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/elements/Param.py 2008-02-29 19:48:00 UTC 
(rev 7906)
+++ grc/branches/grc_reloaded/src/grc/elements/Param.py 2008-03-01 03:19:35 UTC 
(rev 7907)
@@ -150,7 +150,7 @@
                                #if the evaluate failed but added no error 
messages, add the generic one below
                                if not self.get_error_messages():
                                        self._add_error_message('Value "%s" 
cannot be evaluated.'%self.get_value())             
-               except AssertionError: self._add_error_message('Type "%s" is 
not a possible type.'%type)        
+               except AssertionError: self._add_error_message('Type "%s" is 
not a possible type.'%self.get_type())     
        
        def evaluate(self):
                """!

Modified: grc/branches/grc_reloaded/src/grc/elements/Port.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/elements/Port.py  2008-02-29 19:48:00 UTC 
(rev 7906)
+++ grc/branches/grc_reloaded/src/grc/elements/Port.py  2008-03-01 03:19:35 UTC 
(rev 7907)
@@ -53,7 +53,7 @@
                try: assert(not self.is_empty())
                except AssertionError: self._add_error_message('is empty.')
                try: assert(self.get_type() in self.TYPES)
-               except AssertionError: self._add_error_message('Type "%s" is 
not a possible type.'%type)                
+               except AssertionError: self._add_error_message('Type "%s" is 
not a possible type.'%self.get_type())             
        
        def __str__(self): 
                if self.is_source():

Modified: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/FlowGraph.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/FlowGraph.py    
2008-02-29 19:48:00 UTC (rev 7906)
+++ grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/FlowGraph.py    
2008-03-01 03:19:35 UTC (rev 7907)
@@ -24,12 +24,6 @@
 from Block import Block
 from Connection import Connection
 
-from gnuradio import gr
-from gnuradio import blks2
-from gnuradio.gr import firdes
-import math
-import cmath
-
 class FlowGraph(_FlowGraph):
        
        def evaluate(self, expr):
@@ -39,18 +33,17 @@
                @throw Exception bad expression
                @return the evaluated data
                """
-               namespace = dict()
-               namespace['__builtins__'] = __builtins__                
-               namespace['gr'] = gr
-               namespace['firdes'] = firdes
-               namespace['math'] = math
-               namespace['cmath'] = cmath
+               n = dict() #namespace
+               #load imports
+               for block in filter(lambda b: b.get_key() == 'import', 
self.get_blocks()):
+                       try: exec block.get_make() in n
+                       except: pass
                #load variables
                for block in filter(lambda b: 
b.get_key().startswith('variable'), self.get_blocks()):
                        try: 
-                               e = eval(block.get_make(), {}, {})
-                               namespace[block.get_id()] = e
+                               e = eval(block.get_make(), n, n)
+                               n[block.get_id()] = e
                        except: pass
-               e = eval(expr, namespace, {})
+               e = eval(expr, n, n)
                return e
                

Modified: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Generator.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Generator.py    
2008-02-29 19:48:00 UTC (rev 7906)
+++ grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Generator.py    
2008-03-01 03:19:35 UTC (rev 7907)
@@ -65,13 +65,15 @@
                """
                all_blocks = self._flow_graph.get_blocks()
                #get imports
-               imports = ['from gnuradio import gr', 'from gnuradio.gr import 
firdes', 'import math', 'import cmath']
+               imports = list()
                for block in all_blocks: imports.extend(block.get_imports())
+               for block in filter(lambda b: b.get_key() == 'import', 
all_blocks):
+                       imports.append(block.get_make())
                #separate variables
                variables = filter(lambda b: 
b.get_key().startswith('variable'), all_blocks)
                variables = sorted(variables, lambda x, y: cmp(x.get_id(), 
y.get_id())) 
                #separate blocks
-               blocks = filter(lambda b: b not in variables and b.get_key() != 
'options', all_blocks)
+               blocks = filter(lambda b: b not in variables and b.get_key() != 
'import', all_blocks)
                blocks = sorted(blocks, lambda x, y: cmp(x.get_id(), 
y.get_id())) 
                if self._flow_graph.get_option('generate_options') == 'no_gui': 
                
                        imports = sorted(set(imports)) #unique and sorted

Modified: grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Param.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Param.py        
2008-02-29 19:48:00 UTC (rev 7906)
+++ grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Param.py        
2008-03-01 03:19:35 UTC (rev 7907)
@@ -33,7 +33,7 @@
                'file_open', 'file_save',
                'id',
                'source_pad_key', 'sink_pad_key',
-               'grid_pos',
+               'grid_pos', 'import',
        ]
        
        def evaluate(self):
@@ -208,6 +208,16 @@
                                                
self._add_error_message('Another graphical element is using cell 
"%s".'%str(cell))
                                                raise Exception
                        return e
+               elif t == 'import':
+                       n = dict() #new namespace
+                       try: exec v in n
+                       except ImportError: 
+                               self._add_error_message('Import "%s" failed.'%v)
+                               raise Exception
+                       except Exception:
+                               self._add_error_message('Bad import syntax: 
"%s".'%v)
+                               raise Exception
+                       return filter(lambda k: str(k) != '__builtins__', 
n.keys())
                else: raise TypeError, 'Type "%s" not handled'%t
                
        def to_code(self):

Added: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/misc/import.xml
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/misc/import.xml
                          (rev 0)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/misc/import.xml
  2008-03-01 03:19:35 UTC (rev 7907)
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!DOCTYPE block SYSTEM "../block.dtd">
+<!-- 
+###################################################
+##Import python modules into the namespace
+###################################################
+ -->
+<block>
+       <name>Import</name>
+       <key>import</key>
+       <make>$import</make>
+       <param>
+               <name>Import</name>
+               <key>import</key>
+               <value></value>
+               <type>import</type>             
+       </param>
+       <doc>
+Import additional python modules into the namespace.
+
+Examples:
+from gnuradio.gr import firdes
+import math,cmath
+from math import pi 
+       </doc>
+</block>

Modified: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/block_tree.xml
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/block_tree.xml 
    2008-02-29 19:48:00 UTC (rev 7906)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/block_tree.xml 
    2008-03-01 03:19:35 UTC (rev 7907)
@@ -190,6 +190,7 @@
        </cat>
        <cat>
                <name>Misc</name>
+               <block>import</block>
                <block>gr_throttle</block>
                <block>valve</block>
                <block>selector</block>

Modified: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/no_gui.tmpl
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/no_gui.tmpl    
    2008-02-29 19:48:00 UTC (rev 7906)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/no_gui.tmpl    
    2008-03-01 03:19:35 UTC (rev 7907)
@@ -27,7 +27,7 @@
 $("%s = %s"%($var.get_id(), $var.get_make()))
 #end for
 
-#for $blk in $blocks
+#for $blk in filter(lambda b: b.get_make(), $blocks)
 $("%s = %s"%($blk.get_id(), $blk.get_make()))
 #end for
 

Modified: 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/wx_gui.tmpl
===================================================================
--- 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/wx_gui.tmpl    
    2008-02-29 19:48:00 UTC (rev 7906)
+++ 
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/wx_gui.tmpl    
    2008-03-01 03:19:35 UTC (rev 7907)
@@ -73,7 +73,7 @@
 ########################################################
 ##     Create Blocks
 ########################################################
-#for $blk in $blocks
+#for $blk in filter(lambda b: b.get_make(), $blocks)
 $("%s = %s"%($blk.get_id(), $blk.get_make()))
 #end for
 





reply via email to

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