aboutsummaryrefslogtreecommitdiffstats
path: root/python/trx/dict_toggle_sign.py
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2018-12-21 06:27:29 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2019-01-16 17:11:55 +0700
commita1a871ee37959564107fac5b7c1278269418b946 (patch)
treef5d36e592fed4ffde62f0c26f006a937fb67348b /python/trx/dict_toggle_sign.py
parentace92ae2c5b3403436383104b8e8e98f6220901e (diff)
python/trx: rename 'change_sign_of_dict_elements' to 'dict_toggle_sign'
The old name was quite long, resulting into cumbersome imports: from change_sign_of_dict_elements import change_sign_of_dict_elements let's use a shorter variant: from dict_toggle_sign import dict_toggle_sign Change-Id: Ie75e1d6e5e74c7c1cf34154633c1472e4b85dbb6
Diffstat (limited to 'python/trx/dict_toggle_sign.py')
-rw-r--r--python/trx/dict_toggle_sign.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/python/trx/dict_toggle_sign.py b/python/trx/dict_toggle_sign.py
new file mode 100644
index 0000000..d6cd8bd
--- /dev/null
+++ b/python/trx/dict_toggle_sign.py
@@ -0,0 +1,30 @@
+"""
+Embedded Python Blocks:
+
+Each this file is saved, GRC will instantiate the first class it finds to get
+ports and parameters of your block. The arguments to __init__ will be the
+parameters. All of them are required to have default values!
+"""
+
+from gnuradio import gr
+from pmt import *
+
+class dict_toggle_sign(gr.basic_block):
+ def __init__(self): # only default arguments here
+ gr.basic_block.__init__(
+ self,
+ name='Change sign of elts in dict',
+ in_sig=[],
+ out_sig=[]
+ )
+ self.message_port_register_in(intern("dict_in"))
+ self.message_port_register_out(intern("dict_out"))
+ self.set_msg_handler(intern("dict_in"), self.change_sign)
+
+ def change_sign(self, msg):
+ if is_dict(msg):
+ d = to_python(msg)
+ #print d
+ for key, value in d.items():
+ d[key] *= -1
+ self.message_port_pub(intern("dict_out"), to_pmt(d))