forked from osh/gr-pyqt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding stream_lambda block and variable_text_input block (with exampl…
…e grc)
- Loading branch information
Showing
8 changed files
with
1,416 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?xml version="1.0"?> | ||
<block> | ||
<name>Stream Lambda Block</name> | ||
<key>pyqt_stream_lambda</key> | ||
<category>pyqt</category> | ||
<import>import pyqt</import> | ||
<import>import numpy</import> | ||
<make>pyqt.stream_lambda($fn,$n_streams_in*[$type_in.np],$n_streams_out*[$type_out.np])</make> | ||
|
||
<callback>set_fn($fn)</callback> | ||
|
||
<param> | ||
<name>function</name> | ||
<key>fn</key> | ||
<value>lambda input_items, output_index: (input_items[output_index][::2]**2)*0.1</value> | ||
<type>raw</type> | ||
</param> | ||
|
||
<param> | ||
<name>Num Input Streams</name> | ||
<key>n_streams_in</key> | ||
<value>1</value> | ||
<type>int</type> | ||
</param> | ||
|
||
<param> | ||
<name>Num Output Streams</name> | ||
<key>n_streams_out</key> | ||
<value>1</value> | ||
<type>int</type> | ||
</param> | ||
|
||
<param> | ||
<name>Input Data Type</name> | ||
<key>type_in</key> | ||
<type>enum</type> | ||
<option> | ||
<name>Complex</name> | ||
<key>complex</key> | ||
<opt>np:numpy.complex64</opt> | ||
</option> | ||
<option> | ||
<name>Float</name> | ||
<key>float</key> | ||
<opt>np:numpy.float32</opt> | ||
</option> | ||
<option> | ||
<name>Int</name> | ||
<key>int</key> | ||
<opt>np:numpy.int32</opt> | ||
</option> | ||
<option> | ||
<name>Short</name> | ||
<key>short</key> | ||
<opt>np:numpy.int16</opt> | ||
</option> | ||
<option> | ||
<name>Byte</name> | ||
<key>byte</key> | ||
<opt>np:numpy.char</opt> | ||
</option> | ||
</param> | ||
|
||
<param> | ||
<name>Output Data Type</name> | ||
<key>type_out</key> | ||
<type>enum</type> | ||
<option> | ||
<name>Complex</name> | ||
<key>complex</key> | ||
<opt>np:numpy.complex64</opt> | ||
</option> | ||
<option> | ||
<name>Float</name> | ||
<key>float</key> | ||
<opt>np:numpy.float32</opt> | ||
</option> | ||
<option> | ||
<name>Int</name> | ||
<key>int</key> | ||
<opt>np:numpy.int32</opt> | ||
</option> | ||
<option> | ||
<name>Short</name> | ||
<key>short</key> | ||
<opt>np:numpy.int16</opt> | ||
</option> | ||
<option> | ||
<name>Byte</name> | ||
<key>byte</key> | ||
<opt>np:numpy.char</opt> | ||
</option> | ||
</param> | ||
|
||
<sink> | ||
<name>in</name> | ||
<type>$type_in</type> | ||
<nports>$n_streams_in</nports> | ||
</sink> | ||
|
||
<source> | ||
<name>pdus</name> | ||
<type>$type_out</type> | ||
<nports>$n_streams_out</nports> | ||
</source> | ||
</block> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0"?> | ||
<block> | ||
<name>PyQT Text Input Variable</name> | ||
<key>variable_pyqt_text_input</key> | ||
<category>pyqt</category> | ||
<import>import pyqt</import> | ||
<var_make>self.$(id) = $(id) = $value</var_make> | ||
<make>#set $win = 'self._%s_win'%$id | ||
$(win) = pyqt.variable_text_input(self.set_$(id),"$(id)","$(value)","") | ||
$(gui_hint()($win))</make> | ||
<callback>self.set_$(id)($value)</callback> | ||
|
||
<param> | ||
<name>Default Value</name> | ||
<key>value</key> | ||
<value>lambda x: 10*x</value> | ||
<type>raw</type> | ||
</param> | ||
|
||
<param> | ||
<name>GUI Hint</name> | ||
<key>gui_hint</key> | ||
<value></value> | ||
<type>gui_hint</type> | ||
<hide>part</hide> | ||
</param> | ||
</block> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright 2015 Tim O'Shea | ||
# | ||
# 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. | ||
# | ||
import numpy | ||
from gnuradio import gr; | ||
import pmt | ||
|
||
class stream_lambda(gr.sync_block): | ||
def __init__(self, fn, insig=[numpy.complex64], outsig=[numpy.complex64]): | ||
gr.sync_block.__init__(self,"stream_lambda",insig,outsig) | ||
self.set_fn(fn) | ||
self.lvars = {} | ||
|
||
# signature should be: (output_stream_items) = lambda input_items, output_stream_index: .... | ||
def set_fn(self,fn): | ||
self.fn = fn | ||
|
||
def work(self, input_items, output_items): | ||
n_out = 0; | ||
for i in range(0,len(output_items)): | ||
o = self.fn(input_items, i) | ||
output_items[i][0:len(o)] = o[:] | ||
if(n_out == 0 or n_out == len(o)): | ||
n_out = len(o) | ||
else: | ||
raise Exception("Streams must produce same lengths for now with the current stream lambda block interface!") | ||
return n_out | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright 2014 Tim O'Shea | ||
# | ||
# 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. | ||
# | ||
import numpy | ||
from gnuradio import gr; | ||
from scipy import signal | ||
import pylab | ||
import numpy | ||
from PyQt4 import Qt, QtCore, QtGui | ||
import pmt | ||
|
||
class variable_text_input(gr.sync_block, QtGui.QLineEdit): | ||
def __init__(self, fn_update=None, blkname="text_input", val="", label="", *args): | ||
gr.sync_block.__init__(self,blkname,[],[]) | ||
QtGui.QLineEdit.__init__(self, *args) | ||
self.returnPressed.connect(self.text_changed); | ||
self.message_port_register_out(pmt.intern("pdus")); | ||
self.fn_update = fn_update | ||
self.setText(str(val)) | ||
|
||
def text_changed(self): | ||
s = self.text().toUtf8(); | ||
#nvec = numpy.fromstring((s), dtype=numpy.uint8, count=len(s)); | ||
#vec = pmt.to_pmt(nvec); | ||
print s | ||
self.fn_update(eval(str(s))) | ||
#self.message_port_pub(pmt.intern("pdus"), pmt.cons(pmt.PMT_NIL, vec)); | ||
#self.clear(); | ||
|
||
def work(self, input_items, output_items): | ||
pass | ||
|
||
|
||
|
||
|