當前位置: 首頁>>代碼示例>>Python>>正文


Python sample.ObjectType類代碼示例

本文整理匯總了Python中sample.ObjectType的典型用法代碼示例。如果您正苦於以下問題:Python ObjectType類的具體用法?Python ObjectType怎麽用?Python ObjectType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ObjectType類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testReparentWithTheSameParent

 def testReparentWithTheSameParent(self):
     '''Set the same parent twice to check if the ref continue the same'''
     obj = ObjectType()
     parent = ObjectType()
     self.assertEqual(sys.getrefcount(obj), 2)
     obj.setParent(parent)
     self.assertEqual(sys.getrefcount(obj), 3)
     obj.setParent(parent)
     self.assertEqual(sys.getrefcount(obj), 3)
開發者ID:BadSingleton,項目名稱:shiboken2,代碼行數:9,代碼來源:ownership_reparenting_test.py

示例2: testDeleteChild

    def testDeleteChild(self):
        '''Delete child in python should not invalidate child'''
        parent = ObjectType()
        child = ObjectType(parent)
        name = ''.join(random.sample(string.letters, 5))
        child.setObjectName(name)

        del child
        new_child = parent.children()[0]
        self.assertEqual(new_child.objectName(), name)
開發者ID:BadSingleton,項目名稱:shiboken2,代碼行數:10,代碼來源:ownership_delete_child_in_python_test.py

示例3: testObjectTypeReferenceAndPointer

 def testObjectTypeReferenceAndPointer(self):
     '''In C++ we have "function(const ObjectType&, int)",
     in Python we add "function(ValueType)".'''
     obj = ObjectType()
     obj.setObjectName('sbrubbles')
     multiplier = 3.0
     control = len(obj.objectName()) * multiplier
     self.assertEqual(SampleNamespace.passReferenceToObjectType(obj, multiplier), control)
     control = len(obj.objectName())
     self.assertEqual(SampleNamespace.passReferenceToObjectType(obj), control)
開發者ID:Hasimir,項目名稱:Shiboken,代碼行數:10,代碼來源:addedfunction_test.py

示例4: testParentDestructor

    def testParentDestructor(self):
        '''Delete parent object should invalidate child'''
        parent = ObjectType()
        child = ObjectType()
        child.setParent(parent)

        refcount_before = sys.getrefcount(child)

        del parent
        self.assertRaises(RuntimeError, child.objectName)
        self.assertEqual(sys.getrefcount(child), refcount_before-1)
開發者ID:BadSingleton,項目名稱:shiboken2,代碼行數:11,代碼來源:ownership_delete_parent_test.py

示例5: testReparentedObjectTypeIdentityWithChildrenCreatedInCpp

 def testReparentedObjectTypeIdentityWithChildrenCreatedInCpp(self):
     '''Reparent children created in C++ from one parent to another.'''
     object_list = []
     old_parent = ObjectType()
     new_parent = ObjectType()
     for i in range(3):
         obj = ObjectType.create()
         object_list.append(obj)
         obj.setParent(old_parent)
     for obj in object_list:
         obj.setParent(new_parent)
     for child in new_parent.children():
         self.assert_(child in object_list)
開發者ID:BadSingleton,項目名稱:shiboken2,代碼行數:13,代碼來源:ownership_reparenting_test.py

示例6: testDeleteChild

    def testDeleteChild(self):
        '''Delete child in C++ should invalidate child - using C++ wrapper'''
        parent = ObjectType()
        parent.setObjectName('parent')
        child = ObjectType(parent)
        child.setObjectName('child')

        parent.killChild('child')
        self.assertRaises(RuntimeError, child.objectName)
        self.assertEqual(parent.objectName(), 'parent')
開發者ID:BadSingleton,項目名稱:shiboken2,代碼行數:10,代碼來源:ownership_delete_child_in_cpp_test.py

示例7: testNextInFocusChainCycleList

    def testNextInFocusChainCycleList(self):
        '''As above but in for a list of objects'''
        parents = []
        children = []
        focus_chains = []
        for i in range(10):
            parent = ObjectType()
            child = ObjectType(parent)
            next_focus = child.nextInFocusChain()
            parents.append(parent)
            children.append(child)
            focus_chains.append(next_focus)

        shiboken.invalidate(parents)
開發者ID:OpenGeoscience,項目名稱:shiboken,代碼行數:14,代碼來源:objecttype_test.py

示例8: testCpp

    def testCpp(self):
        '''C++ calling C++ virtual method in multiple inheritance scenario'''
        obj = ImplementsNone()
        self.assert_(ObjectType.processEvent([obj], Event(Event.BASIC_EVENT)))
        self.assertRaises(AttributeError, getattr, obj, 'event_processed')

        self.assertEqual(obj.callSum0(1, 2, 3), 6)
開發者ID:Hasimir,項目名稱:Shiboken,代碼行數:7,代碼來源:mi_virtual_methods_test.py

示例9: testEvent

    def testEvent(self):
        '''C++ calling Python reimplementation of virtual in multiple inheritance'''
        obj = ImplementsBoth()
        self.assert_(ObjectType.processEvent([obj], Event(Event.BASIC_EVENT)))
        self.assert_(obj.event_processed)

        self.assertEqual(obj.callSum1(1, 2, 3), 12)
開發者ID:Hasimir,項目名稱:Shiboken,代碼行數:7,代碼來源:mi_virtual_methods_test.py

示例10: testOwnershipTransferenceCppCreated

 def testOwnershipTransferenceCppCreated(self):
     '''Ownership transference using a C++ created object.'''
     o1 = ObjectType.create()
     o1.setObjectName('object1')
     o1_refcnt = sys.getrefcount(o1)
     bb = BlackBox()
     o1_ticket = bb.keepObjectType(o1)
     self.assertRaises(RuntimeError, o1.objectName)
開發者ID:Hasimir,項目名稱:Shiboken,代碼行數:8,代碼來源:ownership_transference_test.py

示例11: testEventLoop

    def testEventLoop(self):
        '''Calling virtuals in a event loop'''
        objs = [ObjectType(), NoOverride(), Override()]

        evaluated = ObjectType.processEvent(objs,
                                        Event(Event.BASIC_EVENT))

        self.assertEqual(evaluated, 3)
        self.assert_(objs[2].called)
開發者ID:BadSingleton,項目名稱:shiboken2,代碼行數:9,代碼來源:event_loop_call_virtual_test.py

示例12: testUseDefaultValues

    def testUseDefaultValues(self):
        o = ObjectType()

        o.setObjectNameWithSize(size=3)
        self.assertEqual(o.objectName(), "<un") # use name='unknown' default argument

        o.setObjectSplittedName("")
        self.assertEqual(o.objectName(), "<unknown>") # user prefix='<unk' and suffix='nown>'
開發者ID:Hasimir,項目名稱:Shiboken,代碼行數:8,代碼來源:objecttype_with_named_args_test.py

示例13: testBasic

    def testBasic(self):
        '''Allowing threads and calling virtuals from C++'''
        number = 10
        objs = [Producer() for x in range(number)]
        thread = Collector(objs)

        thread.start()

        evaluated = ObjectType.processEvent(objs,
                                        Event(Event.BASIC_EVENT))

        thread.join()

        producer_data = [x.data for x in objs]
        self.assertEqual(evaluated, number)
        self.assertEqual(producer_data, thread.data)
開發者ID:BadSingleton,項目名稱:shiboken2,代碼行數:16,代碼來源:event_loop_thread_test.py

示例14: testOwnershipTransference

 def testOwnershipTransference(self):
     '''Ownership transference from Python to C++ and back again.'''
     o1 = ObjectType()
     o1.setObjectName('object1')
     o1_refcnt = sys.getrefcount(o1)
     o2 = ObjectType()
     o2.setObjectName('object2')
     o2_refcnt = sys.getrefcount(o2)
     bb = BlackBox()
     o1_ticket = bb.keepObjectType(o1)
     o2_ticket = bb.keepObjectType(o2)
     self.assertEqual(set(bb.objects()), set([o1, o2]))
     self.assertEqual(str(o1.objectName()), 'object1')
     self.assertEqual(str(o2.objectName()), 'object2')
     self.assertEqual(sys.getrefcount(o1), o1_refcnt + 1) # PySide give +1 ref to object with c++ ownership
     self.assertEqual(sys.getrefcount(o2), o2_refcnt + 1)
     o2 = bb.retrieveObjectType(o2_ticket)
     self.assertEqual(sys.getrefcount(o2), o2_refcnt)
     del bb
     self.assertRaises(RuntimeError, o1.objectName)
     self.assertEqual(str(o2.objectName()), 'object2')
     self.assertEqual(sys.getrefcount(o2), o2_refcnt)
開發者ID:Hasimir,項目名稱:Shiboken,代碼行數:22,代碼來源:ownership_transference_test.py

示例15: testInvalidateChild

    def testInvalidateChild(self):
        '''Invalidating method call should remove child from the care of a parent if it has one.'''
        parent = ObjectType()
        child1 = ObjectType(parent)
        child1.setObjectName('child1')
        child2 = ObjectType.create()
        child2.setParent(parent)
        child2.setObjectName('child2')

        self.assertEqual(parent.children(), [child1, child2])

        bbox = BlackBox()

        # This method steals ownership from Python to C++.
        bbox.keepObjectType(child1)
        self.assertEqual(parent.children(), [child2])

        bbox.keepObjectType(child2)
        self.assertEqual(parent.children(), [])

        del parent

        self.assertEqual(child1.objectName(), 'child1')
        self.assertRaises(RuntimeError, child2.objectName)
開發者ID:Hasimir,項目名稱:Shiboken,代碼行數:24,代碼來源:ownership_invalidate_child_test.py


注:本文中的sample.ObjectType類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。