Skip to content

Commit

Permalink
adding a widget for sending dict pdus from GUI's
Browse files Browse the repository at this point in the history
  • Loading branch information
osh committed Sep 22, 2015
1 parent fc8fb62 commit 611d649
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
1 change: 1 addition & 0 deletions grc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ install(FILES
head.xml
trim_tail.xml
file_message_source.xml
dict_ui_source.xml
pyqt_table.xml DESTINATION share/gnuradio/grc/blocks
)
38 changes: 38 additions & 0 deletions grc/dict_ui_source.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0"?>
<block>
<name>PyQT Dict UI Text/Button Input Source</name>
<key>pyqt_dict_ui_source</key>
<category>pyqt</category>
<import>import pyqt</import>
<make>#set $win = 'self._%s_win'%$id
pyqt.dict_ui_source(defaults=$defaults, submit_text=$submit_text)
self._$(id)_win = self.$(id);
$(gui_hint()($win))
</make>

<param>
<name>Default Fields</name>
<key>defaults</key>
<value>{"filename":"test.dat", "count":500}</value>
<type>raw</type>
</param>
<param>
<name>Button Text</name>
<key>submit_text</key>
<value>Send</value>
<type>string</type>
</param>
<param>
<name>GUI Hint</name>
<key>gui_hint</key>
<value></value>
<type>gui_hint</type>
<hide>part</hide>
</param>

<source>
<name>pdus</name>
<type>message</type>
<optional>1</optional>
</source>
</block>
1 change: 1 addition & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ GR_PYTHON_INSTALL(
skip_head.py
trim_tail.py
file_message_source.py
dict_ui_source.py
table.py DESTINATION ${GR_PYTHON_DIR}/pyqt
)

Expand Down
1 change: 1 addition & 0 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
from trim_tail import *
from file_message_source import *
from table import *
from dict_ui_source import *

# ----------------------------------------------------------------
# Tail of workaround
Expand Down
75 changes: 75 additions & 0 deletions python/dict_ui_source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/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.
#
from PyQt4 import Qt, QtCore, QtGui
import numpy
from gnuradio import gr;
import pylab,numpy,os
import pmt,pprint

class dict_ui_source(gr.sync_block, QtGui.QGroupBox):
def __init__(self,defaults={"filename":"test.dat", "count":500},submit_text="Send", *args):
gr.sync_block.__init__(self,"dict_ui_source",[],[])
QtGui.QGroupBox.__init__(self, *args)

# store locals
self.defaults = defaults

# Set up GUI bits
self.labels = {}
self.textinputs = {}
self.lay = QtGui.QGridLayout(self)
#self.lay = QtGui.QVBoxLayout()
self.setWindowTitle("Many Controls")
for k,v in defaults.iteritems():
i = defaults.keys().index(k)
lbl = QtGui.QLabel(k)
txt = QtGui.QLineEdit(str(v))
self.lay.addWidget(lbl, i, 0)
self.lay.addWidget(txt, i, 1)
self.labels[k] = lbl
self.textinputs[k] = txt
self.button = QtGui.QPushButton(str(submit_text))
self.button.pressed.connect(self.button_clicked)
self.lay.addWidget(self.button, len(defaults.keys()), 0, 1, 2)

# set up message ports
self.message_port_register_out(pmt.intern("pdus"));

def button_clicked(self):
print "clicked"
meta = {}
for k,v in self.textinputs.iteritems():
try:
meta[k] = int(str(v.text()))
except:
meta[k] = str(v.text())
pprint.pprint(meta)
vec = pmt.PMT_NIL
self.message_port_pub(pmt.intern("pdus"),
pmt.cons( pmt.to_pmt(meta), pmt.PMT_NIL ))

def work(self, input_items, output_items):
pass




0 comments on commit 611d649

Please sign in to comment.