They can send message to the specific sight using the window.sight.message 2nd argument function. There is a new function called sendMessage() which make more simple to send message.
1st argument of the sendMessage is a label. 2nd argument of the sendMessage is a sight ids array if it is empty [] then get everyone. 3rd argument is the data (javascript dict)main
parent
617bbe47cc
commit
976fee0004
|
|
@ -1,7 +1,9 @@
|
||||||
import base
|
import base
|
||||||
|
import json
|
||||||
import random
|
import random
|
||||||
from PyQt6.QtCore import QObject, pyqtSlot
|
from PyQt6.QtCore import QObject, pyqtSlot
|
||||||
|
|
||||||
|
|
||||||
class CallHandler(QObject):
|
class CallHandler(QObject):
|
||||||
def __init__(self, sight):
|
def __init__(self, sight):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
@ -13,12 +15,12 @@ class CallHandler(QObject):
|
||||||
|
|
||||||
@pyqtSlot(str, result=str)
|
@pyqtSlot(str, result=str)
|
||||||
def test2(self, t):
|
def test2(self, t):
|
||||||
print(t)
|
print(t)
|
||||||
return t+"_return"
|
return t + "_return"
|
||||||
|
|
||||||
@pyqtSlot(result=str)
|
@pyqtSlot(result=str)
|
||||||
def getDefaultTemplate(self):
|
def getDefaultTemplate(self):
|
||||||
return base.data["default_template"]
|
return base.data["default_template"]
|
||||||
|
|
||||||
@pyqtSlot(int)
|
@pyqtSlot(int)
|
||||||
def setWidth(self, width):
|
def setWidth(self, width):
|
||||||
|
|
@ -28,7 +30,7 @@ class CallHandler(QObject):
|
||||||
def setHeight(self, height):
|
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):
|
def create(self, id, type):
|
||||||
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:
|
||||||
|
|
@ -40,14 +42,14 @@ class CallHandler(QObject):
|
||||||
return new_id;
|
return new_id;
|
||||||
|
|
||||||
@pyqtSlot(str, str, bool)
|
@pyqtSlot(str, str, bool)
|
||||||
def addData(self, key, value, is_global = False):
|
def addData(self, key, value, is_global=False):
|
||||||
if is_global:
|
if is_global:
|
||||||
base.sights.addGlobalData(key,value)
|
base.sights.addGlobalData(key, value)
|
||||||
else:
|
else:
|
||||||
self.sight.addData(key,value)
|
self.sight.addData(key, value)
|
||||||
|
|
||||||
@pyqtSlot(str, bool, result=str)
|
@pyqtSlot(str, bool, result=str)
|
||||||
def getData(self, key, is_global = False):
|
def getData(self, key, is_global=False):
|
||||||
if is_global:
|
if is_global:
|
||||||
return base.sights.getGlobalData(key)
|
return base.sights.getGlobalData(key)
|
||||||
return self.sight.getData(key)
|
return self.sight.getData(key)
|
||||||
|
|
@ -58,24 +60,25 @@ class CallHandler(QObject):
|
||||||
print("Active - " + self.sight.getId())
|
print("Active - " + self.sight.getId())
|
||||||
base.data["active_sight"] = self.sight.getId()
|
base.data["active_sight"] = self.sight.getId()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def close(self):
|
def close(self):
|
||||||
""" CLOSE ITS CHILDREN. It doesnt close the children's children just the current parent children
|
""" CLOSE ITS CHILDREN. It doesnt close the children's children just the current parent children
|
||||||
will be closed. """
|
will be closed. """
|
||||||
for cid in self.sight.getChildren():
|
for cid in self.sight.getChildren():
|
||||||
base.sights.close(cid)
|
base.sights.close(cid)
|
||||||
print("CLOSED - "+cid)
|
print("CLOSED - " + cid)
|
||||||
""" If the parent doesn't exist anymore! """
|
""" If the parent doesn't exist anymore! """
|
||||||
if base.sights.get(self.sight.getParent()) is not None:
|
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. """
|
""" 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.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):
|
||||||
self.sight.showMaximized()
|
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()
|
@pyqtSlot()
|
||||||
def setMinimize(self):
|
def setMinimize(self):
|
||||||
|
|
@ -84,7 +87,8 @@ class CallHandler(QObject):
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def restoreDown(self):
|
def restoreDown(self):
|
||||||
self.sight.showNormal()
|
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
|
self.sight.setLayoutContentMargins(1, 1, 1,
|
||||||
|
1) # because if it is no border then I get setgeometry warning what can't be set
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def setFullscreen(self):
|
def setFullscreen(self):
|
||||||
|
|
@ -94,6 +98,7 @@ class CallHandler(QObject):
|
||||||
def getTitle(self):
|
def getTitle(self):
|
||||||
return self.sight.getTitle();
|
return self.sight.getTitle();
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def move(self):
|
def move(self):
|
||||||
base.data["move"] = True
|
base.data["move"] = True
|
||||||
|
|
@ -104,19 +109,27 @@ class CallHandler(QObject):
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def resize(self):
|
def resize(self):
|
||||||
new_height = base.mousectrl.position[1]-self.sight.pos().y()
|
new_height = base.mousectrl.position[1] - self.sight.pos().y()
|
||||||
new_width = base.mousectrl.position[0]-self.sight.pos().x()
|
new_width = base.mousectrl.position[0] - self.sight.pos().x()
|
||||||
if(new_height<250):
|
if (new_height < 250):
|
||||||
new_height = 250
|
new_height = 250
|
||||||
if(new_width<250):
|
if (new_width < 250):
|
||||||
new_width = 250
|
new_width = 250
|
||||||
self.sight.resize( new_width, new_height)
|
self.sight.resize(new_width, new_height)
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str, str, str)
|
||||||
def message(self, label):
|
def message(self, label, sight_id_json, data):
|
||||||
print("label - " + label)
|
sight_list = json.loads(sight_id_json)
|
||||||
for sight in base.sights.getSights().values():
|
|
||||||
sight.browser.page().runJavaScript("message('"+label+"')", self.ready)
|
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):
|
def ready(self, returnValue):
|
||||||
print(returnValue)
|
if returnValue is not None:
|
||||||
|
print(returnValue)
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,20 @@ if(navigator.userAgent.indexOf("QtWebEngine") > 0) {
|
||||||
function addData(key, value, is_global = false) {
|
function addData(key, value, is_global = false) {
|
||||||
window.sight.addData(key,value, is_global);
|
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) {
|
function getData(key, is_global = false) {
|
||||||
window.sight.getData(key, is_global, function(result) {
|
window.sight.getData(key, is_global, function(result) {
|
||||||
alert(result)
|
alert(result)
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,17 @@
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function message(label) {
|
function message(label, data) {
|
||||||
if(label === "price_change") {
|
if(label === "price_change") {
|
||||||
window.sight.message("changed_now")
|
sendMessage("changed_now")
|
||||||
return "I update my price - "+label
|
return "I update my price - "+label+"; DATA - "+data
|
||||||
|
}
|
||||||
|
|
||||||
|
if(label === "test") {
|
||||||
|
return "MAIN GOT TEST MESSAGE"+"; DATA - "+data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,21 @@
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
//getData("name", true);
|
//getData("name", true);
|
||||||
window.sight.message("price_change")
|
sendMessage("price_change")
|
||||||
|
|
||||||
|
dict = {}
|
||||||
|
dict["account_id"] = 10227;
|
||||||
|
dict["account_name"] = "Test Bank";
|
||||||
|
dict["details"] = {};
|
||||||
|
dict["details"]["phone"] = 123456789
|
||||||
|
dict["details"]["place"] = "New York"
|
||||||
|
sendMessage("test", ["other","main"], dict)
|
||||||
});
|
});
|
||||||
|
|
||||||
function message(label) {
|
function message(label,data) {
|
||||||
if(label === "changed_now") {
|
if(label === "test") {
|
||||||
return "everything alright - " + label
|
data_dict = JSON.parse(data)
|
||||||
|
return "DATA - "+data_dict["account_name"] + " - " + data_dict["details"]["place"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -51,29 +51,41 @@ class SightFactory():
|
||||||
def get(self, id):
|
def get(self, id):
|
||||||
if self.checkKey(id):
|
if self.checkKey(id):
|
||||||
return self.list[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):
|
def close(self, id):
|
||||||
if self.checkKey(id):
|
if self.checkKey(id):
|
||||||
|
self.eventMessage("CLOSING", "sight", id)
|
||||||
if id == "main":
|
if id == "main":
|
||||||
print("Program Exit!")
|
print("Program Exit!")
|
||||||
base.app.exit(0)
|
base.app.exit(0)
|
||||||
self.list[id].close()
|
self.list[id].close()
|
||||||
self.list[id].deleteLater()
|
self.list[id].deleteLater()
|
||||||
del self.list[id]
|
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
|
return True
|
||||||
else:
|
else:
|
||||||
print("The '"+str(id)+"' isn't exist'")
|
print("The '"+str(id)+"' isn't exist'")
|
||||||
return False
|
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):
|
def processes(self):
|
||||||
print(self.list)
|
if len(self.list) > 0:
|
||||||
|
print(self.list)
|
||||||
|
|
||||||
def checkKey(self, id):
|
def checkKey(self, id):
|
||||||
if id in self.list:
|
if id in self.list:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def addGlobalData(self, key, value):
|
def addGlobalData(self, key, value):
|
||||||
self.data[key] = value
|
self.data[key] = value
|
||||||
def getGlobauniquelData(self, key):
|
def getGlobauniquelData(self, key):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue