Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix detect hidden windows for AutoHotkey v2 #285

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions ahk/_async/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,9 @@ async def control_click(
args = [control, title, text, str(button), str(click_count), options, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -476,9 +476,9 @@ async def control_get_text(
args = [control, title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -534,9 +534,9 @@ async def control_get_position(
args = [control, title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -594,9 +594,9 @@ async def control_send(
args = [control, keys, title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -651,9 +651,9 @@ async def set_detect_hidden_windows(self, value: bool) -> None:
raise TypeError(f'detect hidden windows must be a boolean, got object of type {type(value)}')
args = []
if value is True:
args.append('On')
args.append('1')
else:
args.append('Off')
args.append('0')
await self._transport.function_call('AHKSetDetectHiddenWindows', args=args)
return None

Expand All @@ -669,9 +669,9 @@ def _format_win_args(
args = [title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -2228,9 +2228,9 @@ async def win_set_title(
args = [new_title, title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -2286,9 +2286,9 @@ async def win_set_always_on_top(
args = [str(toggle), title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -2521,9 +2521,9 @@ async def win_set_style(
args = [style, title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -2579,9 +2579,9 @@ async def win_set_ex_style(
args = [style, title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -2637,9 +2637,9 @@ async def win_set_region(
args = [options, title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -2695,9 +2695,9 @@ async def win_set_transparent(
args = [str(transparency), title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -2753,9 +2753,9 @@ async def win_set_trans_color(
args = [str(color), title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down
52 changes: 26 additions & 26 deletions ahk/_sync/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ def control_click(
args = [control, title, text, str(button), str(click_count), options, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -471,9 +471,9 @@ def control_get_text(
args = [control, title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -529,9 +529,9 @@ def control_get_position(
args = [control, title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -589,9 +589,9 @@ def control_send(
args = [control, keys, title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -646,9 +646,9 @@ def set_detect_hidden_windows(self, value: bool) -> None:
raise TypeError(f'detect hidden windows must be a boolean, got object of type {type(value)}')
args = []
if value is True:
args.append('On')
args.append('1')
else:
args.append('Off')
args.append('0')
self._transport.function_call('AHKSetDetectHiddenWindows', args=args)
return None

Expand All @@ -664,9 +664,9 @@ def _format_win_args(
args = [title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -2216,9 +2216,9 @@ def win_set_title(
args = [new_title, title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -2274,9 +2274,9 @@ def win_set_always_on_top(
args = [str(toggle), title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -2509,9 +2509,9 @@ def win_set_style(
args = [style, title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -2567,9 +2567,9 @@ def win_set_ex_style(
args = [style, title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -2625,9 +2625,9 @@ def win_set_region(
args = [options, title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -2683,9 +2683,9 @@ def win_set_transparent(
args = [str(transparency), title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down Expand Up @@ -2741,9 +2741,9 @@ def win_set_trans_color(
args = [str(color), title, text, exclude_title, exclude_text]
if detect_hidden_windows is not None:
if detect_hidden_windows is True:
args.append('On')
args.append('1')
elif detect_hidden_windows is False:
args.append('Off')
args.append('0')
else:
raise TypeError(
f'Invalid value for parameter detect_hidden_windows. Expected boolean or None, got {detect_hidden_windows!r}'
Expand Down
12 changes: 12 additions & 0 deletions tests/_async/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ async def test_set_detect_hidden_windows(self):
all_windows = await self.ahk.list_windows()
assert len(all_windows) > len(non_hidden)

async def test_detect_hidden_windows_false_works(self):
await self.ahk.set_detect_hidden_windows(True)
all_windows = await self.ahk.list_windows()
await self.ahk.set_detect_hidden_windows(False)
non_hidden = await self.ahk.list_windows()
assert len(non_hidden) < len(all_windows)

async def test_list_windows_hidden_false(self):
non_hidden = await self.ahk.list_windows()
all_windows = await self.ahk.list_windows(detect_hidden_windows=False)
assert len(non_hidden) == len(all_windows)

async def test_list_windows_hidden(self):
non_hidden = await self.ahk.list_windows()
all_windows = await self.ahk.list_windows(detect_hidden_windows=True)
Expand Down
12 changes: 12 additions & 0 deletions tests/_sync/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ def test_set_detect_hidden_windows(self):
all_windows = self.ahk.list_windows()
assert len(all_windows) > len(non_hidden)

def test_detect_hidden_windows_false_works(self):
self.ahk.set_detect_hidden_windows(True)
all_windows = self.ahk.list_windows()
self.ahk.set_detect_hidden_windows(False)
non_hidden = self.ahk.list_windows()
assert len(non_hidden) < len(all_windows)

def test_list_windows_hidden_false(self):
non_hidden = self.ahk.list_windows()
all_windows = self.ahk.list_windows(detect_hidden_windows=False)
assert len(non_hidden) == len(all_windows)

def test_list_windows_hidden(self):
non_hidden = self.ahk.list_windows()
all_windows = self.ahk.list_windows(detect_hidden_windows=True)
Expand Down
Loading