Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
no controls should return empty list, not none
Browse files Browse the repository at this point in the history
  • Loading branch information
spyoungtech committed Jul 18, 2022
1 parent 75fa001 commit 2e6443e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
9 changes: 9 additions & 0 deletions ahk/_async/window.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Literal
from typing import Sequence
from typing import TYPE_CHECKING
from typing import Union

Expand Down Expand Up @@ -69,6 +70,14 @@ async def get_minmax(self) -> Union[Literal[0], Literal[1], Literal[-1]]:
)
return minmax

async def list_controls(self) -> Sequence['AsyncControl']:
controls = await self._engine.win_get_control_list(title=f'ahk_id {self._ahk_id}')
if controls is None:
raise WindowNotFoundException(
f'Error when trying to enumerate controls for window {self._ahk_id}. The window may have been closed before the operation could be completed'
)
return controls


class AsyncControl:
def __init__(self, window: AsyncWindow, hwnd: str, control_class: str):
Expand Down
9 changes: 9 additions & 0 deletions ahk/_sync/window.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Literal
from typing import Sequence
from typing import TYPE_CHECKING
from typing import Union

Expand Down Expand Up @@ -69,6 +70,14 @@ def get_minmax(self) -> Union[Literal[0], Literal[1], Literal[-1]]:
)
return minmax

def list_controls(self) -> Sequence['SyncControl']:
controls = self._engine.win_get_control_list(title=f'ahk_id {self._ahk_id}')
if controls is None:
raise WindowNotFoundException(
f'Error when trying to enumerate controls for window {self._ahk_id}. The window may have been closed before the operation could be completed'
)
return controls


class SyncControl:
def __init__(self, window: Window, hwnd: str, control_class: str):
Expand Down
2 changes: 1 addition & 1 deletion ahk/daemon.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ AHKWinGetControlList(ByRef command) {
WinGet, ctrListID, ControlListHWND, %title%, %text%, %extitle%, %extext%

if (ctrListID = "") {
return FormatNoValueResponse()
return FormatResponse(WINDOWCONTROLLISTRESPONSEMESSAGE, Format("('{}', [])", ahkid))
}

ctrListArr := StrSplit(ctrList, "`n")
Expand Down
1 change: 0 additions & 1 deletion ahk/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ class WindowControlListResponseMessage(ResponseMessage):

def unpack(self) -> Tuple[str, list[Tuple[str, str]]]:
s = self._raw_content.decode(encoding='utf-8')
breakpoint()
val = ast.literal_eval(s)
assert is_window_control_list_response(val)
return val
Expand Down

0 comments on commit 2e6443e

Please sign in to comment.