GNU Radio Manual and C++ API Reference  v3.9.2.0-89-gb7c7001e
The Free & Open Software Radio Ecosystem
edit_box_msg.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2016 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 #ifndef INCLUDED_QTGUI_EDIT_BOX_MSG_H
12 #define INCLUDED_QTGUI_EDIT_BOX_MSG_H
13 
14 #ifdef ENABLE_PYTHON
15 #include <Python.h>
16 #endif
17 
18 #include <gnuradio/block.h>
19 #include <gnuradio/qtgui/api.h>
21 #include <qapplication.h>
22 
23 namespace gr {
24 namespace qtgui {
25 
26 /*!
27  * \brief Create a QT Edit Box widget where the value is posted as a message.
28  * \ingroup qtgui_blk
29  *
30  * \details
31  * This block creates a QT Edit Box widget that manages data
32  * through message passing interfaces. The 'msg' output port
33  * produces messages based on the text in the edit box and the
34  * data type set by the \p type argument (see
35  * gr::qtgui::data_type_t). The data types are checked, and WARN
36  * log messages are produced when the data is in the wrong
37  * format. Not all errors are explicitly checked for, only that
38  * conversions happen correctly. Failures are either produces as
39  * log messages or the action is simply silently dropped.
40  *
41  * The value of the edit boxes can be programmatically updated
42  * through the 'val' input message port. It is also checked for
43  * the correct data type.
44  *
45  * The \p is_pair argument to the constructor determines if the
46  * edit box handles a key:value pair. If set to True, two edit
47  * boxes are created with the left for the key and right for the
48  * value. The key is always assumed to be a string and the value
49  * is restricted by the data type setting as above.
50  *
51  * The block can take a default value. Because the block is
52  * capable of handling multiple different data types, we enter the
53  * default value as a string in the same way we expect the user to
54  * enter it into the Value edit box of the widget. We convert this
55  * default exactly the same way we convert the user-entered text
56  * in the edit box. See the next paragraph for an explanation for
57  * how to handle complex numbers.
58  *
59  * Complex numbers are currently handled a bit differently than
60  * expected. Because we use the std iostream for complex, complex numbers MUST
61  * be in the form "(a,b)" to represent "a + jb". Note that you cannot even have
62  * a space after the comma, so "(1.23,10.56)" is correct while "(1.23, 10.56)"
63  * will not parse.
64  *
65  * The 'static' mode prevents the user from changing the data type
66  * or the key used in the widget. If also in 'pair' mode, the key
67  * is not displayed and so must be set in the constructor. It is
68  * an error if using static and pair modes with no default key
69  * set.
70  *
71  * Message Ports:
72  *
73  * - msg (output):
74  * Produces a PMT message from the data in the edit box. It
75  * is packaged in the PMT container determined by the \p
76  * type argument to the ctor. If the data in the box is not of
77  * the correct type and the conversion fails, the block
78  * produces a log WARN message but does nothing else with
79  * the data. If the \p is_pair flag is set on this block, it
80  * will produce a PMT pair object where the key (car) is
81  * assumed to be a string and the value (cdr) is determined
82  * by \p type.
83  *
84  * - val (input):
85  * Accepts messages to update the value in the edit
86  * boxes. The messages, as PMTs, are first checked to make
87  * sure that they are the correct type (integer, float,
88  * string, or complex), and unpacks them and converts them
89  * to QStrings to display in the edit box. When using \p
90  * is_pair, the PMT is checked to make sure it is a PMT
91  * pair. Then the key (car) is extracted as a string before
92  * the value (cdr) is processed based on the set data type
93  * of the box.
94  */
95 class QTGUI_API edit_box_msg : virtual public block
96 {
97 public:
98  // gr::qtgui::edit_box_msg::sptr
99  typedef std::shared_ptr<edit_box_msg> sptr;
100 
101  /*!
102  * \brief Constructs the Edit box block.
103  *
104  * \param type the data type of data in the value box.
105  * \param value the default value of the message. This is
106  * entered as a string regardless of the type and
107  * converted internally -- much like how the block
108  * extracts the value from the edit box and converts it.
109  * \param label a label to identify the box on screen.
110  * \param is_pair if we are using a key:value pair.
111  * \param is_static sets the key edit box as a static text box
112  * (cannot be edited live).
113  * \param key Set the key used in a key:value pair message.
114  * \param parent a QWidget parent in the QT app.
115  */
117  const std::string& value = "",
118  const std::string& label = "",
119  bool is_pair = true,
120  bool is_static = true,
121  const std::string& key = "",
122  QWidget* parent = NULL);
123 
124  virtual void exec_() = 0;
125  virtual QWidget* qwidget() = 0;
126 
127 #ifdef ENABLE_PYTHON
128  virtual PyObject* pyqwidget() = 0;
129 #else
130  virtual void* pyqwidget() = 0;
131 #endif
132 
133  QApplication* d_qApplication;
134 };
135 
136 } /* namespace qtgui */
137 } /* namespace gr */
138 
139 #endif /* INCLUDED_QTGUI_EDIT_BOX_MSG_H */
The abstract base class for all 'terminal' processing blocks.
Definition: gnuradio-runtime/include/gnuradio/block.h:60
Create a QT Edit Box widget where the value is posted as a message.
Definition: edit_box_msg.h:96
QApplication * d_qApplication
Definition: edit_box_msg.h:133
virtual void * pyqwidget()=0
std::shared_ptr< edit_box_msg > sptr
Definition: edit_box_msg.h:99
virtual void exec_()=0
static sptr make(gr::qtgui::data_type_t type, const std::string &value="", const std::string &label="", bool is_pair=true, bool is_static=true, const std::string &key="", QWidget *parent=NULL)
Constructs the Edit box block.
virtual QWidget * qwidget()=0
#define QTGUI_API
Definition: gr-qtgui/include/gnuradio/qtgui/api.h:18
data_type_t
Definition: qtgui_types.h:21
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:29
PMT_API bool is_pair(const pmt_t &obj)
Return true if obj is a pair, else false (warning: also returns true for a dict)