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, type): print("----- "+type+"-"+str(id)+"-------") if str(id) == "main" and self.checkKey(id): print("The 'main' window already exist! You can't create more than one 'main' type window!") 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 ['"+type+"'-'"+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 ['"+type+"'-'"+str(id)+"'] already exist!") return None if len(id) == 0: id = self.createUniqueId() self.list[id] = Sight(id, type) print("The ['"+type+"'-'"+str(id)+"'] is created now!") 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 close(self, id): if self.checkKey(id): self.eventMessage("CLOSING", "sight", id) if id == "main": print("Program Exit!") base.app.exit(0) self.list[id].close() 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