1
2 """
3 Interface for items that adquire resources.
4 """
5 from Util import find_if
6
8 """
9 Represents an entity that holds connections to other objects that
10 should be explicitly cleared to avoid object lifetime problems or
11 leaking listeners.
12 """
13
16
17
19 """
20 Compound disconnectable. Collects other disconnectables and
21 disconnects them recursively.
22 """
23
27
29 if slot not in self._registered_disconnectables:
30 self._registered_disconnectables.append(slot)
31 return slot
32
34 if slot in self._registered_disconnectables:
35 self._registered_disconnectables.remove(slot)
36
38 if slot in self._registered_disconnectables:
39 self._registered_disconnectables.remove(slot)
40 slot.disconnect()
41
43 return find_if(predicate, self._registered_disconnectables)
44
46 return slot in self._registered_disconnectables
47
54
55
57 """
58 Context manager that will disconnect the given disconnectable when
59 the context is exited. It returns the original disconnectable.
60 """
61
62 - def __init__(self, managed = None, *a, **k):
65
67 managed = self._managed
68 return managed
69
71 if self._managed is not None:
72 self._managed.disconnect()
73