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
Balazs Birtalan 2023-10-26 18:43:59 +01:00
parent 346c22193d
commit 4965e87980
2 changed files with 36 additions and 3 deletions

View File

@ -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,7 +60,17 @@ 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):

View File

@ -7,11 +7,13 @@ from PyQt6.QtWidgets import QMainWindow, QWidget, QVBoxLayout
class Sight(QWidget): class Sight(QWidget):
def __init__(self, id, type): def __init__(self, id, type):
super().__init__() super().__init__()
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
@ -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.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) 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)