|
@@ -89,12 +89,14 @@ else:
|
|
|
exit()
|
|
|
|
|
|
class Action():
|
|
|
+ name: str
|
|
|
kind: str
|
|
|
extra: Dict
|
|
|
toggled: bool
|
|
|
delay: int
|
|
|
max_delay: int
|
|
|
- def __init__(self, kind, extra=None, toggled=False, delay=0):
|
|
|
+ def __init__(self, name, kind, extra=None, toggled=False, delay=0):
|
|
|
+ self.name
|
|
|
self.kind = kind
|
|
|
self.extra = extra
|
|
|
self.toggled = toggled
|
|
@@ -138,6 +140,7 @@ class Action():
|
|
|
|
|
|
class Tyrell():
|
|
|
keybinds: Dict[str, Action]
|
|
|
+ #mirrors: Dict[str, str] # mirror key -> key in keybinds
|
|
|
toggled: bool
|
|
|
delay: int
|
|
|
hold: int
|
|
@@ -153,12 +156,18 @@ class Tyrell():
|
|
|
self.name = profile_name
|
|
|
if profile_name.endswith(".toml"):
|
|
|
self.name = profile_name.removesuffix(".toml")
|
|
|
- if exists(self.name+".toml"):
|
|
|
- with open(self.name+".toml", "r") as f:
|
|
|
+ if not exists(self.name) or not isdir(self.name):
|
|
|
+ print_err(f"Invalid profile '{self.name}'")
|
|
|
+ print_info(f"This should be a directory")
|
|
|
+ exit()
|
|
|
+ profile_config = join(self.name, self.name+".toml")
|
|
|
+ if exists(profile_config):
|
|
|
+ with open(profile_config, "r") as f:
|
|
|
try:
|
|
|
t = toml_load(f)
|
|
|
except Exception as err:
|
|
|
- print_err(f"Invalid profile '{self.name+'.toml'}'")
|
|
|
+ print_err(f"Invalid profile '{self.name}'")
|
|
|
+ print_info(f"Invalid '{self.name+'.toml'}' config")
|
|
|
print(err)
|
|
|
exit()
|
|
|
self.profile = t
|
|
@@ -175,12 +184,28 @@ class Tyrell():
|
|
|
if "placeholder_name" not in self.profile:
|
|
|
self.profile["placeholder_name"] = False
|
|
|
else:
|
|
|
- print_err(f"Invalid profile '{self.name+'.toml'}'")
|
|
|
+ print_err(f"Invalid profile '{self.name}'")
|
|
|
+ print_info(f"Missing '{self.name+'.toml'}' config")
|
|
|
exit()
|
|
|
self.delay = self.profile["delay"]
|
|
|
self.hold = self.profile["hold"]
|
|
|
self.keybinds = {}
|
|
|
+ #self.mirrors = {}
|
|
|
self.toggled = False
|
|
|
+ if not exists(join(self.name, 'keys')):
|
|
|
+ print_err(f"Invalid profile '{self.name}'")
|
|
|
+ print_info("Missing 'keys' directory (for keybinds)")
|
|
|
+ exit()
|
|
|
+ else:
|
|
|
+ for ent in listdir(join(self.name, "keys")):
|
|
|
+ if ent.startswith(".") or isdir(ent) or not ent.endswith(".toml"):
|
|
|
+ continue
|
|
|
+ with open(join(self.name, "keys", ent), "r") as f:
|
|
|
+ t = toml_load(f)
|
|
|
+ if "duration" in t:
|
|
|
+ self.add_action(t["keybind"], Action(ent.removesuffix(".toml"), t["kind"], extra=t, delay=t["duration"]))
|
|
|
+ else:
|
|
|
+ self.add_action(t["keybind"], Action(ent.removesuffix(".toml"), t["kind"], extra=t))
|
|
|
|
|
|
def toggle(self, all: bool=False, all_tickers: bool=False, all_notickers: bool=False) -> bool:
|
|
|
self.toggled = not self.toggled
|
|
@@ -239,6 +264,8 @@ class Tyrell():
|
|
|
if "placeholder_name" in self.profile:
|
|
|
if self.profile["placeholder_name"] and "write" in act.extra:
|
|
|
act.extra["write"] = act.extra["write"].replace("{name}", self.name)
|
|
|
+ if act.kind == "mirror" and "mirror" in act.extra:
|
|
|
+ self.mirrors[act.extra["mirror"]] = bind
|
|
|
self.keybinds[bind] = act
|
|
|
|
|
|
def remove_action(self, bind: str):
|
|
@@ -247,6 +274,19 @@ class Tyrell():
|
|
|
def is_action(self, bind: str) -> bool:
|
|
|
return self.keybinds[bind] is not None
|
|
|
|
|
|
+ def print_help(self):
|
|
|
+ print_ok(f"{int(1000 / self.profile['tick'])} ticks per second ({self.profile['tick']} ms per tick)")
|
|
|
+ print_ok(f"Name placeholder: {self.profile['placeholder_name']}")
|
|
|
+ print_warn(f"{self.profile['activator']} -> Activate/Deactivate")
|
|
|
+ print_warn(f"{self.profile['helper']} -> Displays Help")
|
|
|
+ for key in self.keybinds:
|
|
|
+ act = self.keybinds[key]
|
|
|
+ if act.max_delay == 0 and act.toggled:
|
|
|
+ print_info(f"{key} -> {act.name}")
|
|
|
+ else:
|
|
|
+ print_info(f"{key} -> {act.name} = {act.toggled} ({act.delay} ticks)")
|
|
|
+ print_ok("Please use " + style("CTRL+C", fg="bright_yellow") + " to stop")
|
|
|
+
|
|
|
def tick(self):
|
|
|
for key in self.keybinds:
|
|
|
act = self.keybinds[key]
|
|
@@ -255,6 +295,21 @@ class Tyrell():
|
|
|
|
|
|
def callback(self, event: KeyboardEvent):
|
|
|
key_name = event.name
|
|
|
+ #if key_name in self.mirrors:
|
|
|
+ # # key mirrors currently lag
|
|
|
+ # act = self.keybinds[self.mirrors[key_name]]
|
|
|
+ # if act.toggled:
|
|
|
+ # if "write" in act.extra:
|
|
|
+ # if event.event_type == "down":
|
|
|
+ # key_down(act.extra["write"])
|
|
|
+ # else:
|
|
|
+ # key_up(act.extra["write"])
|
|
|
+ # elif "button" in act.extra:
|
|
|
+ # if event.event_type == "down":
|
|
|
+ # mouse_down(button=act.extra["button"])
|
|
|
+ # else:
|
|
|
+ # mouse_up(button=act.extra["button"])
|
|
|
+ #if event.event_type == "up":
|
|
|
if key_name == self.profile["activator"]:
|
|
|
if self.toggle():
|
|
|
print_ok("ON")
|
|
@@ -265,17 +320,7 @@ class Tyrell():
|
|
|
#print(f"Code: {event.scan_code}")
|
|
|
#print(f"Modifiers: {event.modifiers}")
|
|
|
if self.profile["helper"] == "?" and "shift" in event.modifiers and event.name == "/" or key_name == self.profile["helper"]:
|
|
|
- print_ok(f"{int(1000 / self.profile['tick'])} ticks per second ({self.profile['tick']} ms per tick)")
|
|
|
- print_ok(f"Name placeholder: {self.profile['placeholder_name']}")
|
|
|
- print_warn(f"{self.profile["activator"]} -> Activate/Deactivate")
|
|
|
- print_warn(f"{self.profile["helper"]} -> Displays Help")
|
|
|
- for key in self.keybinds:
|
|
|
- act = self.keybinds[key]
|
|
|
- if act.max_delay == 0 and act.toggled:
|
|
|
- print_info(f"{key} -> {act.kind}")
|
|
|
- else:
|
|
|
- print_info(f"{key} -> {act.kind} = {act.toggled}")
|
|
|
- print_ok("Please use " + style("CTRL+C", fg="bright_yellow") + " to stop")
|
|
|
+ self.print_help()
|
|
|
elif key_name in self.keybinds:
|
|
|
act = self.keybinds[key_name]
|
|
|
if act.max_delay == 0 and act.toggled:
|
|
@@ -307,32 +352,17 @@ if __name__ == "__main__":
|
|
|
print()
|
|
|
exit()
|
|
|
ty = Tyrell(",".join(argv[1:]))
|
|
|
- if not exists("keys"):
|
|
|
- print_err("Missing 'keys' directory")
|
|
|
- print_info("(Might want some keybinds)")
|
|
|
- exit()
|
|
|
- print_ok(f"{int(1000 / ty.profile['tick'])} ticks per second ({ty.profile['tick']} ms per tick)")
|
|
|
- print_ok(f"Name placeholder: {ty.profile['placeholder_name']}")
|
|
|
- print_warn(f"{ty.profile["activator"]} -> Activate/Deactivate")
|
|
|
- print_warn(f"{ty.profile["helper"]} -> Displays Help")
|
|
|
- for ent in listdir("keys"):
|
|
|
- if ent.startswith(".") or not ent.endswith(".toml") or isdir(ent):
|
|
|
- continue
|
|
|
- with open(join("keys", ent), "r") as f:
|
|
|
- t = toml_load(f)
|
|
|
- if "duration" in t:
|
|
|
- ty.add_action(t["keybind"], Action(t["kind"], extra=t, delay=t["duration"]))
|
|
|
- else:
|
|
|
- ty.add_action(t["keybind"], Action(t["kind"], extra=t))
|
|
|
- print_info(f"{t['keybind']} -> {t['kind']}")
|
|
|
if len(ty.keybinds) == 0:
|
|
|
print_err("Missing keybinds")
|
|
|
print_info("(Might want some keybinds, place them in a 'keys' directory)")
|
|
|
- print_info("( Need an example? Look at 'example.toml')")
|
|
|
+ print_info(f"( Need an example? Look at '{join('_example', 'keys', 'example.toml')}')")
|
|
|
exit()
|
|
|
ty.enable(all_notickers=True)
|
|
|
ty.disable()
|
|
|
- print_ok("Please use " + style("CTRL+C", fg="bright_yellow") + " to stop")
|
|
|
+ ty.print_help()
|
|
|
+ if ty.name == "_example":
|
|
|
+ print_warn("This is the " + style("example", fg="bright_yellow") + ", please define you're own profile")
|
|
|
+ print_info("Please DO NOT EDIT this example profile")
|
|
|
try:
|
|
|
run(ty.mainloop())
|
|
|
except KeyboardInterrupt:
|