Parent and Child relationship is working. If the parent is closed its children will be closed too.
But the child's children not (in this version). The parent knows about its children in self.children list variable. The child knows about its parent in self.parent variable. When a child is closed the its id will be removed its parent (self.children) list variable.main
parent
346c22193d
commit
4965e87980
|
|
@ -33,6 +33,10 @@ class CallHandler(QObject):
|
||||||
new_id = base.sights.create(id, type)
|
new_id = base.sights.create(id, type)
|
||||||
if new_id is not None:
|
if new_id is not None:
|
||||||
base.sights.show(new_id)
|
base.sights.show(new_id)
|
||||||
|
""" The id will be added to its parent. When parent close will be its children closed as well """
|
||||||
|
self.sight.addChild(new_id)
|
||||||
|
""" The child remember its parent. When the child is closed the parent will be know about that. """
|
||||||
|
base.sights.get(new_id).setParent(self.sight.getId())
|
||||||
return new_id;
|
return new_id;
|
||||||
|
|
||||||
@pyqtSlot(str, str, bool)
|
@pyqtSlot(str, str, bool)
|
||||||
|
|
@ -56,8 +60,18 @@ class CallHandler(QObject):
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def close(self):
|
def close(self):
|
||||||
|
""" CLOSE ITS CHILDREN. It doesnt close the children's children just the current parent children
|
||||||
|
will be closed. """
|
||||||
|
for cid in self.sight.getChildren():
|
||||||
|
base.sights.close(cid)
|
||||||
|
print("CLOSED - "+cid)
|
||||||
|
""" If the parent doesn't exist anymore! """
|
||||||
|
if base.sights.get(self.sight.getParent()) is not None:
|
||||||
|
""" The child will be removed from his parent. So the parent wont be know about that because its child closed. """
|
||||||
|
base.sights.get(self.sight.getParent()).removeChild(self.sight.getId())
|
||||||
base.sights.close(self.sight.getId())
|
base.sights.close(self.sight.getId())
|
||||||
|
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def setMaximized(self):
|
def setMaximized(self):
|
||||||
self.sight.showMaximized()
|
self.sight.showMaximized()
|
||||||
|
|
|
||||||
19
sight.py
19
sight.py
|
|
@ -11,6 +11,8 @@ class Sight(QWidget):
|
||||||
self.id = id
|
self.id = id
|
||||||
self.type = type
|
self.type = type
|
||||||
self.data = {} # private data(s) of the sight
|
self.data = {} # private data(s) of the sight
|
||||||
|
self.children = []
|
||||||
|
self.parent = None
|
||||||
|
|
||||||
base.data["active_sight"] = self.id
|
base.data["active_sight"] = self.id
|
||||||
self.title = id
|
self.title = id
|
||||||
|
|
@ -29,6 +31,23 @@ class Sight(QWidget):
|
||||||
|
|
||||||
self.setLayout(self.layout)
|
self.setLayout(self.layout)
|
||||||
|
|
||||||
|
def getParent(self):
|
||||||
|
return self.parent
|
||||||
|
|
||||||
|
def setParent(self, id):
|
||||||
|
self.parent = id
|
||||||
|
|
||||||
|
def addChild(self, id):
|
||||||
|
self.children.insert(0, id)
|
||||||
|
print(self.children)
|
||||||
|
|
||||||
|
def getChildren(self):
|
||||||
|
return self.children
|
||||||
|
|
||||||
|
def removeChild(self, id):
|
||||||
|
self.children.remove(id)
|
||||||
|
print(self.children)
|
||||||
|
|
||||||
def setLayoutContentMargins(self,a,b,c,d):
|
def setLayoutContentMargins(self,a,b,c,d):
|
||||||
self.layout.setContentsMargins(a, b, c, d)
|
self.layout.setContentsMargins(a, b, c, d)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue