I've been trying to get a controller to work with signals (pyqtSignal), but I get this message when interacting with the GUI:
Traceback (most recent call last):
File "main_signals.py", line 102, in <module>
helper.Sinal.Emt.connect(PID.Imprime, QtCore.Qt.QueuedConnection)
AttributeError: 'PyQt4.QtCore.pyqtBoundSignal' object has no attribute 'Emt'
Would someone please tell me what I'm doing wrong, here's the stripped down version of the code (main_signals.py):
# Import 3rd party libraries
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import QObject, pyqtSignal
import time
import pyqtgraph
# Import python standard modules
import sys
# This file holds the MainWindow
import Plotter
# Variables
T = [0]
R = [0]
# Disregard this function
def ReadChannel(channel):
# -----------------------------------------------------------------
class Ctrldr(QtGui.QMainWindow, Plotter.Ui_MainWindow):
def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self)
self.QOutput.clicked.connect(self.Calculo)
# Plotting
@QtCore.pyqtSlot(str, tuple)
def Imprime(self, name, ptm):
global T, R, W
x, y = ptm
R.append(y)
self.graphicsView.plotItem.plot(T, R, pen='b')
# Calculations
def Calculo(self):
global T
t = time.clock()
T.append(t)
Read = ReadChannel(0)
Helper.Sinal.emit("Sensor", (t, Read))
Read = str(Read)
self.QResult.setText(Read)
# -----------------------------------------------------------------
class Helper(QtCore.QObject):
Sinal = QtCore.pyqtSignal(str, tuple)
def __init__(self):
super(self.__class__, self).__init__()
def Emt(self, str, tuple):
self.Sinal.emit(str, tuple)
# -----------------------------------------------------------------
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
PID = Ctrldr()
helper = Helper()
helper.Sinal.connect(PID.Imprime)
PID.show()
app.exec_()
Tried to follow the examples in these 2 pages:
The one that emits the signal is an object, in your Helper it is not an object, but the name of a class, so the solution is to create an object. For another str
and tuple
are reserved words that indicate data types, in the case of pyqtSignal()
its use is correct since pyqtSignal () requires as parameters the types of data it will handle, but do not use it as arguments in Emt()
since you overlapped his name.
# Import 3rd party libraries
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import QObject, pyqtSignal
import time
import pyqtgraph
# Import python standard modules
import sys
# This file holds the MainWindow
import Plotter
# Variables
T = [0]
R = [0]
# Disregard this function
def ReadChannel(channel):
# some process
return channel
# -----------------------------------------------------------------
# -----------------------------------------------------------------
class Helper(QtCore.QObject):
Sinal = QtCore.pyqtSignal(str, tuple)
def Emt(self, arg1, arg2):
self.Sinal.emit(arg1, arg2)
class Ctrldr(QtGui.QMainWindow, Plotter.Ui_MainWindow):
def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self)
self.QOutput.clicked.connect(self.Calculo)
self.helper = Helper(self) # <--- object
# Plotting
@QtCore.pyqtSlot(str, tuple)
def Imprime(self, name, ptm):
global T, R, W
x, y = ptm
R.append(y)
self.graphicsView.plotItem.plot(T, R, pen='b')
# Calculations
def Calculo(self):
global T
t = time.clock()
T.append(t)
Read = ReadChannel(0)
self.helper.Sinal.emit("Sensor", (t, Read))
Read = str(Read)
self.QResult.setText(Read)
# -----------------------------------------------------------------
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
PID = Ctrldr()
helper = Helper()
helper.Sinal.connect(PID.Imprime)
PID.show()
app.exec_()