commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r8537 - in grc/trunk/src: grc grc/gui grc_gnuradio grc


From: jblum
Subject: [Commit-gnuradio] r8537 - in grc/trunk/src: grc grc/gui grc_gnuradio grc_gnuradio/blocks grc_gnuradio/blocks/misc grc_gnuradio/data
Date: Sat, 31 May 2008 17:08:04 -0600 (MDT)

Author: jblum
Date: 2008-05-31 17:08:04 -0600 (Sat, 31 May 2008)
New Revision: 8537

Added:
   grc/trunk/src/grc_gnuradio/data/flow_graph.tmpl
Removed:
   grc/trunk/src/grc_gnuradio/data/no_gui.tmpl
   grc/trunk/src/grc_gnuradio/data/wx_gui.tmpl
Modified:
   grc/trunk/src/grc/ParseXML.py
   grc/trunk/src/grc/gui/MainWindow.py
   grc/trunk/src/grc_gnuradio/Block.py
   grc/trunk/src/grc_gnuradio/FlowGraph.py
   grc/trunk/src/grc_gnuradio/Generator.py
   grc/trunk/src/grc_gnuradio/blocks/misc/import.xml
   grc/trunk/src/grc_gnuradio/blocks/options.xml
Log:
unified template, chmod+x for generated flow graphs, dtd validation fix

Modified: grc/trunk/src/grc/ParseXML.py
===================================================================
--- grc/trunk/src/grc/ParseXML.py       2008-05-31 22:10:58 UTC (rev 8536)
+++ grc/trunk/src/grc/ParseXML.py       2008-05-31 23:08:04 UTC (rev 8537)
@@ -39,7 +39,9 @@
                        raise XMLSyntaxError, '\n'.join(map(str, 
dtd.error_log.filter_from_errors()))
        else:
                parser = etree.XMLParser(dtd_validation=True)
-               xml = etree.parse(xml_file, parser=parser)              
+               xml = etree.parse(xml_file, parser=parser)      
+               if parser.error_log:
+                       raise XMLSyntaxError, '\n'.join(map(str, 
parser.error_log.filter_from_errors()))
 
 def from_file(xml_file):
        """!

Modified: grc/trunk/src/grc/gui/MainWindow.py
===================================================================
--- grc/trunk/src/grc/gui/MainWindow.py 2008-05-31 22:10:58 UTC (rev 8536)
+++ grc/trunk/src/grc/gui/MainWindow.py 2008-05-31 23:08:04 UTC (rev 8537)
@@ -217,7 +217,7 @@
                                self.page_to_be_closed = None   #set the page 
to be closed back to None
                                return
                #stop the flow graph if executing
-               if self.page_to_be_closed.get_pid_file(): 
self.handle_states(FLOW_GRAPH_STOP)
+               if self.page_to_be_closed.get_pid_file(): 
self.handle_states(FLOW_GRAPH_KILL)
                #remove the page
                
self.notebook.remove_page(self.notebook.page_num(self.page_to_be_closed))
                if ensure and self.notebook.get_n_pages() == 0: self.new_page() 
#no pages, make a new one

Modified: grc/trunk/src/grc_gnuradio/Block.py
===================================================================
--- grc/trunk/src/grc_gnuradio/Block.py 2008-05-31 22:10:58 UTC (rev 8536)
+++ grc/trunk/src/grc_gnuradio/Block.py 2008-05-31 23:08:04 UTC (rev 8537)
@@ -95,7 +95,15 @@
                #merge custom doc with doxygen docs 
                return '\n'.join([doc, 
extract_docs.extract(self.get_key())]).strip('\n')
        
-       def get_imports(self): return self._imports
+       def get_imports(self): 
+               """!
+               Resolve all import statements.
+               Split each import statement at newlines.
+               Combine all import statments into a list.
+               Filter empty imports.
+               @return a list of import statements
+               """
+               return filter(lambda i: i, sum(map(lambda i: 
self.resolve_dependencies(i).split('\n'), self._imports), []))
        
        def get_make(self): return self.resolve_dependencies(self._make)
        

Modified: grc/trunk/src/grc_gnuradio/FlowGraph.py
===================================================================
--- grc/trunk/src/grc_gnuradio/FlowGraph.py     2008-05-31 22:10:58 UTC (rev 
8536)
+++ grc/trunk/src/grc_gnuradio/FlowGraph.py     2008-05-31 23:08:04 UTC (rev 
8537)
@@ -26,6 +26,24 @@
 
 class FlowGraph(_FlowGraph):
        
+       def get_imports(self):
+               """!
+               Get a set of all import statments in this flow graph namespace.
+               @return a set of import statements
+               """
+               imports = sum([block.get_imports() for block in 
self.get_blocks()], [])
+               imports = sorted(set(imports))
+               return imports
+       
+       def get_variables(self):
+               """!
+               Get a list of all variables in this flow graph namespace.
+               @return a sorted list of variable blocks
+               """
+               variables = filter(lambda b: b.get_key() in ('variable', 
'variable_slider', 'variable_chooser'), self.get_blocks())
+               variables = sorted(variables, lambda x, y: cmp(x.get_id(), 
y.get_id()))
+               return variables        
+       
        def evaluate(self, expr):
                """!
                Evaluate the expression.
@@ -34,18 +52,18 @@
                @return the evaluated data
                """
                if self.is_flagged():
-                       self.deflag()           
+                       self.deflag()
                        #reload namespace
                        self.n = 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
+                       for imp in self.get_imports():
+                               try: exec imp in n
                                except: pass
                        #load variables
-                       for block in filter(lambda b: b.get_key() in 
('variable', 'variable_slider', 'variable_chooser'), self.get_blocks()):
+                       for variable in self.get_variables():
                                try: 
-                                       e = 
eval(block.get_make().split('\n')[0], n, n)
-                                       n[block.get_id()] = e
+                                       e = 
eval(variable.get_make().split('\n')[0], n, n)
+                                       n[variable.get_id()] = e
                                except: pass
                #evaluate
                e = eval(expr, self.n, self.n)

Modified: grc/trunk/src/grc_gnuradio/Generator.py
===================================================================
--- grc/trunk/src/grc_gnuradio/Generator.py     2008-05-31 22:10:58 UTC (rev 
8536)
+++ grc/trunk/src/grc_gnuradio/Generator.py     2008-05-31 23:08:04 UTC (rev 
8537)
@@ -23,6 +23,7 @@
 import os
 import subprocess
 import sys
+import stat
 from Cheetah.Template import Template
 from grc.Constants import FLOW_GRAPH_FILE_EXTENSION
 
@@ -33,10 +34,8 @@
 
 PATH = os.path.dirname(__file__)
 
-NO_GUI_TEMPLATE = PATH + '/data/no_gui.tmpl'
+FLOW_GRAPH_TEMPLATE = PATH + '/data/flow_graph.tmpl'
 
-WX_GUI_TEMPLATE = PATH + '/data/wx_gui.tmpl'
-
 class Generator(object):
        
        def __init__(self, flow_graph, file_path):
@@ -48,6 +47,8 @@
        def write(self):
                #generate
                open(self.get_file_path(), 'w').write(str(self))
+               mode = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | 
stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH
+               os.chmod(self.get_file_path(), mode)            
                
        def get_popen(self):
                """!
@@ -67,48 +68,17 @@
                Convert the flow graph to python code.
                @return a string of python code
                """
-               all_blocks = self._flow_graph.get_blocks()
-               #get imports
-               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() in ('variable', 
'variable_slider', 'variable_chooser'), 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() != 
'import', all_blocks)
-               blocks = sorted(blocks, lambda x, y: cmp(x.get_id(), 
y.get_id())) 
-               #all callbacks
-               callbacks = sum([block.get_callbacks() for block in blocks], [])
-               if self._flow_graph.get_option('generate_options') == 'no_gui': 
                
-                       imports = sorted(set(imports)) #unique and sorted
-                       #load the namespace
-                       namespace = {
-                               'imports':      imports,
-                               'flow_graph': self._flow_graph,
-                               'variables': variables,
-                               'blocks': blocks,
-                               'connections': 
self._flow_graph.get_connections(),
-                               'callbacks': callbacks,
-                       }
-                       #build the template
-                       t = Template(open(NO_GUI_TEMPLATE, 'r').read(), 
namespace)
-               elif self._flow_graph.get_option('generate_options') == 
'wx_gui':               
-                       imports.append('from grc_gnuradio import wxgui as 
grc_wxgui')
-                       imports.append('import wx')
-                       imports = sorted(set(imports)) #unique and sorted
-                       #load the namespace
-                       namespace = {
-                               'imports':      imports,
-                               'flow_graph': self._flow_graph,
-                               'variables': variables,
-                               'blocks': blocks,
-                               'connections': 
self._flow_graph.get_connections(),
-                               'callbacks': callbacks,
-                       }
-                       #build the template
-                       t = Template(open(WX_GUI_TEMPLATE, 'r').read(), 
namespace)
-               else: print self._flow_graph.get_option('generate_options')
+               #load the namespace
+               namespace = {
+                       'imports':      self._flow_graph.get_imports(),
+                       'flow_graph': self._flow_graph,
+                       'variables': self._flow_graph.get_variables(),
+                       'blocks': sorted(self._flow_graph.get_blocks(), lambda 
x, y: cmp(x.get_id(), y.get_id())),
+                       'connections': self._flow_graph.get_connections(),
+                       'callbacks': sum([block.get_callbacks() for block in 
self._flow_graph.get_blocks()], []),
+                       'gui_type': 
self._flow_graph.get_option('generate_options'),
+               }
+               #build the template
+               t = Template(open(FLOW_GRAPH_TEMPLATE, 'r').read(), namespace)
                return str(t)
-                       
+

Modified: grc/trunk/src/grc_gnuradio/blocks/misc/import.xml
===================================================================
--- grc/trunk/src/grc_gnuradio/blocks/misc/import.xml   2008-05-31 22:10:58 UTC 
(rev 8536)
+++ grc/trunk/src/grc_gnuradio/blocks/misc/import.xml   2008-05-31 23:08:04 UTC 
(rev 8537)
@@ -8,7 +8,8 @@
 <block>
        <name>Import</name>
        <key>import</key>
-       <make>$import</make>
+       <import>$import</import>
+       <make></make>
        <param>
                <name>Import</name>
                <key>import</key>

Modified: grc/trunk/src/grc_gnuradio/blocks/options.xml
===================================================================
--- grc/trunk/src/grc_gnuradio/blocks/options.xml       2008-05-31 22:10:58 UTC 
(rev 8536)
+++ grc/trunk/src/grc_gnuradio/blocks/options.xml       2008-05-31 23:08:04 UTC 
(rev 8537)
@@ -10,7 +10,12 @@
 <block>
        <name>Options</name>
        <key>options</key>
-       <import>from gnuradio import gr</import>
+       <import>from gnuradio import gr
+#if $generate_options.eval == 'wx_gui'
+from grc_gnuradio import wxgui as grc_wxgui
+import wx
+#end if
+</import>
        <make></make>
        <param>
                <name>Title</name>

Added: grc/trunk/src/grc_gnuradio/data/flow_graph.tmpl
===================================================================
--- grc/trunk/src/grc_gnuradio/data/flow_graph.tmpl                             
(rev 0)
+++ grc/trunk/src/grc_gnuradio/data/flow_graph.tmpl     2008-05-31 23:08:04 UTC 
(rev 8537)
@@ -0,0 +1,109 @@
+#!/usr/bin/env python
+########################################################
+##Cheetah template - gnuradio_python
+##
address@hidden imports the import statements
address@hidden flow_graph the flow_graph
address@hidden variables the variable blocks
address@hidden blocks the signal blocks
address@hidden connections the connections
address@hidden callbacks the block callback strings
address@hidden gui_type the type of gui (wx gui or no gui)
+########################################################
+#import time
+#set $DIVIDER = '#'*50
+$DIVIDER
+# Gnuradio Python Flow Graph
+$('# Title: %s'%$flow_graph.get_option('title'))
+$('# Author: %s'%$flow_graph.get_option('author'))
+$('# Description: %s'%$flow_graph.get_option('description'))
+$('# Generated: %s'%time.ctime())
+$DIVIDER
+
+########################################################
+##     Create Imports
+########################################################
+#for $imp in $imports
+$imp
+#end for
+
+#if $gui_type == 'wx_gui'
+       #import os
+       #from grc.Constants import MAIN_WINDOW_PREFIX,DATA_DIR
+       ##set the icon for the wx app
+       #set $WX_APP_ICON = '"%s"'%os.path.abspath($DATA_DIR + 
'/grc-icon-32.png')
+       ##>>> platform dependency! wx under cygwin has issues with icon paths
+       #if sys.platform == 'cygwin'
+       #set $WX_APP_ICON = None
+       #end if
+tb = grc_wxgui.top_block_gui(
+       title="$MAIN_WINDOW_PREFIX - Executing: 
$flow_graph.get_option('title')",
+       icon=$WX_APP_ICON,
+)
+#elif $gui_type == 'no_gui'
+tb = gr.top_block()
+#end if
+
+########################################################
+##     Create Callbacks
+########################################################
+$DIVIDER
+# Callbacks
+$DIVIDER
+#for $var in $variables
+       #set $id = $var.get_id()
+       #set $var_callbacks = filter(lambda c: id in ''.join(c.split('(')[1:]), 
$callbacks)
+def _set_$(id)(_$id):
+       global $id
+       $id = _$id
+       #for $callback in $var_callbacks
+       $callback
+       #end for
+
+#end for
+########################################################
+##     Create Variables
+########################################################
+$DIVIDER
+# Variables
+$DIVIDER
+#for $var in $variables
+$("%s = %s"%($var.get_id(), $var.get_make()))  
+#end for
+
+########################################################
+##     Create Blocks
+########################################################
+$DIVIDER
+# Blocks
+$DIVIDER
+#for $blk in filter(lambda b: b.get_make(), $blocks)
+$("%s = %s"%($blk.get_id(), $blk.get_make()))
+#end for
+
+########################################################
+##     Create Connections
+########################################################
+$DIVIDER
+# Connections
+$DIVIDER
+#for $con in $connections
+       #set $source = $con.get_source()
+       #set $sink = $con.get_sink()
+$("tb.connect((%s, %s), (%s, %s))"%(
+               $source.get_parent().get_id(), 
+               $source.get_key(),
+               $sink.get_parent().get_id(), 
+               $sink.get_key(),
+       )
+)
+#end for
+
+#if $gui_type == 'wx_gui'
+tb.Run()
+#elif $gui_type == 'no_gui'
+tb.start()
+raw_input('Press Enter to quit: ')
+tb.stop()
+#end if
+

Deleted: grc/trunk/src/grc_gnuradio/data/no_gui.tmpl

Deleted: grc/trunk/src/grc_gnuradio/data/wx_gui.tmpl





reply via email to

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