Example #1
0
def test_live_atomref():
    """Test a live atomref."""
    atom = Atom()
    ref = atomref(atom)

    assert ref is atomref(atom)
    assert ref and ref() is atom
    assert "AtomRef" in repr(ref)

    ref.__sizeof__()

    with pytest.raises(TypeError):
        atomref(object())
Example #2
0
def test_live_atomref():
    """Test a live atomref.

    """
    atom = Atom()
    ref = atomref(atom)

    assert ref is atomref(atom)
    assert ref and ref() is atom
    assert 'AtomRef' in repr(ref)

    ref.__sizeof__()

    with pytest.raises(TypeError):
        atomref(object())
Example #3
0
    def init_widget(self):
        widget = self.widget

        # Save a reference so we can retrieve the QtGraphicsItem
        # from the QGraphicsItem
        widget.ref = atomref(self)

        focus_registry.register(widget, self)
        d = self.declaration
        self._extra_features = d.extra_features
        self._setup_features()

        if d.selectable:
            self.set_selectable(d.selectable)
        if d.movable:
            self.set_movable(d.movable)
        if d.tool_tip:
            self.set_tool_tip(d.tool_tip)
        if d.status_tip:
            self.set_status_tip(d.status_tip)
        if not d.enabled:
            self.set_enabled(d.enabled)
        if not d.visible:
            self.set_visible(d.visible)
        if d.opacity != 1:
            self.set_opacity(d.opacity)
        if d.rotation:
            self.set_rotation(d.rotation)
        if d.scale != 1:
            self.set_scale(d.scale)
        self.set_position(d.position)
        self.hook_item_change()
Example #4
0
def test_list_traversal(model, kind):
    """Test traversing atom lists.

    We also test breaking reference cycles between the list and its inner
    attributes.

    """
    m = model()
    l = getattr(m, kind)
    l.append(m)

    referents = []
    if model is CyclicContainerModel:
        referents.append(getattr(model, kind))
    if kind == 'typed':
        referents.append(getattr(model, kind).item)
    referents.append(m)

    assert gc.get_referents(l) == referents

    ref = atomref(m)
    del m, l, referents
    gc.collect()
    if ref():
        print(gc.get_referents(ref()))
    assert not ref()
Example #5
0
def test_list_traversal(model, kind):
    """Test traversing atom lists.

    We also test breaking reference cycles between the list and its inner
    attributes.

    """
    m = model()
    l1 = getattr(m, kind)
    l1.append(m)

    referents = []
    if model is CyclicContainerModel:
        referents.append(getattr(model, kind))
    if kind == "typed":
        referents.append(getattr(model, kind).item)
    referents.append(m)
    # Under Python 3.9+ heap allocated type instance keep a reference to the
    # type
    if version_info >= (3, 9):
        referents.append(
            atomclist if model is CyclicContainerModel else atomlist)

    assert Counter(gc.get_referents(l1)) == Counter(referents)

    ref = atomref(m)
    del m, l1, referents
    gc.collect()
    if ref():
        print(gc.get_referents(ref()))
    assert not ref()
Example #6
0
def test_dead_atomref():
    """Test a dead atomref."""
    atom = Atom()
    ref = atomref(atom)
    del atom
    gc.collect()

    assert not ref and ref() is None
    assert "AtomRef" in repr(ref)

    ref.__sizeof__()
Example #7
0
    def __init__(self, manager):
        """ Initialize a DockContainerMonitor.

        Parameters
        ----------
        mananger : DockManager
            The manager which owns this monitor. Only an atomref will
            be maintained to the manager.

        """
        super(DockContainerMonitor, self).__init__()
        self._manager = atomref(manager)
Example #8
0
    def __init__(self, manager):
        """ Initialize a DockContainerMonitor.

        Parameters
        ----------
        mananger : DockManager
            The manager which owns this monitor. Only an atomref will
            be maintained to the manager.

        """
        super(DockContainerMonitor, self).__init__()
        self._manager = atomref(manager)
Example #9
0
def test_dead_atomref():
    """Test a dead atomref.

    """
    atom = Atom()
    ref = atomref(atom)
    del atom
    gc.collect()

    assert not ref and ref() is None
    assert 'AtomRef' in repr(ref)

    ref.__sizeof__()
    def init_widget(self):
        """ Initialize the state of the toolkit widget.

        This method is called during the top-down pass, just after the
        'create_widget()' method is called. This method should init the
        state of the widget. The child widgets will not yet be created.

        """
        widget = self.widget
        d = self.declaration

        #: Save ref id
        ref = d.ref
        CACHE[ref] = atomref(self)
        widget.set('ref', ref)

        if d.text:
            self.set_text(d.text)
        if d.tail:
            self.set_tail(d.tail)
        if d.style:
            self.set_style(d.style)
        if d.cls:
            self.set_cls(d.cls)
        if d.attrs:
            self.set_attrs(d.attrs)
        if d.id:
            widget.set('id', d.id)
        if d.draggable:
            self.set_draggable(d.draggable)

        # Set any attributes that may be defined
        for name, member in d.members().items():
            if not member.metadata:
                continue
            meta = member.metadata

            # Exclude any attr tags
            if not (meta.get('d_member') and meta.get('d_final')):
                continue

            # Skip any items with attr=false
            elif not meta.get('attr', True):
                continue

            elif isinstance(member, Event):
                continue
            value = getattr(d, name)
            if value:
                self.set_attribute(name, value)
Example #11
0
    def __init__(self, owner, name):
        """ Initialize a SubscriptionObserver.

        Parameters
        ----------
        owner : Declarative
            The declarative owner of interest.

        name : string
            The name to which the operator is bound.

        """
        self.ref = atomref(owner)
        self.name = name
Example #12
0
    def __init__(self, proxy, parent=None):
        """ Initialize a QCustomDockItem.

        Parameters
        ----------
        proxy : QtDockItem
            The proxy object which owns this dock item. Only an atomref
            will be maintained to this object.

        parent : QWidget, optional
            The parent of the window.
        """
        super(QCustomDockItem, self).__init__(parent)
        self._proxy_ref = atomref(proxy)
Example #13
0
def test_traverse_atom():
    """Test that we can break reference cycles involving Atom object."""
    class MyAtom(Atom):

        val = Value()

    a = MyAtom()
    l1 = list()
    a.val = l1
    a.val.append(a)

    ref = atomref(a)
    del a, l1
    gc.collect()

    assert not ref()
Example #14
0
    def __init__(self, proxy, parent, flags=QtCore.Qt.Widget):
        """ Initialize a QWindowDialog.
 
         Parameters
         ----------
         parent : QWidget, optional
             The parent of the dialog.
        """
        super(QWindowDialog, self).__init__(parent, flags)
        # PySide2 segfaults
        self._proxy_ref = None if QT_API in 'pyside2' else atomref(proxy)
        self._expl_min_size = QtCore.QSize()
        self._expl_max_size = QtCore.QSize()
        layout = QWindowLayout()
        layout.setSizeConstraint(QtWidgets.QLayout.SetMinAndMaxSize)
        self.setLayout(layout)
Example #15
0
    def __init__(self, proxy, parent, flags=QtCore.Qt.Widget):
        """ Initialize a QWindowDialog.
 
         Parameters
         ----------
         parent : QWidget, optional
             The parent of the dialog.
        """
        super(QWindowDialog, self).__init__(parent, flags)
        # PySide2 segfaults
        self._proxy_ref = None if QT_API in 'pyside2' else atomref(proxy)
        self._expl_min_size = QtCore.QSize()
        self._expl_max_size = QtCore.QSize()
        layout = QWindowLayout()
        layout.setSizeConstraint(QtWidgets.QLayout.SetMinAndMaxSize)
        self.setLayout(layout)
Example #16
0
    def __init__(self, proxy, parent=None, flags=Qt.Widget):
        """ Initialize a QWindowDialog.

        Parameters
        ----------
        proxy : QtDialog
            The proxy object which owns this dialog. Only an atomref
            will be maintained to this object.

        parent : QWidget, optional
            The parent of the dialog.

        flags : Qt.WindowFlags, optional
            The window flags to pass to the parent constructor.

        """
        super(QWindowDialog, self).__init__(parent, flags)
        self._proxy_ref = atomref(proxy)
Example #17
0
    def __init__(self, proxy, parent=None, flags=Qt.Widget):
        """ Initialize a QWindow.

        Parameters
        ----------
        proxy : QtWindow
            The proxy object which owns this window. Only an atomref
            will be maintained to this object.

        parent : QWidget, optional
            The parent of the window.

        flags : Qt.WindowFlags, optional
            The window flags to pass to the parent constructor.

        """
        super(QWindow, self).__init__(parent, Qt.Window | flags)
        self._proxy_ref = atomref(proxy)
Example #18
0
def test_traverse():
    """Test traversing on deletion."""
    class Holder(Atom):

        smap = Value()

    h = Holder()
    smap = sortedmap()

    # Create a reference cycle
    h.smap = smap
    smap[1] = h

    # Create a weakref to check that the objects involved in teh cycle are
    # collected
    ref = atomref(h)

    del smap, h
    gc.collect()

    assert not ref()
Example #19
0
    def __init__(self, proxy, parent=None, flags=Qt.Widget):
        """ Initialize a QWindowDialog.

        Parameters
        ----------
        proxy : QtDialog
            The proxy object which owns this dialog. Only an atomref
            will be maintained to this object.

        parent : QWidget, optional
            The parent of the dialog.

        flags : Qt.WindowFlags, optional
            The window flags to pass to the parent constructor.

        """
        super().__init__(parent, flags)
        self._expl_min_size = QSize()
        self._expl_max_size = QSize()
        layout = QWindowLayout()
        layout.setSizeConstraint(QLayout.SetMinAndMaxSize)
        self.setLayout(layout)
        self._proxy_ref = atomref(proxy)
Example #20
0
def test_traverse():
    """Test traversing on deletion.

    """

    class Holder(Atom):

        smap = Value()

    h = Holder()
    smap = sortedmap()

    # Create a reference cycle
    h.smap = smap
    smap[1] = h

    # Create a weakref to check that the objects involved in teh cycle are
    # collected
    ref = atomref(h)

    del smap, h
    gc.collect()

    assert not ref()