# Python Hier block using callback

**URL:** <https://www.ruby-forum.com/t/python-hier-block-using-callback/241724>\
**Category:** GNU Radio\
**Created:** [April 27, 2015, 8:45am UTC](https://www.ruby-forum.com/t/python-hier-block-using-callback/241724 "2015-04-27T08:45:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [April 27, 2015, 8:45am UTC](https://www.ruby-forum.com/t/python-hier-block-using-callback/241724/1 "2015-04-27T08:45:21Z")

</div>

Hi all;

I created a python hier block using signal source and a VCO, but I want  
to  
be able to control parameters like amplitude, sensitivity etc il real  
time  
using sliders.

I used callback tag on xml together with the set method but it does not  
work, the parameters does not seem to change at all.

is it possible to achieve what I am trying to do? how can I do it.

your help will be much appreciated.

Regards

Fanatic

---

<div class="post-metadata">

**Author:** ![themba\_m](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ba9def/32.png) [@themba\_m](https://www.ruby-forum.com/u/themba_m)\
**Post date:** [April 27, 2015, 9:32am UTC](https://www.ruby-forum.com/t/python-hier-block-using-callback/241724/2 "2015-04-27T09:32:06Z")

</div>

Hi Themba,

in principle, what you describe sounds right; can you insert some ‘print  
“set\_foobar called”’’ in the set methods of your hier block, to check  
whether they are actually being called?

Greetings,  
Marcus

---

<div class="post-metadata">

**Author:** ![themba\_m](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ba9def/32.png) [@themba\_m](https://www.ruby-forum.com/u/themba_m)\
**Post date:** [April 27, 2015, 10:19am UTC](https://www.ruby-forum.com/t/python-hier-block-using-callback/241724/3 "2015-04-27T10:19:26Z")

</div>

Thank you Marcus for the reply.  
let me show you an example of what I did. but so far i am not getting  
any  
output from it

```
def set_parameters(self,amplitude):
    global d_amplitude
             d_amplitude= amplitude
             print d_amplitude

```

#then on the contructor  
def\_init\_(self, amplitude)  
self.set\_parameter(amplitude)  
analog\_sig\_source = analog.sig\_source\_f(sampling\_rate,  
analog.GR\_TRI\_WAVE, f, d\_amplitude, 0)  
#then connect the block to other blocks

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/python-Hier-block-using-callback-tp53486p53489.html](http://gnuradio.4.n7.nabble.com/python-Hier-block-using-callback-tp53486p53489.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![themba\_m](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ba9def/32.png) [@themba\_m](https://www.ruby-forum.com/u/themba_m)\
**Post date:** [April 27, 2015, 2:22pm UTC](https://www.ruby-forum.com/t/python-hier-block-using-callback/241724/4 "2015-04-27T14:22:37Z")

</div>

Hi Themba,

the interesting point here is where you register your callback. You say  
you’ve included the callback in the .grc file; if that’s the case, you  
should find it searching for the name of the variable you change using a  
slider etc in the python file GRC generates.

Greetings,  
Marcus

---

<div class="post-metadata">

**Author:** ![themba\_m](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ba9def/32.png) [@themba\_m](https://www.ruby-forum.com/u/themba_m)\
**Post date:** [April 27, 2015, 10:17pm UTC](https://www.ruby-forum.com/t/python-hier-block-using-callback/241724/5 "2015-04-27T22:17:02Z")

</div>

the point is that if the print is not appearing, then the callback isn’t  
working as you expect. You should really make sure to use the right  
variable names.  
You’re not really sharing all the interesting information; it’s a bit  
hard to figure this out in what’s becoming a dialogue.  
I’d like to ask you to read  
[http://gnuradio.org/redmine/projects/gnuradio/wiki/ReportingErrors](http://gnuradio.org/redmine/projects/gnuradio/wiki/ReportingErrors)

Best regards,  
Marcus

---

<div class="post-metadata">

**Author:** ![themba\_m](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ba9def/32.png) [@themba\_m](https://www.ruby-forum.com/u/themba_m)\
**Post date:** [April 27, 2015, 10:11pm UTC](https://www.ruby-forum.com/t/python-hier-block-using-callback/241724/6 "2015-04-27T22:11:47Z")

</div>

the callback is on the .xml file from the grc folder, the parameters are  
changing but the waveform is not updating.  
on the other hand, all my custom blocks i get “AttributeError:  
‘top\_block\_sptr’ object has no attribute ‘top\_layout’”.

it was working all along but I just got that recently, I searched the  
forum  
I havent found where there is a solution to this ☹

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/python-Hier-block-using-callback-tp53486p53501.html](http://gnuradio.4.n7.nabble.com/python-Hier-block-using-callback-tp53486p53501.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).
