sightplace-rep/base.py

82 lines
2.6 KiB
Python

import sys
import os
import platform
import configparser
from mouseevents import MouseEvents
from pynput import mouse
from sightfactory import SightFactory
from PyQt6.QtWidgets import QApplication
from pynput.mouse import Controller
import subprocess
def init():
global data, sights, mousectrl, app
#init the basic values
app = QApplication(sys.argv)
mousectrl = Controller()
sights = SightFactory()
data = {}
data["move"] = False
data["active_sight"] = "main"
data["platform"] = {}
data["platform"]["system"] = platform.system()
data["mouse_distance_x"] = 0
data["mouse_distance_y"] = 0
data["display_server"] = ""
if data["platform"]["system"] == "Linux":
args = ["echo -n $XDG_SESSION_TYPE"]
result = subprocess.check_output(args, shell=True)
data["display_server"] = result.decode('ascii')
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.ini file's content
loadConfigTemplate()
#Events
mouseevent = MouseEvents()
start()
def frameSupported():
if data["display_server"] == "wayland":
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()
config.read(data["template_dir"]+"config.ini")
if "DEFAULT" in config:
data["default_template"] = config["DEFAULT"]["default_template"]
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"]
logMsg("LOADED","CONFIG.INI file", where())
else:
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.show("main")
app.exec()
def logMsg(status, msg, where = ""):
if len(str(where)) > 0:
where = "("+where+")"
print("["+status+"]", str(msg), where, sep='\t')