commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r9014 - in grc/trunk: notes scripts src/grc src/grc_gn


From: jblum
Subject: [Commit-gnuradio] r9014 - in grc/trunk: notes scripts src/grc src/grc_gnuradio src/grc_gnuradio/data src/grc_gnuradio/utils
Date: Fri, 25 Jul 2008 08:59:32 -0600 (MDT)

Author: jblum
Date: 2008-07-25 08:59:29 -0600 (Fri, 25 Jul 2008)
New Revision: 9014

Added:
   grc/trunk/src/grc_gnuradio/Constants.py
Modified:
   grc/trunk/notes/todo.txt
   grc/trunk/scripts/grc
   grc/trunk/src/grc/Constants.py
   grc/trunk/src/grc/Preferences.py
   grc/trunk/src/grc_gnuradio/Generator.py
   grc/trunk/src/grc_gnuradio/Platform.py
   grc/trunk/src/grc_gnuradio/data/flow_graph.tmpl
   grc/trunk/src/grc_gnuradio/utils/convert_hier.py
Log:
better hier block library handling

Modified: grc/trunk/notes/todo.txt
===================================================================
--- grc/trunk/notes/todo.txt    2008-07-25 01:12:34 UTC (rev 9013)
+++ grc/trunk/notes/todo.txt    2008-07-25 14:59:29 UTC (rev 9014)
@@ -2,6 +2,7 @@
 -optparse block
 -ofdm wrappers
 -controlled step block
+-throttle with sink only (source is nulled)
 
 ############ Features to Add: ####################
 -param editor, expand entry boxes in focus
@@ -11,7 +12,6 @@
 -hotkeys in action descriptions
 -log slider gui control
 -recursive/nested categories
--internal variables (dont show up as params)
 -multi block selection
 
 ############ Maybe: ####################
@@ -20,9 +20,9 @@
 -hide io type params
 
 ############ Problems: ####################
--library path for hier blocks
--auto generate hier code
--add hier code to python path
+-auto generate hier library
+-auto clean hier library
+-add hier blocks to tree without restart?
 
 ############ Suggestions: ####################
 -simple usrp

Modified: grc/trunk/scripts/grc
===================================================================
--- grc/trunk/scripts/grc       2008-07-25 01:12:34 UTC (rev 9013)
+++ grc/trunk/scripts/grc       2008-07-25 14:59:29 UTC (rev 9014)
@@ -36,7 +36,6 @@
 and you are welcome to redistribute it.
 """%VERSION
        parser = OptionParser(usage=usage, version=version)
-       parser.add_option("-H", "--hier", dest="hier", help="path to hier 
blocks", default="", type="string")
        (options, args) = parser.parse_args()
        #"test" import modules that this program will use
        error = False
@@ -51,6 +50,5 @@
        #end import of modules
        from grc_gnuradio.Platform import Platform
        from grc.ActionHandler import ActionHandler
-       block_paths_external = options.hier and [options.hier] or []
-       ActionHandler(args, Platform(block_paths_external=block_paths_external))
+       ActionHandler(args, Platform())
 

Modified: grc/trunk/src/grc/Constants.py
===================================================================
--- grc/trunk/src/grc/Constants.py      2008-07-25 01:12:34 UTC (rev 9013)
+++ grc/trunk/src/grc/Constants.py      2008-07-25 14:59:29 UTC (rev 9014)
@@ -1,5 +1,5 @@
 """
-Copyright 2007 Free Software Foundation, Inc.
+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
@@ -16,7 +16,7 @@
 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 Constants
address@hidden grc.Constants
 #Global constants
 address@hidden Josh Blum
 
@@ -147,11 +147,11 @@
 IMAGE_FILE_EXTENSION = '.png'
 
 ##The default path for the open/save dialogs.
-DEFAULT_FILE_PATH = os.path.expanduser('~')
+DEFAULT_FILE_PATH = os.getcwd()
 
 ##The default icon for the gtk windows.
 PY_GTK_ICON = os.path.join(DATA_DIR, 'grc-icon-256.png')
 
-##The default user preferences file.
-PREFERENCES_FILE_PATH = os.path.join(DEFAULT_FILE_PATH, 
FLOW_GRAPH_FILE_EXTENSION)
+##The default user preferences file path.
+PREFERENCES_FILE_PATH = os.path.join(os.path.expanduser('~'), 
FLOW_GRAPH_FILE_EXTENSION)
 

Modified: grc/trunk/src/grc/Preferences.py
===================================================================
--- grc/trunk/src/grc/Preferences.py    2008-07-25 01:12:34 UTC (rev 9013)
+++ grc/trunk/src/grc/Preferences.py    2008-07-25 14:59:29 UTC (rev 9014)
@@ -16,11 +16,11 @@
 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 Preferences
address@hidden grc.Preferences
 #Holds global paramerences
 address@hidden Josh Blum
 
-from Constants import PREFERENCES_FILE_PATH, DATA_DIR
+from Constants import PREFERENCES_FILE_PATH, FLOW_GRAPH_DTD
 import ParseXML
 import Messages
 import os
@@ -81,7 +81,7 @@
        Load the preferences from the preferences file.
        """
        try:
-               ParseXML.validate_dtd(PREFERENCES_FILE_PATH, 
os.path.join(DATA_DIR, 'flow_graph.dtd'))
+               ParseXML.validate_dtd(PREFERENCES_FILE_PATH, FLOW_GRAPH_DTD)
                n = ParseXML.from_file(PREFERENCES_FILE_PATH)
                block.import_data(n['block'])
        except: Messages.send_fail_load_preferences()

Added: grc/trunk/src/grc_gnuradio/Constants.py
===================================================================
--- grc/trunk/src/grc_gnuradio/Constants.py                             (rev 0)
+++ grc/trunk/src/grc_gnuradio/Constants.py     2008-07-25 14:59:29 UTC (rev 
9014)
@@ -0,0 +1,46 @@
+"""
+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_gnuradio.Constants
+#Global constants for grc gnuradio package
address@hidden Josh Blum
+
+import os
+import sys
+import stat
+
+##The default binary to execute python files.
+PYEXEC = 'python'
+#>>> platform dependency! MacOS requires pythonw to run wx apps        #
+if sys.platform == 'darwin': PYEXEC = 'pythonw'
+
+#setup paths
+DATA_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data')
+BLOCK_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'blocks')
+HIER_BLOCKS_LIB_PATH = os.path.join(os.path.expanduser('~'), '.grc_gnuradio')
+
+#file creation modes
+TOP_BLOCK_FILE_MODE = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | 
stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH
+HIER_BLOCK_FILE_MODE = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | 
stat.S_IWGRP | stat.S_IROTH
+
+#data files
+FLOW_GRAPH_TEMPLATE = os.path.join(DATA_PATH, 'flow_graph.tmpl')
+BLOCK_DTD = os.path.join(DATA_PATH, 'block.dtd')
+BLOCK_TREE = os.path.join(DATA_PATH, 'block_tree.xml')
+DEFAULT_FLOW_GRAPH = os.path.join(DATA_PATH, 'default_flow_graph.grc.xml')
+

Modified: grc/trunk/src/grc_gnuradio/Generator.py
===================================================================
--- grc/trunk/src/grc_gnuradio/Generator.py     2008-07-25 01:12:34 UTC (rev 
9013)
+++ grc/trunk/src/grc_gnuradio/Generator.py     2008-07-25 14:59:29 UTC (rev 
9014)
@@ -22,20 +22,10 @@
 
 import os
 import subprocess
-import sys
-import stat
 from Cheetah.Template import Template
 from utils import expr_utils
+from Constants import *
 
-##The default binary to execute python files.
-PYEXEC = 'python'
-#>>> platform dependency! MacOS requires pythonw to run wx apps        #
-if sys.platform == 'darwin': PYEXEC = 'pythonw'
-PATH = os.path.abspath(os.path.dirname(__file__))
-FLOW_GRAPH_TEMPLATE = os.path.join(PATH, 'data', 'flow_graph.tmpl')
-TOP_BLOCK_FILE_MODE = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | 
stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH
-HIER_BLOCK_FILE_MODE = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | 
stat.S_IWGRP | stat.S_IROTH
-
 class Generator(object):
 
        def __init__(self, flow_graph, file_path):
@@ -46,8 +36,14 @@
                @param file_path the path to write the file to
                """
                self._flow_graph = flow_graph
+               self._generate_options = 
self._flow_graph.get_option('generate_options')
+               if self._generate_options == 'hb':
+                       self._mode = HIER_BLOCK_FILE_MODE
+                       dirname = HIER_BLOCKS_LIB_PATH
+               else:
+                       self._mode = TOP_BLOCK_FILE_MODE
+                       dirname = os.path.dirname(file_path)
                filename = self._flow_graph.get_option('id') + '.py'
-               dirname = os.path.dirname(file_path)
                self._file_path = os.path.join(dirname, filename)
 
        def get_file_path(self): return self._file_path
@@ -55,10 +51,11 @@
        def write(self):
                #generate
                open(self.get_file_path(), 'w').write(str(self))
-               if self._flow_graph.get_option('generate_options') == 'hb':
-                       mode = HIER_BLOCK_FILE_MODE
-               else: mode = TOP_BLOCK_FILE_MODE
-               os.chmod(self.get_file_path(), mode)
+               if self._generate_options == 'hb':
+                       #convert hier block to xml wrapper
+                       from utils import convert_hier
+                       convert_hier.convert_hier(self._flow_graph, 
self.get_file_path())
+               os.chmod(self.get_file_path(), self._mode)
 
        def get_popen(self):
                """!
@@ -67,7 +64,7 @@
                """
                #execute
                cmds = [PYEXEC, self.get_file_path()]
-               if self._flow_graph.get_option('generate_options') == 'no_gui':
+               if self._generate_options == 'no_gui':
                        cmds = ['xterm', '-e'] + cmds
                p = subprocess.Popen(args=cmds, stdout=subprocess.PIPE, 
stderr=subprocess.STDOUT, shell=False, universal_newlines=True)
                return p
@@ -121,7 +118,7 @@
                        'parameters': parameters,
                        'blocks': blocks,
                        'connections': connections,
-                       'gui_type': 
self._flow_graph.get_option('generate_options'),
+                       'generate_options': self._generate_options,
                        'var_id2expr': var_id2expr,
                        'var_id2deps': var_id2deps,
                        'var_id2cbs': var_id2cbs,

Modified: grc/trunk/src/grc_gnuradio/Platform.py
===================================================================
--- grc/trunk/src/grc_gnuradio/Platform.py      2008-07-25 01:12:34 UTC (rev 
9013)
+++ grc/trunk/src/grc_gnuradio/Platform.py      2008-07-25 14:59:29 UTC (rev 
9014)
@@ -29,13 +29,8 @@
 from Port import Source,Sink
 from Param import Param as _Param
 from Generator import Generator
+from Constants import *
 
-PATH = os.path.abspath(os.path.dirname(__file__))
-BLOCK_PATH = os.path.join(PATH, 'blocks')
-BLOCK_DTD = os.path.join(PATH, 'data', 'block.dtd')
-BLOCK_TREE = os.path.join(PATH, 'data', 'block_tree.xml')
-DEFAULT_FLOW_GRAPH = os.path.join(PATH, 'data', 'default_flow_graph.grc.xml')
-
 class Platform(_Platform):
 
        def __init__(self, block_paths_internal_only=[], 
block_paths_external=[]):
@@ -45,27 +40,16 @@
                @param block_paths_internal_only a list of blocks internal to 
this platform
                @param block_paths_external a list of blocks to load in 
addition to the above blocks
                """
-               temp_files = list()
+               #ensure hier dir
+               if not os.path.exists(HIER_BLOCKS_LIB_PATH): 
os.mkdir(HIER_BLOCKS_LIB_PATH)
                #handle internal/only
                if block_paths_internal_only: 
                        block_paths = map(lambda b: os.path.join(BLOCK_PATH, 
b), ['options.xml'] + block_paths_internal_only)
                else: block_paths = [BLOCK_PATH]
                #handle external
-               if block_paths_external:
-                       from utils import convert_hier
-                       def _load_block(file_path):
-                               try:
-                                       output_file_path = file_path+'.tmp'
-                                       convert_hier.convert_hier(file_path, 
output_file_path)
-                                       block_paths.append(output_file_path)
-                                       temp_files.append(output_file_path)
-                               except: print 'Error converting: %s'%file_path
-                       for block_path_external in block_paths_external:
-                               if os.path.isfile(block_path_external): 
_load_block(block_path_external)
-                               elif os.path.isdir(block_path_external):
-                                       for dirpath,dirnames,filenames in 
os.walk(block_path_external):
-                                               for filename in filter(lambda 
f: f.endswith(FLOW_GRAPH_FILE_EXTENSION), filenames):
-                                                       
_load_block(os.path.join(dirpath, filename))
+               block_paths.extend(block_paths_external)
+               #append custom hiers
+               block_paths.append(HIER_BLOCKS_LIB_PATH)
                #init
                _Platform.__init__(
                        self,
@@ -77,8 +61,6 @@
                        default_flow_graph=DEFAULT_FLOW_GRAPH,
                        generator=Generator,
                )
-               #remove temp files
-               map(os.remove, temp_files)
 
        ##############################################
        # Constructors

Modified: grc/trunk/src/grc_gnuradio/data/flow_graph.tmpl
===================================================================
--- grc/trunk/src/grc_gnuradio/data/flow_graph.tmpl     2008-07-25 01:12:34 UTC 
(rev 9013)
+++ grc/trunk/src/grc_gnuradio/data/flow_graph.tmpl     2008-07-25 14:59:29 UTC 
(rev 9014)
@@ -8,7 +8,7 @@
 address@hidden parameters the paramater blocks
 address@hidden blocks the signal blocks
 address@hidden connections the connections
address@hidden gui_type the type of gui (wx gui or no gui)
address@hidden generate_options the type of flow graph
 address@hidden var_id2expr variable id map to expression
 address@hidden var_id2deps variable id map to direct dependencies
 address@hidden var_id2cbs variable id map to callback strings
@@ -39,7 +39,7 @@
 ########################################################
 #set $class_name = $flow_graph.get_option('id')
 #set $param_str = ', '.join(['self'] + ['%s=%s'%(param.get_id(), 
param.get_make()) for param in $parameters])
-#if $gui_type == 'wx_gui'
+#if $generate_options == 'wx_gui'
        #import os
        #from grc.Constants import MAIN_WINDOW_PREFIX,DATA_DIR
        ##set the icon for the wx app
@@ -56,12 +56,12 @@
                        title="$MAIN_WINDOW_PREFIX - Executing: 
$flow_graph.get_option('title')",
                        icon=$WX_APP_ICON,
                )
-#elif $gui_type == 'no_gui'
+#elif $generate_options == 'no_gui'
 class $(class_name)(gr.top_block):
 
        def __init__($param_str):
                gr.top_block.__init__(self, "$flow_graph.get_option('title')")
-#elif $gui_type == 'hb'
+#elif $generate_options == 'hb'
        #set $in_sig = $flow_graph.get_input_signature()
        #set $out_sig = $flow_graph.get_output_signature()
 class $(class_name)(gr.hier_block2):
@@ -172,12 +172,12 @@
 ##     For top block code, generate a main routine.
 ##     Instantiate the top block and run as gui or cli.
 ########################################################
-#if $gui_type != 'hb'
+#if $generate_options != 'hb'
 if __name__ == '__main__':
        tb = $(class_name)()
-       #if $gui_type == 'wx_gui'
+       #if $generate_options == 'wx_gui'
        tb.Run()
-       #elif $gui_type == 'no_gui'
+       #elif $generate_options == 'no_gui'
        tb.start()
        raw_input('Press Enter to quit: ')
        tb.stop()

Modified: grc/trunk/src/grc_gnuradio/utils/convert_hier.py
===================================================================
--- grc/trunk/src/grc_gnuradio/utils/convert_hier.py    2008-07-25 01:12:34 UTC 
(rev 9013)
+++ grc/trunk/src/grc_gnuradio/utils/convert_hier.py    2008-07-25 14:59:29 UTC 
(rev 9014)
@@ -20,19 +20,11 @@
 #Utility functions to convert a grc hier block to an xml wrapper
 address@hidden Josh Blum
 
-from grc.Constants import FLOW_GRAPH_DTD
+from grc_gnuradio.Platform import BLOCK_DTD
 from grc import ParseXML
-from grc_gnuradio.Platform import Platform, BLOCK_DTD
 from grc.Utils import odict
 
-PLATFORM = Platform()
-
-def convert_hier(input_file_path, output_file_path):
-       #get the flow graph
-       ParseXML.validate_dtd(input_file_path, FLOW_GRAPH_DTD)
-       initial_state = ParseXML.from_file(input_file_path)
-       flow_graph = PLATFORM.get_new_flow_graph()
-       flow_graph.import_data(initial_state)
+def convert_hier(flow_graph, python_file):
        #extract info from the flow graph
        input_sig = flow_graph.get_input_signature()
        output_sig = flow_graph.get_output_signature()
@@ -41,15 +33,16 @@
        block_name = flow_graph.get_option('title')
        block_category = flow_graph.get_option('category')
        block_desc = flow_graph.get_option('description')
+       block_author = flow_graph.get_option('author')
        #build the nested data
        block_n = odict()
        block_n['name'] = block_name
        block_n['key'] = block_key
        block_n['category'] = block_category
-       block_n['import'] = 'import %s'%block_key
+       block_n['import'] = 'execfile("%s")'%python_file
        #make data
-       block_n['make'] = '%s.%s(\n\t%s,\n)'%(
-               block_key, block_key,
+       block_n['make'] = '%s(\n\t%s,\n)'%(
+               block_key,
                ',\n\t'.join(['%s=$%s'%(param.get_id(), param.get_id()) for 
param in parameters]),
        )
        #callback data
@@ -81,11 +74,8 @@
                source_n['nports'] = output_sig['nports']
                block_n['source'] = source_n
        #doc data
-       block_n['doc'] = block_desc
+       block_n['doc'] = "%s\n%s\n%s"%(block_author, block_desc, python_file)
        #write the block_n to file
-       ParseXML.to_file({'block': block_n}, output_file_path)
-       ParseXML.validate_dtd(output_file_path, BLOCK_DTD)
-
-if __name__ == '__main__':
-       import sys
-       convert_hier(sys.argv[1], sys.argv[2])
+       xml_file = python_file + '.xml'
+       ParseXML.to_file({'block': block_n}, xml_file)
+       ParseXML.validate_dtd(xml_file, BLOCK_DTD)





reply via email to

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