Skip to content

Commit

Permalink
Merge b6e8abf into e4d00ae
Browse files Browse the repository at this point in the history
  • Loading branch information
spyoungtech committed May 11, 2023
2 parents e4d00ae + b6e8abf commit 25e43b5
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 2 deletions.
6 changes: 5 additions & 1 deletion ahk/_async/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2698,9 +2698,13 @@ async def image_search(
args = [str(x1), str(y1), str(x2), str(y2)]
if options:
opts = ' '.join(f'*{opt}' for opt in options)
args.append(opts)
args.append(opts + f' {image_path}')
else:
args.append(image_path)

if coord_mode is not None:
args.append(coord_mode)

resp = await self._transport.function_call('AHKImageSearch', args, blocking=blocking)
return resp

Expand Down
20 changes: 20 additions & 0 deletions ahk/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,11 @@
WinSet, TransColor, %color%, %title%, %text%, %extitle%, %extext%
DetectHiddenWindows, %current_detect_hw%
SetTitleMatchMode, %current_match_mode%
SetTitleMatchMode, %current_match_speed%
return FormatNoValueResponse()
{% endblock AHKWinSetTransColor %}
}
Expand All @@ -1590,14 +1595,29 @@
y1 := command[3]
x2 := command[4]
y2 := command[5]
coord_mode := command[7]
current_mode := Format("{}", A_CoordModePixel)
if (coord_mode != "") {
CoordMode, Pixel, %coord_mode%
}
if (x2 = "A_ScreenWidth") {
x2 := A_ScreenWidth
}
if (y2 = "A_ScreenHeight") {
y2 := A_ScreenHeight
}
ImageSearch, xpos, ypos,% x1,% y1,% x2,% y2, %imagepath%
if (coord_mode != "") {
CoordMode, Pixel, %current_mode%
}
if (ErrorLevel = 2) {
s := FormatResponse(EXCEPTIONRESPONSEMESSAGE, "there was a problem that prevented the command from conducting the search (such as failure to open the image file or a badly formatted option)")
} else if (ErrorLevel = 1) {
Expand Down
5 changes: 4 additions & 1 deletion ahk/_sync/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2687,9 +2687,12 @@ def image_search(
args = [str(x1), str(y1), str(x2), str(y2)]
if options:
opts = ' '.join(f'*{opt}' for opt in options)
args.append(opts)
args.append(opts + f' {image_path}')
else:
args.append(image_path)

if coord_mode is not None:
args.append(coord_mode)
resp = self._transport.function_call('AHKImageSearch', args, blocking=blocking)
return resp

Expand Down
20 changes: 20 additions & 0 deletions ahk/templates/daemon.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,11 @@ AHKWinSetTransColor(ByRef command) {


WinSet, TransColor, %color%, %title%, %text%, %extitle%, %extext%

DetectHiddenWindows, %current_detect_hw%
SetTitleMatchMode, %current_match_mode%
SetTitleMatchMode, %current_match_speed%

return FormatNoValueResponse()
{% endblock AHKWinSetTransColor %}
}
Expand All @@ -1587,14 +1592,29 @@ AHKImageSearch(ByRef command) {
y1 := command[3]
x2 := command[4]
y2 := command[5]
coord_mode := command[7]

current_mode := Format("{}", A_CoordModePixel)

if (coord_mode != "") {
CoordMode, Pixel, %coord_mode%
}

if (x2 = "A_ScreenWidth") {
x2 := A_ScreenWidth
}
if (y2 = "A_ScreenHeight") {
y2 := A_ScreenHeight
}

ImageSearch, xpos, ypos,% x1,% y1,% x2,% y2, %imagepath%


if (coord_mode != "") {
CoordMode, Pixel, %current_mode%
}


if (ErrorLevel = 2) {
s := FormatResponse(EXCEPTIONRESPONSEMESSAGE, "there was a problem that prevented the command from conducting the search (such as failure to open the image file or a badly formatted option)")
} else if (ErrorLevel = 1) {
Expand Down
10 changes: 10 additions & 0 deletions tests/_async/test_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ async def test_pixel_search(self):
x2, y2 = pos
assert abs(x2 - x) < 3 and abs(y2 - y) < 3

async def test_image_search_with_option(self):
if os.environ.get('CI'):
self.skipTest('This test does not work in GitHub Actions')
return
self._show_in_thread()
time.sleep(3)
self.im.save('testimage.png')
position = await self.ahk.image_search('testimage.png', color_variation=50)
assert isinstance(position, tuple)

# async def test_pixel_get_color(self):
# x, y = await self.ahk.pixel_search(0xFF0000)
# result = await self.ahk.pixel_get_color(x, y)
Expand Down
10 changes: 10 additions & 0 deletions tests/_sync/test_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ def test_pixel_search(self):
x2, y2 = pos
assert abs(x2 - x) < 3 and abs(y2 - y) < 3

def test_image_search_with_option(self):
if os.environ.get('CI'):
self.skipTest('This test does not work in GitHub Actions')
return
self._show_in_thread()
time.sleep(3)
self.im.save('testimage.png')
position = self.ahk.image_search('testimage.png', color_variation=50)
assert isinstance(position, tuple)

# async def test_pixel_get_color(self):
# x, y = await self.ahk.pixel_search(0xFF0000)
# result = await self.ahk.pixel_get_color(x, y)
Expand Down

0 comments on commit 25e43b5

Please sign in to comment.