Esempio n. 1
0
 def subsizer_item():
     vsizer = wx.BoxSizer(wx.VERTICAL)
     assert sip.ispyowned(vsizer)
     item = s.Add(vsizer)
     assert not sip.ispyowned(vsizer)
     assert s.Detach(vsizer)
     return item
Esempio n. 2
0
 def subsizer_item():
     vsizer = wx.BoxSizer(wx.VERTICAL)
     assert sip.ispyowned(vsizer)
     item = s.Add(vsizer)
     assert not sip.ispyowned(vsizer)
     assert s.Detach(vsizer)
     return item
Esempio n. 3
0
 def subsizer():
     subsizer = wx.BoxSizer(wx.HORIZONTAL)
     assert sip.ispyowned(subsizer)
     s.Add(subsizer)
     assert not sip.ispyowned(subsizer)
     assert s.Detach(subsizer)
     assert sip.ispyowned(subsizer)
     return subsizer
Esempio n. 4
0
 def subsizer():
     subsizer = wx.BoxSizer(wx.HORIZONTAL)
     assert sip.ispyowned(subsizer)
     s.Add(subsizer)
     assert not sip.ispyowned(subsizer)
     assert s.Detach(subsizer)
     assert sip.ispyowned(subsizer)
     return subsizer
Esempio n. 5
0
def assert_ownership(factory, pyowned = True):
    '''
    Given callable "factory" which returns an object, asserts that the
    ownership lies with Python if pyowned is True, else with C++.
    '''
    # create both a strong and a weak reference to the object
    # returned by 'factory'
    obj = factory()
    weak_obj = weakref.ref(obj)

    # use sip.ispyowned(obj) to check ownership trivially
    if SIP:
        assert pyowned == sip.ispyowned(obj)

    # delete the strong reference and collect any garbage
    del obj
    gc.collect()

    obj = weak_obj()
    if pyowned:
        # make sure the weak reference is dead
        assert obj is None
    else:
        # make sure the weak reference is alive
        assert obj is not None
Esempio n. 6
0
    def __del__(self: QObject):
        # Note: This is otherwise quite similar to how PyQt5 does this except
        # for the resurrection (i.e. the wrapper is allowed to be freed, but
        # C++ part is deleteLater-ed).
        if sip.ispyowned(self):
            try:
                own_thread = self.thread() is QThread.currentThread()
            except RuntimeError:
                return
            if not own_thread:
                # object resurrection; keep python wrapper alive and schedule
                # deletion from the object's own thread.
                PyOwned.__delete_later_set.add(self)
                ref = weakref.ref(self)

                # Clear final ref from 'destroyed' signal. As late as possible
                # in QObject' destruction.
                def clear():
                    self = ref()
                    try:
                        PyOwned.__delete_later_set.remove(self)
                    except KeyError:
                        pass

                self.destroyed.connect(clear, Qt.DirectConnection)
                self.deleteLater()
Esempio n. 7
0
def assert_ownership(factory, pyowned=True):
    '''
    Given callable "factory" which returns an object, asserts that the
    ownership lies with Python if pyowned is True, else with C++.
    '''
    # create both a strong and a weak reference to the object
    # returned by 'factory'
    obj = factory()
    weak_obj = weakref.ref(obj)

    # use sip.ispyowned(obj) to check ownership trivially
    if SIP:
        assert pyowned == sip.ispyowned(obj)

    # delete the strong reference and collect any garbage
    del obj
    gc.collect()

    obj = weak_obj()
    if pyowned:
        # make sure the weak reference is dead
        assert obj is None
    else:
        # make sure the weak reference is alive
        assert obj is not None
Esempio n. 8
0
 def test_ownership(self):
     f = wx.Frame(None)
     p = PlatformMessageBinder.ForWindow(f)
     assert not sip.ispyowned(p)
     f.Destroy()
     del f
     wx.GetApp().ProcessIdle()
     gc.collect()
Esempio n. 9
0
def test_GridBagSizer():
    f = wx.Frame(None, -1, 'Test')

    s = f.Sizer = wx.GridBagSizer()

    positions = [
        (0, 0),
        (0, 2),
        (1, 0),
    ]
    spans = [
        (1, 2),
        (1, 1),
        (1, 1),
    ]
    buttons = [
        wx.Button(f, -1, 'button %d' % n) for n in xrange(len(positions))
    ]

    def on_button(e):
        e.EventObject.Destroy()

    f.Bind(wx.EVT_BUTTON, on_button)

    sizer = f.Sizer = wx.GridBagSizer()

    sizer_items = []

    for n, (pos, span) in enumerate(izip(positions, spans)):
        button = buttons[n]
        res = sizer.Add(button, pos, span)

        assert isinstance(res, wx.GBSizerItem) and isinstance(
            res, wx.SizerItem)
        assert res.Pos == res.GetPos() == pos
        assert res.Span == res.GetSpan() == span

        #assert res == sizer.FindItemAtPosition(pos), "%r != %r" % \
        #    (res, sizer.FindItemAtPosition(pos))

        assert res is not None
        assert not ispyowned(res)

        # GetItemPosition
        p1, p2 = sizer.GetItemPosition(button), sizer.GetItemPosition(n)
        assert p1 == p2 == pos
        assert p1.Row == p2.Row == pos[0] != (321321, 321321)
        assert p1.Col == p2.Col == pos[1] != (321321, 321321)

        # GetItemSpan
        s1, s2 = sizer.GetItemSpan(button), sizer.GetItemSpan(n)
        assert s1 == s2 == span
        assert s1.Rowspan == s2.Rowspan == span[0]
        assert s1.Colspan == s2.Colspan == span[1]

    sizer.Layout()
    f.Destroy()
Esempio n. 10
0
def test_GridBagSizer():
    f = wx.Frame(None, -1, 'Test')

    s = f.Sizer = wx.GridBagSizer()

    positions = [(0, 0), (0, 2), (1, 0),]
    spans     = [(1, 2), (1, 1), (1, 1),]
    buttons   = [wx.Button(f, -1, 'button %d' % n)
                 for n in xrange(len(positions))]

    def on_button(e):
        e.EventObject.Destroy()

    f.Bind(wx.EVT_BUTTON, on_button)

    sizer = f.Sizer = wx.GridBagSizer()

    sizer_items = []

    for n, (pos, span) in enumerate(izip(positions, spans)):
        button = buttons[n]
        res = sizer.Add(button, pos, span)

        assert isinstance(res, wx.GBSizerItem) and isinstance(res, wx.SizerItem)
        assert res.Pos  == res.GetPos()  == pos
        assert res.Span == res.GetSpan() == span

        #assert res == sizer.FindItemAtPosition(pos), "%r != %r" % \
        #    (res, sizer.FindItemAtPosition(pos))

        assert res is not None
        assert not ispyowned(res)

        # GetItemPosition
        p1, p2 = sizer.GetItemPosition(button), sizer.GetItemPosition(n)
        assert p1 == p2 == pos
        assert p1.Row == p2.Row == pos[0] != (321321,321321)
        assert p1.Col == p2.Col == pos[1] != (321321,321321)

        # GetItemSpan
        s1, s2 = sizer.GetItemSpan(button), sizer.GetItemSpan(n)
        assert s1 == s2 == span
        assert s1.Rowspan == s2.Rowspan == span[0]
        assert s1.Colspan == s2.Colspan == span[1]


    sizer.Layout()
    f.Destroy()
Esempio n. 11
0
    def foo():
        s = blist.BuddyListSorter()
        s.addSorter(blist.ByFakeRoot('Contacts'))
        s.addSorter(blist.ByGroup(True, 2))
        #        s.addSorter(blist.ByMobile(False))
        #        s.addSorter(blist.ByOnline(False))
        p = Protocol('aim', 'digsby01')
        root = Group(
            'root',
            p,
            'root',
            Group('root1', p, 'root1', Group('Contacts', p, 'subgroup'),
                  Buddy('abc', p)),
        )

        root_ref = ref(root)
        proto_ref = ref(p)
        sorter_ref = ref(s)

        s.set_root(root)

        gathered = s._gather()
        gathered_ref = ref(gathered)

        protocols, ids = gathered._protocol_ids
        #assert protocols == [p]
        #assert ids == ['root'], repr(ids)

        assert not sip.ispyowned(gathered)
        s._done_gather(gathered)
        del gathered
        del s
        del protocols, ids

        del p, root

        assert root_ref() is None
        assert proto_ref() is None

        assert sorter_ref() is None
        assert gathered_ref() is None
        '''
Esempio n. 12
0
    def foo():
        s = blist.BuddyListSorter()
        s.addSorter(blist.ByFakeRoot('Contacts'))
        s.addSorter(blist.ByGroup(True, 2))
#        s.addSorter(blist.ByMobile(False))
#        s.addSorter(blist.ByOnline(False))
        p = Protocol('aim', 'digsby01')
        root = Group('root', p, 'root',
                Group('root1', p, 'root1',
                    Group('Contacts', p, 'subgroup'),
                    Buddy('abc', p)),
                    )

        root_ref = ref(root)
        proto_ref = ref(p)
        sorter_ref = ref(s)

        s.set_root(root)

        gathered = s._gather()
        gathered_ref = ref(gathered)

        protocols, ids = gathered._protocol_ids
        #assert protocols == [p]
        #assert ids == ['root'], repr(ids)

        assert not sip.ispyowned(gathered)
        s._done_gather(gathered)
        del gathered
        del s
        del protocols, ids

        del p, root

        assert root_ref() is None
        assert proto_ref() is None

        assert sorter_ref() is None
        assert gathered_ref() is None

        '''
Esempio n. 13
0
    def sizer_children():
        f = wx.Frame(None)
        p = wx.Panel(f)
        f.Sizer = s = wx.BoxSizer(wx.HORIZONTAL)

        assert s.Add(p)

        item = s.Children[0]
        assert p is item.Window
        assert not sip.ispyowned(item)
        del item
        gc.collect()
        assert not sip.isdeleted(p)

        assert 1 == len(s.Children)
        s.Detach(0)
        assert 0 == len(p.Children)

        f.Destroy()

        wx.GetApp().ProcessIdle()
        return f, s, p
Esempio n. 14
0
    def sizer_children():
        f = wx.Frame(None)
        p = wx.Panel(f)
        f.Sizer = s = wx.BoxSizer(wx.HORIZONTAL)

        assert s.Add(p)

        item = s.Children[0]
        assert p is item.Window
        assert not sip.ispyowned(item)
        del item
        gc.collect()
        assert not sip.isdeleted(p)

        assert 1 == len(s.Children)
        s.Detach(0)
        assert 0 == len(p.Children)

        f.Destroy()

        wx.GetApp().ProcessIdle()
        return f, s, p
Esempio n. 15
0
def test_WindowSetSizer():
    f = wx.Frame(None)
    assert not sip.ispyowned(f)

    b = wx.Button(f, -1, 'test')

    s1 = wx.BoxSizer(wx.HORIZONTAL)
    f.SetSizer(s1)
    assert f.Sizer is s1
    s1.AddStretchSpacer(1)
    s1.Add(b)

    s2 = wx.BoxSizer(wx.VERTICAL)
    f.SetSizer(s2)
    assert f.Sizer is s2
    s2.AddStretchSpacer(1)
    s2.Add(b)

    assert not sip.isdeleted(b)
    assert sip.isdeleted(s1)
    f.Destroy()

    wx.GetApp().ProcessIdle()
    assert sip.isdeleted(f)
Esempio n. 16
0
def test_WindowSetSizer():
    f = wx.Frame(None)
    assert not sip.ispyowned(f)

    b = wx.Button(f, -1, 'test')

    s1 = wx.BoxSizer(wx.HORIZONTAL)
    f.SetSizer(s1)
    assert f.Sizer is s1
    s1.AddStretchSpacer(1)
    s1.Add(b)

    s2 = wx.BoxSizer(wx.VERTICAL)
    f.SetSizer(s2)
    assert f.Sizer is s2
    s2.AddStretchSpacer(1)
    s2.Add(b)

    assert not sip.isdeleted(b)
    assert sip.isdeleted(s1)
    f.Destroy()

    wx.GetApp().ProcessIdle()
    assert sip.isdeleted(f)
Esempio n. 17
0
 def test_ownership(self):
     f = wx.Frame(None)
     p = PlatformMessageBinder.ForWindow(f)
     assert not sip.ispyowned(p)
     f.Destroy(); del f; wx.GetApp().ProcessIdle(); gc.collect()
Esempio n. 18
0
def test_add_transfers():
    t = wx.TextDataObject('test')
    data = wx.DataObjectComposite()
    data.Add(t)
    assert not sip.ispyowned(t)
Esempio n. 19
0
    def test_sorter_ownership(self):
        s = blist.BuddyListSorter()
        b = blist.ByGroup()
        s.addSorter(b)

        assert not sip.ispyowned(b)
Esempio n. 20
0
    def test_sorter_ownership(self):
        s = blist.BuddyListSorter()
        b = blist.ByGroup()
        s.addSorter(b)

        assert not sip.ispyowned(b)
Esempio n. 21
0
def test_scope():
    s = wx.StockGDI.instance()
    assert not sip.ispyowned(s)
    assert_ownership(wx.StockGDI.instance, pyowned = False)
    import gc
    gc.collect()
Esempio n. 22
0
print(type(cc.verts))
print(cc.n_verts)
print(cc.verts)

# v0 = numpy.fromiter(cc.verts , dtype=numpy.float32, count = cc.n_verts)
#print(v0)

re = c.re().asarray(cc.n_verts)
#print(dir(re))
print("forward")
print(re[0])
print(re[1])
print(re[2])
print(re[3])
print("backward")
print(re[0])
print(re[-1])
print(re[-2])
print(re[-3])
print("sdg")
print(re.__getitem__(0))

print(sip.ispyowned(cc)) # True







                dtype=numpy.int32)

c = connectedComponentsComputation.ConnectedComponentsComputation()
c.compute(v[0:8].tostring(), 8, f[0:8].tostring(), 8)

cc = c.getComponent(0)

print(type(cc.verts))
print(cc.n_verts)
print(cc.verts)

# v0 = numpy.fromiter(cc.verts , dtype=numpy.float32, count = cc.n_verts)
#print(v0)

re = c.re().asarray(cc.n_verts)
#print(dir(re))
print("forward")
print(re[0])
print(re[1])
print(re[2])
print(re[3])
print("backward")
print(re[0])
print(re[-1])
print(re[-2])
print(re[-3])
print("sdg")
print(re.__getitem__(0))

print(sip.ispyowned(cc))  # True
Esempio n. 24
0
def test_add_transfers():
    t = wx.TextDataObject('test')
    data = wx.DataObjectComposite()
    data.Add(t)
    assert not sip.ispyowned(t)