Python Snippet: Difference between revisions

From GNU Radio
Jump to navigation Jump to search
(initial creation)
 
m (Added in 3.9)
Line 1: Line 1:
Insert a snippet of Python code directly into the flowgraph at the end of the specified section.
Insert a snippet of Python code directly into the flowgraph at the end of the specified section. <code>Added in 3.9</code>


CAUTION: This is an ADVANCED feature and can lead to unintended consequences in the rendering of a flowgraph.  Use at your own risk.
CAUTION: This is an ADVANCED feature and can lead to unintended consequences in the rendering of a flowgraph.  Use at your own risk.

Revision as of 13:28, 10 March 2021

Insert a snippet of Python code directly into the flowgraph at the end of the specified section. Added in 3.9

CAUTION: This is an ADVANCED feature and can lead to unintended consequences in the rendering of a flowgraph. Use at your own risk.

For each snippet a function is generated with the block name of the snippet (use GRC Show Block IDs option to modify). These functions are then grouped into their respective sections in the rendered flowgraph.

The purpose of the python snippets is to be able to exercise features from within GRC that are not entirely supported by the block callbacks, methods and mechanisms to generate the code. One example of this would be calling UHD timed commands before starting the flowgraph

Indents will be handled upon insertion into the python flowgraph.

  • Example 1:
    epy_mod_0.some_function(self.some_block.some_property)

    Will place the function call in the generated .py file using the name of the appropriate embedded python block in the proper scope
    The scope is relative to the blocks in the flowgraph, e.g. to reference a block, it should be identified as self.block
  • Example 2:
    print('The flowgraph has been stopped')

    With section selected as 'Main - After Stop', will place the print statement after the flowgraph has been stopped.

Parameters

(R): Run-time adjustable

Section of Flowgraph
options: ['Main - After Init', 'Main - After Start', 'Main - After Stop']
Priority
priority within the section; larger number is higher priority
Code Snippet
content of code

Example Flowgraph

Py snippets demo fg.png

Example Output

Py snippets demo out.png

Source Files

C++ files
TODO
Header files
TODO
Public header files
TODO
Block definition
[1]