New class Broadcast (in Messenger) which deliever (send and receive) the message with their data to the receivers (pages).
parent
f257def4d1
commit
b8e1a5cb81
|
|
@ -5,7 +5,6 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
function message(label,data) {
|
function message(label,data) {
|
||||||
|
|
||||||
/* DON'T PUT ANY WINDOW.SIGHT.CONSOLE function or other one which call the logs because causing infinity loop */
|
/* DON'T PUT ANY WINDOW.SIGHT.CONSOLE function or other one which call the logs because causing infinity loop */
|
||||||
if(label === "logs") {
|
if(label === "logs") {
|
||||||
//alert(data)
|
//alert(data)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
<a href="#" id="screate" data-page="other" data-id="other">Create an "Other" sight!</a>
|
|
||||||
|
|
||||||
<a href="#" id="screate" data-page="other">Create an "Other" no id sight!</a>
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
<link rel="stylesheet" type="text/css" href="content/main_text/test.css">
|
|
||||||
|
|
||||||
<div id="example">This is a sentence.</div>
|
|
||||||
<button onclick="h()">JE</button>
|
|
||||||
<script>
|
|
||||||
window.sight.console("This appear in the console from the content/main_text. The content files reach the window.sight.")
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
|
|
||||||
window.sight.console("2")
|
|
||||||
function h(){
|
|
||||||
alert("hello2")
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
#example {
|
|
||||||
background-color: yellow;
|
|
||||||
}
|
|
||||||
|
|
@ -22,17 +22,6 @@
|
||||||
getData("name");*/
|
getData("name");*/
|
||||||
});
|
});
|
||||||
|
|
||||||
function message(label, data) {
|
|
||||||
if(label === "price_change") {
|
|
||||||
sendMessage("changed_now")
|
|
||||||
return "I update my price - "+label+"; DATA - "+data
|
|
||||||
}
|
|
||||||
|
|
||||||
if(label === "test") {
|
|
||||||
return "MAIN GOT TEST MESSAGE"+"; DATA - "+data
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
||||||
21
base.py
21
base.py
|
|
@ -3,10 +3,18 @@ import os
|
||||||
import platform
|
import platform
|
||||||
import configparser
|
import configparser
|
||||||
from log import Log
|
from log import Log
|
||||||
|
|
||||||
|
print("---- [BOOT] ----")
|
||||||
|
from core.registration.registrar import Registrar
|
||||||
|
registrar = Registrar()
|
||||||
|
registrar.registry().register("log","display")
|
||||||
|
registrar.registry().register("console","display")
|
||||||
|
print("---- [END OF BOOT] ----")
|
||||||
|
|
||||||
log = Log(3)
|
log = Log(3)
|
||||||
log.debugOn()
|
log.debugOn()
|
||||||
log.debug_level = 3
|
log.debug_level = 3
|
||||||
log.eventOff()
|
log.eventOn()
|
||||||
|
|
||||||
from mouseevents import MouseEvents
|
from mouseevents import MouseEvents
|
||||||
from pynput import mouse
|
from pynput import mouse
|
||||||
|
|
@ -14,10 +22,16 @@ from sightfactory import SightFactory
|
||||||
from PyQt6.QtWidgets import QApplication
|
from PyQt6.QtWidgets import QApplication
|
||||||
from pynput.mouse import Controller
|
from pynput.mouse import Controller
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def getTimeStamp():
|
||||||
|
return int(time.time())
|
||||||
def init():
|
def init():
|
||||||
global sights, mousectrl, app, data
|
global sights, mousectrl, app, data
|
||||||
data = {}
|
data = {}
|
||||||
|
data["started_time"] = int(time.time())
|
||||||
#init the basic values
|
#init the basic values
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
mousectrl = Controller()
|
mousectrl = Controller()
|
||||||
|
|
@ -66,12 +80,11 @@ def loadConfigTemplate():
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
# Creating admin sight
|
# Creating admin sight
|
||||||
sights.create("sight-admin", "main")
|
#sights.create("sight-admin", "main")
|
||||||
sights.show("sight-admin")
|
#sights.show("sight-admin")
|
||||||
|
|
||||||
# Creating the main Sight
|
# Creating the main Sight
|
||||||
sights.create("main", data["default_template_page"])
|
sights.create("main", data["default_template_page"])
|
||||||
sights.show("main")
|
sights.show("main")
|
||||||
|
|
||||||
|
|
||||||
app.exec()
|
app.exec()
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ import random
|
||||||
import base
|
import base
|
||||||
from base import log
|
from base import log
|
||||||
from PyQt6.QtCore import QObject, pyqtSlot
|
from PyQt6.QtCore import QObject, pyqtSlot
|
||||||
|
from core.messenger.broadcast import Broadcast
|
||||||
|
from core.registration.record import *
|
||||||
|
|
||||||
|
|
||||||
class CallHandler(QObject):
|
class CallHandler(QObject):
|
||||||
|
|
@ -14,10 +16,11 @@ class CallHandler(QObject):
|
||||||
def console(self, msg):
|
def console(self, msg):
|
||||||
log.console(msg)
|
log.console(msg)
|
||||||
|
|
||||||
@pyqtSlot(str, result=str)
|
"""@pyqtSlot(str, result=str)
|
||||||
def test2(self, t):
|
def test2(self, t):
|
||||||
print(t+"s")
|
print(t+"s")
|
||||||
return t + "_return"
|
return t + "_return"
|
||||||
|
"""
|
||||||
|
|
||||||
@pyqtSlot(result=str)
|
@pyqtSlot(result=str)
|
||||||
def getDefaultTemplate(self):
|
def getDefaultTemplate(self):
|
||||||
|
|
@ -37,11 +40,11 @@ class CallHandler(QObject):
|
||||||
|
|
||||||
@pyqtSlot(int, int)
|
@pyqtSlot(int, int)
|
||||||
def setSize(self, width, height):
|
def setSize(self, width, height):
|
||||||
self.sight.resize(width,height);
|
self.sight.resize(width, height);
|
||||||
|
|
||||||
@pyqtSlot(int,int)
|
@pyqtSlot(int, int)
|
||||||
def setPosition(self, x, y):
|
def setPosition(self, x, y):
|
||||||
self.sight.move(x,y)
|
self.sight.move(x, y)
|
||||||
|
|
||||||
@pyqtSlot(result=str)
|
@pyqtSlot(result=str)
|
||||||
def system(self):
|
def system(self):
|
||||||
|
|
@ -56,7 +59,6 @@ class CallHandler(QObject):
|
||||||
self.sight.addChild(new_id)
|
self.sight.addChild(new_id)
|
||||||
""" The child remember its parent. When the child is closed the parent will be know about that. """
|
""" 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())
|
base.sights.get(new_id).setParent(self.sight.getId())
|
||||||
print("PARENT " + str(base.sights.get(new_id).getParent()))
|
|
||||||
return new_id;
|
return new_id;
|
||||||
|
|
||||||
@pyqtSlot(str, str, bool)
|
@pyqtSlot(str, str, bool)
|
||||||
|
|
@ -75,7 +77,7 @@ class CallHandler(QObject):
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def activeSight(self):
|
def activeSight(self):
|
||||||
if base.data["active_sight"] != self.sight.getId():
|
if base.data["active_sight"] != self.sight.getId():
|
||||||
print("Active - " + self.sight.getId())
|
log.byCode("CLA1000E", "Active Sight is " + self.sight.getId())
|
||||||
base.data["active_sight"] = self.sight.getId()
|
base.data["active_sight"] = self.sight.getId()
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
|
|
@ -114,8 +116,6 @@ class CallHandler(QObject):
|
||||||
def endmove(self):
|
def endmove(self):
|
||||||
base.data["move"] = False
|
base.data["move"] = False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@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()
|
||||||
|
|
@ -126,7 +126,7 @@ class CallHandler(QObject):
|
||||||
new_width = 250
|
new_width = 250
|
||||||
self.sight.resize(new_width, new_height)
|
self.sight.resize(new_width, new_height)
|
||||||
|
|
||||||
@pyqtSlot(str, str, str)
|
"""@pyqtSlot(str, str, str)
|
||||||
def message(self, label, sight_id_json, data):
|
def message(self, label, sight_id_json, data):
|
||||||
sight_list = json.loads(sight_id_json)
|
sight_list = json.loads(sight_id_json)
|
||||||
|
|
||||||
|
|
@ -136,7 +136,23 @@ class CallHandler(QObject):
|
||||||
else:
|
else:
|
||||||
for sight_id in sight_list:
|
for sight_id in sight_list:
|
||||||
if base.sights.checkKey(sight_id):
|
if base.sights.checkKey(sight_id):
|
||||||
base.sights.get(sight_id).browser.page().runJavaScript("message('" + label + "', '"+data+"')", self.ready)
|
base.sights.get(sight_id).browser.page().runJavaScript("message('" + label + "', '"+data+"')", self.ready)"""
|
||||||
|
|
||||||
|
@pyqtSlot(str, str)
|
||||||
|
def register(self, type, referral_name):
|
||||||
|
base.registrar.registry().register(type, referral_name)
|
||||||
|
|
||||||
|
@pyqtSlot(str, str, str, str)
|
||||||
|
def dataReceiver(self, h_type, h_referral_data, d_json_data, receiver_array=None):
|
||||||
|
if receiver_array is None:
|
||||||
|
receiver_array = []
|
||||||
|
|
||||||
|
if h_type == "message":
|
||||||
|
r = Record(RecordHeader(h_type, h_referral_data, receiver_array), RecordData(d_json_data))
|
||||||
|
msg = Broadcast()
|
||||||
|
msg.sendMessage(r)
|
||||||
|
# base.sights.get("main").browser.page().runJavaScript("receiveData('" + type + "', '" + referral_data + "', '"+json_data+"')", self.ready)
|
||||||
|
# print("RECEIVEEEE " + base.registrar.receiveData(type, referral_data, json_data))
|
||||||
|
|
||||||
def ready(self, returnValue):
|
def ready(self, returnValue):
|
||||||
if returnValue is not None:
|
if returnValue is not None:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
import base
|
||||||
|
|
||||||
|
|
||||||
|
class Broadcast:
|
||||||
|
def __init__(self):
|
||||||
|
print("MESSENGER")
|
||||||
|
|
||||||
|
def sendMessage(self, record):
|
||||||
|
if base.registrar.checkData(record) is not None:
|
||||||
|
for sight in base.sights.getSights().values():
|
||||||
|
if len(record.getHeader().getReceivers()) == 0:
|
||||||
|
sight.browser.page().runJavaScript("receiveData('" + record.getHeader().getType() + "', '" + record.getHeader().getReferralName() + "', '" + record.getData(
|
||||||
|
True) + "')", self.ready)
|
||||||
|
else:
|
||||||
|
if sight.getPageId() in record.getHeader().getReceivers():
|
||||||
|
sight.browser.page().runJavaScript(
|
||||||
|
"receiveData('" + record.getHeader().getType() + "', '" + record.getHeader().getReferralName() + "', '" + record.getData(
|
||||||
|
True) + "')", self.ready)
|
||||||
|
|
||||||
|
def ready(self, returnValue):
|
||||||
|
if returnValue is not None:
|
||||||
|
print(returnValue)
|
||||||
|
|
@ -0,0 +1,114 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
class RecordHeader():
|
||||||
|
__h_type = ""
|
||||||
|
__h_referral_name = ""
|
||||||
|
__h_receiver_list = []
|
||||||
|
|
||||||
|
def __init__(self, header_type: str, referral_name: str, receiver_list=None):
|
||||||
|
if receiver_list is None:
|
||||||
|
receiver_list = []
|
||||||
|
self.__h_receiver_list = receiver_list
|
||||||
|
|
||||||
|
self.__h_type = header_type
|
||||||
|
self.__h_referral_name = referral_name
|
||||||
|
|
||||||
|
def analyze(self):
|
||||||
|
if type(self.__h_type) != str:
|
||||||
|
print("wrong type value")
|
||||||
|
return False
|
||||||
|
|
||||||
|
self.__h_receiver_list = json.loads(self.__h_receiver_list)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def getType(self):
|
||||||
|
return self.__h_type
|
||||||
|
|
||||||
|
def getReferralName(self):
|
||||||
|
return self.__h_referral_name
|
||||||
|
|
||||||
|
def getReceivers(self):
|
||||||
|
return self.__h_receiver_list
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# NO LIST [] just DICT {} any list in the dict will cause error.
|
||||||
|
def replaceDictCharacters(d):
|
||||||
|
for key, value in d.items():
|
||||||
|
if type(value) == dict:
|
||||||
|
d[key] = replaceDictCharacters(value)
|
||||||
|
else:
|
||||||
|
d[key] = str(value).replace('\\', '\\').replace('\'', "")
|
||||||
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
class RecordData():
|
||||||
|
__data = ""
|
||||||
|
__data_json = ""
|
||||||
|
|
||||||
|
def __init__(self, user_data):
|
||||||
|
if user_data is None:
|
||||||
|
user_data = {}
|
||||||
|
self.__data = user_data
|
||||||
|
self.__data_json = ""
|
||||||
|
|
||||||
|
def analyze(self):
|
||||||
|
if type(self.__data) == str:
|
||||||
|
try:
|
||||||
|
# CREATING PYTHON DICT
|
||||||
|
self.__data = json.loads(self.__data)
|
||||||
|
# CREATING JSON STRING (for sight.js)
|
||||||
|
except ValueError:
|
||||||
|
print("wrong data value")
|
||||||
|
return False
|
||||||
|
if type(self.__data) == dict:
|
||||||
|
self.__data_json = json.dumps(replaceDictCharacters(self.__data))
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def getData(self):
|
||||||
|
return self.__data
|
||||||
|
|
||||||
|
def getDataJson(self):
|
||||||
|
return self.__data_json
|
||||||
|
|
||||||
|
|
||||||
|
class Record():
|
||||||
|
__state = "CREATING"
|
||||||
|
__r_header = ""
|
||||||
|
|
||||||
|
def __init__(self, record_header, record_data):
|
||||||
|
if record_header.__class__.__name__ != "RecordHeader":
|
||||||
|
print("ERROR IT IS NOT A RECORD HEADER")
|
||||||
|
self.__state = "ERROR"
|
||||||
|
return
|
||||||
|
if record_data.__class__.__name__ != "RecordData":
|
||||||
|
print("ERROR IT IS NOT A RECORD DATA")
|
||||||
|
self.__state = "ERROR"
|
||||||
|
return
|
||||||
|
self.__r_header = record_header
|
||||||
|
self.__r_data = record_data
|
||||||
|
self.__state = "NEW"
|
||||||
|
|
||||||
|
def analyze(self):
|
||||||
|
if self.__state == "NEW":
|
||||||
|
if self.__r_header.analyze() is True and self.__r_data.analyze() is True:
|
||||||
|
self.__state = "ANALYZED"
|
||||||
|
else:
|
||||||
|
self.__state = "ANALYZE_FAILED"
|
||||||
|
|
||||||
|
def getState(self):
|
||||||
|
return self.__state
|
||||||
|
|
||||||
|
def getHeader(self):
|
||||||
|
if self.__state == "ANALYZED":
|
||||||
|
return self.__r_header
|
||||||
|
return None
|
||||||
|
|
||||||
|
def getData(self, json_data=False):
|
||||||
|
if self.__state == "ANALYZED":
|
||||||
|
if json_data:
|
||||||
|
return self.__r_data.getDataJson()
|
||||||
|
return self.__r_data.getData()
|
||||||
|
return None
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
from core.registration.record import *
|
||||||
|
from core.registration.registry import Registry
|
||||||
|
|
||||||
|
class Registrar:
|
||||||
|
__registry = ""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
print("Registrar init")
|
||||||
|
self.__registry = Registry()
|
||||||
|
|
||||||
|
def registry(self):
|
||||||
|
return self.__registry
|
||||||
|
|
||||||
|
def checkData(self, record):
|
||||||
|
record.analyze()
|
||||||
|
if record.getState() == "ANALYZED":
|
||||||
|
if self.__registry.exist(record.getHeader().getType(), record.getHeader().getReferralName()):
|
||||||
|
print(record.getData())
|
||||||
|
print(record.getData(True))
|
||||||
|
return record
|
||||||
|
else:
|
||||||
|
print("the record not analyzed")
|
||||||
|
else:
|
||||||
|
print("The type or referral name wasnt registered yet")
|
||||||
|
print("Data is not received!")
|
||||||
|
return None
|
||||||
|
|
||||||
|
"""def receiveData(self, type, referral_name, data):
|
||||||
|
if self.__registry.exist(type, referral_name):
|
||||||
|
record = Record(RecordHeader(type, referral_name), RecordData(data))
|
||||||
|
record.analyze()
|
||||||
|
if record.getState() == "ANALYZED":
|
||||||
|
print("RECEIVED")
|
||||||
|
print(record.getData())
|
||||||
|
print(record.getData(True))
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print("the record not analyzed")
|
||||||
|
else:
|
||||||
|
print("The type or referral name wasnt registered yet")
|
||||||
|
print("Data is not received!")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def sendData(self, type, referral_name, data):
|
||||||
|
if self.__registry.exist(type, referral_name):
|
||||||
|
record = Record(RecordHeader(type, referral_name), RecordData(data))
|
||||||
|
record.analyze()
|
||||||
|
if record.getState() == "ANALYZED":
|
||||||
|
print("SENT")
|
||||||
|
print(record.getData())
|
||||||
|
print(record.getData(True))
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print("the record not analyzed")
|
||||||
|
else:
|
||||||
|
print("The type or referral name wasnt registered yet")
|
||||||
|
print("Data is not sent!")
|
||||||
|
return False"""
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
from typing import Set, List, Any
|
||||||
|
|
||||||
|
from core.registration.types import types
|
||||||
|
from core.registration.record import RecordHeader
|
||||||
|
|
||||||
|
class Registry:
|
||||||
|
__registry_store = {}
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.__registry_store = self.__RegistryStore()
|
||||||
|
|
||||||
|
def register(self, type, referral_name, parameters=None, policy=""):
|
||||||
|
if parameters is None:
|
||||||
|
parameters = {}
|
||||||
|
|
||||||
|
if types.exist(type):
|
||||||
|
self.__registry_store.add(type, referral_name)
|
||||||
|
print("["+type+"] - " + referral_name + " registered.")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print("["+type+"] - " + referral_name + " couldn't registered. Missing the type.")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def unregister(self, type, referral_name):
|
||||||
|
self.__registry_store.remove(type,referral_name)
|
||||||
|
|
||||||
|
def exist(self, type, referral_name):
|
||||||
|
return self.__registry_store.exist(type, referral_name)
|
||||||
|
class __RegistryStore:
|
||||||
|
__store = {}
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
print("Registry Store")
|
||||||
|
|
||||||
|
def add(self, type, referral_name):
|
||||||
|
if type not in self.__store:
|
||||||
|
self.__store[type] = {}
|
||||||
|
if referral_name not in self.__store[type]:
|
||||||
|
self.__store[type][referral_name] = {}
|
||||||
|
self.__store[type][referral_name]["policy"] = ""
|
||||||
|
self.__store[type][referral_name]["parameters"] = ""
|
||||||
|
else:
|
||||||
|
print("This '"+referral_name+"' referral in this '"+type+"' type is already exist!")
|
||||||
|
|
||||||
|
def exist(self, type, referral_name):
|
||||||
|
if type not in self.__store or referral_name not in self.__store[type]:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def remove(self, type, referral_name):
|
||||||
|
self.__store[type].pop(referral_name)
|
||||||
|
if len(self.__store[type]) == 0:
|
||||||
|
self.__store.pop(type)
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
class Types():
|
||||||
|
__types = {}
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.__types["message"] = []
|
||||||
|
self.__types["log"] = []
|
||||||
|
self.__types["console"] = []
|
||||||
|
|
||||||
|
def exist(self, type):
|
||||||
|
return type in self.__types
|
||||||
|
|
||||||
|
|
||||||
|
types = Types()
|
||||||
|
|
@ -133,8 +133,25 @@ label = any unique short message (one word)
|
||||||
sight_id_array = a id list of those sight where the message will be sent to
|
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
|
data = it is a javascript dict (this can contains any key and value) which will be sent
|
||||||
*/
|
*/
|
||||||
function sendMessage(label, sight_id_array = [], data = {}) {
|
/*function sendMessage(label, sight_id_array = [], data = {}) {
|
||||||
window.sight.message(label, JSON.stringify(sight_id_array), JSON.stringify(data));
|
window.sight.message(label, JSON.stringify(sight_id_array), JSON.stringify(data));
|
||||||
|
}*/
|
||||||
|
|
||||||
|
function sendMessage(referral_name, data, to) {
|
||||||
|
sendData("message", referral_name, data, to)
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendData(type, referral_name, data, receiver_array = []) {
|
||||||
|
window.sight.dataReceiver(type, referral_name, JSON.stringify(data), JSON.stringify(receiver_array))
|
||||||
|
}
|
||||||
|
|
||||||
|
function receiveData(type, referral_name, data) {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
if(type === "message") {
|
||||||
|
if (recieveMessage !== "undefined") {
|
||||||
|
recieveMessage(referral_name, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function eventMsg(label, where, data) {
|
function eventMsg(label, where, data) {
|
||||||
|
|
|
||||||
24
log.py
24
log.py
|
|
@ -80,6 +80,20 @@ class Log():
|
||||||
if len(wheres) == 0:
|
if len(wheres) == 0:
|
||||||
wheres = self.whereis()
|
wheres = self.whereis()
|
||||||
|
|
||||||
|
# IT IS FREEZE BY EVENT (runJavascript cant execute lot of request in one time!
|
||||||
|
if type.upper() != "EVENT":
|
||||||
|
dict = {}
|
||||||
|
dict["type"] = type.upper()
|
||||||
|
dict["event_code"] = str(event_code)
|
||||||
|
msg = msg.replace('\\', '\\\\')
|
||||||
|
msg = msg.replace('\'', "")
|
||||||
|
dict["msg"] = msg
|
||||||
|
|
||||||
|
dict["event_state"] = str(event_state)
|
||||||
|
dict["date"] = str(dnow)
|
||||||
|
base.sights.sendMessage("logs", ["sight-admin"], dict)
|
||||||
|
|
||||||
|
|
||||||
""" LOG FILE WRITING """
|
""" LOG FILE WRITING """
|
||||||
if type not in self.debug_modes[0] and type.upper() != "EVENT":
|
if type not in self.debug_modes[0] and type.upper() != "EVENT":
|
||||||
filename = str(dnow.strftime("%d"))+"-"+str(dnow.strftime("%m"))+"-"+str(dnow.year)+".log"
|
filename = str(dnow.strftime("%d"))+"-"+str(dnow.strftime("%m"))+"-"+str(dnow.year)+".log"
|
||||||
|
|
@ -98,6 +112,8 @@ class Log():
|
||||||
f.close()
|
f.close()
|
||||||
""" END LOG FILE WRITING """
|
""" END LOG FILE WRITING """
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
""" LOG DISPLAY """
|
""" LOG DISPLAY """
|
||||||
if serious_error is False:
|
if serious_error is False:
|
||||||
if type.upper() == "EVENT" and self.event_on is False:
|
if type.upper() == "EVENT" and self.event_on is False:
|
||||||
|
|
@ -105,13 +121,7 @@ class Log():
|
||||||
if type not in self.debug_modes[0] and self.debug_level != 3:
|
if type not in self.debug_modes[0] and self.debug_level != 3:
|
||||||
if self.debug is True and type not in self.debug_modes[self.debug_level]:
|
if self.debug is True and type not in self.debug_modes[self.debug_level]:
|
||||||
return
|
return
|
||||||
dict = {}
|
|
||||||
dict["type"] = type.upper()
|
|
||||||
dict["event_code"] = str(event_code)
|
|
||||||
dict["msg"] = msg.replace('\\', '\\\\')
|
|
||||||
dict["event_state"] = str(event_state)
|
|
||||||
dict["date"] = str(dnow)
|
|
||||||
base.sights.sendMessage("logs", ["sight-admin"], dict)
|
|
||||||
|
|
||||||
print("["+type.upper()+"]",event_code, str(msg), wheres, "["+str(dnow)+"]", sep='\t')
|
print("["+type.upper()+"]",event_code, str(msg), wheres, "["+str(dnow)+"]", sep='\t')
|
||||||
""" END LOG DISPLAY """
|
""" END LOG DISPLAY """
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ loge_codes.addEventCode("BLC1001S", "The admin html file content is loaded in th
|
||||||
loge_codes.addEventCode("SF1000E", "The sight is being created.","CREATING")
|
loge_codes.addEventCode("SF1000E", "The sight is being created.","CREATING")
|
||||||
loge_codes.addEventCode("SF1000W", "The sight is already exist with that ID. It can't be create a new one with that id.s")
|
loge_codes.addEventCode("SF1000W", "The sight is already exist with that ID. It can't be create a new one with that id.s")
|
||||||
loge_codes.addEventCode("SF1001W", "The sight ID is not exist. It can't be shown!")
|
loge_codes.addEventCode("SF1001W", "The sight ID is not exist. It can't be shown!")
|
||||||
|
loge_codes.addEventCode("CLA1000E", "New Active Sight.")
|
||||||
|
|
||||||
|
|
||||||
#EVENT BASED
|
#EVENT BASED
|
||||||
loge_codes.addEventCode("MES1000E", "Mouse dragged the Sight and move to other position.", "MOVING")
|
loge_codes.addEventCode("MES1000E", "Mouse dragged the Sight and move to other position.", "MOVING")
|
||||||
|
|
|
||||||
26
main.py
26
main.py
|
|
@ -1,2 +1,28 @@
|
||||||
|
from core.registration.record import *
|
||||||
|
|
||||||
|
from core.registration.registrar import Registrar
|
||||||
|
|
||||||
|
#record = Record(RecordHeader("message", "say_name"),RecordData({"name":"Bala\zs", "details" : {"born" : "budapest"}}))
|
||||||
|
#record0 = Record(RecordHeader("message", "say_name"),RecordData('{"name":"Balazs2", "details" : [{"born" : "budapest2"}]}'))
|
||||||
|
"""
|
||||||
|
print(record.getData())
|
||||||
|
record.analyze()
|
||||||
|
|
||||||
|
print(record.getState())
|
||||||
|
|
||||||
|
if record.getState() == "ANALYZED":
|
||||||
|
print(record.getData())
|
||||||
|
print(record.getData(True))
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
registrar = Registrar()
|
||||||
|
registrar.registry().register("message","say_name")
|
||||||
|
|
||||||
|
user_data = '{"name":"Balazs2", "details" : {"born" : "budapest2"}}'
|
||||||
|
user_data2 = {"name":"Balazs", "details" : {"born" : "budapest"}}
|
||||||
|
print(registrar.receiveData("message","say_name", user_data))
|
||||||
|
print(registrar.sendData("message","say_name", user_data2))
|
||||||
|
"""
|
||||||
|
|
||||||
import base
|
import base
|
||||||
base.init()
|
base.init()
|
||||||
|
|
|
||||||
|
|
@ -22,18 +22,40 @@
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
/*addData("name", "Balazs", true);
|
/*addData("name", "Balazs", true);
|
||||||
getData("name");*/
|
getData("name");*/
|
||||||
|
window.sight.register("message","price_change")
|
||||||
|
window.sight.register("message","updated")
|
||||||
|
/*dict = {}
|
||||||
|
dict["account_id"] = 10227;
|
||||||
|
dict["account_name"] = "Test Bank";
|
||||||
|
dict["details"] = {};
|
||||||
|
dict["details"]["phone"] = 123456789
|
||||||
|
dict["details"]["place"] = "New York"
|
||||||
|
|
||||||
|
sendMessage("test",dict, ["other"])*/
|
||||||
});
|
});
|
||||||
|
|
||||||
function message(label, data) {
|
function recieveMessage(referral_name, data) {
|
||||||
|
if(referral_name === "price_change")
|
||||||
|
alert("MAIN got from OTHER (price_change): "+referral_name + " " + data.account_name+ " " + data.amount + " -> 12500")
|
||||||
|
data.amount = 12500
|
||||||
|
sendMessage("updated", data , ["other"])
|
||||||
|
}
|
||||||
|
|
||||||
|
/*function recieveMessage(referral_name, data) {
|
||||||
|
|
||||||
|
alert(referral_name + " " + data.account_name)
|
||||||
|
}*/
|
||||||
|
|
||||||
|
/*function message(label, data) {
|
||||||
if(label === "price_change") {
|
if(label === "price_change") {
|
||||||
sendMessage("changed_now")
|
//sendMessage("changed_now")
|
||||||
return "I update my price - "+label+"; DATA - "+data
|
return "I update my price - "+label+"; DATA - "+data
|
||||||
}
|
}
|
||||||
|
|
||||||
if(label === "test") {
|
if(label === "test") {
|
||||||
return "MAIN GOT TEST MESSAGE"+"; DATA - "+data
|
return "MAIN GOT TEST MESSAGE"+"; DATA - "+data
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
|
||||||
|
|
@ -9,23 +9,29 @@
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
//getData("name", true);
|
//getData("name", true);
|
||||||
sendMessage("price_change")
|
//sendMessage("price_change")
|
||||||
|
|
||||||
dict = {}
|
dict = {}
|
||||||
dict["account_id"] = 10227;
|
dict["account_id"] = 10227;
|
||||||
dict["account_name"] = "Test Bank";
|
dict["account_name"] = "Test Bank";
|
||||||
|
dict["amount"] = 15000;
|
||||||
dict["details"] = {};
|
dict["details"] = {};
|
||||||
dict["details"]["phone"] = 123456789
|
dict["details"]["phone"] = 123456789
|
||||||
dict["details"]["place"] = "New York"
|
dict["details"]["place"] = "New York"
|
||||||
sendMessage("test", ["other","main"], dict)
|
sendMessage("price_change", dict, ["main"])
|
||||||
});
|
});
|
||||||
|
|
||||||
function message(label,data) {
|
function recieveMessage(referral_name, data) {
|
||||||
|
if(referral_name === "updated")
|
||||||
|
alert("OTHER got from MAIN: updated - " + referral_name + " " + data.account_name+ " " + data.amount)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*function message(label,data) {
|
||||||
if(label === "test") {
|
if(label === "test") {
|
||||||
data_dict = JSON.parse(data)
|
data_dict = JSON.parse(data)
|
||||||
return "DATA - "+data_dict["account_name"] + " - " + data_dict["details"]["place"]
|
return "DATA - "+data_dict["account_name"] + " - " + data_dict["details"]["place"]
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
|
||||||
3
sight.py
3
sight.py
|
|
@ -44,6 +44,9 @@ class Sight(QWidget):
|
||||||
def getParent(self):
|
def getParent(self):
|
||||||
return self.parent
|
return self.parent
|
||||||
|
|
||||||
|
def getPageId(self):
|
||||||
|
return self.page
|
||||||
|
|
||||||
def setParent(self, id):
|
def setParent(self, id):
|
||||||
self.parent = id
|
self.parent = id
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ class SightFactory():
|
||||||
return None
|
return None
|
||||||
if len(id) == 0:
|
if len(id) == 0:
|
||||||
id = self.createUniqueId()
|
id = self.createUniqueId()
|
||||||
|
|
||||||
self.list[id] = Sight(id, page)
|
self.list[id] = Sight(id, page)
|
||||||
return id
|
return id
|
||||||
|
|
||||||
|
|
@ -71,7 +70,6 @@ class SightFactory():
|
||||||
if closeChildrenToo:
|
if closeChildrenToo:
|
||||||
self.closeChildren(id)
|
self.closeChildren(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)
|
||||||
|
|
@ -87,7 +85,6 @@ class SightFactory():
|
||||||
|
|
||||||
def sendMessage(self, label, sight_list, data):
|
def sendMessage(self, label, sight_list, data):
|
||||||
data = json.dumps(data)
|
data = json.dumps(data)
|
||||||
print(data)
|
|
||||||
if len(sight_list) == 0:
|
if len(sight_list) == 0:
|
||||||
for sight in self.list.values():
|
for sight in self.list.values():
|
||||||
sight.browser.page().runJavaScript("message('" + label + "', '"+str(data)+"')", self.ready)
|
sight.browser.page().runJavaScript("message('" + label + "', '"+str(data)+"')", self.ready)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue