-
-
Notifications
You must be signed in to change notification settings - Fork 150
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
Feat/performance test #850
Open
Animesh404
wants to merge
13
commits into
OpenAdaptAI:main
Choose a base branch
from
Animesh404:feature/performance_test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a70ef2c
extracting difference between two images
Animesh404 dda2699
feat:add combine segmentation in visual.py and extract difference in …
Animesh404 7dada60
fix: filter out the masked_image and the desc that are not relevant f…
Animesh404 65c876f
WIP
Animesh404 383002a
testing visual strategy
Animesh404 f745538
Merge remote-tracking branch 'upstream/main' into fix/avoid-unnecessa…
Animesh404 ca30b15
performance test using naivereplaystrategy
Animesh404 cb90893
Merge branch 'main' of https://github.com/OpenAdaptAI/OpenAdapt into …
Animesh404 aa9b901
Merge branch 'main' of https://github.com/OpenAdaptAI/OpenAdapt into …
Animesh404 8450cea
feat: performance test
Animesh404 da5d410
fix: remove unnecessary file changes
Animesh404 929c31b
fix: remove unnecessary file change
Animesh404 36e183f
feat: a11y for macos
Animesh404 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""This module provides platform-specific implementations for window and element | ||
interactions using accessibility APIs. It abstracts the platform differences | ||
and provides a unified interface for retrieving the active window, finding | ||
display elements, and getting element values. | ||
""" | ||
|
||
import sys | ||
|
||
from loguru import logger | ||
|
||
if sys.platform == "darwin": | ||
from . import _macos as impl | ||
|
||
role = "AXStaticText" | ||
elif sys.platform in ("win32", "linux"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove |
||
from . import _windows as impl | ||
|
||
role = "Text" | ||
else: | ||
raise Exception(f"Unsupported platform: {sys.platform}") | ||
|
||
|
||
def get_active_window(): | ||
"""Get the active window object. | ||
|
||
Returns: | ||
The active window object. | ||
""" | ||
try: | ||
return impl.get_active_window() | ||
except Exception as exc: | ||
logger.warning(f"{exc=}") | ||
return None | ||
|
||
|
||
def get_element_value(active_window, role=role): | ||
"""Find the display of active_window. | ||
|
||
Args: | ||
active_window: The parent window to search within. | ||
|
||
Returns: | ||
The found active_window. | ||
""" | ||
try: | ||
return impl.get_element_value(active_window, role) | ||
except Exception as exc: | ||
logger.warning(f"{exc=}") | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import AppKit | ||
import ApplicationServices | ||
|
||
|
||
def get_attribute(element, attribute): | ||
result, value = ApplicationServices.AXUIElementCopyAttributeValue( | ||
element, attribute, None | ||
) | ||
if result == 0: | ||
return value | ||
return None | ||
|
||
|
||
def find_element_by_attribute(element, attribute, value): | ||
if get_attribute(element, attribute) == value: | ||
return element | ||
children = get_attribute(element, ApplicationServices.kAXChildrenAttribute) or [] | ||
for child in children: | ||
found = find_element_by_attribute(child, attribute, value) | ||
if found: | ||
return found | ||
return None | ||
|
||
|
||
def get_active_window(): | ||
"""Get the active window object. | ||
|
||
Returns: | ||
AXUIElement: The active window object. | ||
""" | ||
workspace = AppKit.NSWorkspace.sharedWorkspace() | ||
active_app = workspace.frontmostApplication() | ||
app_element = ApplicationServices.AXUIElementCreateApplication( | ||
active_app.processIdentifier() | ||
) | ||
|
||
error_code, focused_window = ApplicationServices.AXUIElementCopyAttributeValue( | ||
app_element, ApplicationServices.kAXFocusedWindowAttribute, None | ||
) | ||
if error_code: | ||
raise Exception("Could not get the active window.") | ||
return focused_window | ||
|
||
|
||
def get_element_value(element, role="AXStaticText"): | ||
"""Get the value of a specific element . | ||
|
||
Args: | ||
element: The AXUIElement to search within. | ||
|
||
Returns: | ||
str: The value of the element, or an error message if not found. | ||
""" | ||
target_element = find_element_by_attribute( | ||
element, ApplicationServices.kAXRoleAttribute, role | ||
) | ||
if not target_element: | ||
return f"AXStaticText element not found." | ||
|
||
value = get_attribute(target_element, ApplicationServices.kAXValueAttribute) | ||
return value if value else f"No value for AXStaticText element." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from loguru import logger | ||
import pywinauto | ||
import re | ||
|
||
|
||
def get_active_window() -> pywinauto.application.WindowSpecification: | ||
"""Get the active window object. | ||
|
||
Returns: | ||
pywinauto.application.WindowSpecification: The active window object. | ||
""" | ||
app = pywinauto.application.Application(backend="uia").connect(active_only=True) | ||
window = app.top_window() | ||
return window.wrapper_object() | ||
|
||
|
||
def get_element_value(active_window, role="Text"): | ||
"""Find the display element. | ||
|
||
Args: | ||
active_window: The parent window to search within. | ||
role (str): The role of the element to search for. | ||
|
||
Returns: | ||
The found display element value. | ||
|
||
Raises: | ||
ValueError: If the element is not found. | ||
""" | ||
try: | ||
elements = active_window.descendants() # Retrieve all descendants | ||
for elem in elements: | ||
if ( | ||
elem.element_info.control_type == role | ||
and elem.element_info.name.startswith("Display is") | ||
): | ||
# Extract the number from the element's name | ||
match = re.search(r"[-+]?\d*\.?\d+", elem.element_info.name) | ||
if match: | ||
return str(match.group()) | ||
raise ValueError("Display element not found") | ||
except Exception as exc: | ||
logger.warning(f"Error in get_element_value: {exc}") | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove unnecessary indent