Skip to content
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
13 changes: 8 additions & 5 deletions botcity/core/application/functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
from typing import Union
from pywinauto.timings import TimeoutError
from pywinauto.findwindows import ElementNotFoundError
from pywinauto.application import Application, WindowSpecification
Expand All @@ -21,7 +22,7 @@ def connect(backend=Backend.WIN_32, timeout=60000, **connection_selectors) -> Ap
](https://documentation.botcity.dev/frameworks/desktop/windows-apps/).

Returns
app (Application): The Application instance.
app (Application): The Application/Window instance.
"""
connect_exception = None
start_time = time.time()
Expand All @@ -39,12 +40,13 @@ def connect(backend=Backend.WIN_32, timeout=60000, **connection_selectors) -> Ap
time.sleep(config.DEFAULT_SLEEP_AFTER_ACTION/1000.0)


def find_window(app: Application, waiting_time=10000, **selectors) -> WindowSpecification:
def find_window(app: Union[Application, WindowSpecification],
waiting_time=10000, **selectors) -> WindowSpecification:
"""
Find a window of the currently connected application using the available selectors.

Args:
app (Application): The connected application.
app (Application | WindowSpecification): The connected application.
waiting_time (int, optional): Maximum wait time (ms) to search for a hit.
Defaults to 10000ms (10s).
**selectors: Attributes that can be used to filter an element.
Expand All @@ -62,14 +64,15 @@ def find_window(app: Application, waiting_time=10000, **selectors) -> WindowSpec
return None


def find_element(app: Application, from_parent_window: WindowSpecification = None,
def find_element(app: Union[Application, WindowSpecification],
from_parent_window: WindowSpecification = None,
waiting_time=10000, **selectors) -> WindowSpecification:
"""
Find a element of the currently connected application using the available selectors.
You can pass the context window where the element is contained.

Args:
app (Application): The connected application.
app (Application | WindowSpecification): The connected application.
from_parent_window (WindowSpecification, optional): The element's parent window.
waiting_time (int, optional): Maximum wait time (ms) to search for a hit.
Defaults to 10000ms (10s).
Expand Down
10 changes: 5 additions & 5 deletions botcity/core/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,22 @@ def __init__(self):
self._mouse_controller = MouseController()

@property
def app(self):
def app(self) -> Union['Application', 'WindowSpecification']:
"""
The connected application instance to be used.

Returns:
app (Application): The connected Application instance.
app (Application | WindowSpecification): The connected Application/Window instance.
"""
return self._app

@app.setter
def app(self, app):
def app(self, app: Union['Application', 'WindowSpecification']):
"""
The connected application instance to be used.

Args:
app (Application): The connected application to be used.
app (Application | WindowSpecification): The connected Application/Window instance.
"""
self._app = app

Expand Down Expand Up @@ -1623,7 +1623,7 @@ def connect_to_app(self, backend=Backend.WIN_32, timeout=60000, **connection_sel
](https://documentation.botcity.dev/frameworks/desktop/windows-apps/).

Returns
app (Application): The Application instance.
app (Application): The Application/Window instance.
"""
self.app = connect(backend, timeout, **connection_selectors)
return self.app
Expand Down
Loading