Browse Source

actions: added param type hints

Fabian Peter Hammerle 4 years ago
parent
commit
c8fb9e6b97
1 changed files with 34 additions and 7 deletions
  1. 34 7
      rescriptoon/_actions.py

+ 34 - 7
rescriptoon/_actions.py

@@ -11,10 +11,23 @@ class EngineAction:
         self._target_engine_index = target_engine_index
 
     @abc.abstractmethod
-    def execute_on_window(self, overlay, xkeyevent, engine_window):
+    def execute_on_window(
+        self,
+        overlay: "rescriptoon.Overlay",
+        xkeyevent: typing.Union[
+            Xlib.protocol.event.KeyPress, Xlib.protocol.event.KeyRelease
+        ],
+        engine_window: "Xlib.display.Window",
+    ):
         raise NotImplementedError()
 
-    def execute(self, overlay, xkeyevent):
+    def execute(
+        self,
+        overlay: "rescriptoon.Overlay",
+        xkeyevent: typing.Union[
+            Xlib.protocol.event.KeyPress, Xlib.protocol.event.KeyRelease
+        ],
+    ):
         if self._target_engine_index is None:
             for target_window in overlay.engine_windows:
                 self.execute_on_window(overlay, xkeyevent, target_window)
@@ -27,13 +40,20 @@ class EngineAction:
 
 
 class CenterClickAction(EngineAction):
-    def __init__(self, target_engine_index, factor_x, factor_y):
+    def __init__(self, target_engine_index: int, factor_x: float, factor_y: float):
         super().__init__(target_engine_index=target_engine_index,)
         self._button = Xlib.X.Button1
         self._factor_x = factor_x
         self._factor_y = factor_y
 
-    def execute_on_window(self, overlay, xkeyevent, engine_window):
+    def execute_on_window(
+        self,
+        overlay: "rescriptoon.Overlay",
+        xkeyevent: typing.Union[
+            Xlib.protocol.event.KeyPress, Xlib.protocol.event.KeyRelease
+        ],
+        engine_window: "Xlib.display.Window",
+    ):
         engine_geometry = engine_window.get_geometry()
         smaller_dimension = min(engine_geometry.width, engine_geometry.height)
         attr = dict(
@@ -65,7 +85,7 @@ class SelectGagAction(CenterClickAction):
     X_OFFSET = -0.286
     X_FACTOR = 0.081
 
-    def __init__(self, target_engine_index, column_index, factor_y):
+    def __init__(self, target_engine_index: int, column_index: int, factor_y: float):
         super().__init__(
             target_engine_index=target_engine_index,
             factor_x=self.X_OFFSET + self.X_FACTOR * column_index,
@@ -78,7 +98,14 @@ class RewriteKeyEventAction(EngineAction):
         super().__init__(target_engine_index=target_engine_index,)
         self._keysym = keysym
 
-    def execute_on_window(self, overlay, xkeyevent, engine_window):
+    def execute_on_window(
+        self,
+        overlay: "rescriptoon.Overlay",
+        xkeyevent: typing.Union[
+            Xlib.protocol.event.KeyPress, Xlib.protocol.event.KeyRelease
+        ],
+        engine_window: "Xlib.display.Window",
+    ):
         engine_window.send_event(
             type(xkeyevent)(
                 window=engine_window,
@@ -99,6 +126,6 @@ class RewriteKeyEventAction(EngineAction):
 
 
 class ToggleOverlayAction:
-    def execute(self, overlay, xkeyevent):
+    def execute(self, overlay: "rescriptoon.Overlay", xkeyevent: "Xlib.display.Window"):
         if isinstance(xkeyevent, Xlib.protocol.event.KeyPress):
             overlay.toggle()