Log message function in base logMsg(). base.where() give back the current class and function name.

base code is cleaned up.
main
Balazs Birtalan 2023-10-31 07:20:44 +00:00
parent abcc4f41eb
commit fc576a32f5
4 changed files with 36 additions and 18 deletions

34
base.py
View File

@ -15,12 +15,12 @@ def init():
app = QApplication(sys.argv)
mousectrl = Controller()
sights = SightFactory()
data = {}
data["move"] = False
data["active_sight"] = "main"
data["platform"] = {}
data["platform"]["system"] = platform.system()
data["sight_processes"] = {}
data["mouse_distance_x"] = 0
data["mouse_distance_y"] = 0
data["display_server"] = ""
@ -28,11 +28,11 @@ def init():
args = ["echo -n $XDG_SESSION_TYPE"]
result = subprocess.check_output(args, shell=True)
data["display_server"] = result.decode('ascii')
print("D "+data["display_server"])
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
#LOAD the template config content
#LOAD the template config.ini file's content
loadConfigTemplate()
#Events
mouseevent = MouseEvents()
start()
@ -42,6 +42,20 @@ def frameSupported():
return False
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():
config = configparser.ConfigParser()
config.sections()
@ -51,14 +65,18 @@ def loadConfigTemplate():
data["default_template_page"] = config["DEFAULT"]["default_template_page"]
data["default_template_dir"] = data["template_dir"]+data["default_template"]+os.path.sep
data["sight_mode"] = config["DEFAULT"]["sight_mode"]
print("Template config is loaded!")
logMsg("LOADED","CONFIG.INI file", where())
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():
# Creating the main Sight
sights.create("main", data["default_template_page"]);
sights.processes();
sights.show("main");
sights.create("main", data["default_template_page"])
sights.show("main")
app.exec()
def logMsg(status, msg, where = ""):
if len(str(where)) > 0:
where = "("+where+")"
print("["+status+"]", str(msg), where, sep='\t')

View File

@ -15,5 +15,5 @@ class Browser(QWebEngineView):
self.page().setWebChannel(self.channel)
def loadContent(self, page):
print(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())

View File

@ -10,12 +10,12 @@ class CallHandler(QObject):
self.sight = sight
@pyqtSlot(str)
def console(self, t):
print(t)
def console(self, msg):
base.logMsg("CONSOLE", msg)
@pyqtSlot(str, result=str)
def test2(self, t):
print(t)
print(t+"s")
return t + "_return"
@pyqtSlot(result=str)
@ -119,7 +119,7 @@ class CallHandler(QObject):
def message(self, label, sight_id_json, data):
sight_list = json.loads(sight_id_json)
print("Message - " + label)
base.logMsg("MESSAGE",label, base.where())
if len(sight_list) == 0:
for sight in base.sights.getSights().values():
sight.browser.page().runJavaScript("message('" + label + "', '"+data+"')", self.ready)

View File

@ -8,10 +8,10 @@ class SightFactory():
self.data = {} #Global data(s) for the sight(s)
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):
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
if base.data["sight_mode"] == "unique":
@ -39,9 +39,9 @@ class SightFactory():
def show(self, id):
if self.checkKey(id):
self.list[id].show()
print("The '"+str(id)+"' sight is showed!")
base.logMsg("SHOWED","The '"+str(id)+"' sight is showed!", base.where())
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
def getSights(self):