[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r7774 - in grc/branches/grc_reloaded/src/grc: . elemen
From: |
jblum |
Subject: |
[Commit-gnuradio] r7774 - in grc/branches/grc_reloaded/src/grc: . elements platforms/gnuradio_python platforms/gnuradio_python/data |
Date: |
Fri, 22 Feb 2008 11:48:51 -0700 (MST) |
Author: jblum
Date: 2008-02-22 11:48:50 -0700 (Fri, 22 Feb 2008)
New Revision: 7774
Added:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Generator.py
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/no_gui.tmpl
Modified:
grc/branches/grc_reloaded/src/grc/ActionHandler.py
grc/branches/grc_reloaded/src/grc/elements/Platform.py
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Platform.py
Log:
generating no gui flow graphs
Modified: grc/branches/grc_reloaded/src/grc/ActionHandler.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/ActionHandler.py 2008-02-22 17:53:46 UTC
(rev 7773)
+++ grc/branches/grc_reloaded/src/grc/ActionHandler.py 2008-02-22 18:48:50 UTC
(rev 7774)
@@ -273,6 +273,11 @@
else:
try:
ParseXML.to_file(ParseXML.to_xml(self.get_flow_graph().export_data()),
self.get_page().get_file_path())
+ #TODO (tmp)
+ g =
self.get_flow_graph().get_parent().get_generator()
+ g = g(self.get_flow_graph())
+
open(self.get_page().get_file_path().rstrip(FLOW_GRAPH_FILE_EXTENSION) + '.py',
'w').write(str(g))
+
self.get_page().set_saved(True)
except IOError:
Messages.send_fail_save(self.get_page().get_file_path())
@@ -353,7 +358,7 @@
def run(self):
"""Execute the flow graph."""
cmd = '%s "%s" --pid_file="%s" 2> "%s"'%(
- DEFAULT_FLOW_GRAPH_EXEC,
+ PYEXEC,
self.file_path,
self.pid_file,
self.report_file,
Modified: grc/branches/grc_reloaded/src/grc/elements/Platform.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/elements/Platform.py 2008-02-22
17:53:46 UTC (rev 7773)
+++ grc/branches/grc_reloaded/src/grc/elements/Platform.py 2008-02-22
18:48:50 UTC (rev 7774)
@@ -31,7 +31,7 @@
class Platform(_Element):
- def __init__(self, name, key, path, block_tree, default_flow_graph):
+ def __init__(self, name, key, path, block_tree, default_flow_graph,
generator):
"""!
Make a platform from the arguments.
@param name the platform name
@@ -47,6 +47,7 @@
self._path = path
self._block_tree = block_tree
self._default_flow_graph = default_flow_graph
+ self._generator = generator
#create a dummy flow graph for the blocks
flow_graph = _Element(self)
#load the blocks
@@ -84,6 +85,8 @@
def get_default_flow_graph(self): return self._default_flow_graph
+ def get_generator(self): return self._generator
+
##############################################
# Access Blocks
##############################################
Added: grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Generator.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Generator.py
(rev 0)
+++ grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Generator.py
2008-02-22 18:48:50 UTC (rev 7774)
@@ -0,0 +1,61 @@
+"""
+Copyright 2008 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+"""
address@hidden grc.platforms.gnuradio_python.Generator
+#Create python based flow graphs.
address@hidden Josh Blum
+
+import os
+from Cheetah.Template import Template
+
+PATH = os.path.dirname(__file__)
+
+NO_GUI_TEMPLATE = PATH + '/data/no_gui.tmpl'
+
+class Generator(object):
+
+ def __init__(self, flow_graph):
+ self._flow_graph = flow_graph
+
+ def __str__(self):
+ """!
+ Convert the flow graph to python code.
+ @return a string of python code
+ """
+ all_blocks = self._flow_graph.get_blocks()
+ #get imports
+ imports = ['from gnuradio import gr']
+ for block in all_blocks: imports.extend(block.get_deps())
+ imports = set(imports) #all entries unique
+ #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 = sorted(blocks, lambda x, y: cmp(x.get_id(),
y.get_id()))
+ #load the namespace
+ namespace = {
+ 'imports': imports,
+ 'flow_graph': self._flow_graph,
+ 'variables': variables,
+ 'blocks': blocks,
+ 'connections': self._flow_graph.get_connections(),
+ }
+ #build the template
+ t = Template(open(NO_GUI_TEMPLATE, 'r').read(), namespace)
+ return str(t)
Modified:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Platform.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Platform.py
2008-02-22 17:53:46 UTC (rev 7773)
+++ grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Platform.py
2008-02-22 18:48:50 UTC (rev 7774)
@@ -27,6 +27,7 @@
from Block import Block as _Block
from Port import Source,Sink
from Param import Param as _Param
+from Generator import Generator
PATH = os.path.dirname(__file__)
@@ -49,8 +50,9 @@
name='GNURadio Python',
key='gnuradio_python',
path=PATH,
- block_tree = BLOCK_TREE,
- default_flow_graph = DEFAULT_FLOW_GRAPH,
+ block_tree=BLOCK_TREE,
+ default_flow_graph=DEFAULT_FLOW_GRAPH,
+ generator=Generator,
)
##############################################
Added:
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
(rev 0)
+++
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/data/no_gui.tmpl
2008-02-22 18:48:50 UTC (rev 7774)
@@ -0,0 +1,48 @@
+########################################################
+##Cheetah template - gnuradio_python - no_gui
+##
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
+########################################################
+#import time
+$('#'*40)
+# Gnuradio Python Flow Graph (no gui)
+$('# Name: %s'%$flow_graph.get_option('name'))
+$('# Generated: %s'%time.ctime())
+$('#'*40)
+$('"""')
+Description:
+$flow_graph.get_option('description')
+$('"""')
+
+#for $imp in $imports
+$imp
+#end for
+
+#for $var in $variables
+$("%s = %s"%($var.get_id(), $var.get_fcn()))
+#end for
+
+#for $blk in $blocks
+$("%s = %s"%($blk.get_id(), $blk.get_fcn()))
+#end for
+
+tb = gr.top_block()
+
+#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
+
+tb.run()
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r7774 - in grc/branches/grc_reloaded/src/grc: . elements platforms/gnuradio_python platforms/gnuradio_python/data,
jblum <=