apollo преди 4 дни
родител
ревизия
bc8ab0de54
променени са 1 файла, в които са добавени 24 реда и са изтрити 13 реда
  1. 24 13
      tyrell.py

+ 24 - 13
tyrell.py

@@ -7,10 +7,10 @@ from time import sleep as _sleep
 
 from typing import Dict as _Dict, List as _List, Optional as _Option, Any as _Any
 
-VERSION: str = '1.0-rel2'
+VERSION: str = '1.1-rel'
 
 try:
-    from click import echo as _echo, style as _style, command as _command, option as _option, argument as _arg
+    from click import echo as _echo, style as _style, command as _command, argument as _arg
 except ImportError:
     print("ERROR Please activate a virtual environment and install requirements.txt")
     exit()
@@ -317,7 +317,7 @@ def _key_write(write: str, delay:float=50.0, hold:float=20.0):
 
 class Action:
     # Toggle to determine if this action is 'on' or 'off'
-    state: bool
+    _state: bool
     # Key to trigger on (toggle on mirror)
     key: str
     # Kind of action to perform ('click', 'click down', 'key', 'key down', 'mirror')
@@ -344,9 +344,9 @@ class Action:
         assert 'write' in data or 'button' in data, "Action missing 'write' or 'button' (one needed)"
         # Assign class data
         if 'startup' in data:
-            self.state = True
+            self._state = True
         else:
-            self.state = False
+            self._state = False
         self.key = str(data['key'])
         self.kind = str(data['kind'])
         if 'write' in data:
@@ -377,24 +377,24 @@ class Action:
             self.hold = None
     
     def is_on(self) -> bool:
-        return self.state
+        return self._state
     
     def toggle(self, on: bool = False, off: bool = False) -> bool:
         if (not on and not off) or (on and off):
-            self.state = not self.state
+            self._state = not self._state
         elif on and not off:
-            self.state = True
+            self._state = True
         elif off and not on:
-            self.state = False
-        if self.state is False and self.is_ticker():
+            self._state = False
+        if self._state is False and self.is_ticker():
             # Reset elapsed time when set to off
             if self.elapsed is not None:
                 self.elapsed = None
-        elif self.state is True and self.is_ticker():
+        elif self._state is True and self.is_ticker():
             # Start elapsed time when set to on
             if self.elapsed is None:
                 self.elapsed = self.duration
-        return self.state
+        return self._state
     
     def is_ticker(self) -> bool:
         return self.duration is not None
@@ -574,6 +574,12 @@ class Profile:
             self._state = True
         elif off and not on:
             self._state = False
+        if self._state:
+            for act in self._actions:
+                a = self._actions[act]
+                if a.is_ticker() and a.is_on():
+                    a.toggle(False)
+                    _print_off(f"{act} (auto)")
         return self._state
     
     def show_help(self):
@@ -635,7 +641,12 @@ class Profile:
             for act in self._actions:
                 a = self._actions[act]
                 if a.tick():
-                    #_print_warn(f"{act} => tick event fired")
+                    # Print a status if the duration should exceed 5 seconds
+                    # This is so things like afk are more noticeable
+                    if a.duration is not None:
+                        d: float = (a.duration * self.tick) / 1000.0
+                        if d >= 5.0:
+                            _print_info(f"* {act} *")
                     a.do(self.delay, self.hold)
             await _asleep(self.tick / 1000)