Skip to content

Commit

Permalink
Fix actionConfig for helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
IGalat committed Sep 24, 2024
1 parent b0245a9 commit 14637cf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/tapper/helper/_util/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,26 @@
from typing import Callable
from typing import Union

import mss as mss
import mss
import numpy
import numpy as np
import PIL.Image
import PIL.ImageGrab
import tapper
from mss.base import MSSBase
from numpy import ndarray
from tapper.helper._util import image_fuzz
from tapper.model import constants

_bbox_pattern = re.compile(r"\(BBOX_-?\d+_-?\d+_-?\d+_-?\d+\)")

mss = mss.mss()
mss_instance: MSSBase


def get_mss() -> MSSBase:
global mss_instance
mss_instance = mss.mss()
return mss_instance


@lru_cache
Expand Down Expand Up @@ -60,9 +67,12 @@ def get_screenshot_if_none_and_cut(
return maybe_image[bbox[1] : bbox[3], bbox[0] : bbox[2]]
return maybe_image
if bbox:
sct = mss.grab(bbox)
try:
sct = get_mss().grab(bbox)
except Exception as e:
raise e
else:
sct = mss.grab(mss.monitors[0])
sct = get_mss().grab(get_mss().monitors[0])
pil_rgb = PIL.Image.frombytes("RGB", sct.size, sct.bgra, "raw", "BGRX")
return numpy.asarray(pil_rgb)

Expand Down
2 changes: 1 addition & 1 deletion src/tapper/helper/_util/image_fuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ def find(outer: ndarray, inner: ndarray) -> tuple[float, tuple[int, int]]:

comparison = cv2.matchTemplate(outer, inner, cv2.TM_CCORR_NORMED)
_, max_val, _, max_loc = cv2.minMaxLoc(comparison)
return max_val, max_loc
return max_val, max_loc # type: ignore
5 changes: 5 additions & 0 deletions src/tapper/helper/_util/repeater.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from typing import Callable
from typing import Optional

from tapper.action.wrapper import ActionConfig
from tapper.action.wrapper import config_thread_local_storage
from tapper.model.constants import KeyDirBool
from tapper.model.types_ import Signal
from tapper.util import event
Expand All @@ -25,6 +27,9 @@ def run_task(repeatable: Callable[[], Any]) -> None:
global new_repeatable_queued
new_repeatable_queued = False
end_run = lambda: new_repeatable_queued or not running_repeatable
config_thread_local_storage.action_config = ActionConfig(
send_interval=0.01, send_press_duration=0.01
)

to_wait, repeats = registered_repeatables[repeatable]
for _ in range(repeats):
Expand Down

0 comments on commit 14637cf

Please sign in to comment.