[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r10763 - in gnuradio/branches/features/experimental-gu
From: |
jblum |
Subject: |
[Commit-gnuradio] r10763 - in gnuradio/branches/features/experimental-gui: . forms |
Date: |
Fri, 3 Apr 2009 19:32:05 -0600 (MDT) |
Author: jblum
Date: 2009-04-03 19:32:05 -0600 (Fri, 03 Apr 2009)
New Revision: 10763
Modified:
gnuradio/branches/features/experimental-gui/forms/forms.py
gnuradio/branches/features/experimental-gui/usrp2_siggen.py
gnuradio/branches/features/experimental-gui/usrp2_siggen_gui.py
Log:
Siggen GUI working, tested, needs a little cleanup.
Modified: gnuradio/branches/features/experimental-gui/forms/forms.py
===================================================================
--- gnuradio/branches/features/experimental-gui/forms/forms.py 2009-04-04
01:17:04 UTC (rev 10762)
+++ gnuradio/branches/features/experimental-gui/forms/forms.py 2009-04-04
01:32:05 UTC (rev 10763)
@@ -47,15 +47,15 @@
# Base Class Form
########################################################################
class _form_base(pubsub, wx.BoxSizer):
- def __init__(self, parent=None, sizer=None, proportion=0,
style=wx.HORIZONTAL, ps=None, key='', value=None, callback=None,
converter=converters.identity_converter()):
+ def __init__(self, parent=None, sizer=None, proportion=0,
flag=wx.EXPAND, ps=None, key='', value=None, callback=None,
converter=converters.identity_converter()):
pubsub.__init__(self)
- wx.BoxSizer.__init__(self, style)
+ wx.BoxSizer.__init__(self, wx.HORIZONTAL)
self._parent = parent
self._converter = converter
self._callback = callback
self._widgets = list()
#add to the sizer if provided
- if sizer: sizer.Add(self, proportion, wx.EXPAND)
+ if sizer: sizer.Add(self, proportion, flag)
#proxy the pubsub and key into this form
if ps is not None:
assert key
@@ -73,29 +73,21 @@
self.subscribe(EXT_KEY, self._translate_external_to_internal)
if self._callback: self.subscribe(EXT_KEY, self._callback)
- def _add_widget(self, widget, label='', proportion=1,
label_proportion=0, style=wx.HORIZONTAL):
+ def _add_widget(self, widget, label=''):
"""
Add the main widget to this object sizer.
If label is passed, add a label as well.
Register the widget and the label in the widgets list (for
enable/disable).
@param widget the main widget
@param label the optional label
- @param proportion the widget proportion when added to this sizer
- @param label_proportion the label proportion when added to this
sizer
- @param style wx.HORIZONTAL or wx.VERTICAL
"""
self._widgets.append(widget)
- if not label: wx.BoxSizer.Add(self, widget, proportion,
wx.EXPAND)
+ if not label: self.Add(widget, 1, wx.ALIGN_CENTER_VERTICAL)
else:
- label_style, widget_style = {
- wx.HORIZONTAL: (wx.ALIGN_CENTER_VERTICAL |
wx.ALIGN_LEFT, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT),
- wx.VERTICAL: (wx.ALIGN_CENTER_HORIZONTAL |
wx.ALIGN_TOP, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_BOTTOM),
- wx.ALIGN_CENTER: (wx.ALIGN_CENTER,
wx.ALIGN_CENTER),
- }[style]
- label_text = wx.StaticText(self._parent, label=' %s:
'%label)
+ label_text = wx.StaticText(self._parent, label='%s:
'%label)
self._widgets.append(label_text)
- self.Add(label_text, label_proportion, label_style)
- self.Add(widget, proportion, widget_style)
+ self.Add(label_text, 0, wx.ALIGN_CENTER_VERTICAL |
wx.ALIGN_LEFT)
+ self.Add(widget, 1, wx.ALIGN_CENTER_VERTICAL |
wx.ALIGN_RIGHT)
self._init()
def _translate_external_to_internal(self, external):
@@ -157,7 +149,7 @@
_form_base.__init__(self, converter=converter, **kwargs)
self._text_box = wx.TextCtrl(self._parent, size=wx.Size(width,
-1), style=wx.TE_PROCESS_ENTER)
self._text_box.Bind(wx.EVT_TEXT_ENTER, self._handle)
- self._add_widget(self._text_box, label, style=wx.ALIGN_CENTER)
+ self._add_widget(self._text_box, label)
def _handle(self, event): self[INT_KEY] = self._text_box.GetValue()
def _update(self, value): self._text_box.SetValue(value)
@@ -176,17 +168,13 @@
assert step_size or num_steps
if step_size is not None: num_steps = (maximum -
minimum)/step_size
if not converter: converter =
converters.slider_converter(minimum=minimum, maximum=maximum,
num_steps=num_steps, cast=cast)
- _form_base.__init__(self, converter=converter, style=style,
**kwargs)
- if style & wx.SL_HORIZONTAL:
- slider_size = wx.Size(length, -1)
- label_style = wx.HORIZONTAL
- elif style & wx.SL_VERTICAL:
- slider_size = wx.Size(-1, length)
- label_style = wx.VERTICAL
+ _form_base.__init__(self, converter=converter, **kwargs)
+ if style & wx.SL_HORIZONTAL: slider_size = wx.Size(length, -1)
+ elif style & wx.SL_VERTICAL: slider_size = wx.Size(-1, length)
else: raise NotImplementedError
self._slider = wx.Slider(self._parent, minValue=0,
maxValue=num_steps, size=slider_size, style=style)
self._slider.Bind(wx.EVT_SCROLL, self._handle)
- self._add_widget(self._slider, label, proportion=1,
style=label_style)
+ self._add_widget(self._slider, label)
def _handle(self, event): self[INT_KEY] = self._slider.GetValue()
def _update(self, value): self._slider.SetValue(value)
Modified: gnuradio/branches/features/experimental-gui/usrp2_siggen.py
===================================================================
--- gnuradio/branches/features/experimental-gui/usrp2_siggen.py 2009-04-04
01:17:04 UTC (rev 10762)
+++ gnuradio/branches/features/experimental-gui/usrp2_siggen.py 2009-04-04
01:32:05 UTC (rev 10763)
@@ -37,8 +37,11 @@
WAVEFORM2_FREQ_KEY = 'waveform2_freq'
FREQ_RANGE_KEY = 'freq_range'
GAIN_RANGE_KEY = 'gain_range'
+GIGE_RATE_KEY = 'gige'
TYPE_KEY = 'type'
+def setter(ps, key, val): ps[key] = val
+
from gnuradio import gr, eng_notation, usrp2
from gnuradio.gr.pubsub import pubsub
from gnuradio.eng_option import eng_option
@@ -60,7 +63,7 @@
def set_gain(self, *args, **kwargs): return True
def freq_range(self, *args, **kwargs): return (-100e6, 100e6)
def interface_name(self, *args, **kwargs): return 'eth-x'
-usrp2.sink_32fc = dummy_usrp2
+#usrp2.sink_32fc = dummy_usrp2
n2s = eng_notation.num_to_str
@@ -82,6 +85,8 @@
self._verbose = options.verbose
#initialize values from options
self.set_usrp2(options)
+ self.subscribe(INTERP_KEY, lambda i: setter(self, ETH_RATE_KEY,
self[DAC_RATE_KEY]/i))
+ self.subscribe(ETH_RATE_KEY, lambda e: setter(self, GIGE_RATE_KEY,
e*32))
self[INTERP_KEY] = options.interp
self[GAIN_KEY] = options.gain
self[TX_FREQ_KEY] = options.tx_freq
@@ -111,14 +116,14 @@
self._u = usrp2.sink_32fc(options.interface, options.mac_addr)
self.publish(INTERFACE_KEY, self._u.interface_name)
self.publish(MAC_ADDR_KEY, self._u.mac_addr)
- self.publish(DBOARD_ID_KEY, self._u.daughterboard_id)
+ self.publish(DBOARD_ID_KEY, lambda: hex(self._u.daughterboard_id()))
self.publish(DAC_RATE_KEY, self._u.dac_rate)
self.publish(FREQ_RANGE_KEY, self._u.freq_range)
self.publish(GAIN_RANGE_KEY, self._u.gain_range)
if self._verbose:
print "Network interface:", self[INTERFACE_KEY]
print "Network address:", self[MAC_ADDR_KEY]
- print "Daughterboard ID:", hex(self[DBOARD_ID_KEY])
+ print "Daughterboard ID:", self[DBOARD_ID_KEY]
def set_interp(self, interp):
if interp < 4 or interp > 512: # FIXME get from flowgraph
@@ -128,20 +133,18 @@
if not self._u.set_interp(interp):
raise RuntimeError("Failed to set interpolation rate %i" %
(interp,))
- self.publish(ETH_RATE_KEY, lambda: self[DAC_RATE_KEY]/self[INTERP_KEY])
if self._verbose:
print "USRP2 interpolation rate:", self[INTERP_KEY]
print "USRP2 IF bandwidth: %sHz" % (n2s(self[ETH_RATE_KEY]),)
- if (self[TYPE_KEY] == gr.GR_SIN_WAVE or
- self[TYPE_KEY] == gr.GR_CONST_WAVE):
+ if self[TYPE_KEY] in (gr.GR_SIN_WAVE, gr.GR_CONST_WAVE):
self._src.set_sampling_freq(self[ETH_RATE_KEY])
elif self[TYPE_KEY] == "2tone":
self._src1.set_sampling_freq(self[ETH_RATE_KEY])
- self._src1.set_sampling_freq(self[ETH_RATE_KEY])
+ self._src2.set_sampling_freq(self[ETH_RATE_KEY])
elif self[TYPE_KEY] == "sweep":
self._src1.set_sampling_freq(self[ETH_RATE_KEY])
-
self._src1.set_sampling_freq(self[WAVEFORM_FREQ_KEY]*2*math.pi/self[ETH_RATE_KEY])
+
self._src2.set_sampling_freq(self[WAVEFORM_FREQ_KEY]*2*math.pi/self[ETH_RATE_KEY])
else:
return True # Waveform not yet set
@@ -193,8 +196,11 @@
def set_waveform_freq(self, freq):
if self[TYPE_KEY] == gr.GR_SIN_WAVE:
self._src.set_frequency(freq)
- elif self[TYPE_KEY] == "2tone" or self[TYPE_KEY] == "sweep":
+ elif self[TYPE_KEY] == "2tone":
self._src1.set_frequency(freq)
+ elif self[TYPE_KEY] == 'sweep':
+ #there is no set sensitivity, redo fg
+ self[TYPE_KEY] = self[TYPE_KEY]
return True
def set_waveform2_freq(self, freq):
@@ -277,10 +283,7 @@
if self._verbose: print "Amplitude out of range:", amplitude
return False
- if (self[TYPE_KEY] == gr.GR_SIN_WAVE or
- self[TYPE_KEY] == gr.GR_CONST_WAVE or
- self[TYPE_KEY] == gr.GR_GAUSSIAN or
- self[TYPE_KEY] == gr.GR_UNIFORM):
+ if self[TYPE_KEY] in (gr.GR_SIN_WAVE, gr.GR_CONST_WAVE,
gr.GR_GAUSSIAN, gr.GR_UNIFORM):
self._src.set_amplitude(amplitude)
elif self[TYPE_KEY] == "2tone":
self._src1.set_amplitude(amplitude/2.0)
@@ -330,7 +333,7 @@
help="Generate a swept sine wave")
parser.add_option("-a", "--amplitude", type="eng_float", default=0.1,
help="Set output amplitude to AMPL (0.0-1.0)
[default=%default]", metavar="AMPL")
- parser.add_option("-v", "--verbose", action="store_true", default=True,
+ parser.add_option("-v", "--verbose", action="store_true", default=False,
help="Use verbose console output [default=%default]")
(options, args) = parser.parse_args()
Modified: gnuradio/branches/features/experimental-gui/usrp2_siggen_gui.py
===================================================================
--- gnuradio/branches/features/experimental-gui/usrp2_siggen_gui.py
2009-04-04 01:17:04 UTC (rev 10762)
+++ gnuradio/branches/features/experimental-gui/usrp2_siggen_gui.py
2009-04-04 01:32:05 UTC (rev 10763)
@@ -22,13 +22,15 @@
import wx
from gnuradio import gr
+from gnuradio.gr.pubsub import pubsub
from gnuradio.wxgui import form, slider, gui
import usrp2_siggen
import sys, math
import forms
-class app_gui(object):
+class app_gui(pubsub):
def __init__(self, frame, panel, vbox, top_block, options, args):
+ pubsub.__init__(self)
self.frame = frame # Use for top-level application window frame
self.panel = panel # Use as parent class for created windows
self.vbox = vbox # Use as sizer for created windows
@@ -50,63 +52,77 @@
##################################################
bb_vbox = forms.static_box_sizer(parent=self.panel, label="Baseband
Modulation", orient=wx.VERTICAL, bold=True)
self.vbox.Add(bb_vbox, 0, wx.EXPAND)
- # Add baseband controls to top window sizer
+ sine_bb_hbox = wx.BoxSizer(wx.HORIZONTAL)
+ sweep_bb_hbox = wx.BoxSizer(wx.HORIZONTAL)
+ tone_bb_hbox = wx.BoxSizer(wx.HORIZONTAL)
self.vbox.AddSpacer(10)
self.vbox.AddStretchSpacer()
- type_notebook = wx.Notebook(self.panel)
- type_pages = list()
- for i, wfm in enumerate(usrp2_siggen.waveforms.keys()):
- panel = wx.Panel(type_notebook)
- type_pages.append(panel)
- box = wx.BoxSizer(wx.HORIZONTAL)
- panel.SetSizer(box)
- if wfm == gr.GR_SIN_WAVE:
- forms.text_box(
- parent=panel, sizer=box,
- label='Frequency (Hz)',
- ps=self.tb,
- key=usrp2_siggen.WAVEFORM_FREQ_KEY,
- converter=forms.float_converter(),
- )
- elif wfm == 'sweep':
- forms.text_box(
- parent=panel, sizer=box,
- label='Frequency (Hz)',
- ps=self.tb,
- key=usrp2_siggen.WAVEFORM_FREQ_KEY,
- converter=forms.float_converter(),
- )
- forms.text_box(
- parent=panel, sizer=box,
- label='Sweep Rate (Hz)',
- ps=self.tb,
- key=usrp2_siggen.WAVEFORM2_FREQ_KEY,
- converter=forms.float_converter(),
- )
- elif wfm == '2tone':
- forms.text_box(
- parent=panel, sizer=box,
- label='Frequency 1 (Hz)',
- ps=self.tb,
- key=usrp2_siggen.WAVEFORM_FREQ_KEY,
- converter=forms.float_converter(),
- )
- forms.text_box(
- parent=panel, sizer=box,
- label='Frequency 2 (Hz)',
- ps=self.tb,
- key=usrp2_siggen.WAVEFORM2_FREQ_KEY,
- converter=forms.float_converter(),
- )
- forms.notebook(
+ #callback to show/hide forms
+ def set_type(type):
+ sine_bb_hbox.ShowItems(type == gr.GR_SIN_WAVE)
+ sweep_bb_hbox.ShowItems(type == 'sweep')
+ tone_bb_hbox.ShowItems(type == '2tone')
+ self.vbox.Layout()
+ self.tb.subscribe(usrp2_siggen.TYPE_KEY, set_type)
+ #create sine forms
+ sine_bb_hbox.AddSpacer(10)
+ forms.text_box(
+ parent=self.panel, sizer=sine_bb_hbox,
+ label='Frequency (Hz)',
+ ps=self.tb,
+ key=usrp2_siggen.WAVEFORM_FREQ_KEY,
+ converter=forms.float_converter(),
+ )
+ sine_bb_hbox.AddStretchSpacer()
+ #create sweep forms
+ sweep_bb_hbox.AddSpacer(10)
+ forms.text_box(
+ parent=self.panel, sizer=sweep_bb_hbox,
+ label='Sweep Width (Hz)',
+ ps=self.tb,
+ key=usrp2_siggen.WAVEFORM_FREQ_KEY,
+ converter=forms.float_converter(),
+ )
+ sweep_bb_hbox.AddStretchSpacer()
+ forms.text_box(
+ parent=self.panel, sizer=sweep_bb_hbox,
+ label='Sweep Rate (Hz)',
+ ps=self.tb,
+ key=usrp2_siggen.WAVEFORM2_FREQ_KEY,
+ converter=forms.float_converter(),
+ )
+ sweep_bb_hbox.AddStretchSpacer()
+ #create 2tone forms
+ tone_bb_hbox.AddSpacer(10)
+ forms.text_box(
+ parent=self.panel, sizer=tone_bb_hbox,
+ label='Tone 1 (Hz)',
+ ps=self.tb,
+ key=usrp2_siggen.WAVEFORM_FREQ_KEY,
+ converter=forms.float_converter(),
+ )
+ tone_bb_hbox.AddStretchSpacer()
+ forms.text_box(
+ parent=self.panel, sizer=tone_bb_hbox,
+ label='Tone 2 (Hz)',
+ ps=self.tb,
+ key=usrp2_siggen.WAVEFORM2_FREQ_KEY,
+ converter=forms.float_converter(),
+ )
+ tone_bb_hbox.AddStretchSpacer()
+ forms.radio_buttons(
parent=self.panel, sizer=bb_vbox,
choices=usrp2_siggen.waveforms.keys(),
labels=usrp2_siggen.waveforms.values(),
- notebook=type_notebook,
- pages=type_pages,
ps=self.tb,
key=usrp2_siggen.TYPE_KEY,
+ style=wx.NO_BORDER | wx.RA_HORIZONTAL,
)
+ bb_vbox.AddSpacer(10)
+ bb_vbox.Add(sine_bb_hbox, 0, wx.EXPAND)
+ bb_vbox.Add(sweep_bb_hbox, 0, wx.EXPAND)
+ bb_vbox.Add(tone_bb_hbox, 0, wx.EXPAND)
+ set_type(self.tb[usrp2_siggen.TYPE_KEY])
##################################################
# Frequency controls
##################################################
@@ -198,26 +214,27 @@
num_steps=100,
)
lvl_hbox.AddSpacer(5)
- gain_hbox.AddSpacer(5)
- forms.text_box(
- parent=self.panel, sizer=gain_hbox,
- proportion=1,
- converter=forms.float_converter(),
- ps=self.tb,
- key=usrp2_siggen.GAIN_KEY,
- label="TX Gain (dB)",
- )
- gain_hbox.AddSpacer(10)
- forms.slider(
- parent=self.panel, sizer=gain_hbox,
- proportion=2,
- ps=self.tb,
- key=usrp2_siggen.GAIN_KEY,
- minimum=self.tb[usrp2_siggen.GAIN_RANGE_KEY][0],
- maximum=self.tb[usrp2_siggen.GAIN_RANGE_KEY][1],
- step_size=self.tb[usrp2_siggen.GAIN_RANGE_KEY][2],
- )
- gain_hbox.AddSpacer(5)
+ if self.tb[usrp2_siggen.GAIN_RANGE_KEY][0] <
self.tb[usrp2_siggen.GAIN_RANGE_KEY][1]:
+ gain_hbox.AddSpacer(5)
+ forms.text_box(
+ parent=self.panel, sizer=gain_hbox,
+ proportion=1,
+ converter=forms.float_converter(),
+ ps=self.tb,
+ key=usrp2_siggen.GAIN_KEY,
+ label="TX Gain (dB)",
+ )
+ gain_hbox.AddSpacer(10)
+ forms.slider(
+ parent=self.panel, sizer=gain_hbox,
+ proportion=2,
+ ps=self.tb,
+ key=usrp2_siggen.GAIN_KEY,
+ minimum=self.tb[usrp2_siggen.GAIN_RANGE_KEY][0],
+ maximum=self.tb[usrp2_siggen.GAIN_RANGE_KEY][1],
+ step_size=self.tb[usrp2_siggen.GAIN_RANGE_KEY][2],
+ )
+ gain_hbox.AddSpacer(5)
##################################################
# Sample Rate controls
##################################################
@@ -228,29 +245,26 @@
sam_hbox.AddSpacer(5)
forms.text_box(
parent=self.panel, sizer=sam_hbox,
- proportion=1,
converter=forms.int_converter(),
ps=self.tb,
key=usrp2_siggen.INTERP_KEY,
label="Interpolation",
)
- sam_hbox.AddSpacer(10)
+ sam_hbox.AddStretchSpacer(20)
forms.static_text(
parent=self.panel, sizer=sam_hbox,
label='Sample Rate (sps)',
ps=self.tb,
key=usrp2_siggen.ETH_RATE_KEY,
converter=forms.float_converter(),
- proportion=1,
)
- sam_hbox.AddSpacer(10)
+ sam_hbox.AddStretchSpacer(20)
forms.static_text(
parent=self.panel, sizer=sam_hbox,
label='GbE Rate (bits/sec)',
ps=self.tb,
- key=usrp2_siggen.ETH_RATE_KEY,
+ key=usrp2_siggen.GIGE_RATE_KEY,
converter=forms.float_converter(),
- proportion=2,
)
sam_hbox.AddSpacer(5)
##################################################
@@ -267,25 +281,22 @@
ps=self.tb,
key=usrp2_siggen.INTERFACE_KEY,
converter=forms.str_converter(),
- proportion=2,
)
- u2_hbox.AddSpacer(10)
+ u2_hbox.AddStretchSpacer(20)
forms.static_text(
parent=self.panel, sizer=u2_hbox,
label='MAC Address',
ps=self.tb,
key=usrp2_siggen.MAC_ADDR_KEY,
converter=forms.str_converter(),
- proportion=2,
)
- u2_hbox.AddSpacer(10)
+ u2_hbox.AddStretchSpacer(20)
forms.static_text(
parent=self.panel, sizer=u2_hbox,
label='Daughterboard ID',
ps=self.tb,
key=usrp2_siggen.DBOARD_ID_KEY,
- converter=forms.int_converter(),
- proportion=2,
+ converter=forms.str_converter(),
)
u2_hbox.AddSpacer(5)
self.vbox.AddSpacer(5)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r10763 - in gnuradio/branches/features/experimental-gui: . forms,
jblum <=