GNU Radio Manual and C++ API Reference  3.7.13.4
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  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_QTGUI_EDIT_BOX_MSG_H
24 #define INCLUDED_QTGUI_EDIT_BOX_MSG_H
25 
26 #ifdef ENABLE_PYTHON
27 #include <Python.h>
28 #endif
29 
31 #include <gnuradio/qtgui/api.h>
32 #include <gnuradio/block.h>
33 #include <qapplication.h>
34 
35 namespace gr {
36  namespace qtgui {
37 
38  /*!
39  * \brief Create a QT Edit Box widget where the value is posted as a message.
40  * \ingroup qtgui_blk
41  *
42  * \details
43  * This block creates a QT Edit Box widget that manages data
44  * through message passing interfaces. The 'msg' output port
45  * produces messages based on the text in the edit box and the
46  * data type set by the \p type argument (see
47  * gr::qtgui::data_type_t). The data types are checked, and WARN
48  * log messages are produced when the data is in the wrong
49  * format. Not all errors are explicitly checked for, only that
50  * conversions happen correctly. Failures are either produces as
51  * log messages or the action is simply silently dropped.
52  *
53  * The value of the edit boxes can be programmatically updated
54  * through the 'val' input message port. It is also checked for
55  * the correct data type.
56  *
57  * The \p is_pair argument to the constructor determines if the
58  * edit box handles a key:value pair. If set to True, two edit
59  * boxes are created with the left for the key and right for the
60  * value. The key is always assumed to be a string and the value
61  * is restricted by the data type setting as above.
62  *
63  * The block can take a default value. Because the block is
64  * capable of handling multiple different data types, we enter the
65  * default value as a string in the same way we expect the user to
66  * enter it into the Value edit box of the widget. We convert this
67  * default exactly the same way we convert the user-entered text
68  * in the edit box. See the next paragraph for an explanation for
69  * how to handle complex numbers.
70  *
71  * Complex numbers are currently handled a bit differently than
72  * expected. Because we use the Boost lexical_cast function,
73  * complex numbers MUST be in the form "(a,b)" to represent "a +
74  * jb". Note that you cannot even have a space after the comma, so
75  * "(1.23,10.56)" is correct while "(1.23, 10.56)" will not parse.
76  *
77  * The 'static' mode prevents the user from changing the data type
78  * or the key used in the widget. If also in 'pair' mode, the key
79  * is not displayed and so must be set in the constructor. It is
80  * an error if using static and pair modes with no default key
81  * set.
82  *
83  * Message Ports:
84  *
85  * - msg (output):
86  * Produces a PMT message from the data in the edit box. It
87  * is packaged in the PMT container determined by the \p
88  * type argument to the ctor. If the data in the box is not of
89  * the correct type and the conversion fails, the block
90  * produces a log WARN message but does nothing else with
91  * the data. If the \p is_pair flag is set on this block, it
92  * will produce a PMT pair object where the key (car) is
93  * assumed to be a string and the value (cdr) is determined
94  * by \p type.
95  *
96  * - val (input):
97  * Accepts messages to update the value in the edit
98  * boxes. The messages, as PMTs, are first checked to make
99  * sure that they are the correct type (integer, float,
100  * string, or complex), and unpacks them and converts them
101  * to QStrings to display in the edit box. When using \p
102  * is_pair, the PMT is checked to make sure it is a PMT
103  * pair. Then the key (car) is extracted as a string before
104  * the value (cdr) is processed based on the set data type
105  * of the box.
106  */
107  class QTGUI_API edit_box_msg : virtual public block
108  {
109  public:
110  // gr::qtgui::edit_box_msg::sptr
111  typedef boost::shared_ptr<edit_box_msg> sptr;
112 
113  /*!
114  * \brief Constructs the Edit box block.
115  *
116  * \param type the data type of data in the value box.
117  * \param value the default value of the message. This is
118  * entered as a string regardless of the type and
119  * converted internally -- much like how the block
120  * extracts the value from the edit box and converts it.
121  * \param label a label to identify the box on screen.
122  * \param is_pair if we are using a key:value pair.
123  * \param is_static sets the key edit box as a static text box
124  * (cannot be edited live).
125  * \param key Set the key used in a key:value pair message.
126  * \param parent a QWidget parent in the QT app.
127  */
128  static sptr make(gr::qtgui::data_type_t type,
129  const std::string &value="",
130  const std::string &label="",
131  bool is_pair=true,
132  bool is_static=true,
133  const std::string &key="",
134  QWidget *parent=NULL);
135 
136  virtual void exec_() = 0;
137  virtual QWidget* qwidget() = 0;
138 
139 #ifdef ENABLE_PYTHON
140  virtual PyObject* pyqwidget() = 0;
141 #else
142  virtual void* pyqwidget() = 0;
143 #endif
144 
145  QApplication *d_qApplication;
146  };
147 
148  } /* namespace qtgui */
149 } /* namespace gr */
150 
151 #endif /* INCLUDED_QTGUI_EDIT_BOX_MSG_H */
data_type_t
Definition: qtgui_types.h:33
#define QTGUI_API
Definition: gr-qtgui/include/gnuradio/qtgui/api.h:30
boost::shared_ptr< edit_box_msg > sptr
Definition: edit_box_msg.h:111
Include this header to use the message passing features.
Definition: logger.h:695
Create a QT Edit Box widget where the value is posted as a message.
Definition: edit_box_msg.h:107
QApplication * d_qApplication
Definition: edit_box_msg.h:145
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)
The abstract base class for all &#39;terminal&#39; processing blocks.A signal processing flow is constructed ...
Definition: block.h:65