Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event signal is emmitted twice every time

I am working on GUI appplication. From main window I open new popup window Dialog=myDialog() (so both are now open). If i press button on that new popup window, and catch signal with this code:

class Ui_DialogCalibration(object):
def setupUi(self, DialogCalibration):
    DialogCalibration.setObjectName(_fromUtf8("DialogCalibration"))
    DialogCalibration.resize(888, 378)
    self.widget = QtGui.QWidget(DialogCalibration)
    self.widget.setGeometry(QtCore.QRect(10, 150, 641, 144))
    self.widget.setObjectName(_fromUtf8("widget"))
    self.horizontalLayout_5 = QtGui.QHBoxLayout(self.widget)
    self.horizontalLayout_5.setMargin(0)
    self.horizontalLayout_5.setObjectName(_fromUtf8("horizontalLayout_5"))
    self.radioButtonManual = QtGui.QRadioButton(self.widget)
    self.radioButtonManual.setObjectName(_fromUtf8("radioButtonManual"))
    self.horizontalLayout_5.addWidget(self.radioButtonManual)
    self.verticalLayout = QtGui.QVBoxLayout()
    self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
    self.horizontalLayout_4 = QtGui.QHBoxLayout()
    self.horizontalLayout_4.setObjectName(_fromUtf8("horizontalLayout_4"))
    self.verticalLayout_4 = QtGui.QVBoxLayout()
    self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4"))
    self.pushButtonDesnoX = QtGui.QPushButton(self.widget)
    self.pushButtonDesnoX.setObjectName(_fromUtf8("pushButtonDesnoX"))
    self.verticalLayout_4.addWidget(self.pushButtonDesnoX)
    self.lineEdit = QtGui.QLineEdit(self.widget)
    self.lineEdit.setText(_fromUtf8(""))
    self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
    self.verticalLayout_4.addWidget(self.lineEdit)
    self.pushButtonLijevoX = QtGui.QPushButton(self.widget)
    self.pushButtonLijevoX.setObjectName(_fromUtf8("pushButtonLijevoX"))
    self.verticalLayout_4.addWidget(self.pushButtonLijevoX)
    self.horizontalLayout_4.addLayout(self.verticalLayout_4)
    self.verticalLayout_3 = QtGui.QVBoxLayout()
    self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3"))
    self.pushButtonDesnoY = QtGui.QPushButton(self.widget)
    self.pushButtonDesnoY.setObjectName(_fromUtf8("pushButtonDesnoY"))
    self.verticalLayout_3.addWidget(self.pushButtonDesnoY)
    self.lineEdit_2 = QtGui.QLineEdit(self.widget)
    self.lineEdit_2.setText(_fromUtf8(""))
    self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2"))
    self.verticalLayout_3.addWidget(self.lineEdit_2)
    self.pushButtonLijevoY = QtGui.QPushButton(self.widget)
    self.pushButtonLijevoY.setObjectName(_fromUtf8("pushButtonLijevoY"))
    self.verticalLayout_3.addWidget(self.pushButtonLijevoY)
    self.horizontalLayout_4.addLayout(self.verticalLayout_3)
    self.verticalLayout_2 = QtGui.QVBoxLayout()
    self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
    self.pushButtonDesnoZ = QtGui.QPushButton(self.widget)
    self.pushButtonDesnoZ.setObjectName(_fromUtf8("pushButtonDesnoZ"))
    self.verticalLayout_2.addWidget(self.pushButtonDesnoZ)
    self.lineEdit_3 = QtGui.QLineEdit(self.widget)
    self.lineEdit_3.setText(_fromUtf8(""))
    self.lineEdit_3.setObjectName(_fromUtf8("lineEdit_3"))
    self.verticalLayout_2.addWidget(self.lineEdit_3)
    self.pushButtoLijevoZ = QtGui.QPushButton(self.widget)
    self.pushButtoLijevoZ.setObjectName(_fromUtf8("pushButtoLijevoZ"))
    self.verticalLayout_2.addWidget(self.pushButtoLijevoZ)
    self.horizontalLayout_4.addLayout(self.verticalLayout_2)
    self.verticalLayout.addLayout(self.horizontalLayout_4)
    self.pushButtonSondaSettings = QtGui.QPushButton(self.widget)
    self.pushButtonSondaSettings.setObjectName(_fromUtf8("pushButtonSondaSettings"))
    self.verticalLayout.addWidget(self.pushButtonSondaSettings)
    self.pushButtonReset = QtGui.QPushButton(self.widget)
    self.pushButtonReset.setObjectName(_fromUtf8("pushButtonReset"))
    self.verticalLayout.addWidget(self.pushButtonReset)
    self.horizontalLayout_5.addLayout(self.verticalLayout)
    self.verticalLayout_5 = QtGui.QVBoxLayout()
    self.verticalLayout_5.setObjectName(_fromUtf8("verticalLayout_5"))
    self.labelPozition = QtGui.QLabel(self.widget)
    self.labelPozition.setObjectName(_fromUtf8("labelPozition"))
    self.verticalLayout_5.addWidget(self.labelPozition)
    self.horizontalLayout = QtGui.QHBoxLayout()
    self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
    self.labelpozitionX = QtGui.QLabel(self.widget)
    self.labelpozitionX.setObjectName(_fromUtf8("labelpozitionX"))
    self.horizontalLayout.addWidget(self.labelpozitionX)
    self.lineEditPozitionX = QtGui.QLineEdit(self.widget)
    self.lineEditPozitionX.setObjectName(_fromUtf8("lineEditPozitionX"))
    self.horizontalLayout.addWidget(self.lineEditPozitionX)
    self.verticalLayout_5.addLayout(self.horizontalLayout)
    self.horizontalLayout_2 = QtGui.QHBoxLayout()
    self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
    self.labelPozitionY = QtGui.QLabel(self.widget)
    self.labelPozitionY.setObjectName(_fromUtf8("labelPozitionY"))
    self.horizontalLayout_2.addWidget(self.labelPozitionY)
    self.lineEditPozitionY = QtGui.QLineEdit(self.widget)
    self.lineEditPozitionY.setObjectName(_fromUtf8("lineEditPozitionY"))
    self.horizontalLayout_2.addWidget(self.lineEditPozitionY)
    self.verticalLayout_5.addLayout(self.horizontalLayout_2)
    self.horizontalLayout_3 = QtGui.QHBoxLayout()
    self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3"))
    self.labelPozitionZ = QtGui.QLabel(self.widget)
    self.labelPozitionZ.setObjectName(_fromUtf8("labelPozitionZ"))
    self.horizontalLayout_3.addWidget(self.labelPozitionZ)
    self.lineEditPozitionZ = QtGui.QLineEdit(self.widget)
    self.lineEditPozitionZ.setObjectName(_fromUtf8("lineEditPozitionZ"))
    self.horizontalLayout_3.addWidget(self.lineEditPozitionZ)
    self.verticalLayout_5.addLayout(self.horizontalLayout_3)
    self.horizontalLayout_5.addLayout(self.verticalLayout_5)
    self.widget1 = QtGui.QWidget(DialogCalibration)
    self.widget1.setGeometry(QtCore.QRect(20, 40, 631, 91))
    self.widget1.setObjectName(_fromUtf8("widget1"))
    self.verticalLayout_6 = QtGui.QVBoxLayout(self.widget1)
    self.verticalLayout_6.setMargin(0)
    self.verticalLayout_6.setObjectName(_fromUtf8("verticalLayout_6"))
    self.radioButtonAutomatic = QtGui.QRadioButton(self.widget1)
    self.radioButtonAutomatic.setObjectName(_fromUtf8("radioButtonAutomatic"))
    self.verticalLayout_6.addWidget(self.radioButtonAutomatic)
    self.buttonBox = QtGui.QDialogButtonBox(self.widget1)
    self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
    self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
    self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
    self.verticalLayout_6.addWidget(self.buttonBox)
    self.labelpozitionX.setBuddy(self.lineEditPozitionX)
    self.labelPozitionY.setBuddy(self.lineEditPozitionY)
    self.labelPozitionZ.setBuddy(self.lineEditPozitionZ)
    self.radioButtonManual.toggle()
    self.buttonBox.setEnabled(False)
    self.pushButtonDesnoX.setEnabled(False)
    self.pushButtonDesnoY.setEnabled(False)
    self.pushButtonDesnoZ.setEnabled(False)
    self.pushButtonLijevoX.setEnabled(False)
    self.pushButtonLijevoY.setEnabled(False)
    self.pushButtoLijevoZ.setEnabled(False)
    self.pushButtonReset.setEnabled(False)
    self.lineEdit.setText("1")
    self.lineEdit_2.setText("1")
    self.lineEdit_3.setText("1")
    self.X=None
    self.Y=None
    self.Z=None

    self.retranslateUi(DialogCalibration)
    QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), DialogCalibration.accept)
    QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), DialogCalibration.reject)
    QtCore.QMetaObject.connectSlotsByName(DialogCalibration)

 class myDialog(QtGui.QDialog,Ui_DialogCalibration):
def __init__(self,sonda, parent=None):
    super(myDialog, self).__init__( parent)
    self.toupleSonda=sonda
    self.setupUi(self)
def on_pushButtonDesnoX_clicked(self):

    value=int(self.lineEdit.text())
    self.X=self.X+value
    print self.X

def retranslateUi(self, DialogCalibration):
    DialogCalibration.setWindowTitle(QtGui.QApplication.translate("DialogCalibration", "Calibration", None, QtGui.QApplication.UnicodeUTF8))
    self.radioButtonManual.setText(QtGui.QApplication.translate("DialogCalibration", "manual", None, QtGui.QApplication.UnicodeUTF8))
    self.pushButtonDesnoX.setText(QtGui.QApplication.translate("DialogCalibration", "Desno X", None, QtGui.QApplication.UnicodeUTF8))
    self.pushButtonLijevoX.setText(QtGui.QApplication.translate("DialogCalibration", "Lijevo X", None, QtGui.QApplication.UnicodeUTF8))
    self.pushButtonDesnoY.setText(QtGui.QApplication.translate("DialogCalibration", "Naprijed Y", None, QtGui.QApplication.UnicodeUTF8))
    self.pushButtonLijevoY.setText(QtGui.QApplication.translate("DialogCalibration", "Nazad Y", None, QtGui.QApplication.UnicodeUTF8))
    self.pushButtonDesnoZ.setText(QtGui.QApplication.translate("DialogCalibration", "Gore Z", None, QtGui.QApplication.UnicodeUTF8))
    self.pushButtoLijevoZ.setText(QtGui.QApplication.translate("DialogCalibration", "Dolje Z", None, QtGui.QApplication.UnicodeUTF8))
    self.pushButtonSondaSettings.setText(QtGui.QApplication.translate("DialogCalibration", "Load", None, QtGui.QApplication.UnicodeUTF8))
    self.pushButtonReset.setText(QtGui.QApplication.translate("DialogCalibration", "Reset", None, QtGui.QApplication.UnicodeUTF8))
    self.labelPozition.setText(QtGui.QApplication.translate("DialogCalibration", "Current pozition", None, QtGui.QApplication.UnicodeUTF8))
    self.labelpozitionX.setText(QtGui.QApplication.translate("DialogCalibration", "X", None, QtGui.QApplication.UnicodeUTF8))
    self.labelPozitionY.setText(QtGui.QApplication.translate("DialogCalibration", "Y", None, QtGui.QApplication.UnicodeUTF8))
    self.labelPozitionZ.setText(QtGui.QApplication.translate("DialogCalibration", "Z", None, QtGui.QApplication.UnicodeUTF8))
    self.radioButtonAutomatic.setText(QtGui.QApplication.translate("DialogCalibration", "automatic", None, QtGui.QApplication.UnicodeUTF8))

I got this oouput

1

2

So, this method has been executed twice. How can i fix this problem? Same happens on every other signal emmitted on popup window

like image 372
Error Avatar asked Jan 14 '13 02:01

Error


People also ask

Can a signal start multiple process instances of a signal?

Note: A thrown signal can start multiple process instances when multiple process definitions have a signal start event with the same signal name. The XML representation of a signal start event is the normal start event declaration with a signalEventDefinition child-element:

What happens when two signal boundary events occur at the same time?

If you have two active signal boundary events catching the same signal event, both boundary events are triggered, even if they are part of different process instances. You can use expressions for the name in the signal event definition. The name is then resolved as soon as a process reaches the scope of the signal.

What is a a signal?

A signal is an event of global scope (broadcast semantics) and is delivered to all active handlers. The following is an example of two separate processes communicating using signals.

What is the XML representation of a signal start event?

The XML representation of a signal start event is the normal start event declaration with a signalEventDefinition child-element: When a token arrives at the signal intermediate catching event, it will wait there until a signal with the proper name arrives. The following extensions are supported for the Signal Intermediate Catching Event:


1 Answers

Quoting from the docs:

[Connecting the both variations of the signal] also happens with signals that take optional arguments. Qt implements this using multiple signals. For example, QtGui.QAbstractButton has the following signal:

void clicked(bool checked = false);

Qt implements this as the following:

void clicked(); 
void clicked(bool checked);

The pyqtSlot() decorator can be used to specify which of the signals should be connected to the slot.

So your issue comes from the fact that clicked signal of a QPushButton has two overloads. Since Qt can connect signals to slots with less arguments, connectSlotsByName can successfully connect both overloads to your slot, thus calling the slot twice for each click.

You need to specify the appropriate overload by pyqtSlot:

@QtCore.pyqtSlot() # signal with no arguments
def on_pushButtonDesnoX_clicked(self):
    value=int(self.lineEdit.text())
    self.X=self.X+value
    print self.X
like image 126
Avaris Avatar answered Oct 18 '22 03:10

Avaris