Tuesday, September 24, 2019

[Discuss-gnuradio] Using Qt5 widgets in an Embedded Python block

Hi,

My flowgraph has an Embedded Python block feeding a Throttle feeding a
Text sink (https://github.com/dl1ksv/gr-display). In my Embedded Python
block I have a QLineEdit widget and a QTextEdit widget. The user input
is fed to the output port.

My problem is that I don't know how to tie the widgets to the parent GR.
I get the following error:
```
Param - Code(_source_code):
Can't create an instance of your block: arguments did not match any
overloaded call:
QTextEdit(parent: QWidget = None): argument 1 has unexpected type
'cons_in'
QTextEdit(str, parent: QWidget = None): argument 1 has unexpected
type 'cons_in'
```

Here is my code:
```
"""
Embedded Python Block
"""

# 09/23/2019 Barry Duggan

import numpy as np
from gnuradio import gr
from PyQt5.QtWidgets import (QWidget, QLineEdit, QPushButton,
QTextEdit, QGridLayout, QApplication)
from PyQt5.QtGui import QCursor
from PyQt5.QtCore import Qt, pyqtSlot

d_buffer = ""
textboxValue = ""

class cons_in (gr.sync_block):

def __init__(self):
gr.sync_block.__init__(self,
name='Console Input', # will show up in GRC
in_sig=None,
out_sig=[np.byte])
self.initUI()

def initUI(self):

# create text display area
self.textarea = QTextEdit(self)
self.textarea.setReadOnly(True)

# create input text area
self.textbox = QLineEdit(self)
self.textbox.editingFinished.connect(self.onEnter)
self.textbox.setFocus()

grid = QGridLayout()
grid.setSpacing(10)

grid.addWidget(self.textarea, 0, 0, 5, 1)
grid.addWidget(self.textbox, 5, 0)

self.setLayout(grid)
self.show()

def onEnter(self):
global d_buffer
global textboxValue

textboxValue = self.textbox.text()
d_buffer += (textboxValue + "\n")
self.textarea.setText(d_buffer)
self.textbox.setText("")

def work(self, input_items, output_items):
global textboxValue

# <send textboxValue to output port>
_num_elem = len(textboxValue)
for x in range (_num_elem):
output_items[0][x] = textboxValue[x]
return (_num_elem)
```

A stand-alone version of the code works properly.

Thank you for your help!
--
Barry Duggan

_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

No comments:

Post a Comment