2023-05-17 10:16:15 +00:00
|
|
|
import base
|
|
|
|
|
import random
|
|
|
|
|
from sight import Sight
|
|
|
|
|
|
|
|
|
|
class SightFactory():
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.list = {}
|
|
|
|
|
self.data = {} #Global data(s) for the sight(s)
|
|
|
|
|
|
2023-10-27 13:14:49 +00:00
|
|
|
def create(self, id, page):
|
|
|
|
|
print("----- "+page+"-"+str(id)+"-------")
|
2023-05-17 10:16:15 +00:00
|
|
|
|
|
|
|
|
if str(id) == "main" and self.checkKey(id):
|
2023-10-27 13:14:49 +00:00
|
|
|
print("The 'main' window already exist! You can't create more than one 'main' page sight!")
|
2023-05-17 10:16:15 +00:00
|
|
|
return None
|
|
|
|
|
|
2023-10-26 15:58:46 +00:00
|
|
|
if base.data["sight_mode"] == "unique":
|
2023-05-17 10:16:15 +00:00
|
|
|
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):
|
2023-10-27 13:14:49 +00:00
|
|
|
print("This ['"+page+"'-'"+str(id)+"'] already exist!")
|
2023-05-17 10:16:15 +00:00
|
|
|
return None
|
2023-10-26 15:58:46 +00:00
|
|
|
if base.data["sight_mode"] == "auto":
|
2023-05-17 10:16:15 +00:00
|
|
|
if len(id) == 0:
|
|
|
|
|
id = self.createUniqueId()
|
|
|
|
|
if len(id) > 0 and self.checkKey(id) and str(id) != "main":
|
|
|
|
|
id = self.createUniqueId()
|
2023-10-26 15:58:46 +00:00
|
|
|
if base.data["sight_mode"] == "normal":
|
|
|
|
|
if self.checkKey(id) and len(id) != 0:
|
2023-10-27 13:14:49 +00:00
|
|
|
print("This ['"+page+"'-'"+str(id)+"'] already exist!")
|
2023-10-26 15:58:46 +00:00
|
|
|
return None
|
|
|
|
|
if len(id) == 0:
|
|
|
|
|
id = self.createUniqueId()
|
2023-05-17 10:16:15 +00:00
|
|
|
|
2023-10-27 13:14:49 +00:00
|
|
|
self.list[id] = Sight(id, page)
|
2023-05-17 10:16:15 +00:00
|
|
|
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
|
2023-10-26 18:47:39 +00:00
|
|
|
|
|
|
|
|
def getSights(self):
|
|
|
|
|
return self.list
|
|
|
|
|
|
2023-05-17 10:16:15 +00:00
|
|
|
def get(self, id):
|
|
|
|
|
if self.checkKey(id):
|
|
|
|
|
return self.list[id]
|
2023-10-27 08:58:33 +00:00
|
|
|
"""print("This '"+str(id)+"' id isn't exist to get!")"""
|
2023-10-30 19:43:35 +00:00
|
|
|
|
|
|
|
|
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()) )
|
2023-05-17 10:16:15 +00:00
|
|
|
|
2023-10-30 19:43:35 +00:00
|
|
|
def close(self, id, closeChildrenToo=True):
|
|
|
|
|
if closeChildrenToo:
|
|
|
|
|
self.closeChildren(id)
|
2023-05-17 10:16:15 +00:00
|
|
|
if self.checkKey(id):
|
2023-10-27 08:58:33 +00:00
|
|
|
self.eventMessage("CLOSING", "sight", id)
|
2023-05-17 10:16:15 +00:00
|
|
|
if id == "main":
|
|
|
|
|
print("Program Exit!")
|
|
|
|
|
base.app.exit(0)
|
|
|
|
|
self.list[id].close()
|
2023-10-30 19:43:35 +00:00
|
|
|
if id in self.list:
|
|
|
|
|
self.list[id].deleteLater()
|
|
|
|
|
del self.list[id]
|
2023-10-27 08:58:33 +00:00
|
|
|
"""print("The '"+str(id)+"' is closed now!")"""
|
|
|
|
|
self.eventMessage("CLOSED", "sight", id)
|
2023-05-17 10:16:15 +00:00
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
print("The '"+str(id)+"' isn't exist'")
|
|
|
|
|
return False
|
2023-10-27 08:58:33 +00:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
2023-05-17 10:16:15 +00:00
|
|
|
def processes(self):
|
2023-10-27 08:58:33 +00:00
|
|
|
if len(self.list) > 0:
|
|
|
|
|
print(self.list)
|
2023-05-17 10:16:15 +00:00
|
|
|
|
|
|
|
|
def checkKey(self, id):
|
|
|
|
|
if id in self.list:
|
|
|
|
|
return True
|
|
|
|
|
return False
|
2023-10-27 08:58:33 +00:00
|
|
|
|
2023-05-17 10:16:15 +00:00
|
|
|
def addGlobalData(self, key, value):
|
|
|
|
|
self.data[key] = value
|
2023-10-26 15:58:46 +00:00
|
|
|
def getGlobauniquelData(self, key):
|
2023-05-17 10:16:15 +00:00
|
|
|
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()
|
2023-10-30 19:43:35 +00:00
|
|
|
return new_id
|