diff --git a/callhandler.py b/callhandler.py index d581572..983421f 100644 --- a/callhandler.py +++ b/callhandler.py @@ -1,34 +1,36 @@ import base +import json import random from PyQt6.QtCore import QObject, pyqtSlot + class CallHandler(QObject): def __init__(self, sight): super().__init__() self.sight = sight - + @pyqtSlot(str) def console(self, t): print(t) - + @pyqtSlot(str, result=str) def test2(self, t): - print(t) - return t+"_return" - + print(t) + return t + "_return" + @pyqtSlot(result=str) def getDefaultTemplate(self): - return base.data["default_template"] - + return base.data["default_template"] + @pyqtSlot(int) def setWidth(self, width): self.sight.resize(width, self.sight.height()); - + @pyqtSlot(int) def setHeight(self, height): - self.sight.resize(self.sight.width(), height); + self.sight.resize(self.sight.width(), height); - @pyqtSlot(str, str, result = str) + @pyqtSlot(str, str, result=str) def create(self, id, type): new_id = base.sights.create(id, type) if new_id is not None: @@ -38,62 +40,65 @@ class CallHandler(QObject): """ 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) - def addData(self, key, value, is_global = False): + def addData(self, key, value, is_global=False): if is_global: - base.sights.addGlobalData(key,value) + base.sights.addGlobalData(key, value) else: - self.sight.addData(key,value) - + self.sight.addData(key, value) + @pyqtSlot(str, bool, result=str) - def getData(self, key, is_global = False): + def getData(self, key, is_global=False): if is_global: return base.sights.getGlobalData(key) return self.sight.getData(key) - + @pyqtSlot() def activeSight(self): if base.data["active_sight"] != self.sight.getId(): print("Active - " + self.sight.getId()) base.data["active_sight"] = self.sight.getId() - + + + @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) + 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): + def setMaximized(self): self.sight.showMaximized() - self.sight.setLayoutContentMargins(0,0,0,0) #because there will be a transparented line as a border - + self.sight.setLayoutContentMargins(0, 0, 0, 0) # because there will be a transparented line as a border + @pyqtSlot() def setMinimize(self): self.sight.showMinimized() - + @pyqtSlot() def restoreDown(self): self.sight.showNormal() - self.sight.setLayoutContentMargins(1,1,1,1) #because if it is no border then I get setgeometry warning what can't be set - - @pyqtSlot() + self.sight.setLayoutContentMargins(1, 1, 1, + 1) # because if it is no border then I get setgeometry warning what can't be set + + @pyqtSlot() def setFullscreen(self): self.sight.showFullScreen() - + """@pyqtSlot(result=str) def getTitle(self): return self.sight.getTitle(); - """ + """ + @pyqtSlot() def move(self): base.data["move"] = True @@ -101,22 +106,30 @@ class CallHandler(QObject): @pyqtSlot() def endmove(self): base.data["move"] = False - + @pyqtSlot() def resize(self): - new_height = base.mousectrl.position[1]-self.sight.pos().y() - new_width = base.mousectrl.position[0]-self.sight.pos().x() - if(new_height<250): + new_height = base.mousectrl.position[1] - self.sight.pos().y() + new_width = base.mousectrl.position[0] - self.sight.pos().x() + if (new_height < 250): new_height = 250 - if(new_width<250): - new_width = 250 - self.sight.resize( new_width, new_height) + if (new_width < 250): + new_width = 250 + self.sight.resize(new_width, new_height) - @pyqtSlot(str) - def message(self, label): - print("label - " + label) - for sight in base.sights.getSights().values(): - sight.browser.page().runJavaScript("message('"+label+"')", self.ready) + @pyqtSlot(str, str, str) + def message(self, label, sight_id_json, data): + sight_list = json.loads(sight_id_json) + + print("Message - " + label) + if len(sight_list) == 0: + for sight in base.sights.getSights().values(): + sight.browser.page().runJavaScript("message('" + label + "', '"+data+"')", self.ready) + else: + for sight_id in sight_list: + if base.sights.checkKey(sight_id): + base.sights.get(sight_id).browser.page().runJavaScript("message('" + label + "', '"+data+"')", self.ready) def ready(self, returnValue): - print(returnValue) \ No newline at end of file + if returnValue is not None: + print(returnValue) diff --git a/place/js/sight.js b/place/js/sight.js index 1d3d3e3..9ceeb60 100644 --- a/place/js/sight.js +++ b/place/js/sight.js @@ -120,6 +120,20 @@ if(navigator.userAgent.indexOf("QtWebEngine") > 0) { function addData(key, value, is_global = false) { window.sight.addData(key,value, is_global); } + +/* +label = any unique short message (one word) +sight_id_array = a id list of those sight where the message will be sent to +data = it is a javascript dict (this can contains any key and value) which will be sent + */ +function sendMessage(label, sight_id_array = [], data = {}) { + window.sight.message(label, JSON.stringify(sight_id_array), JSON.stringify(data)); +} + +function eventMsg(label, where, data) { + return "["+label+"] - " +where+" ("+data+")"; +} + function getData(key, is_global = false) { window.sight.getData(key, is_global, function(result) { alert(result) diff --git a/place/templates/base/main.html b/place/templates/base/main.html index d24f384..e366a4b 100644 --- a/place/templates/base/main.html +++ b/place/templates/base/main.html @@ -24,12 +24,17 @@ }); - function message(label) { + function message(label, data) { if(label === "price_change") { - window.sight.message("changed_now") - return "I update my price - "+label + sendMessage("changed_now") + return "I update my price - "+label+"; DATA - "+data + } + + if(label === "test") { + return "MAIN GOT TEST MESSAGE"+"; DATA - "+data } } + diff --git a/place/templates/base/other.html b/place/templates/base/other.html index d46be26..564ca8c 100644 --- a/place/templates/base/other.html +++ b/place/templates/base/other.html @@ -9,12 +9,21 @@ diff --git a/sightfactory.py b/sightfactory.py index 363ef11..7507885 100644 --- a/sightfactory.py +++ b/sightfactory.py @@ -51,29 +51,41 @@ class SightFactory(): def get(self, id): if self.checkKey(id): return self.list[id] - print("This '"+str(id)+"' id isn't exist to get!") + """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!") + """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): - print(self.list) + 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):