Last active
January 1, 2022 21:29
-
-
Save Jeija/8940244b1714d0fd4d6662626aab35d9 to your computer and use it in GitHub Desktop.
GNURadio: Translate variable change events to Qt Main Thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
id: qt_variable_update | |
label: Qt Variable Update | |
flags: [ python ] | |
parameters: | |
- id: value | |
label: Input Variable | |
dtype: int | |
- id: target | |
label: Output Variable | |
dtype: string | |
templates: | |
imports: from gnuradio import qtvarupdate | |
make: qtvarupdate.update_int(${ 'self.set_' + context.get('target')() }) | |
callbacks: | |
- set_value(${value}) | |
file_format: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from gnuradio import gr | |
from PyQt5 import QtCore | |
class update_int(gr.sync_block): | |
""" | |
docstring for block update_int | |
""" | |
class QtToMainThread(QtCore.QObject): | |
valueChanged = QtCore.pyqtSignal(int) | |
def __init__(self, cb): | |
QtCore.QObject.__init__(self) | |
self.valueChanged.connect(self.onValueChanged) | |
self.cb = cb | |
def set_value(self, value): | |
self.valueChanged.emit(value) | |
@QtCore.pyqtSlot(int) | |
def onValueChanged(self, value): | |
self.cb(value) | |
def __init__(self, callback): | |
gr.basic_block.__init__(self, | |
name="update_int", | |
in_sig=[], | |
out_sig=[]) | |
self.toMainThread = update_int.QtToMainThread(callback) | |
def set_value(self, value): | |
self.toMainThread.set_value(int(value)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment