import base import random from sight import Sight class SightFactory(): def __init__(self): self.list = {} self.data = {} #Global data(s) for the sight(s) def create(self, id, page): print("----- "+page+"-"+str(id)+"-------") if str(id) == "main" and self.checkKey(id): print("The 'main' window already exist! You can't create more than one 'main' page sight!") return None if base.data["sight_mode"] == "unique": if len(id) == 0: print("No ID was given! In single mode need declare an ID to the Sight in advance!") return None if self.checkKey(id): print("This ['"+page+"'-'"+str(id)+"'] already exist!") return None if base.data["sight_mode"] == "auto": if len(id) == 0: id = self.createUniqueId() if len(id) > 0 and self.checkKey(id) and str(id) != "main": id = self.createUniqueId() if base.data["sight_mode"] == "normal": if self.checkKey(id) and len(id) != 0: print("This ['"+page+"'-'"+str(id)+"'] already exist!") return None if len(id) == 0: id = self.createUniqueId() self.list[id] = Sight(id, page) return id def show(self, id): if self.checkKey(id): self.list[id].show() print("The '"+str(id)+"' sight is showed!") return True print("This '"+str(id)+"' id isn't exist to show!") return False def getSights(self): return self.list def get(self, id): if self.checkKey(id): return self.list[id] """print("This '"+str(id)+"' id isn't exist to get!")""" def closeChildren(self, id, removeFromParent = True): """ CLOSE ITS CHILDREN. It doesnt close the children's children just the current parent children will be closed. """ for cid in self.get(id).getChildren(): self.close(cid) print("CLOSED - " + cid) if removeFromParent: """ If the parent doesn't exist anymore! """ if self.get(self.get(id).getParent()) is not None: children = self.get(self.get(id).getParent()).getChildren() if len(children) > 0: self.get(self.get(id).getParent()).removeChild(id) print("AFTER REMOVED CHILDREN " + str(self.get(self.get(id).getParent()).getChildren()) ) def close(self, id, closeChildrenToo=True): if closeChildrenToo: self.closeChildren(id) if self.checkKey(id): self.eventMessage("CLOSING", "sight", id) if id == "main": print("Program Exit!") base.app.exit(0) self.list[id].close() if id in self.list: self.list[id].deleteLater() del self.list[id] """print("The '"+str(id)+"' is closed now!")""" self.eventMessage("CLOSED", "sight", id) return True else: print("The '"+str(id)+"' isn't exist'") return False def eventMessage(self, label, where, data): for sight in self.list.values(): sight.browser.page().runJavaScript("eventMsg('" + label + "', '" + where + "', '" + data + "')", self.ready) def ready(self, returnValue): if returnValue is not None: print(returnValue) def processes(self): if len(self.list) > 0: print(self.list) def checkKey(self, id): if id in self.list: return True return False def addGlobalData(self, key, value): self.data[key] = value def getGlobauniquelData(self, key): if key in self.data: return self.data[key] return None def createUniqueId(self): new_id = str(random.randint(1000, 9999)) if self.checkKey(new_id): self.createUniqueId() return new_id