diff options
-rw-r--r-- | config/grc_gr_qtgui.m4 | 2 | ||||
-rw-r--r-- | gr-qtgui/Makefile.am | 7 | ||||
-rw-r--r-- | gr-qtgui/grc/.gitignore | 2 | ||||
-rw-r--r-- | gr-qtgui/grc/Makefile.am | 28 | ||||
-rw-r--r-- | gr-qtgui/grc/qtgui_sink_x.xml (renamed from grc/blocks/qtgui_sink_x.xml) | 3 | ||||
-rw-r--r-- | gr-qtgui/grc/qtgui_variable_slider.xml | 114 | ||||
-rw-r--r-- | gr-qtgui/python/.gitignore | 2 | ||||
-rw-r--r-- | gr-qtgui/python/Makefile.am | 29 | ||||
-rw-r--r-- | gr-qtgui/python/forms/__init__.py (renamed from gr-qtgui/src/python/forms/__init__.py) | 2 | ||||
-rw-r--r-- | gr-qtgui/python/forms/converters.py (renamed from gr-qtgui/src/python/forms/converters.py) | 0 | ||||
-rw-r--r-- | gr-qtgui/python/forms/forms.py | 140 | ||||
-rw-r--r-- | gr-qtgui/src/python/Makefile.am | 7 | ||||
-rw-r--r-- | gr-qtgui/src/python/forms/forms.py | 82 | ||||
-rw-r--r-- | grc/blocks/Makefile.am | 3 | ||||
-rw-r--r-- | grc/python/flow_graph.tmpl | 13 |
15 files changed, 336 insertions, 98 deletions
diff --git a/config/grc_gr_qtgui.m4 b/config/grc_gr_qtgui.m4 index 4027bb332..6a69dd7a8 100644 --- a/config/grc_gr_qtgui.m4 +++ b/config/grc_gr_qtgui.m4 @@ -82,6 +82,8 @@ AC_DEFUN([GRC_GR_QTGUI],[ AC_CONFIG_FILES([ \ gr-qtgui/Makefile \ + gr-qtgui/grc/Makefile \ + gr-qtgui/python/Makefile \ gr-qtgui/src/Makefile \ gr-qtgui/src/lib/Makefile \ gr-qtgui/src/python/Makefile \ diff --git a/gr-qtgui/Makefile.am b/gr-qtgui/Makefile.am index d53f96c1f..66746e5e8 100644 --- a/gr-qtgui/Makefile.am +++ b/gr-qtgui/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2008 Free Software Foundation, Inc. +# Copyright 2008-2010 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -23,3 +23,8 @@ include $(top_srcdir)/Makefile.common SUBDIRS = src DIST_SUBDIRS = src + +if PYTHON +SUBDIRS += grc +SUBDIRS += python +endif diff --git a/gr-qtgui/grc/.gitignore b/gr-qtgui/grc/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/gr-qtgui/grc/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/gr-qtgui/grc/Makefile.am b/gr-qtgui/grc/Makefile.am new file mode 100644 index 000000000..226e9d137 --- /dev/null +++ b/gr-qtgui/grc/Makefile.am @@ -0,0 +1,28 @@ +# +# Copyright 2010 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. +# + +include $(top_srcdir)/Makefile.common + +grcblocksdir = $(grc_blocksdir) + +dist_grcblocks_DATA = \ + qtgui_sink_x.xml \ + qtgui_variable_slider.xml diff --git a/grc/blocks/qtgui_sink_x.xml b/gr-qtgui/grc/qtgui_sink_x.xml index c9fa12eef..8182f8d94 100644 --- a/grc/blocks/qtgui_sink_x.xml +++ b/gr-qtgui/grc/qtgui_sink_x.xml @@ -7,6 +7,7 @@ <block> <name>QT GUI Sink</name> <key>qtgui_sink_x</key> + <category>Graphical Sinks</category> <import>from gnuradio.qtgui import qtgui</import> <import>from gnuradio.gr import firdes</import> <import>import sip</import> @@ -23,7 +24,7 @@ $plotconst, \#plotconst ) self._$(id)_win = sip.wrapinstance(self.$(id).pyqwidget(), QtGui.QWidget) -self._$(id)_win.show()</make> +self.layout.addWidget(self._$(id)_win)</make> <callback>set_frequency_range($fc, $bw)</callback> <param> <name>Type</name> diff --git a/gr-qtgui/grc/qtgui_variable_slider.xml b/gr-qtgui/grc/qtgui_variable_slider.xml new file mode 100644 index 000000000..37f102ecb --- /dev/null +++ b/gr-qtgui/grc/qtgui_variable_slider.xml @@ -0,0 +1,114 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Variable Slider: +## a combined slider and text box form +################################################### + --> +<block> + <name>QT GUI Variable Slider</name> + <key>variable_qtgui_slider</key> + <category>Variables</category> + <import>from gnuradio.qtgui import forms</import> + <import>from PyQt4.QtCore import Qt</import> + <var_make>self.$(id) = $(id) = $value</var_make> + <make>#set $win = '_%s_sizer'%$id +$win = QtGui.QBoxLayout(QtGui.QBoxLayout.TopToBottom) +self._$(id)_text_box = forms.text_box( + parent=self, + value=self.$id, + callback=self.set_$(id), + #if $label() + label=$label, + #else + label='$id', + #end if + converter=forms.$(converver)(), +) +$(win).addWidget(self._$(id)_text_box) +self._$(id)_slider = forms.slider( + value=self.$id, + callback=self.set_$(id), + start=$start, + stop=$stop, + step=$step, + orient=$orient, + cast=$(converver.slider_cast), +) +$(win).addWidget(self._$(id)_slider) +self.layout.addLayout($win)</make> + <callback>self.set_$(id)($value)</callback> + <callback>self._$(id)_slider.set_value($id)</callback> + <callback>self._$(id)_text_box.set_value($id)</callback> + <param> + <name>Label</name> + <key>label</key> + <value></value> + <type>string</type> + <hide>#if $label() then 'none' else 'part'#</hide> + </param> + <param> + <name>Default Value</name> + <key>value</key> + <value>50</value> + <type>real</type> + </param> + <param> + <name>Start</name> + <key>start</key> + <value>0</value> + <type>real</type> + </param> + <param> + <name>Stop</name> + <key>stop</key> + <value>100</value> + <type>real</type> + </param> + <param> + <name>Step</name> + <key>step</key> + <value>1</value> + <type>real</type> + <hide>part</hide> + </param> + <param> + <name>Orientation</name> + <key>orient</key> + <value>Qt.Horizontal</value> + <type>enum</type> + <hide>part</hide> + <option> + <name>Horizontal</name> + <key>Qt.Horizontal</key> + </option> + <option> + <name>Vertical</name> + <key>Qt.Vertical</key> + </option> + </param> + <param> + <name>Converter</name> + <key>converver</key> + <value>float_converter</value> + <type>enum</type> + <option> + <name>Float</name> + <key>float_converter</key> + <opt>slider_cast:float</opt> + </option> + <option> + <name>Integer</name> + <key>int_converter</key> + <opt>slider_cast:int</opt> + </option> + </param> + <check>$start <= $value <= $stop</check> + <check>$start < $stop</check> + <doc> +This block creates a variable with a slider. \ +Leave the label blank to use the variable id as the label. \ +The value must be a real number. \ +The value must be between the start and the stop. + </doc> +</block> diff --git a/gr-qtgui/python/.gitignore b/gr-qtgui/python/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/gr-qtgui/python/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/gr-qtgui/python/Makefile.am b/gr-qtgui/python/Makefile.am new file mode 100644 index 000000000..5f6d22b17 --- /dev/null +++ b/gr-qtgui/python/Makefile.am @@ -0,0 +1,29 @@ +# +# Copyright 2010 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. +# + +include $(top_srcdir)/Makefile.common + +qtguiformspythondir = $(grpythondir)/qtgui/forms + +qtguiformspython_PYTHON = \ + forms/__init__.py \ + forms/converters.py \ + forms/forms.py diff --git a/gr-qtgui/src/python/forms/__init__.py b/gr-qtgui/python/forms/__init__.py index bb8ac2057..0f4391bb8 100644 --- a/gr-qtgui/src/python/forms/__init__.py +++ b/gr-qtgui/python/forms/__init__.py @@ -29,4 +29,4 @@ from converters import \ ######################################################################## # External Forms ######################################################################## -from forms import slider +from forms import slider, text_box diff --git a/gr-qtgui/src/python/forms/converters.py b/gr-qtgui/python/forms/converters.py index 53c966d32..53c966d32 100644 --- a/gr-qtgui/src/python/forms/converters.py +++ b/gr-qtgui/python/forms/converters.py diff --git a/gr-qtgui/python/forms/forms.py b/gr-qtgui/python/forms/forms.py new file mode 100644 index 000000000..56ee72499 --- /dev/null +++ b/gr-qtgui/python/forms/forms.py @@ -0,0 +1,140 @@ +# +# Copyright 2010 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 PyQt4 import QtGui +from PyQt4.QtCore import Qt + +import converters + +######################################################################## +# Base class for all forms +######################################################################## +class _form_base(QtGui.QWidget): + def __init__(self, parent=None, converter=None, callback=None, value=None): + QtGui.QWidget.__init__(self, parent) + self._layout = QtGui.QBoxLayout(QtGui.QBoxLayout.LeftToRight, self) + self._converter = converter + self._callback = callback + self._value = value + + def _add_widget(self, widget, label): + if label: + label_widget = QtGui.QLabel(self) + label_widget.setText('%s: '%label) + self._layout.addWidget(label_widget, True) + self._layout.addWidget(widget, stretch=1) + #disable callback, update, re-enable + callback = self._callback + self._callback = None + self.set_value(self.get_value()) + self._callback = callback + + def get_value(self): + return self._value + + def set_value(self, value): + self._value = value + self._base_update(self._converter.external_to_internal(value)) + + def _base_update(self, int_val): + self._update(int_val) + + def _base_handle(self, int_val): + self._value = self._converter.internal_to_external(int_val) + if self._callback: self._callback(self._value) + +######################################################################## +# Slider base class, shared by log and linear sliders +######################################################################## +class _slider_base(_form_base): + def __init__(self, label='', length=-1, num_steps=100, orient=Qt.Horizontal, **kwargs): + _form_base.__init__(self, **kwargs) + self._slider = QtGui.QSlider(parent=self) + self._slider.setOrientation(orient) + self._slider.setRange(0, num_steps) + if length > 0: + if orient == Qt.Horizontal: + slider_size = self._slider.setWidth(length) + if orient == Qt.Vertical: + slider_size = self._slider.setHeight(length) + self._add_widget(self._slider, label) + self._slider.valueChanged.connect(self._handle) + + def _handle(self, event): + value = self._slider.value() + if self._cache != value: self._base_handle(value) + def _update(self, value): + self._cache = int(round(value)) + self._slider.setValue(self._cache) + +######################################################################## +# Linear slider form +######################################################################## +class slider(_slider_base): + """ + A generic linear slider. + @param parent the parent widget + @param value the default value + @param label title label for this widget (optional) + @param length the length of the slider in px (optional) + @param orient Qt.Horizontal Veritcal (default=horizontal) + @param start the start value + @param stop the stop value + @param num_steps the number of slider steps (or specify step_size) + @param step_size the step between slider jumps (or specify num_steps) + @param cast a cast function, int, or float (default=float) + """ + def __init__(self, start, stop, step=None, num_steps=100, cast=float, **kwargs): + assert step or num_steps + if step is not None: num_steps = (stop - start)/step + converter = converters.slider_converter(start=start, stop=stop, num_steps=num_steps, cast=cast) + _slider_base.__init__(self, converter=converter, num_steps=num_steps, **kwargs) + +######################################################################## +# Text Box Form +######################################################################## +class text_box(_form_base): + """ + A text box form. + @param parent the parent widget + @param sizer add this widget to sizer if provided (optional) + @param value the default value + @param label title label for this widget (optional) + @param converter forms.str_converter(), int_converter(), float_converter()... + """ + def __init__(self, label='', converter=converters.eval_converter(), **kwargs): + _form_base.__init__(self, converter=converter, **kwargs) + self._text_box = QtGui.QLineEdit(self) + self._default_style_sheet = self._text_box.styleSheet() + self._text_box.textChanged.connect(self._set_color_changed) + self._text_box.returnPressed.connect(self._handle) + self._add_widget(self._text_box, label) + + def _set_color_default(self): + self._text_box.setStyleSheet(self._default_style_sheet) + + def _set_color_changed(self, *args): + self._text_box.setStyleSheet("QWidget { background-color: #EEDDDD }") + + def _handle(self): self._base_handle(str(self._text_box.text())) + def _update(self, value): + self._text_box.setText(value) + self._set_color_default() diff --git a/gr-qtgui/src/python/Makefile.am b/gr-qtgui/src/python/Makefile.am index c24ba14d9..31df63a44 100644 --- a/gr-qtgui/src/python/Makefile.am +++ b/gr-qtgui/src/python/Makefile.am @@ -36,10 +36,3 @@ qtguipythondir = $(grpythondir)/qtgui qtguipython_PYTHON = \ __init__.py - -qtguiformspythondir = $(grpythondir)/qtgui/forms - -qtguiformspython_PYTHON = \ - forms/__init__.py \ - forms/converters.py \ - forms/forms.py diff --git a/gr-qtgui/src/python/forms/forms.py b/gr-qtgui/src/python/forms/forms.py deleted file mode 100644 index c6b7c9fcf..000000000 --- a/gr-qtgui/src/python/forms/forms.py +++ /dev/null @@ -1,82 +0,0 @@ -# -# Copyright 2010 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 PyQt4 import QtGui -from PyQt4 import QtCore - -import converters - -class _form_base(QtGui.QWidget): - def __init__(self, parent=None, converter=None, callback=None, value=None): - QtGui.QWidget.__init__(self, parent) - self._converter = converter - self._callback = callback - self.set_value(value) - - def get_value(self): - return self._value - - def set_value(self, value): - self._value = value - self._base_update(self._converter.external_to_internal(value)) - - def _base_update(self, int_val): - self._update(int_val) - - def _base_handle(self, int_val): - self._value = self._converter.internal_to_external(int_val) - if self._callback: self._callback(self._value) - -class _slider_base(_form_base): - def __init__(self, label='', length=-1, num_steps=100, orient=QtCore.Qt.Horizontal, **kwargs): - _form_base.__init__(self, **kwargs) - self._slider = QtGui.QSlider(parent=self) - self._slider.setOrientation(orient) - self._slider.setRange(0, num_steps) - if length > 0: - if orient == QtCore.Qt.Horizontal: - slider_size = self._slider.setWidth(length) - if orient == QtCore.Qt.Vertical: - slider_size = self._slider.setHeight(length) - self.slider.valueChanged.connect(self._handle) - - def _handle(self, event): self._base_handle(self._slider.value()) - def _update(self, value): self._slider.setValue(int(round(value))) - -class slider(_slider_base): - """ - A generic linear slider. - @param parent the parent widget - @param value the default value - @param label title label for this widget (optional) - @param length the length of the slider in px (optional) - @param orient Qt.Horizontal Veritcal (default=horizontal) - @param start the start value - @param stop the stop value - @param num_steps the number of slider steps (or specify step_size) - @param step_size the step between slider jumps (or specify num_steps) - @param cast a cast function, int, or float (default=float) - """ - def __init__(self, start, stop, num_steps=100, step_size=None, cast=float, **kwargs): - assert step_size or num_steps - if step_size is not None: num_steps = (stop - start)/step_size - converter = converters.slider_converter(start=start, stop=stop, num_steps=num_steps, cast=cast) - _slider_base.__init__(self, converter=converter, num_steps=num_steps, **kwargs) diff --git a/grc/blocks/Makefile.am b/grc/blocks/Makefile.am index ea3c94cbe..56893b46f 100644 --- a/grc/blocks/Makefile.am +++ b/grc/blocks/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2008, 2009 Free Software Foundation, Inc. +# Copyright 2008-2010 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -203,7 +203,6 @@ dist_ourdata_DATA = \ pad_source.xml \ parameter.xml \ probe_function.xml \ - qtgui_sink_x.xml \ random_source_x.xml \ root_raised_cosine_filter.xml \ trellis_encoder_xx.xml \ diff --git a/grc/python/flow_graph.tmpl b/grc/python/flow_graph.tmpl index 676da33b4..108e15ca0 100644 --- a/grc/python/flow_graph.tmpl +++ b/grc/python/flow_graph.tmpl @@ -60,11 +60,12 @@ class $(class_name)(grc_wxgui.top_block_gui): self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) #end if #elif $generate_options == 'qt_gui' -class $(class_name)(gr.top_block): +class $(class_name)(gr.top_block, QtGui.QWidget): def __init__($param_str): gr.top_block.__init__(self, "$title") - self.qapp = QtGui.QApplication(sys.argv) + QtGui.QWidget.__init__(self) + self.layout = QtGui.QBoxLayout(QtGui.QBoxLayout.TopToBottom, self) #elif $generate_options == 'no_gui' class $(class_name)(gr.top_block): @@ -245,15 +246,19 @@ if __name__ == '__main__': if gr.enable_realtime_scheduling() != gr.RT_OK: print "Error: failed to enable realtime scheduling." #end if - tb = $(class_name)($(', '.join($params_eq_list))) #if $generate_options == 'wx_gui' + tb = $(class_name)($(', '.join($params_eq_list))) tb.Run($flow_graph.get_option('run')) #elif $generate_options == 'qt_gui' + qapp = QtGui.QApplication(sys.argv) + tb = $(class_name)($(', '.join($params_eq_list))) tb.start() - tb.qapp.exec_() + tb.show() + qapp.exec_() #elif $generate_options == 'no_gui' #set $run_options = $flow_graph.get_option('run_options') #if $run_options == 'prompt' + tb = $(class_name)($(', '.join($params_eq_list))) tb.start() raw_input('Press Enter to quit: ') tb.stop() |