Hi-

I've got an application with 3 plot windows and a control area in the bottom. Depending on the screen resolution, the control area on the bottom is "covered" by the lowest of the 3 plot windows. The applicatoin works fine at 1600x1200 but less well at 1440x900, and certainly at lower resolutions the control boxes are getting covered.

What can I do so that even at lower resolutions I can see the entire application? I've tried adjusting the middle numeric field (vbox.add(self.scope.win, 4, wx.EXPAND)) in the vbox.add entry from 4 to 0, which helps for 1440x900 but this doesn't work for all resolutions and I don't know what this value represents anyway. Is there a recommendation for making my application resolution-independent? I've attached the python-code. Any advice is appreciated!

thanks,
eric

************************************
Eric H. Matlis, Ph.D.
Aerospace & Mechanical Engineering Dept.
120 Hessert Center for Aerospace Research
University of Notre Dame
Notre Dame, IN 46556-5684
Phone: (574) 631-6054
Fax:   (574) 631-8355
#!/usr/bin/env python

from gnuradio import gr, gru, eng_notation, optfir
from gnuradio import audio
from gnuradio import usrp
from gnuradio import blks
from gnuradio.eng_option import eng_option
from gnuradio.wxgui import slider, powermate
from gnuradio.wxgui import stdgui, fftsink, form, scopesink
from optparse import OptionParser
import usrp_dbid
import sys
import math
import wx
import wx.lib.evtmgr as em

def pick_subdevice(u):
    """
    The user didn't specify a subdevice on the command line.
    Try for one of these, in order: TV_RX, BASIC_RX, whatever is on side A.

    @return a subdev_spec
    """
    return usrp.pick_subdev(u, (usrp_dbid.TV_RX,
                                usrp_dbid.TV_RX_REV_2,
                                usrp_dbid.BASIC_RX))


plot1 = 1
plot2 = 1
plot3 = 1

class am_plasma_rx_graph (stdgui.gui_flow_graph):
    def __init__(self,frame,panel,vbox,argv):
        stdgui.gui_flow_graph.__init__ (self,frame,panel,vbox,argv)

        parser=OptionParser(option_class=eng_option)
        parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
                          help="select USRP Rx side A or B (default=A)")
        parser.add_option("-f", "--freq", type="eng_float", default=3e6,
                          help="set frequency to FREQ", metavar="FREQ")
        parser.add_option("-g", "--gain", type="int", default=10,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-O", "--audio-output", type="string", default="",
                          help="pcm device name.  E.g., hw:0,0 or surround51 or 
/dev/dsp")

        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)
        
        self.frame = frame
        self.panel = panel
        
        self.vol = 0
        self.state = "FREQ"
        self.freq = 0

        # build graph
        
        self.u = usrp.source_c()                    # usrp is data source

        adc_rate = self.u.adc_rate()                # 64 MS/s
        usrp_decim = 250
        self.u.set_decim_rate(usrp_decim)
        usrp_rate = adc_rate / usrp_decim           # 256 kS/s
        chanfilt_decim = 16
        #chanfilt_decim = 512
        demod_rate = usrp_rate / chanfilt_decim     # 16 kHz
        audio_decimation = 1
        audio_rate = demod_rate / audio_decimation  # 16 kHz


        if options.rx_subdev_spec is None:
            options.rx_subdev_spec = pick_subdevice(self.u)

        # Select USRP channel (0)
        self.u.set_mux(usrp.determine_rx_mux_value(self.u, 
options.rx_subdev_spec))
        # Tune to the desired IF frequency
        self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)

        # Channelize the signal of interest.
        chan_filt_coeffs = gr.firdes.low_pass (1,           # gain
                                            usrp_rate,   # sampling rate
                                            #1000,
                                            6000,        # passband cutoff
                                            500,       # stopband cutoff
                                            gr.firdes.WIN_HANN)
        self.lpfilter =  gr.fir_filter_ccf (chanfilt_decim,chan_filt_coeffs)

        # Demodulate with classic sqrt (I*I + Q*Q)
        self.magblock = gr.complex_to_mag()
        self.volume_control = gr.multiply_const_ff(self.vol)

        # Deemphasis.  Is this necessary on AM?
        #TAU  = 75e-6  # 75us in US, 50us in EUR
        #fftaps = [ 1 - math.exp(-1/TAU/usrp_rate), 0]
        #fbtaps= [ 0 , math.exp(-1/TAU/usrp_rate) ]
        
        #self.deemph = gr.iir_filter_ffd(fftaps,fbtaps)

        # sound card as final sink
        audio_sink = audio.sink (int (audio_rate),
                                 options.audio_output,
                                 False)   # ok_to_block
        
        # now wire it all together
        self.connect (self.u, self.lpfilter)
        self.connect (self.lpfilter, self.magblock)
        self.connect (self.magblock, self.volume_control)
        self.connect (self.volume_control, (audio_sink, 0))

        #self.connect (self.volume_control, audio_filter)
        #self.connect (audio_filter, (audio_sink, 0))
        #self.connect (self.volume_control,self.deemph)
        #self.connect (self.deemph,audio_filter)
        #self.connect (audio_filter, (audio_sink, 0))

        self._build_gui(vbox, usrp_rate, demod_rate, audio_rate)


        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.subdev.gain_range()
            options.gain = float(g[0]+g[1])/2

        if abs(options.freq) < 1e6:
            options.freq *= 1e6

        # set initial values

        self.set_gain(options.gain)
        if not(self.set_freq(options.freq)):
            self._set_status_msg("Failed to set initial frequency")


    def _set_status_msg(self, msg, which=0):
        self.frame.GetStatusBar().SetStatusText(msg, which)


    def _build_gui(self, vbox, usrp_rate, demod_rate, audio_rate):

        def _form_set_freq(kv):
            return self.set_freq(kv['freq'])


        if plot1:
            self.src_fft = fftsink.fft_sink_c (self, self.panel, title="Data 
from Sensor",
                                               fft_size=1024, 
sample_rate=usrp_rate)
            self.connect (self.u, self.src_fft)
            vbox.Add (self.src_fft.win, 0, wx.EXPAND)

        if plot2:
            self.post_filt = fftsink.fft_sink_f (self, self.panel, title="AM 
Demodulated FFT", fft_size=1024, sample_rate=demod_rate)
            self.connect (self.magblock,self.post_filt)
            vbox.Add (self.post_filt.win, 0, wx.EXPAND)

        if plot3:
            self.scope = scopesink.scope_sink_f(self, self.panel, title="AM 
Demodulated Time Series", sample_rate=demod_rate)
            self.connect(self.magblock, self.scope)
            vbox.Add (self.scope.win, 0, wx.EXPAND)


        # control area form at bottom
        self.myform = myform = form.form()
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add((5,0), 0)
        myform['freq'] = form.float_field(
            parent=self.panel, sizer=hbox, label="Carrier Freq", weight=1,
            callback=myform.check_input_and_call(_form_set_freq, 
self._set_status_msg))

        hbox.Add((5,0), 0)
        myform['freq_slider'] = \
            form.quantized_slider_field(parent=self.panel, sizer=hbox, weight=3,
                                        range=(.5e6, 3.5e6, 0.001e6),
                                        callback=self.set_freq)
        hbox.Add((5,0), 0)
        vbox.Add(hbox, 0, wx.EXPAND)

        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add((5,0), 0)
        
        myform['gain'] = \
            form.quantized_slider_field(parent=self.panel, sizer=hbox, 
label="Gain",
                                        weight=3, 
range=self.subdev.gain_range(),
                                        callback=self.set_gain)
        hbox.Add((5,0), 0)
        vbox.Add(hbox, 0, wx.EXPAND)

        try:
            self.knob = powermate.powermate(self.frame)
            self.rot = 0
            powermate.EVT_POWERMATE_ROTATE (self.frame, self.on_rotate)
            powermate.EVT_POWERMATE_BUTTON (self.frame, self.on_button)
        except:
            print "FYI: No Powermate or Contour Knob found"


    def on_rotate (self, event):
        self.rot += event.delta
        if (self.state == "FREQ"):
            if self.rot >= 3:
                self.set_freq(self.freq + .001e6)
                self.rot -= 3
            elif self.rot <=-3:
                self.set_freq(self.freq - .001e6)
                self.rot += 3
        else:
            step = self.subdev.gain_range()[2]
            if self.rot >= 3:
                self.set_gain(self.gain + step)
                self.rot -= 3
            elif self.rot <=-3:
                self.set_gain(self.gain - step)
                self.rot += 3
            self.update_status_bar ()
            
    def on_button (self, event):
        if event.value == 0:        # button up
            return
        self.rot = 0
        if self.state == "FREQ":
            self.state = "GAIN"
        else:
            self.state = "FREQ"
        self.update_status_bar ()
        
                                        
    def set_freq(self, target_freq):
        """
        Set the center frequency we're interested in.

        @param target_freq: frequency in Hz
        @rypte: bool

        Tuning is a two step process.  First we ask the front-end to
        tune as close to the desired frequency as it can.  Then we use
        the result of that operation and our target_frequency to
        determine the value for the digital down converter.
        """
        r = usrp.tune(self.u, 0, self.subdev, target_freq)
        
        if r:
            self.freq = target_freq
            self.myform['freq'].set_value(target_freq)         # update 
displayed value
            self.myform['freq_slider'].set_value(target_freq)  # update 
displayed value
            self.update_status_bar()
            self._set_status_msg("OK", 0)
            return True

        self._set_status_msg("Failed", 0)
        return False

    def set_gain(self, gain):
        self.gain=gain
        self.myform['gain'].set_value(gain)     # update displayed value
        self.subdev.set_gain(gain)
        self.update_status_bar ()

    def update_status_bar (self):
        msg = "Gain:%r  Setting:%s" % (self.gain, self.state)
        self._set_status_msg(msg, 1)
        if plot1: 
          self.src_fft.set_baseband_freq(self.freq)

    def gain_range(self):
        return (0, 20, 1)


if __name__ == '__main__':
    app = stdgui.stdapp (am_plasma_rx_graph, "USRP PLASMA AM RX")
    app.MainLoop ()

_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to