Thnx for all the suggestions...Now i have made amendments to my program and
its working now...but there is a new problem now....I am now calling a
python script generated by GNU Radio Companion(for those who know about GRC
will understand my question better)...when i press the execute button i get
the following error..Both files are as attached.Is there a different way to
call a script generated by GRC??

Form: <class 'gnuradio.wxgui.forms.forms.text_box'> ->  Error translating
value: "<__main__.MyFrame; proxy of <Swig Object of type 'wxFrame *' at
0x30f44a0> >"
    bad operand type for abs(): 'MyFrame'
    Enter a float with optional scale suffix.  E.g., 100.1M
Form: <class 'gnuradio.wxgui.forms.forms.slider'> ->  Error translating
value: "<__main__.MyFrame; proxy of <Swig Object of type 'wxFrame *' at
0x30f44a0> >"
    unsupported operand type(s) for -: 'MyFrame' and 'float'
    Value should be within slider range
Using Volk machine: avx_64_mmx_orc
Traceback (most recent call last):
  File "wxgui.py", line 26, in Execute
    self.aNewFrame = uhd_fft.uhd_fft(self)
  File "/home/ali/Desktop/WXGUI/uhd_fft.py", line 155, in __init__
    size=((-1, 400)),
  File
"/usr/local/lib/python2.7/dist-packages/gnuradio/wxgui/fftsink_gl.py", line
126, in __init__
    persist_alpha=persist_alpha,
  File
"/usr/local/lib/python2.7/dist-packages/gnuradio/wxgui/fft_window.py", line
304, in __init__
    self.update_grid()
  File
"/usr/local/lib/python2.7/dist-packages/gnuradio/wxgui/fft_window.py", line
401, in update_grid
    baseband_freq - sample_rate/2.0,
TypeError: unsupported operand type(s) for -: 'MyFrame' and 'float'
Traceback (most recent call last):
  File
"/usr/local/lib/python2.7/dist-packages/gnuradio/wxgui/forms/forms.py",
line 102, in <lambda>
    widget.Bind(EVT_DATA, lambda x: self._update(x.data))
  File
"/usr/local/lib/python2.7/dist-packages/gnuradio/wxgui/forms/forms.py",
line 248, in _update
    def _update(self, value): self._text_box.SetValue(value);
self._update_color()
  File
"/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_controls.py",
line 1754, in SetValue
    return _controls_.TextCtrl_SetValue(*args, **kwargs)
TypeError: String or Unicode type required
Traceback (most recent call last):
  File
"/usr/local/lib/python2.7/dist-packages/gnuradio/wxgui/forms/forms.py",
line 102, in <lambda>
    widget.Bind(EVT_DATA, lambda x: self._update(x.data))
  File
"/usr/local/lib/python2.7/dist-packages/gnuradio/wxgui/forms/forms.py",
line 181, in _update
    def _update(self, value): self._slider.SetValue(int(round(value)))
TypeError: a float is required




On Thu, Jun 12, 2014 at 6:39 PM, Alan Gauld <alan.ga...@btinternet.com>
wrote:

> On 12/06/14 05:51, jason sam wrote:
>
>> Hi All,
>> I am new to wxPython.I have made a simple GUI that contains a button and
>> by pressing that button i am calling another .py
>> file(top_block.py)...
>>
>
> No you are not.
> You are importing it and then trying to access something called start
> which doesn't exist. importing is not the same as running a script.
> For a start the _name__ attribute will not be __main__ so your if clause
> at the bottom won't be executed. But the class definition
> code will have been run so you can access and create those classes
> from your wxGUI module.
>
> However, it is very strange practice to try to create a second
> GUI program from a first (not totally unheard of but uncommon).
> More usually you would define a dialog and open that from
> your Execute method.
>
>
>  top_block.start()
>>
>> The error is:
>>
>> AttributeError: 'module' object has no attribute 'start'
>>
>
> Please always post the full error message not just a summary.
> It has all sorts of useful extra details in there. In this case it doesn't
> matter because as the error says your module has no start attribute -
> because you didn't create one.
>
>
>
>  code are also welcome.The same error is received when i
>> use'top_block.run()'.Is there any alternative to this commands?
>>
>
> Yep, you didn't define a run() function either.
> modules can only execute what you define within them (and one or two
> special case attributes defined by Python; all starting with __
>
> Thee are several other oddities in your code but this is
> probably enough for now.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.flickr.com/photos/alangauldphotos
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
#!/usr/bin/env python
##################################################
# Gnuradio Python Flow Graph
# Title: UHD FFT
# Author: Example
# Description: UHD FFT Waveform Plotter
# Generated: Sun May 25 01:21:34 2014
##################################################

from gnuradio import analog
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio import wxgui
from gnuradio.eng_option import eng_option
from gnuradio.fft import window
from gnuradio.filter import firdes
from gnuradio.wxgui import fftsink2
from gnuradio.wxgui import forms
from gnuradio.wxgui import scopesink2
from gnuradio.wxgui import waterfallsink2
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import numpy
import wx

class uhd_fft(grc_wxgui.top_block_gui):

    def __init__(self, param_freq=2.45e9, param_gain=0, address="addr=192.168.11.2", param_samp_rate=1e6):
        grc_wxgui.top_block_gui.__init__(self, title="UHD FFT")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Parameters
        ##################################################
        self.param_freq = param_freq
        self.param_gain = param_gain
        self.address = address
        self.param_samp_rate = param_samp_rate

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = param_samp_rate
        self.gain = gain = param_gain
        self.freq = freq = param_freq
        self.ant = ant = "RX2"

        ##################################################
        # Blocks
        ##################################################
        self._samp_rate_text_box = forms.text_box(
        	parent=self.GetWin(),
        	value=self.samp_rate,
        	callback=self.set_samp_rate,
        	label="Sample Rate",
        	converter=forms.float_converter(),
        )
        self.GridAdd(self._samp_rate_text_box, 1, 0, 1, 3)
        self.nb0 = self.nb0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "FFT")
        self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "Waterfall")
        self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "Scope")
        self.GridAdd(self.nb0, 0, 0, 1, 1)
        _freq_sizer = wx.BoxSizer(wx.VERTICAL)
        self._freq_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_freq_sizer,
        	value=self.freq,
        	callback=self.set_freq,
        	label="RX Tune Frequency",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._freq_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_freq_sizer,
        	value=self.freq,
        	callback=self.set_freq,
        	minimum=50e6,
        	maximum=6e9,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.Add(_freq_sizer)
        self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c(
        	self.nb0.GetPage(1).GetWin(),
        	baseband_freq=0,
        	dynamic_range=100,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=512,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="Waterfall Plot",
        	size=((-1, 400)),
        )
        self.nb0.GetPage(1).Add(self.wxgui_waterfallsink2_0.win)
        self.wxgui_scopesink2_0 = scopesink2.scope_sink_c(
        	self.nb0.GetPage(2).GetWin(),
        	title="Scope Plot",
        	sample_rate=samp_rate,
        	v_scale=0,
        	v_offset=0,
        	t_scale=0,
        	ac_couple=False,
        	xy_mode=False,
        	num_inputs=1,
        	trig_mode=wxgui.TRIG_MODE_AUTO,
        	y_axis_label="Counts",
        )
        self.nb0.GetPage(2).Add(self.wxgui_scopesink2_0.win)
        _gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._gain_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_gain_sizer,
        	value=self.gain,
        	callback=self.set_gain,
        	label="RX Gain",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._gain_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_gain_sizer,
        	value=self.gain,
        	callback=self.set_gain,
        	minimum=0,
        	maximum=31.5,
        	num_steps=63,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_gain_sizer, 2, 0, 1, 8)
        self.fft = fftsink2.fft_sink_c(
        	self.nb0.GetPage(0).GetWin(),
        	baseband_freq=freq,
        	y_per_div=10,
        	y_divs=15,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="FFT Plot",
        	peak_hold=False,
        	size=((-1, 400)),
        )
        self.nb0.GetPage(0).Add(self.fft.win)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self._ant_chooser = forms.radio_buttons(
        	parent=self.GetWin(),
        	value=self.ant,
        	callback=self.set_ant,
        	label="Antenna",
        	choices=["RX2","TX/RX"],
        	labels=["RX2","TX/RX"],
        	style=wx.RA_HORIZONTAL,
        )
        self.GridAdd(self._ant_chooser, 1, 4, 1, 2)
        self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 50, 1, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.wxgui_scopesink2_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.fft, 0))
        self.connect((self.blocks_throttle_0, 0), (self.wxgui_waterfallsink2_0, 0))


# QT sink close method reimplementation

    def get_param_freq(self):
        return self.param_freq

    def set_param_freq(self, param_freq):
        self.param_freq = param_freq
        self.set_freq(self.param_freq)

    def get_param_gain(self):
        return self.param_gain

    def set_param_gain(self, param_gain):
        self.param_gain = param_gain
        self.set_gain(self.param_gain)

    def get_address(self):
        return self.address

    def set_address(self, address):
        self.address = address

    def get_param_samp_rate(self):
        return self.param_samp_rate

    def set_param_samp_rate(self, param_samp_rate):
        self.param_samp_rate = param_samp_rate
        self.set_samp_rate(self.param_samp_rate)

    def get_samp_rate(self):
        return self.samp_rate

    def set_samp_rate(self, samp_rate):
        self.samp_rate = samp_rate
        self.analog_sig_source_x_0.set_sampling_freq(self.samp_rate)
        self.wxgui_scopesink2_0.set_sample_rate(self.samp_rate)
        self.fft.set_sample_rate(self.samp_rate)
        self.wxgui_waterfallsink2_0.set_sample_rate(self.samp_rate)
        self.blocks_throttle_0.set_sample_rate(self.samp_rate)
        self._samp_rate_text_box.set_value(self.samp_rate)

    def get_gain(self):
        return self.gain

    def set_gain(self, gain):
        self.gain = gain
        self._gain_slider.set_value(self.gain)
        self._gain_text_box.set_value(self.gain)

    def get_freq(self):
        return self.freq

    def set_freq(self, freq):
        self.freq = freq
        self.fft.set_baseband_freq(self.freq)
        self._freq_slider.set_value(self.freq)
        self._freq_text_box.set_value(self.freq)

    def get_ant(self):
        return self.ant

    def set_ant(self, ant):
        self.ant = ant
        self._ant_chooser.set_value(self.ant)

if __name__ == '__main__':
    import ctypes
    import sys
    if sys.platform.startswith('linux'):
        try:
            x11 = ctypes.cdll.LoadLibrary('libX11.so')
            x11.XInitThreads()
        except:
            print "Warning: failed to XInitThreads()"
    parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
    parser.add_option("-f", "--param-freq", dest="param_freq", type="eng_float", default=eng_notation.num_to_str(2.45e9),
        help="Set Default Frequency [default=%default]")
    parser.add_option("-g", "--param-gain", dest="param_gain", type="eng_float", default=eng_notation.num_to_str(0),
        help="Set Default Gain [default=%default]")
    parser.add_option("-a", "--address", dest="address", type="string", default="addr=192.168.11.2",
        help="Set IP Address [default=%default]")
    parser.add_option("-s", "--param-samp-rate", dest="param_samp_rate", type="eng_float", default=eng_notation.num_to_str(1e6),
        help="Set Sample Rate [default=%default]")
    (options, args) = parser.parse_args()
    tb = uhd_fft(param_freq=options.param_freq, param_gain=options.param_gain, address=options.address, param_samp_rate=options.param_samp_rate)
    tb.Start(True)
    tb.Wait()

import wx

class MyApp(wx.App):
	def OnInit(self):
		self.frame = MyFrame(None, title="Analyze ")
		self.SetTopWindow(self.frame)
		self.frame.Show()
		return True
class MyFrame(wx.Frame):
	def __init__(self, parent, id=wx.ID_ANY, title="",
	pos=wx.DefaultPosition, size=wx.DefaultSize,
	style=wx.DEFAULT_FRAME_STYLE,
	name="MyFrame"):
		super(MyFrame, self).__init__(parent, id, title,
		pos, size, style, name)
		# Attributes
		self.panel = wx.Panel(self)
		self.panel.SetBackgroundColour(wx.BLACK)
		self.button3=wx.Button(self, -1, ' Execute ', wx.Point(235, 90),
                 wx.DefaultSize)
        	self.Bind(wx.EVT_BUTTON, self.Execute,self.button3)
       		

	def Execute(self,event):
		import uhd_fft   # normally you would move this to the beginning of your module
		self.aNewFrame = uhd_fft.uhd_fft(self)
		self.aNewFrame.Show()
		
	
if __name__ == "__main__":
	app = MyApp(False)
	app.MainLoop()
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to