[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 05/16: qtgui: improved type checking for ra
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 05/16: qtgui: improved type checking for range block and simplifies python. |
Date: |
Sun, 26 Apr 2015 23:18:03 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch master
in repository gnuradio.
commit 15fc0e3b72e655e5e1c8ebe9a077836c24fded6f
Author: Seth Hitefield <address@hidden>
Date: Wed Apr 22 04:12:51 2015 -0400
qtgui: improved type checking for range block and simplifies python.
Removes Long as a possible type. Doesn't really help in Python and GRC
doesn't recognize it easily.
---
gr-qtgui/grc/qtgui_range.xml | 17 ++++++-----
gr-qtgui/python/qtgui/range.py | 65 ++++++++++++++++++++++++++----------------
2 files changed, 48 insertions(+), 34 deletions(-)
diff --git a/gr-qtgui/grc/qtgui_range.xml b/gr-qtgui/grc/qtgui_range.xml
index 36bd330..71b614c 100644
--- a/gr-qtgui/grc/qtgui_range.xml
+++ b/gr-qtgui/grc/qtgui_range.xml
@@ -16,7 +16,7 @@
#set $label = '"%s"'%$id
#end if
$(range) = Range($start, $stop, $step, $value, $min_len)
-$(win) = RangeWidget($range, self.set_$(id), $label, "$widget", $astype)
+$(win) = RangeWidget($range, self.set_$(id), $label, "$widget", $rangeType)
$(gui_hint()($win))</make>
<callback>self.set_$(id)($value)</callback>
@@ -30,41 +30,40 @@ $(gui_hint()($win))</make>
<param>
<name>Type</name>
- <key>astype</key>
+ <key>rangeType</key>
<value>"float"</value>
<type>enum</type>
<hide>part</hide>
- <option><name>Float</name><key>"float"</key></option>
- <option><name>Int</name><key>"int"</key></option>
- <option><name>Long</name><key>"long"</key></option>
+ <option><name>Float</name><key>float</key><opt>type:float</opt></option>
+ <option><name>Int</name><key>int</key><opt>type:int</opt></option>
</param>
<param>
<name>Default Value</name>
<key>value</key>
<value>50</value>
- <type>real</type>
+ <type>$rangeType.type</type>
</param>
<param>
<name>Start</name>
<key>start</key>
<value>0</value>
- <type>real</type>
+ <type>$rangeType.type</type>
</param>
<param>
<name>Stop</name>
<key>stop</key>
<value>100</value>
- <type>real</type>
+ <type>$rangeType.type</type>
</param>
<param>
<name>Step</name>
<key>step</key>
<value>1</value>
- <type>real</type>
+ <type>$rangeType.type</type>
</param>
<param>
diff --git a/gr-qtgui/python/qtgui/range.py b/gr-qtgui/python/qtgui/range.py
index bb7c100..3eafc90 100755
--- a/gr-qtgui/python/qtgui/range.py
+++ b/gr-qtgui/python/qtgui/range.py
@@ -64,16 +64,15 @@ class Range(object):
class RangeWidget(QtGui.QWidget):
- def __init__(self, ranges, slot, label, style, astype="float"):
+ def __init__(self, ranges, slot, label, style, rangeType=float):
""" Creates the QT Range widget """
QtGui.QWidget.__init__(self)
self.range = ranges
self.style = style
- # astype tells the block how to return the value as a standard
- # Python type. Can be: long, int, or float.
- types = {"float": float, "long": long, "int": int}
+ # rangeType tells the block how to return the value as a standard
+ self.rangeType = rangeType
# Top-block function to call when any value changes
# Some widgets call this directly when their value changes.
@@ -84,27 +83,26 @@ class RangeWidget(QtGui.QWidget):
label = Qt.QLabel(label)
layout.addWidget(label)
-
if style == "dial":
- self.d_widget = self.Dial(self, self.range, self.notifyChanged,
types[astype])
+ self.d_widget = self.Dial(self, self.range, self.notifyChanged,
rangeType)
elif style == "slider":
- self.d_widget = self.Slider(self, self.range, self.notifyChanged,
types[astype])
+ self.d_widget = self.Slider(self, self.range, self.notifyChanged,
rangeType)
elif style == "counter":
# The counter widget can be directly wired to the notifyChanged
slot
- self.d_widget = self.Counter(self, self.range, self.notifyChanged,
types[astype])
+ self.d_widget = self.Counter(self, self.range, self.notifyChanged,
rangeType)
else:
# The CounterSlider needs its own internal handlers before calling
notifyChanged
- self.d_widget = self.CounterSlider(self, self.range,
self.notifyChanged, types[astype])
+ self.d_widget = self.CounterSlider(self, self.range,
self.notifyChanged, rangeType)
layout.addWidget(self.d_widget)
self.setLayout(layout)
class Dial(QtGui.QDial):
""" Creates the range using a dial """
- def __init__(self, parent, ranges, slot, astype=float):
+ def __init__(self, parent, ranges, slot, rangeType=float):
QtGui.QDial.__init__(self, parent)
- self.astype = astype
+ self.rangeType = rangeType
# Setup the dial
self.setRange(0, ranges.nsteps-1)
@@ -123,14 +121,14 @@ class RangeWidget(QtGui.QWidget):
def changed(self, value):
""" Handles maping the value to the right range before calling the
slot. """
val = self.range.map_range(value)
- self.notifyChanged(self.astype(val))
+ self.notifyChanged(self.rangeType(val))
class Slider(QtGui.QSlider):
""" Creates the range using a slider """
- def __init__(self, parent, ranges, slot, astype=float):
+ def __init__(self, parent, ranges, slot, rangeType=float):
QtGui.QSlider.__init__(self, QtCore.Qt.Horizontal, parent)
- self.astype = astype
+ self.rangeType = rangeType
# Setup the slider
#self.setFocusPolicy(QtCore.Qt.NoFocus)
@@ -158,7 +156,7 @@ class RangeWidget(QtGui.QWidget):
def changed(self, value):
""" Handle the valueChanged signal and map the value into the
correct range """
val = self.range.map_range(value)
- self.notifyChanged(self.astype(val))
+ self.notifyChanged(self.rangeType(val))
def mousePressEvent(self, event):
if((event.button() == QtCore.Qt.LeftButton)):
@@ -177,10 +175,10 @@ class RangeWidget(QtGui.QWidget):
class Counter(QtGui.QDoubleSpinBox):
""" Creates the range using a counter """
- def __init__(self, parent, ranges, slot, astype=float):
+ def __init__(self, parent, ranges, slot, rangeType=float):
QtGui.QDoubleSpinBox.__init__(self, parent)
- self.astype = astype
+ self.rangeType = rangeType
# Setup the counter
self.setRange(ranges.min, ranges.max)
@@ -195,20 +193,20 @@ class RangeWidget(QtGui.QWidget):
def changed(self, value):
""" Handle the valueChanged signal by converting to the right type
"""
- self.notifyChanged(self.astype(value))
+ self.notifyChanged(self.rangeType(value))
class CounterSlider(QtGui.QWidget):
""" Creates the range using a counter and slider """
- def __init__(self, parent, ranges, slot, astype=float):
+ def __init__(self, parent, ranges, slot, rangeType=float):
QtGui.QWidget.__init__(self, parent)
- self.astype = astype
+ self.rangeType = rangeType
# Slot to call in the parent
self.notifyChanged = slot
- self.slider = RangeWidget.Slider(parent, ranges,
self.sliderChanged, astype)
- self.counter = RangeWidget.Counter(parent, ranges,
self.counterChanged, astype)
+ self.slider = RangeWidget.Slider(parent, ranges,
self.sliderChanged, rangeType)
+ self.counter = RangeWidget.Counter(parent, ranges,
self.counterChanged, rangeType)
# Need another horizontal layout to wrap the other widgets.
layout = Qt.QHBoxLayout()
@@ -225,8 +223,8 @@ class RangeWidget(QtGui.QWidget):
# If the counter was changed, ignore any of these events
if not self.ignoreSlider:
# Value is already float. Just set the counter
- self.counter.setValue(self.astype(value))
- self.notifyChanged(self.astype(value))
+ self.counter.setValue(self.rangeType(value))
+ self.notifyChanged(self.rangeType(value))
self.ignoreSlider = False
def counterChanged(self, value):
@@ -241,4 +239,21 @@ class RangeWidget(QtGui.QWidget):
self.ignoreSlider = True
self.slider.setValue(new)
- self.notifyChanged(self.astype(value))
+ self.notifyChanged(self.rangeType(value))
+
+
+if __name__ == "__main__":
+ from PyQt4 import Qt
+ import sys
+
+ def valueChanged(frequency):
+ print("Value updated - " + str(frequency))
+
+ app = Qt.QApplication(sys.argv)
+ widget = RangeWidget(Range(0, 100, 10, 1, 100), valueChanged, "Test",
"counter_slider", int)
+
+ widget.show()
+ widget.setWindowTitle("Test Qt Range")
+ app.exec_()
+
+ widget = None
- [Commit-gnuradio] [gnuradio] branch master updated (c0a88be -> 327f070), git, 2015/04/26
- [Commit-gnuradio] [gnuradio] 16/16: Merge remote-tracking branch 'gnuradio-wg-grc/master_grcwg', git, 2015/04/26
- [Commit-gnuradio] [gnuradio] 14/16: Merge remote-tracking branch 'tom/qtgui/range_type', git, 2015/04/26
- [Commit-gnuradio] [gnuradio] 15/16: Merge remote-tracking branch 'nowls/burst_shaping', git, 2015/04/26
- [Commit-gnuradio] [gnuradio] 04/16: grc: Add check for GTK initialization, git, 2015/04/26
- [Commit-gnuradio] [gnuradio] 13/16: Merge remote-tracking branch 'mmueller/pwr_squelch_add_tags', git, 2015/04/26
- [Commit-gnuradio] [gnuradio] 12/16: Merge remote-tracking branch 'tom/ctrlport/fixes1', git, 2015/04/26
- [Commit-gnuradio] [gnuradio] 06/16: controlport: use proper default return value from prefs get_bool., git, 2015/04/26
- [Commit-gnuradio] [gnuradio] 08/16: digital: fix skipped sample handling in burst_shaper, git, 2015/04/26
- [Commit-gnuradio] [gnuradio] 05/16: qtgui: improved type checking for range block and simplifies python.,
git <=
- [Commit-gnuradio] [gnuradio] 02/16: controlport: fixed up performance monitor., git, 2015/04/26
- [Commit-gnuradio] [gnuradio] 03/16: qtgui: adds Type setting for Range widget., git, 2015/04/26
- [Commit-gnuradio] [gnuradio] 01/16: controlport: fixed controlport probes., git, 2015/04/26
- [Commit-gnuradio] [gnuradio] 07/16: analog: Power Squelch now emit tags on start/end of bursts, git, 2015/04/26
- [Commit-gnuradio] [gnuradio] 09/16: digital: added tag propagation to burst_shaper blocks, git, 2015/04/26
- [Commit-gnuradio] [gnuradio] 10/16: blocks: better implementation of peak_detector2. Address #783., git, 2015/04/26
- [Commit-gnuradio] [gnuradio] 11/16: blocks: more fixups to peak_detector2., git, 2015/04/26