Skip to content

Commit dca2bad

Browse files
committed
update docstrings
1 parent ed35de1 commit dca2bad

File tree

2 files changed

+206
-6
lines changed

2 files changed

+206
-6
lines changed

ahk/_async/engine.py

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ def add_hotkey(
147147
- If you add a hotkey after the hotkey thread/instance is active, it will be restarted automatically
148148
- `async` functions are not directly supported as callbacks, however you may write a synchronous function that calls `asyncio.run`/`loop.create_task` etc.
149149
150-
:param hotkey: an instance of ahk.hotkey.Hotkey
150+
:param keyname: the key trigger for the hotkey, such as ``#n`` (win+n)
151+
:param callback: callback function to call when the hotkey is triggered
152+
:param ex_handler: a function which accepts two parameters: the keyname for the hotkey and the exception raised by the callback function.
153+
:return:
151154
"""
152155
hotkey = Hotkey(keyname, callback, ex_handler=ex_handler)
153156
with warnings.catch_warnings(record=True) as caught_warnings:
@@ -172,7 +175,11 @@ def add_hotstring(
172175
- You must call the `start_hotkeys` method for registered hotstrings to be active
173176
- All hotstrings (and hotkeys) run in a single AHK process instance separate from other AHK processes.
174177
175-
:param hotstring: an instance of ahk.hotkey.Hotstring
178+
:param trigger: the trigger phrase for the hotstring, e.g., ``btw``
179+
:param replacement_or_callback: the replacement phrase (e.g., ``by the way``) or a Python callable to execute in response to the hotstring trigger
180+
:param ex_handler: a function which accepts two parameters: the hotstring and the exception raised by the callback function.
181+
:param options: the hotstring options -- same meanings as in AutoHotkey.
182+
:return:
176183
"""
177184
hotstring = Hotstring(trigger, replacement_or_callback, ex_handler=ex_handler, options=options)
178185
with warnings.catch_warnings(record=True) as caught_warnings:
@@ -269,6 +276,21 @@ async def control_click(
269276
detect_hidden_windows: Optional[bool] = None,
270277
blocking: bool = True,
271278
) -> Union[None, AsyncFutureResult[None]]:
279+
"""
280+
281+
:param button: the mouse button to use
282+
:param click_count: how many times to click
283+
:param options: options -- same meaning as in AutoHotkey
284+
:param control: the control to click
285+
:param title:
286+
:param text:
287+
:param exclude_title:
288+
:param exclude_text:
289+
:param title_match_mode:
290+
:param detect_hidden_windows:
291+
:param blocking:
292+
:return:
293+
"""
272294
args = [control, title, text, str(button), str(click_count), options, exclude_title, exclude_text]
273295
if detect_hidden_windows is not None:
274296
if detect_hidden_windows is True:
@@ -325,6 +347,19 @@ async def control_get_text(
325347
detect_hidden_windows: Optional[bool] = None,
326348
blocking: bool = True,
327349
) -> Union[str, AsyncFutureResult[str]]:
350+
"""
351+
Analog to ``ControlGetText``
352+
353+
:param control:
354+
:param title:
355+
:param text:
356+
:param exclude_title:
357+
:param exclude_text:
358+
:param title_match_mode:
359+
:param detect_hidden_windows:
360+
:param blocking:
361+
:return:
362+
"""
328363
args = [control, title, text, exclude_title, exclude_text]
329364
if detect_hidden_windows is not None:
330365
if detect_hidden_windows is True:
@@ -380,6 +415,19 @@ async def control_get_position(
380415
detect_hidden_windows: Optional[bool] = None,
381416
blocking: bool = True,
382417
) -> Union[Position, AsyncFutureResult[Position]]:
418+
"""
419+
Analog to ``ControlGetPos``
420+
421+
:param control:
422+
:param title:
423+
:param text:
424+
:param exclude_title:
425+
:param exclude_text:
426+
:param title_match_mode:
427+
:param detect_hidden_windows:
428+
:param blocking:
429+
:return:
430+
"""
383431
args = [control, title, text, exclude_title, exclude_text]
384432
if detect_hidden_windows is not None:
385433
if detect_hidden_windows is True:
@@ -438,7 +486,7 @@ async def control_send(
438486
blocking: bool = True,
439487
) -> Union[None, AsyncFutureResult[None]]:
440488
"""
441-
Analog for ControlSend
489+
Analog for ``ControlSend``
442490
443491
Reference: https://www.autohotkey.com/docs/commands/ControlSend.htm
444492
@@ -582,6 +630,19 @@ async def list_windows(
582630
detect_hidden_windows: Optional[bool] = None,
583631
blocking: bool = True,
584632
) -> Union[List[AsyncWindow], AsyncFutureResult[List[AsyncWindow]]]:
633+
"""
634+
Enumerate all windows matching the criteria.
635+
636+
637+
:param title:
638+
:param text:
639+
:param exclude_title:
640+
:param exclude_text:
641+
:param title_match_mode:
642+
:param detect_hidden_windows:
643+
:param blocking:
644+
:return:
645+
"""
585646
args = self._format_win_args(
586647
title=title,
587648
text=text,
@@ -606,6 +667,13 @@ async def get_mouse_position(self, coord_mode: Optional[CoordModeRelativeTo] = N
606667
async def get_mouse_position(
607668
self, coord_mode: Optional[CoordModeRelativeTo] = None, *, blocking: bool = True
608669
) -> Union[Tuple[int, int], AsyncFutureResult[Tuple[int, int]]]:
670+
"""
671+
Analog for ``MouseGetPos``
672+
673+
:param coord_mode:
674+
:param blocking:
675+
:return:
676+
"""
609677
if coord_mode:
610678
args = [str(coord_mode)]
611679
else:
@@ -615,13 +683,24 @@ async def get_mouse_position(
615683

616684
@property
617685
def mouse_position(self) -> AsyncPropertyReturnTupleIntInt:
686+
"""
687+
Convenience property for ``get_mouse_position``
688+
689+
:return:
690+
"""
618691
warnings.warn( # unasync: remove
619692
_PROPERTY_DEPRECATION_WARNING_MESSAGE.format('mouse_position'), category=DeprecationWarning, stacklevel=2
620693
)
621694
return self.get_mouse_position()
622695

623696
@mouse_position.setter
624697
def mouse_position(self, new_position: Tuple[int, int]) -> None:
698+
"""
699+
Convenience setter for ``mouse_move``
700+
701+
:param new_position: a tuple of x,y coordinates to move to
702+
:return:
703+
"""
625704
raise RuntimeError('Use of the mouse_position setter is not supported in the async API.') # unasync: remove
626705
x, y = new_position
627706
return self.mouse_move(x=x, y=y, speed=0, relative=False)
@@ -645,6 +724,16 @@ async def mouse_move(
645724
relative: bool = False,
646725
blocking: bool = True,
647726
) -> Union[None, AsyncFutureResult[None]]:
727+
"""
728+
Analog for ``MouseMove``
729+
730+
:param x:
731+
:param y:
732+
:param speed:
733+
:param relative:
734+
:param blocking:
735+
:return:
736+
"""
648737
if relative and (x is None or y is None):
649738
x = x or 0
650739
y = y or 0
@@ -678,12 +767,23 @@ async def get_active_window(self, blocking: bool = True) -> Union[Optional[Async
678767
async def get_active_window(
679768
self, blocking: bool = True
680769
) -> Union[Optional[AsyncWindow], AsyncFutureResult[Optional[AsyncWindow]]]:
770+
"""
771+
Gets the currently active window.
772+
773+
:param blocking:
774+
:return:
775+
"""
681776
return await self.win_get(
682777
title='A', detect_hidden_windows=False, title_match_mode=(1, 'Fast'), blocking=blocking
683778
)
684779

685780
@property
686781
def active_window(self) -> AsyncPropertyReturnOptionalAsyncWindow:
782+
"""
783+
Gets the currently active window
784+
785+
:return:
786+
"""
687787
warnings.warn( # unasync: remove
688788
_PROPERTY_DEPRECATION_WARNING_MESSAGE.format('active_window'), category=DeprecationWarning, stacklevel=2
689789
)

ahk/_sync/engine.py

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ def add_hotkey(
143143
- If you add a hotkey after the hotkey thread/instance is active, it will be restarted automatically
144144
- `async` functions are not directly supported as callbacks, however you may write a synchronous function that calls `asyncio.run`/`loop.create_task` etc.
145145
146-
:param hotkey: an instance of ahk.hotkey.Hotkey
146+
:param keyname: the key trigger for the hotkey, such as ``#n`` (win+n)
147+
:param callback: callback function to call when the hotkey is triggered
148+
:param ex_handler: a function which accepts two parameters: the keyname for the hotkey and the exception raised by the callback function.
149+
:return:
147150
"""
148151
hotkey = Hotkey(keyname, callback, ex_handler=ex_handler)
149152
with warnings.catch_warnings(record=True) as caught_warnings:
@@ -168,7 +171,11 @@ def add_hotstring(
168171
- You must call the `start_hotkeys` method for registered hotstrings to be active
169172
- All hotstrings (and hotkeys) run in a single AHK process instance separate from other AHK processes.
170173
171-
:param hotstring: an instance of ahk.hotkey.Hotstring
174+
:param trigger: the trigger phrase for the hotstring, e.g., ``btw``
175+
:param replacement_or_callback: the replacement phrase (e.g., ``by the way``) or a Python callable to execute in response to the hotstring trigger
176+
:param ex_handler: a function which accepts two parameters: the hotstring and the exception raised by the callback function.
177+
:param options: the hotstring options -- same meanings as in AutoHotkey.
178+
:return:
172179
"""
173180
hotstring = Hotstring(trigger, replacement_or_callback, ex_handler=ex_handler, options=options)
174181
with warnings.catch_warnings(record=True) as caught_warnings:
@@ -265,6 +272,21 @@ def control_click(
265272
detect_hidden_windows: Optional[bool] = None,
266273
blocking: bool = True,
267274
) -> Union[None, FutureResult[None]]:
275+
"""
276+
277+
:param button: the mouse button to use
278+
:param click_count: how many times to click
279+
:param options: options -- same meaning as in AutoHotkey
280+
:param control: the control to click
281+
:param title:
282+
:param text:
283+
:param exclude_title:
284+
:param exclude_text:
285+
:param title_match_mode:
286+
:param detect_hidden_windows:
287+
:param blocking:
288+
:return:
289+
"""
268290
args = [control, title, text, str(button), str(click_count), options, exclude_title, exclude_text]
269291
if detect_hidden_windows is not None:
270292
if detect_hidden_windows is True:
@@ -321,6 +343,19 @@ def control_get_text(
321343
detect_hidden_windows: Optional[bool] = None,
322344
blocking: bool = True,
323345
) -> Union[str, FutureResult[str]]:
346+
"""
347+
Analog to ``ControlGetText``
348+
349+
:param control:
350+
:param title:
351+
:param text:
352+
:param exclude_title:
353+
:param exclude_text:
354+
:param title_match_mode:
355+
:param detect_hidden_windows:
356+
:param blocking:
357+
:return:
358+
"""
324359
args = [control, title, text, exclude_title, exclude_text]
325360
if detect_hidden_windows is not None:
326361
if detect_hidden_windows is True:
@@ -376,6 +411,19 @@ def control_get_position(
376411
detect_hidden_windows: Optional[bool] = None,
377412
blocking: bool = True,
378413
) -> Union[Position, FutureResult[Position]]:
414+
"""
415+
Analog to ``ControlGetPos``
416+
417+
:param control:
418+
:param title:
419+
:param text:
420+
:param exclude_title:
421+
:param exclude_text:
422+
:param title_match_mode:
423+
:param detect_hidden_windows:
424+
:param blocking:
425+
:return:
426+
"""
379427
args = [control, title, text, exclude_title, exclude_text]
380428
if detect_hidden_windows is not None:
381429
if detect_hidden_windows is True:
@@ -434,7 +482,7 @@ def control_send(
434482
blocking: bool = True,
435483
) -> Union[None, FutureResult[None]]:
436484
"""
437-
Analog for ControlSend
485+
Analog for ``ControlSend``
438486
439487
Reference: https://www.autohotkey.com/docs/commands/ControlSend.htm
440488
@@ -578,6 +626,19 @@ def list_windows(
578626
detect_hidden_windows: Optional[bool] = None,
579627
blocking: bool = True,
580628
) -> Union[List[Window], FutureResult[List[Window]]]:
629+
"""
630+
Enumerate all windows matching the criteria.
631+
632+
633+
:param title:
634+
:param text:
635+
:param exclude_title:
636+
:param exclude_text:
637+
:param title_match_mode:
638+
:param detect_hidden_windows:
639+
:param blocking:
640+
:return:
641+
"""
581642
args = self._format_win_args(
582643
title=title,
583644
text=text,
@@ -602,6 +663,13 @@ def get_mouse_position(self, coord_mode: Optional[CoordModeRelativeTo] = None, *
602663
def get_mouse_position(
603664
self, coord_mode: Optional[CoordModeRelativeTo] = None, *, blocking: bool = True
604665
) -> Union[Tuple[int, int], FutureResult[Tuple[int, int]]]:
666+
"""
667+
Analog for ``MouseGetPos``
668+
669+
:param coord_mode:
670+
:param blocking:
671+
:return:
672+
"""
605673
if coord_mode:
606674
args = [str(coord_mode)]
607675
else:
@@ -611,10 +679,21 @@ def get_mouse_position(
611679

612680
@property
613681
def mouse_position(self) -> SyncPropertyReturnTupleIntInt:
682+
"""
683+
Convenience property for ``get_mouse_position``
684+
685+
:return:
686+
"""
614687
return self.get_mouse_position()
615688

616689
@mouse_position.setter
617690
def mouse_position(self, new_position: Tuple[int, int]) -> None:
691+
"""
692+
Convenience setter for ``mouse_move``
693+
694+
:param new_position: a tuple of x,y coordinates to move to
695+
:return:
696+
"""
618697
x, y = new_position
619698
return self.mouse_move(x=x, y=y, speed=0, relative=False)
620699

@@ -637,6 +716,16 @@ def mouse_move(
637716
relative: bool = False,
638717
blocking: bool = True,
639718
) -> Union[None, FutureResult[None]]:
719+
"""
720+
Analog for ``MouseMove``
721+
722+
:param x:
723+
:param y:
724+
:param speed:
725+
:param relative:
726+
:param blocking:
727+
:return:
728+
"""
640729
if relative and (x is None or y is None):
641730
x = x or 0
642731
y = y or 0
@@ -670,12 +759,23 @@ def get_active_window(self, blocking: bool = True) -> Union[Optional[Window], Fu
670759
def get_active_window(
671760
self, blocking: bool = True
672761
) -> Union[Optional[Window], FutureResult[Optional[Window]]]:
762+
"""
763+
Gets the currently active window.
764+
765+
:param blocking:
766+
:return:
767+
"""
673768
return self.win_get(
674769
title='A', detect_hidden_windows=False, title_match_mode=(1, 'Fast'), blocking=blocking
675770
)
676771

677772
@property
678773
def active_window(self) -> SyncPropertyReturnOptionalAsyncWindow:
774+
"""
775+
Gets the currently active window
776+
777+
:return:
778+
"""
679779
return self.get_active_window()
680780

681781
def find_windows(

0 commit comments

Comments
 (0)