diff options
author | Sebastian Koslowski <koslowski@kit.edu> | 2016-04-15 21:02:51 +0200 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2016-04-15 21:09:19 +0200 |
commit | 8cfc8b3408916ccb156fc25102bc1d9346bc004b (patch) | |
tree | 5c38adfedca3f4f4073d0621840ea578dd67ed4d /grc | |
parent | 036264ef5c8e2376acd426a99ca42d29390e3e2a (diff) | |
parent | bdf85171b8a35004cdbf634f48ff696787b5fbde (diff) |
Merge remote-tracking branch 'upstream/master' into refactoring
Diffstat (limited to 'grc')
31 files changed, 53 insertions, 1412 deletions
diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt index e21f6b2d22..a764e3dc4d 100644 --- a/grc/CMakeLists.txt +++ b/grc/CMakeLists.txt @@ -134,7 +134,6 @@ endif(WIN32) # Add subdirectories ######################################################################## add_subdirectory(blocks) -add_subdirectory(grc_gnuradio) add_subdirectory(gui) add_subdirectory(python) add_subdirectory(scripts) diff --git a/grc/blocks/blks2_error_rate.xml b/grc/blocks/blks2_error_rate.xml deleted file mode 100644 index 91a303206d..0000000000 --- a/grc/blocks/blks2_error_rate.xml +++ /dev/null @@ -1,69 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -##Error Rate: -## Custom blks2 block -################################################### - --> -<block> - <name>Error Rate</name> - <key>blks2_error_rate</key> - <import>from grc_gnuradio import blks2 as grc_blks2</import> - <make>grc_blks2.error_rate( - type=$type, - win_size=$win_size, - bits_per_symbol=$bits_per_symbol, -)</make> - <param> - <name>Type</name> - <key>type</key> - <type>enum</type> - <option> - <name>Bit Error Rate</name> - <key>'BER'</key> - <opt>hide_bps:</opt> - </option> - <option> - <name>Symbol Error Rate</name> - <key>'SER'</key> - <opt>hide_bps:all</opt> - </option> - </param> - <param> - <name>Window Size</name> - <key>win_size</key> - <value>1000</value> - <type>int</type> - </param> - <param> - <name>Bits per Symbol</name> - <key>bits_per_symbol</key> - <value>2</value> - <type>int</type> - <hide>$type.hide_bps</hide> - </param> - <sink> - <name>ref</name> - <type>byte</type> - </sink> - <sink> - <name>in</name> - <type>byte</type> - </sink> - <source> - <name>out</name> - <type>float</type> - </source> - <doc> -Calculate the bit error rate (BER) or the symbol error rate (SER) over a number of samples given by the window size. \ -The actual window size will start at size one and grow to the full window size as new samples arrive. \ -Once the window has reached full size, old samples are shifted out of the window and new samples shfited in. - -The error block compares the input byte stream to the reference byte stream. \ -For example, the reference byte stream could be the input to a modulator, \ -and the input byte stream could be the output of a modulator. - -Each byte in the incoming stream represents one symbol. \ -The bits per symbol parameter is only useful for calculating the BER. - </doc> -</block> diff --git a/grc/blocks/blks2_packet_decoder.xml b/grc/blocks/blks2_packet_decoder.xml deleted file mode 100644 index 07b0d1f2eb..0000000000 --- a/grc/blocks/blks2_packet_decoder.xml +++ /dev/null @@ -1,75 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -##Packet Decoder -################################################### - --> -<block> - <name>Packet Decoder</name> - <key>blks2_packet_decoder</key> - <import>from grc_gnuradio import blks2 as grc_blks2</import> - <make>grc_blks2.packet_demod_$(type.fcn)(grc_blks2.packet_decoder( - access_code=$access_code, - threshold=$threshold, - callback=lambda ok, payload: self.$(id).recv_pkt(ok, payload), - ), -)</make> - <param> - <name>Output Type</name> - <key>type</key> - <value>float</value> - <type>enum</type> - <option> - <name>Complex</name> - <key>complex</key> - <opt>fcn:c</opt> - </option> - <option> - <name>Float</name> - <key>float</key> - <opt>fcn:f</opt> - </option> - <option> - <name>Int</name> - <key>int</key> - <opt>fcn:i</opt> - </option> - <option> - <name>Short</name> - <key>short</key> - <opt>fcn:s</opt> - </option> - <option> - <name>Byte</name> - <key>byte</key> - <opt>fcn:b</opt> - </option> - </param> - <param> - <name>Access Code</name> - <key>access_code</key> - <value></value> - <type>string</type> - </param> - <param> - <name>Threshold</name> - <key>threshold</key> - <value>-1</value> - <type>int</type> - </param> - <sink> - <name>in</name> - <type>byte</type> - </sink> - <source> - <name>out</name> - <type>$type</type> - </source> - <doc> -Packet decoder block, for use with the gnuradio demodulator blocks: gmsk, psk, qam. - -Access Code: string of 1's and 0's, leave blank for automatic. - -Threshold: -1 for automatic. - </doc> -</block> diff --git a/grc/blocks/blks2_packet_encoder.xml b/grc/blocks/blks2_packet_encoder.xml deleted file mode 100644 index 88e1ba350c..0000000000 --- a/grc/blocks/blks2_packet_encoder.xml +++ /dev/null @@ -1,119 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -##Packet Encoder -################################################### - --> -<block> - <name>Packet Encoder</name> - <key>blks2_packet_encoder</key> - <import>from grc_gnuradio import blks2 as grc_blks2</import> - <make>grc_blks2.packet_mod_$(type.fcn)(grc_blks2.packet_encoder( - samples_per_symbol=$samples_per_symbol, - bits_per_symbol=$bits_per_symbol, - preamble=$preamble, - access_code=$access_code, - pad_for_usrp=$pad_for_usrp, - ), - payload_length=$payload_length, -)</make> - <param> - <name>Input Type</name> - <key>type</key> - <value>float</value> - <type>enum</type> - <option> - <name>Complex</name> - <key>complex</key> - <opt>fcn:c</opt> - </option> - <option> - <name>Float</name> - <key>float</key> - <opt>fcn:f</opt> - </option> - <option> - <name>Int</name> - <key>int</key> - <opt>fcn:i</opt> - </option> - <option> - <name>Short</name> - <key>short</key> - <opt>fcn:s</opt> - </option> - <option> - <name>Byte</name> - <key>byte</key> - <opt>fcn:b</opt> - </option> - </param> - <param> - <name>Samples/Symbol</name> - <key>samples_per_symbol</key> - <type>int</type> - </param> - <param> - <name>Bits/Symbol</name> - <key>bits_per_symbol</key> - <type>int</type> - </param> - <param> - <name>Preamble</name> - <key>preamble</key> - <value></value> - <type>string</type> - </param> - <param> - <name>Access Code</name> - <key>access_code</key> - <value></value> - <type>string</type> - </param> - <param> - <name>Pad for USRP</name> - <key>pad_for_usrp</key> - <type>enum</type> - <option> - <name>Yes</name> - <key>True</key> - </option> - <option> - <name>No</name> - <key>False</key> - </option> - </param> - <param> - <name>Payload Length</name> - <key>payload_length</key> - <value>0</value> - <type>int</type> - </param> - <sink> - <name>in</name> - <type>$type</type> - </sink> - <source> - <name>out</name> - <type>byte</type> - </source> - <doc> -Packet encoder block, for use with the gnuradio modulator blocks: gmsk, dpsk, qam. - -Preamble: string of 1's and 0's, leave blank for automatic. - -Access Code: string of 1's and 0's, leave blank for automatic. - -Payload Length: 0 for automatic. - -Bits/Symbol should be set accordingly: - gmsk -> 1 - dbpsk -> 1 - dqpsk -> 2 - d8psk -> 3 - qam8 -> 3 - qam16 -> 4 - qam64 -> 6 - qam256 -> 8 - </doc> -</block> diff --git a/grc/blocks/blks2_selector.xml b/grc/blocks/blks2_selector.xml deleted file mode 100644 index 2d89df1860..0000000000 --- a/grc/blocks/blks2_selector.xml +++ /dev/null @@ -1,97 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -##Selector: -## Custom blks2 block -################################################### - --> -<block> - <name>Selector</name> - <key>blks2_selector</key> - <import>from grc_gnuradio import blks2 as grc_blks2</import> - <make>grc_blks2.selector( - item_size=$type.size*$vlen, - num_inputs=$num_inputs, - num_outputs=$num_outputs, - input_index=$input_index, - output_index=$output_index, -)</make> - <callback>set_input_index(int($input_index))</callback> - <callback>set_output_index(int($output_index))</callback> - <param> - <name>Type</name> - <key>type</key> - <type>enum</type> - <option> - <name>Complex</name> - <key>complex</key> - <opt>size:gr.sizeof_gr_complex</opt> - </option> - <option> - <name>Float</name> - <key>float</key> - <opt>size:gr.sizeof_float</opt> - </option> - <option> - <name>Int</name> - <key>int</key> - <opt>size:gr.sizeof_int</opt> - </option> - <option> - <name>Short</name> - <key>short</key> - <opt>size:gr.sizeof_short</opt> - </option> - <option> - <name>Byte</name> - <key>byte</key> - <opt>size:gr.sizeof_char</opt> - </option> - </param> - <param> - <name>Num Inputs</name> - <key>num_inputs</key> - <value>2</value> - <type>int</type> - </param> - <param> - <name>Num Outputs</name> - <key>num_outputs</key> - <value>2</value> - <type>int</type> - </param> - <param> - <name>Input Index</name> - <key>input_index</key> - <value>0</value> - <type>int</type> - </param> - <param> - <name>Output Index</name> - <key>output_index</key> - <value>0</value> - <type>int</type> - </param> - <param> - <name>Vec Length</name> - <key>vlen</key> - <value>1</value> - <type>int</type> - </param> - <check>$vlen > 0</check> - <sink> - <name>in</name> - <type>$type</type> - <vlen>$vlen</vlen> - <nports>$num_inputs</nports> - </sink> - <source> - <name>out</name> - <type>$type</type> - <vlen>$vlen</vlen> - <nports>$num_outputs</nports> - </source> - <doc> -Connect the sink at input index to the source at output index. Leave all other ports disconnected. - </doc> -</block> diff --git a/grc/blocks/blks2_tcp_sink.xml b/grc/blocks/blks2_tcp_sink.xml deleted file mode 100644 index cfe7b42d84..0000000000 --- a/grc/blocks/blks2_tcp_sink.xml +++ /dev/null @@ -1,89 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -##TCP Sink: Custom blks2 block -################################################### - --> -<block> - <name>TCP Sink</name> - <key>blks2_tcp_sink</key> - <import>from grc_gnuradio import blks2 as grc_blks2</import> - <make>grc_blks2.tcp_sink( - itemsize=$type.size*$vlen, - addr=$addr, - port=$port, - server=$server, -)</make> - <param> - <name>Input Type</name> - <key>type</key> - <type>enum</type> - <option> - <name>Complex</name> - <key>complex</key> - <opt>size:gr.sizeof_gr_complex</opt> - </option> - <option> - <name>Float</name> - <key>float</key> - <opt>size:gr.sizeof_float</opt> - </option> - <option> - <name>Int</name> - <key>int</key> - <opt>size:gr.sizeof_int</opt> - </option> - <option> - <name>Short</name> - <key>short</key> - <opt>size:gr.sizeof_short</opt> - </option> - <option> - <name>Byte</name> - <key>byte</key> - <opt>size:gr.sizeof_char</opt> - </option> - </param> - <param> - <name>Address</name> - <key>addr</key> - <value>127.0.0.1</value> - <type>string</type> - </param> - <param> - <name>Port</name> - <key>port</key> - <value>0</value> - <type>int</type> - </param> - <param> - <name>Mode</name> - <key>server</key> - <value>False</value> - <type>enum</type> - <option> - <name>Server</name> - <key>True</key> - </option> - <option> - <name>Client</name> - <key>False</key> - </option> - </param> - <param> - <name>Vec Length</name> - <key>vlen</key> - <value>1</value> - <type>int</type> - </param> - <check>$vlen > 0</check> - <sink> - <name>in</name> - <type>$type</type> - <vlen>$vlen</vlen> - </sink> - <doc> -In client mode, we attempt to connect to a server at the given address and port. \ -In server mode, we bind a socket to the given address and port and accept the first client. - </doc> -</block> diff --git a/grc/blocks/blks2_tcp_source.xml b/grc/blocks/blks2_tcp_source.xml deleted file mode 100644 index 6bf742aa00..0000000000 --- a/grc/blocks/blks2_tcp_source.xml +++ /dev/null @@ -1,89 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -##TCP Source: Custom blks2 block -################################################### - --> -<block> - <name>TCP Source</name> - <key>blks2_tcp_source</key> - <import>from grc_gnuradio import blks2 as grc_blks2</import> - <make>grc_blks2.tcp_source( - itemsize=$type.size*$vlen, - addr=$addr, - port=$port, - server=$server, -)</make> - <param> - <name>Output Type</name> - <key>type</key> - <type>enum</type> - <option> - <name>Complex</name> - <key>complex</key> - <opt>size:gr.sizeof_gr_complex</opt> - </option> - <option> - <name>Float</name> - <key>float</key> - <opt>size:gr.sizeof_float</opt> - </option> - <option> - <name>Int</name> - <key>int</key> - <opt>size:gr.sizeof_int</opt> - </option> - <option> - <name>Short</name> - <key>short</key> - <opt>size:gr.sizeof_short</opt> - </option> - <option> - <name>Byte</name> - <key>byte</key> - <opt>size:gr.sizeof_char</opt> - </option> - </param> - <param> - <name>Address</name> - <key>addr</key> - <value>127.0.0.1</value> - <type>string</type> - </param> - <param> - <name>Port</name> - <key>port</key> - <value>0</value> - <type>int</type> - </param> - <param> - <name>Mode</name> - <key>server</key> - <value>True</value> - <type>enum</type> - <option> - <name>Server</name> - <key>True</key> - </option> - <option> - <name>Client</name> - <key>False</key> - </option> - </param> - <param> - <name>Vec Length</name> - <key>vlen</key> - <value>1</value> - <type>int</type> - </param> - <check>$vlen > 0</check> - <source> - <name>out</name> - <type>$type</type> - <vlen>$vlen</vlen> - </source> - <doc> -In client mode, we attempt to connect to a server at the given address and port. \ -In server mode, we bind a socket to the given address and port and accept the first client. - </doc> -</block> diff --git a/grc/blocks/blks2_valve.xml b/grc/blocks/blks2_valve.xml deleted file mode 100644 index 47c553523f..0000000000 --- a/grc/blocks/blks2_valve.xml +++ /dev/null @@ -1,72 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -##Valve: -## Custom blks2 block -################################################### - --> -<block> - <name>Valve</name> - <key>blks2_valve</key> - <import>from grc_gnuradio import blks2 as grc_blks2</import> - <make>grc_blks2.valve(item_size=$type.size*$vlen, open=bool($open))</make> - <callback>set_open(bool($open))</callback> - <param> - <name>Type</name> - <key>type</key> - <type>enum</type> - <option> - <name>Complex</name> - <key>complex</key> - <opt>size:gr.sizeof_gr_complex</opt> - </option> - <option> - <name>Float</name> - <key>float</key> - <opt>size:gr.sizeof_float</opt> - </option> - <option> - <name>Int</name> - <key>int</key> - <opt>size:gr.sizeof_int</opt> - </option> - <option> - <name>Short</name> - <key>short</key> - <opt>size:gr.sizeof_short</opt> - </option> - <option> - <name>Byte</name> - <key>byte</key> - <opt>size:gr.sizeof_char</opt> - </option> - </param> - <param> - <name>Open</name> - <key>open</key> - <value>0</value> - <type>raw</type> - </param> - <param> - <name>Vec Length</name> - <key>vlen</key> - <value>1</value> - <type>int</type> - </param> - <check>$vlen > 0</check> - <sink> - <name>in</name> - <type>$type</type> - <vlen>$vlen</vlen> - <nports>$num_inputs</nports> - </sink> - <source> - <name>out</name> - <type>$type</type> - <vlen>$vlen</vlen> - <nports>$num_outputs</nports> - </source> - <doc> -Connect output to input when valve is closed (not open). - </doc> -</block> diff --git a/grc/blocks/block_tree.xml b/grc/blocks/block_tree.xml index d07c52e9c5..a8775d6872 100644 --- a/grc/blocks/block_tree.xml +++ b/grc/blocks/block_tree.xml @@ -20,23 +20,6 @@ <block>note</block> <block>import</block> - - <block>blks2_selector</block> - <block>blks2_valve</block> - <block>blks2_error_rate</block> - - <block>xmlrpc_server</block> - <block>xmlrpc_client</block> - </cat> - <cat> - <name>Networking Tools</name> - <block>blks2_tcp_source</block> - <block>blks2_tcp_sink</block> - </cat> - <cat> - <name>Packet Operators</name> - <block>blks2_packet_decoder</block> - <block>blks2_packet_encoder</block> </cat> <cat> <name>Variables</name> diff --git a/grc/blocks/xmlrpc_client.xml b/grc/blocks/xmlrpc_client.xml deleted file mode 100644 index dc4d154d14..0000000000 --- a/grc/blocks/xmlrpc_client.xml +++ /dev/null @@ -1,42 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -##Simple XMLRPC Client -################################################### - --> -<block> - <name>XMLRPC Client</name> - <key>xmlrpc_client</key> - <import>import xmlrpclib</import> - <make>xmlrpclib.Server('http://$(addr()):$(port)')</make> - <callback>$(callback())($variable)</callback> - <param> - <name>Address</name> - <key>addr</key> - <value>localhost</value> - <type>string</type> - </param> - <param> - <name>Port</name> - <key>port</key> - <value>8080</value> - <type>int</type> - </param> - <param> - <name>Callback</name> - <key>callback</key> - <value>set_</value> - <type>string</type> - </param> - <param> - <name>Variable</name> - <key>variable</key> - <type>raw</type> - </param> - <doc> -This block will create an XMLRPC client. \ -The client will execute the callback on the server when the variable is changed. \ -The callback should be a the name of a function registered on the server. \ -The variable should be an expression containing a the name of a variable in flow graph. - </doc> -</block> diff --git a/grc/blocks/xmlrpc_server.xml b/grc/blocks/xmlrpc_server.xml deleted file mode 100644 index 602d444161..0000000000 --- a/grc/blocks/xmlrpc_server.xml +++ /dev/null @@ -1,41 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -##Simple XMLRPC Server -################################################### - --> -<block> - <name>XMLRPC Server</name> - <key>xmlrpc_server</key> - <import>import SimpleXMLRPCServer</import> - <import>import threading</import> - <make>SimpleXMLRPCServer.SimpleXMLRPCServer(($addr, $port), allow_none=True) -self.$(id).register_instance(self) -self.$(id)_thread = threading.Thread(target=self.$(id).serve_forever) -self.$(id)_thread.daemon = True -self.$(id)_thread.start()</make> - <param> - <name>Address</name> - <key>addr</key> - <value>localhost</value> - <type>string</type> - </param> - <param> - <name>Port</name> - <key>port</key> - <value>8080</value> - <type>int</type> - </param> - <doc> -This block will start an XMLRPC server. \ -The server provides access to the run, start, stop, wait functions of the flow graph. \ -The server also provides access to the variable callbacks in the flow graph. \ -Ex: If the variable is called freq, the function provided by the server will be called set_freq(new_freq). - -Example client in python: - -import xmlrpclib -s = xmlrpclib.Server('http://localhost:8080') -s.set_freq(5000) - </doc> -</block> diff --git a/grc/core/Block.py b/grc/core/Block.py index c2c7d4e821..6708986939 100644 --- a/grc/core/Block.py +++ b/grc/core/Block.py @@ -21,7 +21,6 @@ import collections import itertools from Cheetah.Template import Template -from UserDict import UserDict from .utils import epy_block_io, odict from . Constants import ( @@ -442,11 +441,10 @@ class Block(Element): self._params.remove(param) for key, value in blk_io.params: - if key in params: + try: param = params[key] - if not param.value_is_default(): - param.set_value(value) - else: + param.set_default(value) + except KeyError: # need to make a new param name = key.replace('_', ' ').title() n = odict(dict(name=name, key=key, type='raw', value=value)) param = platform.Param(block=self, n=n) diff --git a/grc/core/Element.py b/grc/core/Element.py index c999d6704f..b96edb0a72 100644 --- a/grc/core/Element.py +++ b/grc/core/Element.py @@ -41,9 +41,9 @@ class Element(object): Is this element valid? Returns: - true when the element is enabled and has no error messages + true when the element is enabled and has no error messages or is bypassed """ - return not self.get_error_messages() or not self.get_enabled() + return (not self.get_error_messages() or not self.get_enabled()) or self.get_bypassed() def add_error_message(self, msg): """ @@ -57,14 +57,14 @@ class Element(object): def get_error_messages(self): """ Get the list of error messages from this element and all of its children. - Do not include the error messages from disabled children. + Do not include the error messages from disabled or bypassed children. Cleverly indent the children error messages for printing purposes. Returns: a list of error message strings """ error_messages = list(self._error_messages) # Make a copy - for child in filter(lambda c: c.get_enabled(), self.get_children()): + for child in filter(lambda c: c.get_enabled() and not c.get_bypassed(), self.get_children()): for msg in child.get_error_messages(): error_messages.append("{}:\n\t{}".format(child, msg.replace("\n", "\n\t"))) return error_messages @@ -80,6 +80,9 @@ class Element(object): def get_enabled(self): return True + def get_bypassed(self): + return False + ############################################## # Tree-like API ############################################## diff --git a/grc/core/FlowGraph.py b/grc/core/FlowGraph.py index 177d16baa9..313af3107a 100644 --- a/grc/core/FlowGraph.py +++ b/grc/core/FlowGraph.py @@ -424,7 +424,7 @@ class FlowGraph(Element): block.import_data(block_n) - self.rewrite() + self.rewrite() # evaluate stuff like nports before adding connections # build the connections def verify_and_get_port(key, block, dir): diff --git a/grc/core/Param.py b/grc/core/Param.py index 04c4967f53..d155800c43 100644 --- a/grc/core/Param.py +++ b/grc/core/Param.py @@ -683,8 +683,10 @@ class Param(Element): # Must be a string self._value = str(value) - def value_is_default(self): - return self._default == self._value + def set_default(self, value): + if self._default == self._value: + self.set_value(value) + self._default = str(value) def get_type(self): return self.get_parent().resolve_dependencies(self._type) diff --git a/grc/core/ParseXML.py b/grc/core/ParseXML.py index 987fa2a13d..c9f6541ee7 100644 --- a/grc/core/ParseXML.py +++ b/grc/core/ParseXML.py @@ -22,6 +22,7 @@ from lxml import etree from .utils import odict xml_failures = {} +etree.set_default_parser(etree.XMLParser(remove_comments=True)) class XMLSyntaxError(Exception): diff --git a/grc/core/Port.py b/grc/core/Port.py index 4964a94c2b..6a8f484082 100644 --- a/grc/core/Port.py +++ b/grc/core/Port.py @@ -129,7 +129,7 @@ class Port(Element): # Grab the data self._name = n['name'] self._key = n['key'] - self._type = n['type'] + self._type = n['type'] or '' self._domain = n['domain'] self._hide = n.find('hide') or '' self._dir = dir diff --git a/grc/core/generator/flow_graph.tmpl b/grc/core/generator/flow_graph.tmpl index bd8025b676..ecdb89390e 100644 --- a/grc/core/generator/flow_graph.tmpl +++ b/grc/core/generator/flow_graph.tmpl @@ -274,8 +274,8 @@ gr.io_signaturev($(len($io_sigs)), $(len($io_sigs)), [$(', '.join($size_strs))]) self.settings = Qt.QSettings("GNU Radio", "$class_name") self.settings.setValue("geometry", self.saveGeometry()) event.accept() - #if $flow_graph.get_option('qt_qss_theme') + def setStyleSheetFromFile(self, filename): try: if not os.path.exists(filename): @@ -336,7 +336,12 @@ $short_id#slurp def argument_parser(): - parser = OptionParser(option_class=eng_option, usage="%prog: [options]") + #set $desc_args = 'usage="%prog: [options]", option_class=eng_option' + #if $flow_graph.get_option('description') + #set $desc_args += ', description=description' + description = $repr($flow_graph.get_option('description')) + #end if + parser = OptionParser($desc_args) #for $param in $parameters #set $type = $param.get_param('type').get_value() #if $type diff --git a/grc/grc_gnuradio/CMakeLists.txt b/grc/grc_gnuradio/CMakeLists.txt deleted file mode 100644 index e992a60a39..0000000000 --- a/grc/grc_gnuradio/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright 2011 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. - -######################################################################## -GR_PYTHON_INSTALL( - FILES __init__.py - DESTINATION ${GR_PYTHON_DIR}/grc_gnuradio - COMPONENT "grc" -) - -GR_PYTHON_INSTALL(FILES - blks2/__init__.py - blks2/error_rate.py - blks2/packet.py - blks2/selector.py - blks2/tcp.py - DESTINATION ${GR_PYTHON_DIR}/grc_gnuradio/blks2 - COMPONENT "grc" -) diff --git a/grc/grc_gnuradio/README b/grc/grc_gnuradio/README deleted file mode 100644 index 897eed65ca..0000000000 --- a/grc/grc_gnuradio/README +++ /dev/null @@ -1,11 +0,0 @@ -This is the grc_gnuradio module. -It contains supplemental python modules that grc uses at runtime. -The supplemental modules are meant to mimic modules in gnuradio. -These will be phased-out as new functionaility is merged into gnuradio. - -The blk2s module wraps many blocks in blks2 and gives them streaming outputs. -Will be phased-out by new message passing implementations. -Other blks2 blocks will hopefully make their way into blks2impl. - -The wxgui module contains a top_block + wxgui frame. -Will be phased-out by gui.py in wxgui and a new top block template. diff --git a/grc/grc_gnuradio/__init__.py b/grc/grc_gnuradio/__init__.py deleted file mode 100644 index 8b13789179..0000000000 --- a/grc/grc_gnuradio/__init__.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/grc/grc_gnuradio/blks2/__init__.py b/grc/grc_gnuradio/blks2/__init__.py deleted file mode 100644 index e6941ab91b..0000000000 --- a/grc/grc_gnuradio/blks2/__init__.py +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright 2008-2011 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -from selector import selector, valve -from packet import options, packet_encoder, packet_decoder, \ - packet_mod_b, packet_mod_s, packet_mod_i, packet_mod_f, packet_mod_c, \ - packet_demod_b, packet_demod_s, packet_demod_i, packet_demod_f, packet_demod_c -from error_rate import error_rate -from tcp import tcp_source, tcp_sink diff --git a/grc/grc_gnuradio/blks2/error_rate.py b/grc/grc_gnuradio/blks2/error_rate.py deleted file mode 100644 index 9bf387030a..0000000000 --- a/grc/grc_gnuradio/blks2/error_rate.py +++ /dev/null @@ -1,140 +0,0 @@ -# Copyright 2008 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -default_win_size = 1000 - -from gnuradio import gr -from gnuradio import blocks -import gnuradio.gr.gr_threading as _threading -import numpy - -#generate 1s counts array -_1s_counts = [sum([1&(i>>j) for j in range(8)]) for i in range(2**8)] - -class input_watcher(_threading.Thread): - """ - Read samples from the message queue and hand them to the callback. - """ - - def __init__(self, msgq, callback): - self._msgq = msgq - self._callback = callback - _threading.Thread.__init__(self) - self.setDaemon(1) - self.keep_running = True - self.start() - - def run(self): - r = '' - while True: - msg = self._msgq.delete_head() - itemsize = int(msg.arg1()) - nitems = int(msg.arg2()) - s = r + msg.to_string() - i = (nitems-nitems%2)*itemsize - r = s[i:] - s = s[:i] - samples = numpy.fromstring(s, numpy.int8) - self._callback(samples) - -class error_rate(gr.hier_block2): - """ - Sample the incoming data streams (byte) and calculate the bit or symbol error rate. - Write the running rate to the output data stream (float). - """ - - def __init__(self, type='BER', win_size=default_win_size, bits_per_symbol=2): - """ - Error rate constructor. - - Args: - type: a string 'BER' or 'SER' - win_size: the number of samples to calculate over - bits_per_symbol: the number of information bits per symbol (BER only) - """ - #init - gr.hier_block2.__init__( - self, 'error_rate', - gr.io_signature(2, 2, gr.sizeof_char), - gr.io_signature(1, 1, gr.sizeof_float), - ) - assert type in ('BER', 'SER') - self._max_samples = win_size - self._bits_per_symbol = bits_per_symbol - #setup message queue - msg_source = blocks.message_source(gr.sizeof_float, 1) - self._msgq_source = msg_source.msgq() - msgq_sink = gr.msg_queue(2) - msg_sink = blocks.message_sink(gr.sizeof_char, msgq_sink, False) #False -> blocking - inter = blocks.interleave(gr.sizeof_char) - #start thread - self._num_errs = 0 - self._err_index = 0 - self._num_samps = 0 - self._err_array = numpy.zeros(self._max_samples, numpy.int8) - if type == 'BER': - input_watcher(msgq_sink, self._handler_ber) - elif type == 'SER': - input_watcher(msgq_sink, self._handler_ser) - #connect - self.connect(msg_source, self) - self.connect((self, 0), (inter, 0)) - self.connect((self, 1), (inter, 1)) - self.connect(inter, msg_sink) - - def _handler_ber(self, samples): - num = len(samples)/2 - arr = numpy.zeros(num, numpy.float32) - for i in range(num): - old_err = self._err_array[self._err_index] - #record error - self._err_array[self._err_index] = _1s_counts[samples[i*2] ^ samples[i*2 + 1]] - self._num_errs = self._num_errs + self._err_array[self._err_index] - old_err - #increment index - self._err_index = (self._err_index + 1)%self._max_samples - self._num_samps = min(self._num_samps + 1, self._max_samples) - #write sample - arr[i] = float(self._num_errs)/float(self._num_samps*self._bits_per_symbol) - #write message - msg = gr.message_from_string(arr.tostring(), 0, gr.sizeof_float, num) - self._msgq_source.insert_tail(msg) - - def _handler_ser(self, samples): - num = len(samples)/2 - arr = numpy.zeros(num, numpy.float32) - for i in range(num): - old_err = self._err_array[self._err_index] - #record error - ref = samples[i*2] - res = samples[i*2 + 1] - if ref == res: - self._err_array[self._err_index] = 0 - else: - self._err_array[self._err_index] = 1 - #update number of errors - self._num_errs = self._num_errs + self._err_array[self._err_index] - old_err - #increment index - self._err_index = (self._err_index + 1)%self._max_samples - self._num_samps = min(self._num_samps + 1, self._max_samples) - #write sample - arr[i] = float(self._num_errs)/float(self._num_samps) - #write message - msg = gr.message_from_string(arr.tostring(), 0, gr.sizeof_float, num) - self._msgq_source.insert_tail(msg) diff --git a/grc/grc_gnuradio/blks2/packet.py b/grc/grc_gnuradio/blks2/packet.py deleted file mode 100644 index ef79afde64..0000000000 --- a/grc/grc_gnuradio/blks2/packet.py +++ /dev/null @@ -1,257 +0,0 @@ -# Copyright 2008,2009,2012-2013 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -from gnuradio import gr, digital -from gnuradio import blocks -from gnuradio.digital import packet_utils -import gnuradio.gr.gr_threading as _threading - -##payload length in bytes -DEFAULT_PAYLOAD_LEN = 512 - -##how many messages in a queue -DEFAULT_MSGQ_LIMIT = 2 - -##threshold for unmaking packets -DEFAULT_THRESHOLD = 12 - -################################################## -## Options Class for OFDM -################################################## -class options(object): - def __init__(self, **kwargs): - for key, value in kwargs.iteritems(): setattr(self, key, value) - -################################################## -## Packet Encoder -################################################## -class _packet_encoder_thread(_threading.Thread): - - def __init__(self, msgq, payload_length, send): - self._msgq = msgq - self._payload_length = payload_length - self._send = send - _threading.Thread.__init__(self) - self.setDaemon(1) - self.keep_running = True - self.start() - - def run(self): - sample = '' #residual sample - while self.keep_running: - msg = self._msgq.delete_head() #blocking read of message queue - sample = sample + msg.to_string() #get the body of the msg as a string - while len(sample) >= self._payload_length: - payload = sample[:self._payload_length] - sample = sample[self._payload_length:] - self._send(payload) - -class packet_encoder(gr.hier_block2): - """ - Hierarchical block for wrapping packet-based modulators. - """ - - def __init__(self, samples_per_symbol, bits_per_symbol, preamble='', access_code='', pad_for_usrp=True): - """ - packet_mod constructor. - - Args: - samples_per_symbol: number of samples per symbol - bits_per_symbol: number of bits per symbol - preamble: string of ascii 0's and 1's - access_code: AKA sync vector - pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples - """ - #setup parameters - self._samples_per_symbol = samples_per_symbol - self._bits_per_symbol = bits_per_symbol - self._pad_for_usrp = pad_for_usrp - if not preamble: #get preamble - preamble = packet_utils.default_preamble - if not access_code: #get access code - access_code = packet_utils.default_access_code - if not packet_utils.is_1_0_string(preamble): - raise ValueError, "Invalid preamble %r. Must be string of 1's and 0's" % (preamble,) - if not packet_utils.is_1_0_string(access_code): - raise ValueError, "Invalid access_code %r. Must be string of 1's and 0's" % (access_code,) - self._preamble = preamble - self._access_code = access_code - self._pad_for_usrp = pad_for_usrp - #create blocks - msg_source = blocks.message_source(gr.sizeof_char, DEFAULT_MSGQ_LIMIT) - self._msgq_out = msg_source.msgq() - #initialize hier2 - gr.hier_block2.__init__( - self, - "packet_encoder", - gr.io_signature(0, 0, 0), # Input signature - gr.io_signature(1, 1, gr.sizeof_char) # Output signature - ) - #connect - self.connect(msg_source, self) - - def send_pkt(self, payload): - """ - Wrap the payload in a packet and push onto the message queue. - - Args: - payload: string, data to send - """ - packet = packet_utils.make_packet( - payload, - self._samples_per_symbol, - self._bits_per_symbol, - self._preamble, - self._access_code, - self._pad_for_usrp - ) - msg = gr.message_from_string(packet) - self._msgq_out.insert_tail(msg) - -################################################## -## Packet Decoder -################################################## -class _packet_decoder_thread(_threading.Thread): - - def __init__(self, msgq, callback): - _threading.Thread.__init__(self) - self.setDaemon(1) - self._msgq = msgq - self.callback = callback - self.keep_running = True - self.start() - - def run(self): - while self.keep_running: - msg = self._msgq.delete_head() - ok, payload = packet_utils.unmake_packet(msg.to_string(), int(msg.arg1())) - if self.callback: - self.callback(ok, payload) - -class packet_decoder(gr.hier_block2): - """ - Hierarchical block for wrapping packet-based demodulators. - """ - - def __init__(self, access_code='', threshold=-1, callback=None): - """ - packet_demod constructor. - - Args: - access_code: AKA sync vector - threshold: detect access_code with up to threshold bits wrong (0 -> use default) - callback: a function of args: ok, payload - """ - #access code - if not access_code: #get access code - access_code = packet_utils.default_access_code - if not packet_utils.is_1_0_string(access_code): - raise ValueError, "Invalid access_code %r. Must be string of 1's and 0's" % (access_code,) - self._access_code = access_code - #threshold - if threshold < 0: threshold = DEFAULT_THRESHOLD - self._threshold = threshold - #blocks - msgq = gr.msg_queue(DEFAULT_MSGQ_LIMIT) #holds packets from the PHY - correlator = digital.correlate_access_code_bb(self._access_code, self._threshold) - framer_sink = digital.framer_sink_1(msgq) - #initialize hier2 - gr.hier_block2.__init__( - self, - "packet_decoder", - gr.io_signature(1, 1, gr.sizeof_char), # Input signature - gr.io_signature(0, 0, 0) # Output signature - ) - #connect - self.connect(self, correlator, framer_sink) - #start thread - _packet_decoder_thread(msgq, callback) - -################################################## -## Packet Mod for OFDM Mod and Packet Encoder -################################################## -class packet_mod_base(gr.hier_block2): - """ - Hierarchical block for wrapping packet source block. - """ - - def __init__(self, packet_source=None, payload_length=0): - if not payload_length: #get payload length - payload_length = DEFAULT_PAYLOAD_LEN - if payload_length%self._item_size_in != 0: #verify that packet length is a multiple of the stream size - raise ValueError, 'The payload length: "%d" is not a mutiple of the stream size: "%d".'%(payload_length, self._item_size_in) - #initialize hier2 - gr.hier_block2.__init__( - self, - "ofdm_mod", - gr.io_signature(1, 1, self._item_size_in), # Input signature - gr.io_signature(1, 1, packet_source.output_signature().sizeof_stream_item(0)) # Output signature - ) - #create blocks - msgq = gr.msg_queue(DEFAULT_MSGQ_LIMIT) - msg_sink = blocks.message_sink(self._item_size_in, msgq, False) #False -> blocking - #connect - self.connect(self, msg_sink) - self.connect(packet_source, self) - #start thread - _packet_encoder_thread(msgq, payload_length, packet_source.send_pkt) - -class packet_mod_b(packet_mod_base): _item_size_in = gr.sizeof_char -class packet_mod_s(packet_mod_base): _item_size_in = gr.sizeof_short -class packet_mod_i(packet_mod_base): _item_size_in = gr.sizeof_int -class packet_mod_f(packet_mod_base): _item_size_in = gr.sizeof_float -class packet_mod_c(packet_mod_base): _item_size_in = gr.sizeof_gr_complex - -################################################## -## Packet Demod for OFDM Demod and Packet Decoder -################################################## -class packet_demod_base(gr.hier_block2): - """ - Hierarchical block for wrapping packet sink block. - """ - - def __init__(self, packet_sink=None): - #initialize hier2 - gr.hier_block2.__init__( - self, - "ofdm_mod", - gr.io_signature(1, 1, packet_sink.input_signature().sizeof_stream_item(0)), # Input signature - gr.io_signature(1, 1, self._item_size_out) # Output signature - ) - #create blocks - msg_source = blocks.message_source(self._item_size_out, DEFAULT_MSGQ_LIMIT) - self._msgq_out = msg_source.msgq() - #connect - self.connect(self, packet_sink) - self.connect(msg_source, self) - if packet_sink.output_signature().sizeof_stream_item(0): - self.connect(packet_sink, - blocks.null_sink(packet_sink.output_signature().sizeof_stream_item(0))) - - def recv_pkt(self, ok, payload): - msg = gr.message_from_string(payload, 0, self._item_size_out, - len(payload)/self._item_size_out) - if ok: self._msgq_out.insert_tail(msg) - -class packet_demod_b(packet_demod_base): _item_size_out = gr.sizeof_char -class packet_demod_s(packet_demod_base): _item_size_out = gr.sizeof_short -class packet_demod_i(packet_demod_base): _item_size_out = gr.sizeof_int -class packet_demod_f(packet_demod_base): _item_size_out = gr.sizeof_float -class packet_demod_c(packet_demod_base): _item_size_out = gr.sizeof_gr_complex diff --git a/grc/grc_gnuradio/blks2/selector.py b/grc/grc_gnuradio/blks2/selector.py deleted file mode 100644 index 24e3844658..0000000000 --- a/grc/grc_gnuradio/blks2/selector.py +++ /dev/null @@ -1,142 +0,0 @@ -# -# Copyright 2008,2013 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -from gnuradio import gr -from gnuradio import blocks - -class selector(gr.hier_block2): - """A hier2 block with N inputs and M outputs, where data is only forwarded through input n to output m.""" - def __init__(self, item_size, num_inputs, num_outputs, input_index, output_index): - """ - Selector constructor. - - Args: - item_size: the size of the gr data stream in bytes - num_inputs: the number of inputs (integer) - num_outputs: the number of outputs (integer) - input_index: the index for the source data - output_index: the index for the destination data - """ - gr.hier_block2.__init__( - self, 'selector', - gr.io_signature(num_inputs, num_inputs, item_size), - gr.io_signature(num_outputs, num_outputs, item_size), - ) - #terminator blocks for unused inputs and outputs - self.input_terminators = [blocks.null_sink(item_size) for i in range(num_inputs)] - self.output_terminators = [blocks.head(item_size, 0) for i in range(num_outputs)] - self.copy = blocks.copy(item_size) - #connections - for i in range(num_inputs): self.connect((self, i), self.input_terminators[i]) - for i in range(num_outputs): self.connect(blocks.null_source(item_size), - self.output_terminators[i], (self, i)) - self.item_size = item_size - self.input_index = input_index - self.output_index = output_index - self.num_inputs = num_inputs - self.num_outputs = num_outputs - self._connect_current() - - def _indexes_valid(self): - """ - Are the input and output indexes within range of the number of inputs and outputs? - - Returns: - true if input index and output index are in range - """ - return self.input_index in range(self.num_inputs) and self.output_index in range(self.num_outputs) - - def _connect_current(self): - """If the input and output indexes are valid: - disconnect the blocks at the input and output index from their terminators, - and connect them to one another. Then connect the terminators to one another.""" - if self._indexes_valid(): - self.disconnect((self, self.input_index), self.input_terminators[self.input_index]) - self.disconnect(self.output_terminators[self.output_index], (self, self.output_index)) - self.connect((self, self.input_index), self.copy) - self.connect(self.copy, (self, self.output_index)) - self.connect(self.output_terminators[self.output_index], self.input_terminators[self.input_index]) - - def _disconnect_current(self): - """If the input and output indexes are valid: - disconnect the blocks at the input and output index from one another, - and the terminators at the input and output index from one another. - Reconnect the blocks to the terminators.""" - if self._indexes_valid(): - self.disconnect((self, self.input_index), self.copy) - self.disconnect(self.copy, (self, self.output_index)) - self.disconnect(self.output_terminators[self.output_index], self.input_terminators[self.input_index]) - self.connect((self, self.input_index), self.input_terminators[self.input_index]) - self.connect(self.output_terminators[self.output_index], (self, self.output_index)) - - def set_input_index(self, input_index): - """ - Change the block to the new input index if the index changed. - - Args: - input_index: the new input index - """ - if self.input_index != input_index: - self.lock() - self._disconnect_current() - self.input_index = input_index - self._connect_current() - self.unlock() - - def set_output_index(self, output_index): - """ - Change the block to the new output index if the index changed. - - Args: - output_index: the new output index - """ - if self.output_index != output_index: - self.lock() - self._disconnect_current() - self.output_index = output_index - self._connect_current() - self.unlock() - -class valve(selector): - """Wrapper for selector with 1 input and 1 output.""" - - def __init__(self, item_size, open): - """ - Constructor for valve. - - Args: - item_size: the size of the gr data stream in bytes - open: true if initial valve state is open - """ - if open: output_index = -1 - else: output_index = 0 - selector.__init__(self, item_size, 1, 1, 0, output_index) - - def set_open(self, open): - """ - Callback to set open state. - - Args: - open: true to set valve state to open - """ - if open: output_index = -1 - else: output_index = 0 - self.set_output_index(output_index) diff --git a/grc/grc_gnuradio/blks2/tcp.py b/grc/grc_gnuradio/blks2/tcp.py deleted file mode 100644 index aee90fad2c..0000000000 --- a/grc/grc_gnuradio/blks2/tcp.py +++ /dev/null @@ -1,70 +0,0 @@ -# -# Copyright 2009 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -from gnuradio import gr, blocks -import socket -import os - -def _get_sock_fd(addr, port, server): - """ - Get the file descriptor for the socket. - As a client, block on connect, dup the socket descriptor. - As a server, block on accept, dup the client descriptor. - - Args: - addr: the ip address string - port: the tcp port number - server: true for server mode, false for client mode - - Returns: - the file descriptor number - """ - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - if server: - sock.bind((addr, port)) - sock.listen(1) - clientsock, address = sock.accept() - return os.dup(clientsock.fileno()) - else: - sock.connect((addr, port)) - return os.dup(sock.fileno()) - -class tcp_source(gr.hier_block2): - def __init__(self, itemsize, addr, port, server=True): - #init hier block - gr.hier_block2.__init__( - self, 'tcp_source', - gr.io_signature(0, 0, 0), - gr.io_signature(1, 1, itemsize), - ) - fd = _get_sock_fd(addr, port, server) - self.connect(blocks.file_descriptor_source(itemsize, fd), self) - -class tcp_sink(gr.hier_block2): - def __init__(self, itemsize, addr, port, server=False): - #init hier block - gr.hier_block2.__init__( - self, 'tcp_sink', - gr.io_signature(1, 1, itemsize), - gr.io_signature(0, 0, 0), - ) - fd = _get_sock_fd(addr, port, server) - self.connect(self, blocks.file_descriptor_sink(itemsize, fd)) diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py index 24add2780f..37514c9867 100644 --- a/grc/gui/ActionHandler.py +++ b/grc/gui/ActionHandler.py @@ -138,6 +138,7 @@ class ActionHandler: Actions.TOGGLE_SHOW_CODE_PREVIEW_TAB, Actions.TOGGLE_SHOW_FLOWGRAPH_COMPLEXITY, Actions.FLOW_GRAPH_OPEN_QSS_THEME, + Actions.SELECT_ALL, ): action.set_sensitive(True) if hasattr(action, 'load_from_preferences'): @@ -157,6 +158,8 @@ class ActionHandler: pass #do nothing, update routines below elif action == Actions.NOTHING_SELECT: self.get_flow_graph().unselect() + elif action == Actions.SELECT_ALL: + self.get_flow_graph().select_all() ################################################## # Enable/Disable ################################################## diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py index d53375f291..354e536a82 100644 --- a/grc/gui/Actions.py +++ b/grc/gui/Actions.py @@ -226,6 +226,12 @@ FLOW_GRAPH_REDO = Action( keypresses=(gtk.keysyms.y, gtk.gdk.CONTROL_MASK), ) NOTHING_SELECT = Action() +SELECT_ALL = Action( + label='Select _All', + tooltip='Select all blocks and connections in the flow graph', + stock_id=gtk.STOCK_SELECT_ALL, + keypresses=(gtk.keysyms.a, gtk.gdk.CONTROL_MASK), +) ELEMENT_SELECT = Action() ELEMENT_CREATE = Action() ELEMENT_DELETE = Action( diff --git a/grc/gui/Bars.py b/grc/gui/Bars.py index 19f041f508..259aa6ed8b 100644 --- a/grc/gui/Bars.py +++ b/grc/gui/Bars.py @@ -82,6 +82,7 @@ MENU_BAR_LIST = ( Actions.BLOCK_COPY, Actions.BLOCK_PASTE, Actions.ELEMENT_DELETE, + Actions.SELECT_ALL, None, Actions.BLOCK_ROTATE_CCW, Actions.BLOCK_ROTATE_CW, diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py index c7c64c6e7d..15488cc59b 100644 --- a/grc/gui/FlowGraph.py +++ b/grc/gui/FlowGraph.py @@ -53,7 +53,7 @@ class FlowGraph(Element, _Flowgraph): #important vars dealing with mouse event tracking self.element_moved = False self.mouse_pressed = False - self.unselect() + self._selected_elements = [] self.press_coor = (0, 0) #selected ports self._old_selected_port = None @@ -203,11 +203,15 @@ class FlowGraph(Element, _Flowgraph): v_adj = self.get_scroll_pane().get_vadjustment() x_off = h_adj.get_value() - x_min + h_adj.page_size/4 y_off = v_adj.get_value() - y_min + v_adj.page_size/4 + if len(self.get_elements()) <= 1: + x_off, y_off = 0, 0 #create blocks for block_n in blocks_n: block_key = block_n.find('key') if block_key == 'options': continue block = self.new_block(block_key) + if not block: + continue # unknown block was pasted (e.g. dummy block) selected.add(block) #set params params_n = block_n.findall('param') @@ -444,6 +448,10 @@ class FlowGraph(Element, _Flowgraph): """ self._selected_elements = [] + def select_all(self): + """Select all blocks in the flow graph""" + self._selected_elements = list(self.get_elements()) + def what_is_selected(self, coor, coor_m=None): """ What is selected? diff --git a/grc/gui/NotebookPage.py b/grc/gui/NotebookPage.py index 2c1fd7c3b3..6614649c89 100644 --- a/grc/gui/NotebookPage.py +++ b/grc/gui/NotebookPage.py @@ -26,9 +26,6 @@ from Constants import MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT from DrawingArea import DrawingArea import os -############################################################ -## Notebook Page -############################################################ class NotebookPage(gtk.HBox): """A page in the notebook.""" @@ -79,6 +76,7 @@ class NotebookPage(gtk.HBox): self.scrolled_window = gtk.ScrolledWindow() self.scrolled_window.set_size_request(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT) self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + self.scrolled_window.connect('key-press-event', self._handle_scroll_window_key_press) self.drawing_area = DrawingArea(self.get_flow_graph()) self.scrolled_window.add_with_viewport(self.get_drawing_area()) self.pack_start(self.scrolled_window) @@ -88,6 +86,15 @@ class NotebookPage(gtk.HBox): def get_drawing_area(self): return self.drawing_area + def _handle_scroll_window_key_press(self, widget, event): + """forward Ctrl-PgUp/Down to NotebookPage (switch fg instead of horiz. scroll""" + is_ctrl_pg = ( + event.state & gtk.gdk.CONTROL_MASK and + event.keyval in (gtk.keysyms.Page_Up, gtk.keysyms.Page_Down) + ) + if is_ctrl_pg: + return self.get_parent().event(event) + def get_generator(self): """ Get the generator object for this flow graph. |