summaryrefslogtreecommitdiff
path: root/gr-qtgui/python/qtgui/msgpushbutton.py
diff options
context:
space:
mode:
Diffstat (limited to 'gr-qtgui/python/qtgui/msgpushbutton.py')
-rw-r--r--gr-qtgui/python/qtgui/msgpushbutton.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/gr-qtgui/python/qtgui/msgpushbutton.py b/gr-qtgui/python/qtgui/msgpushbutton.py
new file mode 100644
index 0000000000..bee142cac7
--- /dev/null
+++ b/gr-qtgui/python/qtgui/msgpushbutton.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright 2020 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+#
+
+from PyQt5 import Qt
+from gnuradio import gr
+import pmt
+
+class MsgPushButton(gr.sync_block, Qt.QPushButton):
+ """
+ This block creates a variable push button that creates a message
+ when clicked. Leave the label blank to use the variable id as
+ the label. You can define both the output message pmt name as
+ well as the value and value type.
+ """
+ def __init__(self, lbl, msgName, msgValue, relBackColor, relFontColor):
+ gr.sync_block.__init__(self, name="MsgPushButton", in_sig=None, out_sig=None)
+ Qt.QPushButton.__init__(self, lbl)
+
+ self.lbl = lbl
+ self.msgName = msgName
+ self.msgValue = msgValue
+
+ styleStr = ""
+ if relBackColor != 'default':
+ styleStr = "background-color: " + relBackColor + "; "
+
+ if relFontColor:
+ styleStr += "color: " + relFontColor + "; "
+
+ self.setStyleSheet(styleStr)
+
+ self.clicked[bool].connect(self.onBtnClicked)
+
+ self.message_port_register_out(pmt.intern("pressed"))
+
+ def onBtnClicked(self, pressed):
+ if type(self.msgValue) == int:
+ self.message_port_pub(pmt.intern("pressed"),
+ pmt.cons(pmt.intern(self.msgName), pmt.from_long(self.msgValue)))
+ elif type(self.msgValue) == float:
+ self.message_port_pub(pmt.intern("pressed"),
+ pmt.cons(pmt.intern(self.msgName), pmt.from_float(self.msgValue)))
+ elif type(self.msgValue) == str:
+ self.message_port_pub(pmt.intern("pressed"),
+ pmt.cons(pmt.intern(self.msgName), pmt.intern(self.msgValue)))
+ elif type(self.msgValue) == bool:
+ self.message_port_pub(pmt.intern("pressed"),
+ pmt.cons(pmt.intern(self.msgName), pmt.from_bool(self.msgValue)))