Is there a way of outputting a choice of text on screen dependent on the value of a variable in GNU Radio?

Yes — there are several ways to show text on screen in GNU Radio based on the value of a variable, and the best method depends on where the variable lives (Python flowgraph, C++ block, message stream, or GUI).

Below are the practical, commonly-used approaches, from simplest to most powerful.


1️⃣ Use a QT GUI Label (Best for GRC / Python variables)

How it works

You bind the label’s text to a Python expression that depends on a variable.

Steps (GRC)

  1. Add QT GUI Label
  2. Set:
    • Label → e.g. Status
    • Value → Python expression

Example

“LOCKED” if pll_locked else “SEARCHING”

or numeric logic:

“REF MODE” if refAction == 1 else “ANT MODE”

Result

The label updates automatically whenever the variable changes.

Best for:

  • Flowgraph variables
  • Sliders, checkboxes
  • Quick status indicators

2️⃣ Use a Message Debug block (Quick & dirty)

If your variable exists in a block and you already use message ports:

self.message_port_pub(

    pmt.intern(“status”),

    pmt.intern(“REF MODE”)

)

Attach Message Debug → see text in the console.

Best for:

  • Debugging
  • Internal state inspection

❌ Not GUI-friendly


3️⃣ Use QT GUI Message Sink (Best for text output from blocks)

How it works

You send PMT strings from a block → they appear as text in the GUI.

Python example

self.message_port_pub(

    pmt.intern(“msg”),

    pmt.intern(“Collecting Reference”)

)

In GRC

  • Add QT GUI Message Sink
  • Connect the message port

C++ equivalent

message_port_pub(

    pmt::intern(“msg”),

    pmt::intern(“Collecting Reference”)

);

Best for:

  • Status messages
  • Mode changes
  • Human-readable text

4️⃣ Dynamic Text via QT GUI Hint / Title (Hacky but works)

Some QT blocks allow expressions in:

  • Title
  • Y-axis label
  • Legend text

Example:

“Mode: ” + (“REF” if refAction else “ANT”)

⚠️ Updates less reliably; depends on block.


5️⃣ Use a Custom Python QT Widget (Most powerful)

If you need:

  • Multi-line text
  • Colors
  • Fonts
  • Alerts
  • Conditional formatting

You can embed a PyQt widget in GNU Radio.

Example snippet:

label.setText(“REF MODE”)

label.setStyleSheet(“color: red; font-weight: bold;”)

Best for complex GUIs


6️⃣ From an Embedded C++ Block → GUI (Your case)

Since your ezra_sink already uses message ports, this is ideal:

C++ block

message_port_pub(

    pmt::intern(“status”),

    pmt::intern(“Collecting ANT”)

);

GRC

  • Add QT GUI Message Sink
  • Connect status port

Decision Table

RequirementBest Method
Simple text from variableQT GUI Label
DebuggingMessage Debug
Text from C++ blockQT GUI Message Sink
Colored / styled textCustom Qt widget
Based on internal state machineMessage port → GUI

Recommended for ezRA

For your state machine (REF / ANT / FLUSH):

  • Publish a string only when state changes
  • Display via QT GUI Message Sink

Example:

if (d_state != d_state_last) {

    message_port_pub(pmt::intern(“status”),

                     pmt::intern(“STATE: COLLECTING REF”));

    d_state_last = d_state;

}


By Admin

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.