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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
    def testEmpty(self):
        #QObject.objectName('')
        name = ''
        obj = QObject()
        obj.setObjectName(name)

        self.assertEqual(name, obj.objectName())
Exemplo n.º 5
0
    def testSimple(self):
        #QObject.objectName(string)
        name = 'object1'
        obj = QObject()
        obj.setObjectName(name)

        self.assertEqual(name, obj.objectName())
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    def __init__(self):
        """
        Initializes manager.

        """
        self._widget = None
        self._qObject = QObject()
Exemplo n.º 8
0
 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"))
Exemplo n.º 9
0
 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)
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
 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")
Exemplo n.º 12
0
    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())
Exemplo n.º 13
0
    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_('привет мир!'))
Exemplo n.º 14
0
 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)
Exemplo n.º 16
0
 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))
Exemplo n.º 17
0
    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!'))
Exemplo n.º 18
0
 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))
Exemplo n.º 19
0
    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)
Exemplo n.º 20
0
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)
Exemplo n.º 22
0
    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])
Exemplo n.º 23
0
    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 = []
Exemplo n.º 24
0
 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())
Exemplo n.º 25
0
    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])
Exemplo n.º 26
0
 def testQFlagsOnQVariant(self):
     o = QObject()
     o.setProperty("foo", QIODevice.ReadOnly | QIODevice.WriteOnly)
     self.assertEqual(type(o.property("foo")), QIODevice.OpenMode)
Exemplo n.º 27
0
 def testQTimer(self):
     parent = ExtQTimer()
     child = QObject()
     child.setParent(parent)
     self.assertTrue(parent.child_event_received)
Exemplo n.º 28
0
 def testSetUnicodeRetrieveUnicode(self):
     #Set Python unicode string and retrieve unicode
     obj = QObject()
     obj.setObjectName(py3k.unicode_('ümlaut'))
     self.assertEqual(obj.objectName(), py3k.unicode_('ümlaut'))
Exemplo n.º 29
0
 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()