diff --git a/callhandler.py b/callhandler.py index f75051e..5e724dd 100644 --- a/callhandler.py +++ b/callhandler.py @@ -33,6 +33,10 @@ class CallHandler(QObject): new_id = base.sights.create(id, type) if new_id is not None: 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; @pyqtSlot(str, str, bool) @@ -56,7 +60,17 @@ class CallHandler(QObject): @pyqtSlot() 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()) + @pyqtSlot() def setMaximized(self): diff --git a/sight.py b/sight.py index 75ff285..8107a3c 100644 --- a/sight.py +++ b/sight.py @@ -7,11 +7,13 @@ from PyQt6.QtWidgets import QMainWindow, QWidget, QVBoxLayout class Sight(QWidget): def __init__(self, id, type): super().__init__() - + self.id = id self.type = type self.data = {} # private data(s) of the sight - + self.children = [] + self.parent = None + base.data["active_sight"] = self.id self.title = id @@ -28,7 +30,24 @@ class Sight(QWidget): self.layout.setContentsMargins(1, 1, 1, 1); #Need 1,1,1,1 if it is 0,0,0,0 I got setgeometry warnings 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): self.layout.setContentsMargins(a, b, c, d)