Пример #1
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)
Пример #2
0
    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)
Пример #3
0
 def testReprFunction(self):
     reprPen = repr(QPen())
     self.assertTrue(reprPen.startswith("<PySide.QtGui.QPen"))
     reprBrush = repr(QBrush())
     self.assertTrue(reprBrush.startswith("<PySide.QtGui.QBrush"))
     reprObject = repr(QObject())
     self.assertTrue(reprObject.startswith("<PySide.QtCore.QObject"))
Пример #4
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)
Пример #5
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_(''))
Пример #6
0
    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)
Пример #7
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")
Пример #8
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())
Пример #9
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.assert_(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
Пример #10
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.trUtf8('Hello World!'))
        self.assertEqual(obj.objectName(), py3k.unicode_('привет мир!'))
Пример #11
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))
Пример #12
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!'))
 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))
Пример #14
0
    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)
Пример #15
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)
Пример #16
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 = []
Пример #17
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("<PySide.QtCore.QObject object at ",
                         repr(QObject())[:33])
        self.assertEqual("<PySide.QtCore.QObject object at ",
                         repr(PySide.QtCore.QObject())[:33])
        self.assertEqual("<PySide.QtGui.QWidget object at ",
                         repr(QWidget())[:32])
        self.assertEqual("<PySide.QtGui.QGraphicsWidget(this = 0x",
                         repr(QGraphicsWidget())[:39])
Пример #18
0
    def test_qt():
        from PySide.QtCore import QObject

        @Q_Q
        class _A(object):
            def __init__(self, q):
                pass

            def __del__(self):
                print "del B"

        class A(QObject):
            def __init__(self):
                super(A, self).__init__()
                self.__d = _A(self)

            def __del__(self):
                print "del A"

        a = A()
        b = QObject()
        #b.setParent(a)
        a = 0
Пример #19
0
 def testString(self):
     # No implicit conversions from QByteArray to python string
     ba = QByteArray("object name")
     obj = QObject()
     self.assertRaises(TypeError, obj.setObjectName, ba)
Пример #20
0
 def testDestroyed(self):
     """Emission of QObject.destroyed() to a python slot"""
     obj = QObject()
     QObject.connect(obj, SIGNAL('destroyed()'), self.destroyed_cb)
     del obj
     self.assert_(self.called)
Пример #21
0
 def run(self):
     #Start-quit sequence
     self.qobj = QObject()
     mutex.lock()
     self.called = True
     mutex.unlock()
Пример #22
0
 def testInvalidDisconnection(self):
     o = QObject()
     self.assertRaises(RuntimeError, o.destroyed.disconnect, self.callback)
Пример #23
0
 def setUp(self):
     #Acquire resources
     self.obj = QObject()
Пример #24
0
 def testSignalWithObject(self):
     o = MyObject()
     o.sig6.connect(o.slotObject)
     arg = QObject()
     o.sig6.emit(arg)
     self.assertEqual(arg, o._o)
Пример #25
0
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
State machines for the Bitmask app.
"""
import logging

from PySide import QtCore
from PySide.QtCore import QStateMachine, QState, Signal
from PySide.QtCore import QObject

from leap.bitmask.services import connections
from leap.common.check import leap_assert_type

logger = logging.getLogger(__name__)

_tr = QObject().tr

# Indexes for the state dict
_ON = "on"
_OFF = "off"
_CON = "connecting"
_DIS = "disconnecting"


class SignallingState(QState):
    """
    A state that emits a custom signal on entry.
    """
    def __init__(self, signal, parent=None, name=None):
        """
        Initializer.
Пример #26
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'))
Пример #27
0
 def testSetRegularStringRetrieveUnicode(self):
     #Set regular Python string retrieve unicode
     obj = QObject()
     obj.setObjectName('test')
     self.assertEqual(obj.objectName(), py3k.unicode_('test'))
Пример #28
0
 def testCase(self):
     o = QObject()
     o.deleteLater()
     del o
     QTimer.singleShot(100, self.app.quit)
     self.app.exec_()
Пример #29
0
 def testQTimer(self):
     parent = ExtQTimer()
     child = QObject()
     child.setParent(parent)
     self.assert_(parent.child_event_received)
Пример #30
0
 def testQObject(self):
     parent = ExtQObject()
     child = QObject()
     child.setParent(parent)
     self.assertTrue(parent.child_event_received)