From 4051927ea3821e51848fc31f3fc79a4024b84696 Mon Sep 17 00:00:00 2001 From: Anonymus Raccoon Date: Sat, 25 Apr 2020 19:35:44 +0200 Subject: [PATCH] Allowing x commands to be disabled --- main.py | 15 +++++++++++---- trick.py | 10 +++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 6334911..d05fca0 100755 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import time import pyxhook +import sys from term_utils import Term from command_helper import CommandHelper @@ -12,6 +13,7 @@ class AnonymousGoose: self.should_exit = False self.stopped = False self.tricks = [] + self.log = [] self.keyboard_listener = pyxhook.HookManager() self.keyboard_listener.KeyUp = self.key_pressed self.keyboard_listener.HookKeyboard() @@ -24,7 +26,7 @@ class AnonymousGoose: for trick in self.tricks: trick.revert() - def run(self): + def run(self, disable_x): next_trick_time = 5 while not self.should_exit: try: @@ -33,7 +35,7 @@ class AnonymousGoose: time.sleep(1) next_trick_time -= 1 if next_trick_time <= 0: - trick = Trick.get_random_trick() + trick = Trick.get_random_trick(not disable_x) next_trick_time = trick.delay trick.run() if trick.is_reversible: @@ -44,7 +46,10 @@ class AnonymousGoose: def key_pressed(self, key): if key.Ascii == 27: self.should_exit = True - + else: + self.log.append(key.key_pressed) + print(self.log) + def stop(self): if self.stopped: return @@ -53,6 +58,8 @@ class AnonymousGoose: if __name__ == "__main__": + disable_x = len(sys.argv) == 2 and sys.argv[1] == '-x' + goose = AnonymousGoose() - goose.run() + goose.run(disable_x) goose.stop() diff --git a/trick.py b/trick.py index 0bb75d0..4158b1a 100644 --- a/trick.py +++ b/trick.py @@ -28,7 +28,7 @@ class Trick(ABC): raise NotImplementedError @staticmethod - def get_random_trick(): + def get_random_trick(keep_x): from tricks.laughing_goose import LaughingGooseTrick from tricks.glorify_goose import GlorifyGooseTrick from tricks.anim_ascii import AnimAsciiTrick @@ -37,9 +37,13 @@ class Trick(ABC): tricks = [ LaughingGooseTrick, GlorifyGooseTrick, - #AnimAsciiTrick, + #AnimAsciiTrick + ] + x_tricks = [ ReflectionTrick, RotationTrick ] - + + if keep_x: + return random.choice(tricks + x_tricks)() return random.choice(tricks)()