Log message function in base logMsg(). base.where() give back the current class and function name.
base code is cleaned up.main
parent
abcc4f41eb
commit
fc576a32f5
34
base.py
34
base.py
|
|
@ -15,12 +15,12 @@ def init():
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
mousectrl = Controller()
|
mousectrl = Controller()
|
||||||
sights = SightFactory()
|
sights = SightFactory()
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
data["move"] = False
|
data["move"] = False
|
||||||
data["active_sight"] = "main"
|
data["active_sight"] = "main"
|
||||||
data["platform"] = {}
|
data["platform"] = {}
|
||||||
data["platform"]["system"] = platform.system()
|
data["platform"]["system"] = platform.system()
|
||||||
data["sight_processes"] = {}
|
|
||||||
data["mouse_distance_x"] = 0
|
data["mouse_distance_x"] = 0
|
||||||
data["mouse_distance_y"] = 0
|
data["mouse_distance_y"] = 0
|
||||||
data["display_server"] = ""
|
data["display_server"] = ""
|
||||||
|
|
@ -28,11 +28,11 @@ def init():
|
||||||
args = ["echo -n $XDG_SESSION_TYPE"]
|
args = ["echo -n $XDG_SESSION_TYPE"]
|
||||||
result = subprocess.check_output(args, shell=True)
|
result = subprocess.check_output(args, shell=True)
|
||||||
data["display_server"] = result.decode('ascii')
|
data["display_server"] = result.decode('ascii')
|
||||||
print("D "+data["display_server"])
|
|
||||||
data["base_dir"]=os.path.abspath(os.getcwd())+os.path.sep
|
data["base_dir"]=os.path.abspath(os.getcwd())+os.path.sep
|
||||||
data["template_dir"]=data["base_dir"]+"place"+os.path.sep+"templates"+os.path.sep
|
data["template_dir"]=data["base_dir"]+"place"+os.path.sep+"templates"+os.path.sep
|
||||||
#LOAD the template config content
|
#LOAD the template config.ini file's content
|
||||||
loadConfigTemplate()
|
loadConfigTemplate()
|
||||||
|
|
||||||
#Events
|
#Events
|
||||||
mouseevent = MouseEvents()
|
mouseevent = MouseEvents()
|
||||||
start()
|
start()
|
||||||
|
|
@ -42,6 +42,20 @@ def frameSupported():
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def where():
|
||||||
|
# for current func name, specify 0 or no argument.
|
||||||
|
# for name of caller of current func, specify 1.
|
||||||
|
# for name of caller of caller of current func, specify 2. etc.
|
||||||
|
currentFuncName = lambda n=0: sys._getframe(n + 1).f_code.co_name
|
||||||
|
|
||||||
|
try:
|
||||||
|
currentClassName = sys._getframe(1).f_locals["self"].__class__.__name__
|
||||||
|
except KeyError:
|
||||||
|
currentClassName = None
|
||||||
|
|
||||||
|
return str(currentClassName) + " -> " + currentFuncName(1)
|
||||||
|
|
||||||
def loadConfigTemplate():
|
def loadConfigTemplate():
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.sections()
|
config.sections()
|
||||||
|
|
@ -51,14 +65,18 @@ def loadConfigTemplate():
|
||||||
data["default_template_page"] = config["DEFAULT"]["default_template_page"]
|
data["default_template_page"] = config["DEFAULT"]["default_template_page"]
|
||||||
data["default_template_dir"] = data["template_dir"]+data["default_template"]+os.path.sep
|
data["default_template_dir"] = data["template_dir"]+data["default_template"]+os.path.sep
|
||||||
data["sight_mode"] = config["DEFAULT"]["sight_mode"]
|
data["sight_mode"] = config["DEFAULT"]["sight_mode"]
|
||||||
print("Template config is loaded!")
|
logMsg("LOADED","CONFIG.INI file", where())
|
||||||
else:
|
else:
|
||||||
print("Missing 'DEFAULT' data from the templates config.ini folder. It can't start!")
|
logMsg("ERROR", "Missing 'DEFAULT' data from the templates config.ini folder. It can't start!", where())
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
# Creating the main Sight
|
# Creating the main Sight
|
||||||
sights.create("main", data["default_template_page"]);
|
sights.create("main", data["default_template_page"])
|
||||||
sights.processes();
|
sights.show("main")
|
||||||
sights.show("main");
|
|
||||||
|
|
||||||
app.exec()
|
app.exec()
|
||||||
|
|
||||||
|
def logMsg(status, msg, where = ""):
|
||||||
|
if len(str(where)) > 0:
|
||||||
|
where = "("+where+")"
|
||||||
|
print("["+status+"]", str(msg), where, sep='\t')
|
||||||
|
|
@ -15,5 +15,5 @@ class Browser(QWebEngineView):
|
||||||
self.page().setWebChannel(self.channel)
|
self.page().setWebChannel(self.channel)
|
||||||
|
|
||||||
def loadContent(self, page):
|
def loadContent(self, page):
|
||||||
print(base.data["default_template_dir"]+page+".html")
|
|
||||||
self.load(QUrl.fromLocalFile(base.data["default_template_dir"]+page+".html"))
|
self.load(QUrl.fromLocalFile(base.data["default_template_dir"]+page+".html"))
|
||||||
|
base.logMsg("LOADED", base.data["default_template_dir"]+page+".html", base.where())
|
||||||
|
|
@ -10,12 +10,12 @@ class CallHandler(QObject):
|
||||||
self.sight = sight
|
self.sight = sight
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def console(self, t):
|
def console(self, msg):
|
||||||
print(t)
|
base.logMsg("CONSOLE", msg)
|
||||||
|
|
||||||
@pyqtSlot(str, result=str)
|
@pyqtSlot(str, result=str)
|
||||||
def test2(self, t):
|
def test2(self, t):
|
||||||
print(t)
|
print(t+"s")
|
||||||
return t + "_return"
|
return t + "_return"
|
||||||
|
|
||||||
@pyqtSlot(result=str)
|
@pyqtSlot(result=str)
|
||||||
|
|
@ -119,7 +119,7 @@ class CallHandler(QObject):
|
||||||
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)
|
||||||
|
|
||||||
print("Message - " + label)
|
base.logMsg("MESSAGE",label, base.where())
|
||||||
if len(sight_list) == 0:
|
if len(sight_list) == 0:
|
||||||
for sight in base.sights.getSights().values():
|
for sight in base.sights.getSights().values():
|
||||||
sight.browser.page().runJavaScript("message('" + label + "', '"+data+"')", self.ready)
|
sight.browser.page().runJavaScript("message('" + label + "', '"+data+"')", self.ready)
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@ class SightFactory():
|
||||||
self.data = {} #Global data(s) for the sight(s)
|
self.data = {} #Global data(s) for the sight(s)
|
||||||
|
|
||||||
def create(self, id, page):
|
def create(self, id, page):
|
||||||
print("----- "+page+"-"+str(id)+"-------")
|
base.logMsg("CREATING","The page '" + str(page) + "' with '"+str(id)+"' id.",base.where())
|
||||||
|
|
||||||
if str(id) == "main" and self.checkKey(id):
|
if str(id) == "main" and self.checkKey(id):
|
||||||
print("The 'main' window already exist! You can't create more than one 'main' page sight!")
|
base.logMsg("WARNING", "The '"+str(id)+"' window already exist! You can't create more than one 'main' page sight!", base.where())
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if base.data["sight_mode"] == "unique":
|
if base.data["sight_mode"] == "unique":
|
||||||
|
|
@ -39,9 +39,9 @@ class SightFactory():
|
||||||
def show(self, id):
|
def show(self, id):
|
||||||
if self.checkKey(id):
|
if self.checkKey(id):
|
||||||
self.list[id].show()
|
self.list[id].show()
|
||||||
print("The '"+str(id)+"' sight is showed!")
|
base.logMsg("SHOWED","The '"+str(id)+"' sight is showed!", base.where())
|
||||||
return True
|
return True
|
||||||
print("This '"+str(id)+"' id isn't exist to show!")
|
base.logMsg("MISSING", "This '"+str(id)+"' id isn't exist to show!", base.where())
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def getSights(self):
|
def getSights(self):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue