diff options
-rw-r--r-- | grc/blocks/epy_block.xml | 25 | ||||
-rw-r--r-- | grc/core/Block.py | 6 | ||||
-rw-r--r-- | grc/gui/FlowGraph.py | 11 |
3 files changed, 28 insertions, 14 deletions
diff --git a/grc/blocks/epy_block.xml b/grc/blocks/epy_block.xml index e56186ec65..d443d29c31 100644 --- a/grc/blocks/epy_block.xml +++ b/grc/blocks/epy_block.xml @@ -17,29 +17,40 @@ <value>""" Embedded Python Blocks: -Each this file is saved, GRC will instantiate the first class it finds to get -ports and parameters of your block. The arguments to __init__ will be the -parameters. All of them are required to have default values! +Each time this file is saved, GRC will instantiate the first class it finds +to get ports and parameters of your block. The arguments to __init__ will +be the parameters. All of them are required to have default values! """ + import numpy as np from gnuradio import gr class blk(gr.sync_block): - def __init__(self, factor=1.0): # only default arguments here + """Embedded Python Block example - a simple multiply const""" + + def __init__(self, example_param=1.0): # only default arguments here + """arguments to this function show up as parameters in GRC""" gr.sync_block.__init__( self, - name='Embedded Python Block', + name='Embedded Python Block', # will show up in GRC in_sig=[np.complex64], out_sig=[np.complex64] ) - self.factor = factor + self.factor = example_param def work(self, input_items, output_items): + """example: multiply with constant""" output_items[0][:] = input_items[0] * self.factor return len(output_items[0]) </value> <type>_multiline_python_external</type> <hide>part</hide> </param> - <doc>Doc me, baby!</doc> + <doc>This block represents an arbitrary GNU Radio Python Block. + +Its source code can be accessed through the parameter 'Code' which opens your editor. Each time you save changes in the editor, GRC will update the block. This includes the number, names and defaults of the parameters, the ports (stream and message) and the block name and documentation. + +Block Documentation: +(will be replaced the docstring of your block class) +</doc> </block> diff --git a/grc/core/Block.py b/grc/core/Block.py index 6708986939..cb4eb0db61 100644 --- a/grc/core/Block.py +++ b/grc/core/Block.py @@ -408,7 +408,7 @@ class Block(Element): param_src = self.get_param('_source_code') src = param_src.get_value() - src_hash = hash(src) + src_hash = hash((self.get_id(), src)) if src_hash == self._epy_source_hash: return @@ -430,8 +430,8 @@ class Block(Element): self._epy_source_hash = src_hash self._name = blk_io.name or blk_io.cls self._doc = blk_io.doc - self._imports[0] = 'from {} import {}'.format(self.get_id(), blk_io.cls) - self._make = '{}({})'.format(blk_io.cls, ', '.join( + self._imports[0] = 'import ' + self.get_id() + self._make = '{0}.{1}({2})'.format(self.get_id(), blk_io.cls, ', '.join( '{0}=${0}'.format(key) for key, _ in blk_io.params)) params = {} diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py index 15488cc59b..357f87c894 100644 --- a/grc/gui/FlowGraph.py +++ b/grc/gui/FlowGraph.py @@ -214,10 +214,13 @@ class FlowGraph(Element, _Flowgraph): continue # unknown block was pasted (e.g. dummy block) selected.add(block) #set params - params_n = block_n.findall('param') - for param_n in params_n: - param_key = param_n.find('key') - param_value = param_n.find('value') + params = dict((n.find('key'), n.find('value')) + for n in block_n.findall('param')) + if block_key == 'epy_block': + block.get_param('_io_cache').set_value(params.pop('_io_cache')) + block.get_param('_source_code').set_value(params.pop('_source_code')) + block.rewrite() # this creates the other params + for param_key, param_value in params.iteritems(): #setup id parameter if param_key == 'id': old_id2block[param_value] = block |