|
@@ -8,12 +8,24 @@ import Xlib.protocol.event
|
|
|
import Xlib.X
|
|
|
import Xlib.XK
|
|
|
|
|
|
+from rescriptoon._keys import keysym_to_label
|
|
|
+
|
|
|
_XKEYEVENT_TYPE = typing.Union[
|
|
|
Xlib.protocol.event.KeyPress, Xlib.protocol.event.KeyRelease
|
|
|
]
|
|
|
|
|
|
|
|
|
-class EngineAction:
|
|
|
+class _Action:
|
|
|
+ @abc.abstractmethod
|
|
|
+ def execute(self, overlay: "rescriptoon.Overlay", xkeyevent: _XKEYEVENT_TYPE):
|
|
|
+ raise NotImplementedError()
|
|
|
+
|
|
|
+ @abc.abstractproperty
|
|
|
+ def description(self) -> str:
|
|
|
+ raise NotImplementedError()
|
|
|
+
|
|
|
+
|
|
|
+class EngineAction(_Action):
|
|
|
def __init__(self, target_engine_index: typing.Optional[int] = None):
|
|
|
self._target_engine_index = target_engine_index
|
|
|
|
|
@@ -39,6 +51,12 @@ class EngineAction:
|
|
|
overlay, xkeyevent, overlay.engine_windows[self._target_engine_index]
|
|
|
)
|
|
|
|
|
|
+ @property
|
|
|
+ def _engine_label(self) -> str:
|
|
|
+ if self._target_engine_index is None:
|
|
|
+ return "all engines"
|
|
|
+ return "engine #{}".format(self._target_engine_index)
|
|
|
+
|
|
|
|
|
|
class CenterClickAction(EngineAction):
|
|
|
def __init__(self, target_engine_index: int, factor_x: float, factor_y: float):
|
|
@@ -84,12 +102,23 @@ class SelectGagAction(CenterClickAction):
|
|
|
X_OFFSET = -0.286
|
|
|
X_FACTOR = 0.081
|
|
|
|
|
|
- def __init__(self, target_engine_index: int, column_index: int, factor_y: float):
|
|
|
+ def __init__(
|
|
|
+ self,
|
|
|
+ target_engine_index: int,
|
|
|
+ column_index: int,
|
|
|
+ factor_y: float,
|
|
|
+ gag_name: str,
|
|
|
+ ):
|
|
|
super().__init__(
|
|
|
target_engine_index=target_engine_index,
|
|
|
factor_x=self.X_OFFSET + self.X_FACTOR * column_index,
|
|
|
factor_y=factor_y,
|
|
|
)
|
|
|
+ self._gag_name = gag_name
|
|
|
+
|
|
|
+ @property
|
|
|
+ def description(self) -> str:
|
|
|
+ return "select {} in battle @ {}".format(self._gag_name, self._engine_label)
|
|
|
|
|
|
|
|
|
def _send_rewritten_xkeyevent(
|
|
@@ -118,7 +147,11 @@ def _send_rewritten_xkeyevent(
|
|
|
|
|
|
|
|
|
class RewriteKeyEventAction(EngineAction):
|
|
|
- def __init__(self, target_engine_index: typing.Optional[int] = None, keysym=None):
|
|
|
+ def __init__(
|
|
|
+ self,
|
|
|
+ target_engine_index: typing.Optional[int] = None,
|
|
|
+ keysym: typing.Optional[int] = None,
|
|
|
+ ):
|
|
|
super().__init__(target_engine_index=target_engine_index,)
|
|
|
self._keysym = keysym
|
|
|
|
|
@@ -131,9 +164,17 @@ class RewriteKeyEventAction(EngineAction):
|
|
|
_send_rewritten_xkeyevent(
|
|
|
event_template=xkeyevent,
|
|
|
window=engine_window,
|
|
|
- keycode=overlay.xdisplay.keysym_to_keycode(self._keysym),
|
|
|
+ keycode=overlay.xdisplay.keysym_to_keycode(self._keysym)
|
|
|
+ if self._keysym is not None
|
|
|
+ else xkeyevent.detail,
|
|
|
)
|
|
|
|
|
|
+ @property
|
|
|
+ def description(self) -> str:
|
|
|
+ if self._keysym is None:
|
|
|
+ return "forward to {}".format(self._engine_label)
|
|
|
+ return "send {} to {}".format(keysym_to_label(self._keysym), self._engine_label)
|
|
|
+
|
|
|
|
|
|
class LowThrowAction(EngineAction):
|
|
|
|
|
@@ -162,8 +203,16 @@ class LowThrowAction(EngineAction):
|
|
|
event_type=Xlib.protocol.event.KeyRelease,
|
|
|
)
|
|
|
|
|
|
+ @property
|
|
|
+ def description(self) -> str:
|
|
|
+ return "low throw @ {}".format(self._engine_label)
|
|
|
|
|
|
-class ToggleOverlayAction:
|
|
|
- def execute(self, overlay: "rescriptoon.Overlay", xkeyevent: "Xlib.display.Window"):
|
|
|
+
|
|
|
+class ToggleOverlayAction(_Action):
|
|
|
+ def execute(self, overlay: "rescriptoon.Overlay", xkeyevent: _XKEYEVENT_TYPE):
|
|
|
if isinstance(xkeyevent, Xlib.protocol.event.KeyPress):
|
|
|
overlay.toggle()
|
|
|
+
|
|
|
+ @property
|
|
|
+ def description(self) -> str:
|
|
|
+ return "enable/disable rescriptoon"
|