2022-08-28 23:47:15 +00:00
|
|
|
# Python imports
|
2023-03-04 03:19:39 +00:00
|
|
|
import os
|
|
|
|
import builtins
|
|
|
|
import threading
|
2022-02-15 08:11:00 +00:00
|
|
|
|
2022-08-28 23:47:15 +00:00
|
|
|
# Lib imports
|
|
|
|
|
|
|
|
# Application imports
|
2024-03-01 01:42:40 +00:00
|
|
|
from libs.logger import Logger
|
|
|
|
|
2024-02-29 03:27:13 +00:00
|
|
|
from libs.pyautogui_control import ControlMixin
|
|
|
|
from libs.endpoint_registry import EndpointRegistry
|
|
|
|
from libs.event_system import EventSystem
|
2022-08-28 23:47:15 +00:00
|
|
|
|
|
|
|
|
2022-08-30 22:17:35 +00:00
|
|
|
|
2022-08-28 23:47:15 +00:00
|
|
|
# NOTE: Threads WILL NOT die with parent's destruction.
|
|
|
|
def threaded_wrapper(fn):
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=False).start()
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
# NOTE: Threads WILL die with parent's destruction.
|
|
|
|
def daemon_threaded_wrapper(fn):
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-03-04 03:19:39 +00:00
|
|
|
class MissingConfigError(Exception):
|
|
|
|
pass
|
|
|
|
|
2022-08-28 23:47:15 +00:00
|
|
|
|
|
|
|
class Pyautogui_Controller(ControlMixin):
|
2022-02-15 08:11:00 +00:00
|
|
|
def __init__(self):
|
2022-08-30 22:17:35 +00:00
|
|
|
self.isCtrlOn = False
|
|
|
|
self.isShiftOn = False
|
|
|
|
self.isAltOn = False
|
|
|
|
|
2022-02-15 08:11:00 +00:00
|
|
|
|
2022-08-28 23:47:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
keys_json = {
|
|
|
|
"keys": {
|
|
|
|
"row1": {
|
|
|
|
"pKeys": ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
|
2023-03-04 03:19:39 +00:00
|
|
|
"sKeys": ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
|
2022-08-28 23:47:15 +00:00
|
|
|
},
|
|
|
|
"row2": {
|
|
|
|
"pKeys": ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'],
|
2023-03-04 03:19:39 +00:00
|
|
|
"sKeys": ['\\', '^', '#', '$', '%', '&', '-', '_', '"', '*']
|
2022-08-28 23:47:15 +00:00
|
|
|
},
|
|
|
|
"row3": {
|
|
|
|
"pKeys": ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', "'"],
|
2023-03-04 03:19:39 +00:00
|
|
|
"sKeys": ['/', '|', ':', '=', '+', '', '', '', ';', '!']
|
2022-08-28 23:47:15 +00:00
|
|
|
},
|
|
|
|
"row4": {
|
|
|
|
"pKeys": ['z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '?'],
|
2023-03-04 03:19:39 +00:00
|
|
|
"sKeys": ['', '', '<', '>', '[', ']', '(', ')', '{', '}']
|
2022-08-28 23:47:15 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# NOTE: Just reminding myself we can add to builtins two different ways...
|
|
|
|
# __builtins__.update({"event_system": Builtins()})
|
2023-03-04 03:19:39 +00:00
|
|
|
builtins.app_name = "Mouse-Keyboard"
|
2022-08-28 23:47:15 +00:00
|
|
|
builtins.threaded = threaded_wrapper
|
|
|
|
builtins.daemon_threaded = daemon_threaded_wrapper
|
|
|
|
builtins.keys_set = keys_json
|
|
|
|
builtins.trace_debug = False
|
|
|
|
builtins.debug = False
|
|
|
|
builtins.app_settings = None
|
2023-03-04 03:19:39 +00:00
|
|
|
builtins.get_clipboard = ['xclip','-selection', 'clipboard', '-o']
|
|
|
|
builtins.set_clipboard = ['xclip','-selection','clipboard']
|
2024-03-01 01:42:40 +00:00
|
|
|
builtins.FKEYS = [ f"F{i}" for i in range(1, 13) ]
|
|
|
|
builtins.LSIDE_KEYS = ["<Ctrl>", "<Shift>", "<Alt>"]
|
|
|
|
builtins.RSIDE_KEYS = ["</Ctrl>", "</Shift>", "</Alt>"]
|
2023-03-04 03:19:39 +00:00
|
|
|
|
|
|
|
|
2024-03-01 01:42:40 +00:00
|
|
|
_USER_HOME = os.path.expanduser('~')
|
|
|
|
_USR_PATH = f"/usr/share/{app_name.lower()}"
|
|
|
|
_CONFIG_PATH = f"{_USER_HOME}/.config/{app_name.lower()}"
|
|
|
|
_ICON_FILE = f"{_CONFIG_PATH}/icons/{app_name.lower()}.png"
|
|
|
|
_CSS_FILE = f"{_CONFIG_PATH}/stylesheet.css"
|
2024-08-31 05:46:53 +00:00
|
|
|
_DICT_FILE = f"{_CONFIG_PATH}/edmt_dictionary.json"
|
2024-03-01 01:42:40 +00:00
|
|
|
_EMOJI_FILE = f"{_CONFIG_PATH}/emoji.json"
|
2024-08-31 05:46:53 +00:00
|
|
|
_LOG_PATH = f"{_CONFIG_PATH}"
|
2024-03-01 01:42:40 +00:00
|
|
|
ch_log_lvl: int = 10
|
|
|
|
fh_log_lvl: int = 20
|
2023-03-04 03:19:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(_ICON_FILE):
|
|
|
|
_ICON_FILE = f"{_USR_PATH}/icons/{app_name.lower()}.png"
|
|
|
|
if not os.path.exists(_ICON_FILE):
|
|
|
|
raise MissingConfigError("Unable to find the application icon.")
|
|
|
|
|
|
|
|
if not os.path.exists(_CSS_FILE):
|
|
|
|
_CSS_FILE = f"{_USR_PATH}/stylesheet.css"
|
|
|
|
if not os.path.exists(_CSS_FILE):
|
|
|
|
raise MissingConfigError("Unable to find the stylesheet.")
|
|
|
|
|
|
|
|
if not os.path.exists(_EMOJI_FILE):
|
|
|
|
_EMOJI_FILE = f"{_USR_PATH}/emoji.json"
|
|
|
|
if not os.path.exists(_EMOJI_FILE):
|
|
|
|
raise MissingConfigError("Unable to find the stylesheet.")
|
|
|
|
|
|
|
|
|
|
|
|
builtins.CONFIG_PATH = _CONFIG_PATH
|
|
|
|
builtins.ICON_FILE = _ICON_FILE
|
|
|
|
builtins.CSS_FILE = _CSS_FILE
|
2024-08-31 05:46:53 +00:00
|
|
|
builtins.DICT_FILE = _DICT_FILE
|
2023-03-04 03:19:39 +00:00
|
|
|
builtins.EMOJI_FILE = _EMOJI_FILE
|
2024-03-01 01:42:40 +00:00
|
|
|
|
|
|
|
|
2024-08-31 05:46:53 +00:00
|
|
|
builtins.logger = Logger(_LOG_PATH, ch_log_lvl, fh_log_lvl).get_logger()
|
2024-03-01 01:42:40 +00:00
|
|
|
builtins.endpoint_registry = EndpointRegistry()
|
|
|
|
builtins.event_system = EventSystem()
|
|
|
|
builtins.typwriter = Pyautogui_Controller()
|