Oct-01-2019, 05:00 PM
In this exercise, I am using a python webserver to change the parameters' values inside my configuration file (.ini file). To do that I have a few widgets (roundsliders) that I am using to change the values of the parameters. So, once I call/import the file then start dragging the sliders and hit submit then the values should change based on the values I assigned.
The error I am facing with now is with changing the value of parameter # 1. It tells me that "object has no attribute 'change_param_1".
Any idea on how to solve this problem!
Also, if you think there is an easier approach to edit the params values then I would appreciate your suggestions.
python code:
The error I am facing with now is with changing the value of parameter # 1. It tells me that "object has no attribute 'change_param_1".
Any idea on how to solve this problem!
Also, if you think there is an easier approach to edit the params values then I would appreciate your suggestions.
python code:
from __future__ import print_function from gnuradio import blocks from gnuradio import eng_notation from gnuradio import gr from gnuradio.eng_option import eng_option from gnuradio.filter import firdes from optparse import OptionParser import time from flask import Flask, flash, request, redirect, jsonify, render_template_string, g, current_app import ConfigParser config = ConfigParser.RawConfigParser() config.add_section('Params') class Top_Block(gr.top_block): def __init__(self): gr.top_block.__init__(self, "Top Block 22") def getfile(self, filename, param_1=0, param_2=0, param_3=0): self.param_1 = param_1 print('[Top_Block] __init__: param_1:', self.param_1) self.param_2 = param_2 print('[Top_Block] __init__: param_2:', self.param_2) self.param_3 = param_3 print('[Top_Block] __init__: param_3:', self.param_3) with open(filename, 'wb') as configfile: config.write(configfile) def change_param_1(self, value=None): if value is not None: self.param_1 = value print('[Top_Block] change: param_1:', value) config.set_param_1('Params', 'param_1', value) def change_param_2(self, value=None): if value is not None: self.param_2 = value print('[Top_Block] change: param_2:', value) config.set('Params', 'param_2', value) def change_param_3(self, value=None): if value is not None: self.param_3 = value print('[Top_Block] change: param_3:', value) config.set('Params', 'param_3', value) def change(self, param_1=None, param_2=None, param_3=None): self.change_param_1(param_1) self.change_param_2(param_2) self.change_param_3(param_3) def turn_off(self): self.change(0, 0, 0) #=============================================================== app = Flask(__name__) @app.route("/") def index(): current_app.tb = Top_Block() current_app.tb.start() args_filename = request.args.get('filename', '') # return render_template_string('''<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Project</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3.2/roundslider.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3.2/roundslider.min.js"></script> <style type="text/css"> form { display: flex; top: 5px; margin:20px; border-width: 2px; border-bottom-color:#3300ff; border-bottom-style: solid; width: 1900px; border: 5px solid green; border-radius: .5em; padding: 5px; align-items: center; } </style> <h1> <form action="getfile" method="POST" enctype="multipart/form-data"> <font size="10"><pre class="tab"> Import INI File: </pre></font> <input type="file" name="file"> <input type="submit" value="Submit"> </form> <style> .container { display: flex; } .child { margin-left:100px; } </style> <body> <div class="container"> <div class="child"> <div id="slider1" class='slider row1 col1'></div> <center> <p>param_1</p> </center> </div> <div class="child"> <div id="slider2" class='slider row1 col2'></div> <center> <p>param_2</p> </center> </div> <div class="child"> <div id="slider3" class='slider row1 col3'></div> <center> <p>param_3</p> </center> </div> </div> <script> // create sliders $("#slider1").roundSlider({ sliderType: "min-range", radius: 150, min: 0, max: 10000000000, value: 0, // default value at start //change: function(event) { $.getJSON('/valueofslider', {slide1_val: event.value}); } change: function(event) { $.getJSON('/set_param_1/' + event.value); } }); $("#slider2").roundSlider({ sliderType: "min-range", radius: 150, min: 0, max: 10000000000, value: 0, // default value at start //change: function(event) { $.getJSON('/valueofslider', {slide2_val: event.value}); } change: function(event) { $.getJSON('/set_param_2/' + event.value); } }); $("#slider3").roundSlider({ sliderType: "min-range", radius: 150, min: 0, max: 10000000000, value: 0, // default value at start //change: function(event) { $.getJSON('/valueofslider', {slide3_val: event.value}); } change: function(event) { $.getJSON('/set_param_3/' + event.value); } }); </script> </body> </html>''', filename=args_filename) @app.route('/getfile', methods=['GET','POST']) def getfile(): result = request.files.get('file') print('[/getfile] result:', result.filename) if result: result.save(result.filename) current_app.tb.getfile(result.filename) return redirect('/') @app.route('/off') def off(): current_app.tb.turn_off() return 'off' @app.route('/set_param_1/<int:value>') def set_param_1(value): current_app.tb.change_param_1(value) return str(value) @app.route('/set_param_2/<int:value>') def set_param_2(value): current_app.tb.change_param_2(value) return str(value) @app.route('/set_param_3/<int:value>') def set_param_3(value): current_app.tb.change_param_3(value) return str(value) @app.route('/valueofslider') def slide(): param_1 = request.args.get('slide1_val', None) param_2 = request.args.get('slide2_val', None) param_3 = request.args.get('slide3_val', None) return 'param_1: {}, param_2: {}, param_3: {}'.format(param_1, param_2, param_3) def main(): app.run(host='0.0.0.0', debug=True) if __name__ == '__main__': main()Traceback:
* Serving Flask app "writeToConfigFile" (lazy loading) * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Debug mode: on * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit) * Restarting with stat * Debugger is active! * Debugger PIN: 138-727-058 127.0.0.1 - - [01/Oct/2019 11:16:22] "GET / HTTP/1.1" 200 - 127.0.0.1 - - [01/Oct/2019 11:16:23] "GET /set_param_1/719618996 HTTP/1.1" 500 - Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 2463, in __call__ return self.wsgi_app(environ, start_response) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 2449, in wsgi_app response = self.handle_exception(e) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1866, in handle_exception reraise(exc_type, exc_value, tb) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 2446, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1951, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in handle_user_exception reraise(exc_type, exc_value, tb) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1949, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1935, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/home/fit-pc/Desktop/random exercises/INI/writeToConfigFile.py", line 235, in set_param_1 current_app.tb.change_param_1(value) File "/usr/lib/python2.7/dist-packages/gnuradio/gr/hier_block2.py", line 92, in __getattr__ return getattr(self._impl, name) AttributeError: 'top_block_sptr' object has no attribute 'change_param_1'Location of error:
![[Image: uuC0h7.png]](https://imagizer.imageshack.com/img923/6783/uuC0h7.png)