def testButton(self): #Connecting a lambda to a QPushButton.clicked() obj = QPushButton('label') ctr = Control() func = lambda: setattr(ctr, 'arg', True) QObject.connect(obj, SIGNAL('clicked()'), func) obj.click() self.assert_(ctr.arg) QObject.disconnect(obj, SIGNAL('clicked()'), func)
def testObjectRefcount(self): """Emission of QObject.destroyed() to a python slot""" def callback(): pass obj = QObject() refcount = getrefcount(obj) QObject.connect(obj, SIGNAL('destroyed()'), callback) self.assertEqual(refcount, getrefcount(obj)) QObject.disconnect(obj, SIGNAL('destroyed()'), callback) self.assertEqual(refcount, getrefcount(obj))
def testSpinButton(self): #Connecting a lambda to a QPushButton.clicked() obj = QSpinBox() ctr = Control() arg = 444 func = lambda x: setattr(ctr, 'arg', 444) QObject.connect(obj, SIGNAL('valueChanged(int)'), func) obj.setValue(444) self.assertEqual(ctr.arg, arg) QObject.disconnect(obj, SIGNAL('valueChanged(int)'), func)
def testDisconnect(self): obj1 = Dummy() QObject.connect(obj1, SIGNAL('foo(int)'), self.callback) QObject.disconnect(obj1, SIGNAL('foo(int)'), self.callback) self.args = (42, ) obj1.emit(SIGNAL('foo(int)'), *self.args) self.assert_(not self.called)
def testDisconnect(self): obj1 = Dummy() QObject.connect(obj1, SIGNAL("foo(int)"), self.callback) QObject.disconnect(obj1, SIGNAL("foo(int)"), self.callback) self.args = (42,) obj1.emit(SIGNAL("foo(int)"), *self.args) self.assert_(not self.called)
def testRefCount(self): def cb(*args): pass self.assertEqual(getrefcount(cb), 2) QObject.connect(self.emitter, SIGNAL('destroyed()'), cb) self.assertEqual(getrefcount(cb), 3) QObject.disconnect(self.emitter, SIGNAL('destroyed()'), cb) self.assertEqual(getrefcount(cb), 2)
def connectCitra(self): if self.pushButtonConnect.text() == "Connect": self.pushButtonConnect.setText("Disconnect") index = self.comboBoxGameSelection.currentIndex() self.comboBoxGameSelection.setEnabled(False) if index == 0: self.manager = ManagerXY() elif index == 1: self.manager = ManagerORAS() elif index == 2: self.manager = ManagerSM() else: self.manager = ManagerUSUM() seed = self.manager.readInitialSeed() if seed == 0: message = QMessageBox() message.setText( "Initial seed not valid.\nCheck that you are using the correct game or the latest version of the game" ) message.exec_() self.manager = None return self.allowUpdate = True self.toggleEnable(True, index) self.labelStatus.setText("Connected") self.mainRNG = False self.eggRNG = False self.sosRNG = False QObject.disconnect(self, SIGNAL("update()"), self, SLOT("updateMainRNG6()")) QObject.disconnect(self, SIGNAL("update()"), self, SLOT("updateEggRNG6()")) QObject.disconnect(self, SIGNAL("update()"), self, SLOT("updateMainRNG7()")) QObject.disconnect(self, SIGNAL("update()"), self, SLOT("updateEggRNG7()")) QObject.disconnect(self, SIGNAL("update()"), self, SLOT("updateSOSRNG()")) if index == 0 or index == 1: self.update.connect(self.updateMainRNG6) self.update.connect(self.updateEggRNG6) else: self.update.connect(self.updateMainRNG7) self.update.connect(self.updateEggRNG7) self.update.connect(self.updateSOSRNG) t = threading.Thread(target=self.autoUpdate) time.sleep(1) t.start() else: self.pushButtonConnect.setText("Connect") self.allowUpdate = False self.manager = None self.toggleEnable(False, self.comboBoxGameSelection.currentIndex()) index = self.comboBoxGameSelection.currentIndex() if index == 0 or index == 1: self.pushButtonMainUpdate6.setText("Update") self.pushButtonEggUpdate6.setText("Update") else: self.pushButtonMainUpdate7.setText("Update") self.pushButtonEggUpdate7.setText("Update") self.pushButtonSOSUpdate.setText("Update") self.labelStatus.setText("Disconnected") self.comboBoxGameSelection.setEnabled(True)
def stop(self): self.period_timer.stop() self.duration_timer.stop() # disconnect all QObject.disconnect(self.period_timer) QObject.disconnect(self.duration_timer)