Skip to content

Commit ed35de1

Browse files
committed
implement win_wait_close
1 parent 8888688 commit ed35de1

File tree

6 files changed

+170
-16
lines changed

6 files changed

+170
-16
lines changed

ahk/_async/engine.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2830,6 +2830,40 @@ async def win_wait_not_active(
28302830
resp = await self._transport.function_call('AHKWinWaitNotActive', args, blocking=blocking, engine=self)
28312831
return resp
28322832

2833+
# fmt: off
2834+
@overload
2835+
async def win_wait_close(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None) -> None: ...
2836+
@overload
2837+
async def win_wait_close(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: Literal[False]) -> AsyncFutureResult[None]: ...
2838+
@overload
2839+
async def win_wait_close(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: Literal[True]) -> None: ...
2840+
@overload
2841+
async def win_wait_close(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: bool = True) -> Union[None, AsyncFutureResult[None]]: ...
2842+
# fmt: on
2843+
async def win_wait_close(
2844+
self,
2845+
title: str = '',
2846+
text: str = '',
2847+
exclude_title: str = '',
2848+
exclude_text: str = '',
2849+
*,
2850+
title_match_mode: Optional[TitleMatchMode] = None,
2851+
detect_hidden_windows: Optional[bool] = None,
2852+
timeout: Optional[int] = None,
2853+
blocking: bool = True,
2854+
) -> Union[None, AsyncFutureResult[None]]:
2855+
args = self._format_win_args(
2856+
title=title,
2857+
text=text,
2858+
exclude_title=exclude_title,
2859+
exclude_text=exclude_text,
2860+
title_match_mode=title_match_mode,
2861+
detect_hidden_windows=detect_hidden_windows,
2862+
)
2863+
args.append(str(timeout) if timeout else '')
2864+
resp = await self._transport.function_call('AHKWinWaitClose', args, blocking=blocking, engine=self)
2865+
return resp
2866+
28332867
# fmt: off
28342868
@overload
28352869
async def win_show(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None) -> None: ...

ahk/_async/transport.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def result(self, timeout: Optional[float] = None) -> T_SyncFuture:
162162
'AHKWindowList',
163163
'AHKWinWait',
164164
'AHKWinWaitActive',
165+
'AHKWinWaitClose',
165166
'AHKWinWaitNotActive',
166167
'AHKClick',
167168
'AHKSetCapsLockState',
@@ -556,8 +557,8 @@ async def function_call(self, function_name: Literal['AHKClipWait'], args: Optio
556557

557558
# @overload
558559
# async def function_call(self, function_name: Literal['HideTrayTip'], args: Optional[List[str]] = None) -> None: ...
559-
# @overload
560-
# async def function_call(self, function_name: Literal['WinWaitClose'], args: Optional[List[str]] = None) -> None: ...
560+
@overload
561+
async def function_call(self, function_name: Literal['AHKWinWaitClose'], args: Optional[List[str]] = None, *, blocking: bool = True, engine: Optional[AsyncAHK] = None) -> Union[None, AsyncFutureResult[None]]: ...
561562
@overload
562563
async def function_call(self, function_name: Literal['AHKRegRead'], args: Optional[List[str]] = None, *, blocking: bool = True) -> Union[str, AsyncFutureResult[str]]: ...
563564
@overload

ahk/_constants.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,49 @@
347347
{% endblock AHKWinWaitNotActive %}
348348
}
349349
350+
AHKWinWaitClose(ByRef command) {
351+
{% block AHKWinWaitClose %}
352+
global TIMEOUTRESPONSEMESSAGE
353+
354+
title := command[2]
355+
text := command[3]
356+
extitle := command[4]
357+
extext := command[5]
358+
detect_hw := command[6]
359+
match_mode := command[7]
360+
match_speed := command[8]
361+
timeout := command[9]
362+
current_match_mode := Format("{}", A_TitleMatchMode)
363+
current_match_speed := Format("{}", A_TitleMatchModeSpeed)
364+
if (match_mode != "") {
365+
SetTitleMatchMode, %match_mode%
366+
}
367+
if (match_speed != "") {
368+
SetTitleMatchMode, %match_speed%
369+
}
370+
current_detect_hw := Format("{}", A_DetectHiddenWindows)
371+
372+
if (detect_hw != "") {
373+
DetectHiddenWindows, %detect_hw%
374+
}
375+
if (timeout != "") {
376+
WinWaitClose, %title%, %text%, %timeout%, %extitle%, %extext%
377+
} else {
378+
WinWaitClose, %title%, %text%,, %extitle%, %extext%
379+
}
380+
if (ErrorLevel = 1) {
381+
resp := FormatResponse(TIMEOUTRESPONSEMESSAGE, "WinWait timed out waiting for window")
382+
} else {
383+
resp := FormatNoValueResponse()
384+
}
350385
386+
DetectHiddenWindows, %current_detect_hw%
387+
SetTitleMatchMode, %current_match_mode%
388+
SetTitleMatchMode, %current_match_speed%
389+
390+
return resp
391+
{% endblock AHKWinWaitClose %}
392+
}
351393
352394
AHKWinMinimize(ByRef command) {
353395
{% block AHKWinMinimize %}

ahk/_sync/engine.py

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,13 +2719,13 @@ def win_restore(
27192719

27202720
# fmt: off
27212721
@overload
2722-
def win_wait( self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None) -> Window: ...
2722+
def win_wait(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None) -> Window: ...
27232723
@overload
2724-
def win_wait( self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: Literal[False]) -> FutureResult[Window]: ...
2724+
def win_wait(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: Literal[False]) -> FutureResult[Window]: ...
27252725
@overload
2726-
def win_wait( self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: Literal[True]) -> Window: ...
2726+
def win_wait(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: Literal[True]) -> Window: ...
27272727
@overload
2728-
def win_wait( self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: bool = True) -> Union[Window, FutureResult[Window]]: ...
2728+
def win_wait(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: bool = True) -> Union[Window, FutureResult[Window]]: ...
27292729
# fmt: on
27302730
def win_wait(
27312731
self,
@@ -2753,13 +2753,13 @@ def win_wait(
27532753

27542754
# fmt: off
27552755
@overload
2756-
def win_wait_active( self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None) -> Window: ...
2756+
def win_wait_active(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None) -> Window: ...
27572757
@overload
2758-
def win_wait_active( self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: Literal[False]) -> FutureResult[Window]: ...
2758+
def win_wait_active(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: Literal[False]) -> FutureResult[Window]: ...
27592759
@overload
2760-
def win_wait_active( self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: Literal[True]) -> Window: ...
2760+
def win_wait_active(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: Literal[True]) -> Window: ...
27612761
@overload
2762-
def win_wait_active( self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: bool = True) -> Union[Window, FutureResult[Window]]: ...
2762+
def win_wait_active(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: bool = True) -> Union[Window, FutureResult[Window]]: ...
27632763
# fmt: on
27642764
def win_wait_active(
27652765
self,
@@ -2787,13 +2787,13 @@ def win_wait_active(
27872787

27882788
# fmt: off
27892789
@overload
2790-
def win_wait_not_active( self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None) -> Window: ...
2790+
def win_wait_not_active(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None) -> Window: ...
27912791
@overload
2792-
def win_wait_not_active( self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: Literal[False]) -> FutureResult[Window]: ...
2792+
def win_wait_not_active(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: Literal[False]) -> FutureResult[Window]: ...
27932793
@overload
2794-
def win_wait_not_active( self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: Literal[True]) -> Window: ...
2794+
def win_wait_not_active(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: Literal[True]) -> Window: ...
27952795
@overload
2796-
def win_wait_not_active( self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: bool = True) -> Union[Window, FutureResult[Window]]: ...
2796+
def win_wait_not_active(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: bool = True) -> Union[Window, FutureResult[Window]]: ...
27972797
# fmt: on
27982798
def win_wait_not_active(
27992799
self,
@@ -2819,6 +2819,40 @@ def win_wait_not_active(
28192819
resp = self._transport.function_call('AHKWinWaitNotActive', args, blocking=blocking, engine=self)
28202820
return resp
28212821

2822+
# fmt: off
2823+
@overload
2824+
def win_wait_close(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None) -> None: ...
2825+
@overload
2826+
def win_wait_close(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: Literal[False]) -> FutureResult[None]: ...
2827+
@overload
2828+
def win_wait_close(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: Literal[True]) -> None: ...
2829+
@overload
2830+
def win_wait_close(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None, timeout: Optional[int] = None, blocking: bool = True) -> Union[None, FutureResult[None]]: ...
2831+
# fmt: on
2832+
def win_wait_close(
2833+
self,
2834+
title: str = '',
2835+
text: str = '',
2836+
exclude_title: str = '',
2837+
exclude_text: str = '',
2838+
*,
2839+
title_match_mode: Optional[TitleMatchMode] = None,
2840+
detect_hidden_windows: Optional[bool] = None,
2841+
timeout: Optional[int] = None,
2842+
blocking: bool = True,
2843+
) -> Union[None, FutureResult[None]]:
2844+
args = self._format_win_args(
2845+
title=title,
2846+
text=text,
2847+
exclude_title=exclude_title,
2848+
exclude_text=exclude_text,
2849+
title_match_mode=title_match_mode,
2850+
detect_hidden_windows=detect_hidden_windows,
2851+
)
2852+
args.append(str(timeout) if timeout else '')
2853+
resp = self._transport.function_call('AHKWinWaitClose', args, blocking=blocking, engine=self)
2854+
return resp
2855+
28222856
# fmt: off
28232857
@overload
28242858
def win_show(self, title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', *, title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None) -> None: ...

ahk/_sync/transport.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ def result(self, timeout: Optional[float] = None) -> T_SyncFuture:
154154
'AHKWindowList',
155155
'AHKWinWait',
156156
'AHKWinWaitActive',
157+
'AHKWinWaitClose',
157158
'AHKWinWaitNotActive',
158159
'AHKClick',
159160
'AHKSetCapsLockState',
@@ -537,8 +538,8 @@ def function_call(self, function_name: Literal['AHKClipWait'], args: Optional[Li
537538

538539
# @overload
539540
# async def function_call(self, function_name: Literal['HideTrayTip'], args: Optional[List[str]] = None) -> None: ...
540-
# @overload
541-
# async def function_call(self, function_name: Literal['WinWaitClose'], args: Optional[List[str]] = None) -> None: ...
541+
@overload
542+
def function_call(self, function_name: Literal['AHKWinWaitClose'], args: Optional[List[str]] = None, *, blocking: bool = True, engine: Optional[AHK] = None) -> Union[None, FutureResult[None]]: ...
542543
@overload
543544
def function_call(self, function_name: Literal['AHKRegRead'], args: Optional[List[str]] = None, *, blocking: bool = True) -> Union[str, FutureResult[str]]: ...
544545
@overload

ahk/templates/daemon.ahk

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,49 @@ AHKWinWaitNotActive(ByRef command) {
344344
{% endblock AHKWinWaitNotActive %}
345345
}
346346

347+
AHKWinWaitClose(ByRef command) {
348+
{% block AHKWinWaitClose %}
349+
global TIMEOUTRESPONSEMESSAGE
350+
351+
title := command[2]
352+
text := command[3]
353+
extitle := command[4]
354+
extext := command[5]
355+
detect_hw := command[6]
356+
match_mode := command[7]
357+
match_speed := command[8]
358+
timeout := command[9]
359+
current_match_mode := Format("{}", A_TitleMatchMode)
360+
current_match_speed := Format("{}", A_TitleMatchModeSpeed)
361+
if (match_mode != "") {
362+
SetTitleMatchMode, %match_mode%
363+
}
364+
if (match_speed != "") {
365+
SetTitleMatchMode, %match_speed%
366+
}
367+
current_detect_hw := Format("{}", A_DetectHiddenWindows)
368+
369+
if (detect_hw != "") {
370+
DetectHiddenWindows, %detect_hw%
371+
}
372+
if (timeout != "") {
373+
WinWaitClose, %title%, %text%, %timeout%, %extitle%, %extext%
374+
} else {
375+
WinWaitClose, %title%, %text%,, %extitle%, %extext%
376+
}
377+
if (ErrorLevel = 1) {
378+
resp := FormatResponse(TIMEOUTRESPONSEMESSAGE, "WinWait timed out waiting for window")
379+
} else {
380+
resp := FormatNoValueResponse()
381+
}
347382

383+
DetectHiddenWindows, %current_detect_hw%
384+
SetTitleMatchMode, %current_match_mode%
385+
SetTitleMatchMode, %current_match_speed%
386+
387+
return resp
388+
{% endblock AHKWinWaitClose %}
389+
}
348390

349391
AHKWinMinimize(ByRef command) {
350392
{% block AHKWinMinimize %}

0 commit comments

Comments
 (0)