def testInstallEventFilterRefCountAfterDelete(self): '''Bug 910 - installEventFilter() increments reference count on target object http://bugs.pyside.org/show_bug.cgi?id=910''' obj = QObject() filt = QObject() self.assertEqual(sys.getrefcount(obj), 2) self.assertEqual(sys.getrefcount(filt), 2) obj.installEventFilter(filt) self.assertEqual(sys.getrefcount(obj), 2) self.assertEqual(sys.getrefcount(filt), 2) wref = weakref.ref(obj) del obj self.assertEqual(wref(), None)
def testQCoreAppChildren(self): #QObject.children() after creating a QCoreApplication # Minimal test: # 1- Create QCoreApp # 2- Create parent and childrens # 3- While keeping the children alive, call parent.children() # 4- Delete parent app = QCoreApplication([]) parent = QObject() children = [QObject(parent) for x in range(25)] # Uncomment the lines below to make the test pass # del children # del child2 del parent # XXX Segfaults here self.assert_(True)
def testChildEventMonkeyPatch(self): #Test if the new childEvent injected on QObject instance is called from C++ parent = QObject() def childEvent(obj, event): self.duck_childEvent_called = True parent.childEvent = MethodType(childEvent, parent, QObject) child = QObject() child.setParent(parent) self.assertTrue(self.duck_childEvent_called) # This is done to decrease the refcount of the vm object # allowing the object wrapper to be deleted before the # BindingManager. This is useful when compiling Shiboken # for debug, since the BindingManager destructor has an # assert that checks if the wrapper mapper is empty. parent.childEvent = None
def testEmpty(self): #QObject.objectName('') name = '' obj = QObject() obj.setObjectName(name) self.assertEqual(name, obj.objectName())
def testSimple(self): #QObject.objectName(string) name = 'object1' obj = QObject() obj.setObjectName(name) self.assertEqual(name, obj.objectName())
def add_source_path_object(self): src_path = QObject(self) h_layout = QHBoxLayout(self.srcGrp) label = QLabel(f'Source_{len(self.src_path_objects)}') h_layout.addWidget(label) line_edit = QLineEdit(self.srcGrp) h_layout.addWidget(line_edit) tool_btn = QToolButton(self.srcGrp) tool_btn.setText('...') h_layout.addWidget(tool_btn) del_btn = QPushButton(self.srcGrp) del_btn.setIcon(IconRsc.get_icon('delete')) h_layout.addWidget(del_btn) del_btn.src_path = src_path del_btn.released.connect(self.remove_source_path_object) path_widget = SetDirectoryPath(self, line_edit=line_edit, tool_button=tool_btn) src_path.layout = h_layout src_path.path_widget = path_widget # Save widget in path objects list and add widget to source path layout self.src_path_objects.append(src_path) self.srcLayout.addLayout(h_layout)
def __init__(self): """ Initializes manager. """ self._widget = None self._qObject = QObject()
def testReprFunction(self): reprPen = repr(QPen()) self.assertTrue(reprPen.startswith("<PySide2.QtGui.QPen")) reprBrush = repr(QBrush()) self.assertTrue(reprBrush.startswith("<PySide2.QtGui.QBrush")) reprObject = repr(QObject()) self.assertTrue(reprObject.startswith("<PySide2.QtCore.QObject"))
def testIt(self): global called called = False o = QObject() o.connect(o, SIGNAL("ASignal()"), functools.partial(someSlot, "partial ..")) o.emit(SIGNAL("ASignal()")) self.assertTrue(called)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Create a QObject and move it to mainloop thread self._invoker = QObject() self._invoker.moveToThread(QApplication.instance().thread()) self._invoker.customEvent = self._custom_event
def testConnection(self): o = TestObject(0) c = QObject() c.setObjectName("child") self._child = None o.childrenChanged.connect(self.childrenChanged) o.addChild(c) self.assertEquals(self._child.objectName(), "child")
def testWrongType(self): '''Wrong type passed to QFlags binary operators''' self.assertRaises(TypeError, Qt.NoItemFlags | '43') self.assertRaises(TypeError, Qt.NoItemFlags & '43') self.assertRaises(TypeError, 'jabba' & Qt.NoItemFlags) self.assertRaises(TypeError, 'hut' & Qt.NoItemFlags) self.assertRaises(TypeError, Qt.NoItemFlags & QObject())
def testUtf8(self): translator = QTranslator() translator.load(os.path.join(self.trdir, 'trans_russian.qm')) self.app.installTranslator(translator) obj = QObject() obj.setObjectName(obj.tr('Hello World!')) self.assertEqual(obj.objectName(), py3k.unicode_('привет мир!'))
def testQStringDefault(self): obj = QObject() obj.setObjectName('foo') self.assertEqual(obj.objectName(), py3k.unicode_('foo')) obj.setObjectName(py3k.unicode_('áâãà')) self.assertEqual(obj.objectName(), py3k.unicode_('áâãà')) obj.setObjectName(None) self.assertEqual(obj.objectName(), py3k.unicode_(''))
def testInstallEventFilterRefCountAfterRemove(self): # Bug 910 obj = QObject() filt = QObject() self.assertEqual(sys.getrefcount(obj), 2) self.assertEqual(sys.getrefcount(filt), 2) obj.installEventFilter(filt) self.assertEqual(sys.getrefcount(obj), 2) self.assertEqual(sys.getrefcount(filt), 2) obj.removeEventFilter(filt) self.assertEqual(sys.getrefcount(obj), 2) self.assertEqual(sys.getrefcount(filt), 2) wref = weakref.ref(obj) del obj self.assertEqual(wref(), None)
def testBasic(self): '''QObject.signalsBlocked() and blockSignals() The signals aren't blocked by default. blockSignals returns the previous value''' obj = QObject() self.assert_(not obj.signalsBlocked()) self.assert_(not obj.blockSignals(True)) self.assert_(obj.signalsBlocked()) self.assert_(obj.blockSignals(False))
def testLatin(self): #Set string value to Latin translator = QTranslator() translator.load(os.path.join(self.trdir, 'trans_latin.qm')) self.app.installTranslator(translator) obj = QObject() obj.setObjectName(obj.tr('Hello World!')) self.assertEqual(obj.objectName(), py3k.unicode_('Orbis, te saluto!'))
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 testRefCount(self): o = QObject() filt = MyFilter() o.installEventFilter(filt) self.assertEqual(sys.getrefcount(o), 2) o.installEventFilter(filt) self.assertEqual(sys.getrefcount(o), 2) o.removeEventFilter(filt) self.assertEqual(sys.getrefcount(o), 2)
def test_listModel_typed_add(): m = QTypedObjectListModel(T=DummyNode) assert m.roleForName('name') != -1 node = DummyNode("DummyNode_1") m.add(node) assert m.data(m.index(0), m.roleForName('name')) == "DummyNode_1" obj = QObject() with pytest.raises(TypeError): m.add(obj)
def testSharedSignalEmission(self): o = QObject() m = MyObject() o.connect(SIGNAL("foo2()"), m.mySlot) m.connect(SIGNAL("foo2()"), m.mySlot) o.emit(SIGNAL("foo2()")) self.assertEqual(m._slotCalledCount, 1) del o m.emit(SIGNAL("foo2()")) self.assertEqual(m._slotCalledCount, 2)
def testIt(self): app = QApplication([]) self.assertEqual("<__main__.MyQObject object at ", repr(MyQObject())[:30]) self.assertEqual("<__main__.MyQWidget object at ", repr(MyQWidget())[:30]) self.assertEqual("<__main__.MyQGraphicsObject(0x", repr(MyQGraphicsObject())[:30]) self.assertEqual("<__main__.MyQGraphicsItem(0x", repr(MyQGraphicsItem())[:28]) self.assertEqual("<PySide2.QtCore.QObject object at ", repr(QObject())[:34]) self.assertEqual("<PySide2.QtCore.QObject object at ", repr(PySide2.QtCore.QObject())[:34]) self.assertEqual("<PySide2.QtWidgets.QWidget object at ", repr(QWidget())[:37]) self.assertEqual("<PySide2.QtWidgets.QGraphicsWidget(0x", repr(QGraphicsWidget())[:37])
def testDisconnectCleanup(self): for c in range(MAX_LOOPS): self._count = 0 self._senders = [] for i in range(MAX_OBJECTS): o = QObject() QObject.connect(o, SIGNAL("fire()"), lambda: self.myCB()) self._senders.append(o) o.emit(SIGNAL("fire()")) self.assertEqual(self._count, MAX_OBJECTS) #delete all senders will disconnect the signals self._senders = []
def testBasic(self): '''QObject.signalsBlocked() and blockSignals() The signals aren't blocked by default. blockSignals returns the previous value''' obj = QObject() self.assertTrue(not obj.signalsBlocked()) self.assertTrue(not obj.blockSignals(True)) self.assertTrue(obj.signalsBlocked()) self.assertTrue(obj.blockSignals(False)) blocker = QSignalBlocker(obj) self.assertTrue(obj.signalsBlocked()) blocker.unblock() self.assertTrue(not obj.signalsBlocked()) blocker.reblock() self.assertTrue(obj.signalsBlocked()) del blocker self.assertTrue(not obj.signalsBlocked())
def testIt(self): app = QApplication([]) self.assertEqual("<__main__.MyQObject object at ", repr(MyQObject())[:30]) self.assertEqual("<__main__.MyQWidget object at ", repr(MyQWidget())[:30]) self.assertEqual("<__main__.MyQGraphicsObject(this = 0x", repr(MyQGraphicsObject())[:37]) self.assertEqual("<__main__.MyQGraphicsItem(this = 0x", repr(MyQGraphicsItem())[:35]) self.assertEqual("<PySide2.QtCore.QObject object at ", repr(QObject())[:33]) self.assertEqual("<PySide2.QtCore.QObject object at ", repr(PySide2.QtCore.QObject())[:33]) self.assertEqual("<PySide2.QtGui.QWidget object at ", repr(QWidget())[:32]) self.assertEqual("<PySide2.QtGui.QGraphicsWidget(this = 0x", repr(QGraphicsWidget())[:39])
def testQFlagsOnQVariant(self): o = QObject() o.setProperty("foo", QIODevice.ReadOnly | QIODevice.WriteOnly) self.assertEqual(type(o.property("foo")), QIODevice.OpenMode)
def testQTimer(self): parent = ExtQTimer() child = QObject() child.setParent(parent) self.assertTrue(parent.child_event_received)
def testSetUnicodeRetrieveUnicode(self): #Set Python unicode string and retrieve unicode obj = QObject() obj.setObjectName(py3k.unicode_('ümlaut')) self.assertEqual(obj.objectName(), py3k.unicode_('ümlaut'))
def testSetRegularStringRetrieveUnicode(self): #Set regular Python string retrieve unicode obj = QObject() obj.setObjectName('test') self.assertEqual(obj.objectName(), py3k.unicode_('test'))
def run(self): #Start-quit sequence self.qobj = QObject() mutex.lock() self.called = True mutex.unlock()