Device Reference
This document provides a reference for the abstract base classes (blueprints) that define the core functionalities for different types of devices in Pymordial. Each blueprint serves as a contract for concrete device implementations.
Bridge Device
Bases: ABC
Abstract base class for device bridges (e.g., ADB, Win32).
Defines the low-level commands to control the device hardware or emulator.
Source code in src/pymordial/core/blueprints/bridge_device.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
capture_screenshot()
abstractmethod
Captures a single frame from the device.
Source code in src/pymordial/core/blueprints/bridge_device.py
73 74 75 76 | |
close_app()
abstractmethod
Closes an application on the device.
Source code in src/pymordial/core/blueprints/bridge_device.py
43 44 45 46 | |
connect()
abstractmethod
Connects to the device bridge.
Source code in src/pymordial/core/blueprints/bridge_device.py
13 14 15 16 | |
disconnect()
abstractmethod
Disconnects from the device bridge.
Source code in src/pymordial/core/blueprints/bridge_device.py
18 19 20 21 | |
get_latest_frame()
abstractmethod
Retrieves the most recent frame from the stream.
Source code in src/pymordial/core/blueprints/bridge_device.py
88 89 90 91 | |
go_home()
abstractmethod
Simulates pressing the Home button.
Source code in src/pymordial/core/blueprints/bridge_device.py
58 59 60 61 | |
is_app_running()
abstractmethod
Checks if an application is currently running.
Source code in src/pymordial/core/blueprints/bridge_device.py
33 34 35 36 | |
open_app()
abstractmethod
Opens an application on the device.
Source code in src/pymordial/core/blueprints/bridge_device.py
28 29 30 31 | |
press_enter()
abstractmethod
Simulates pressing the Enter key.
Source code in src/pymordial/core/blueprints/bridge_device.py
63 64 65 66 | |
press_esc()
abstractmethod
Simulates pressing the Escape/Back key.
Source code in src/pymordial/core/blueprints/bridge_device.py
68 69 70 71 | |
run_command()
abstractmethod
Executes a raw shell command on the device.
Source code in src/pymordial/core/blueprints/bridge_device.py
23 24 25 26 | |
show_recent_apps()
abstractmethod
Shows the recent apps overview.
Source code in src/pymordial/core/blueprints/bridge_device.py
38 39 40 41 | |
start_stream()
abstractmethod
Starts a persistent video/screen stream.
Source code in src/pymordial/core/blueprints/bridge_device.py
78 79 80 81 | |
stop_stream()
abstractmethod
Stops the persistent video/screen stream.
Source code in src/pymordial/core/blueprints/bridge_device.py
83 84 85 86 | |
tap()
abstractmethod
Simulates a tap/click event.
Source code in src/pymordial/core/blueprints/bridge_device.py
48 49 50 51 | |
type_text()
abstractmethod
Simulates text input.
Source code in src/pymordial/core/blueprints/bridge_device.py
53 54 55 56 | |
Vision Device
Bases: ABC
Abstract base class for vision-based device interaction.
Defines the contract for visual operations such as screen scaling, pixel color checking, and text extraction/finding.
Source code in src/pymordial/core/blueprints/vision_device.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
check_pixel_color()
abstractmethod
Verifies if a specific pixel matches a target color.
Returns:
| Type | Description |
|---|---|
bool | None
|
True if color matches within tolerance, False if not, None if error. |
Source code in src/pymordial/core/blueprints/vision_device.py
25 26 27 28 29 30 31 32 | |
check_text()
abstractmethod
Checks if specific text is visible on the screen.
Returns:
| Type | Description |
|---|---|
bool
|
True if text is found, False otherwise. |
Source code in src/pymordial/core/blueprints/vision_device.py
61 62 63 64 65 66 67 68 | |
find_text()
abstractmethod
Finds the coordinates of specific text on the screen.
Returns:
| Type | Description |
|---|---|
tuple[int, int] | None
|
A tuple of (x, y) coordinates if text is found, None otherwise. |
Source code in src/pymordial/core/blueprints/vision_device.py
52 53 54 55 56 57 58 59 | |
read_text()
abstractmethod
Reads all text from the current screen.
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of strings representing the text lines found on screen. |
Source code in src/pymordial/core/blueprints/vision_device.py
70 71 72 73 74 75 76 77 | |
scale_img_to_screen()
abstractmethod
Scales the reference image to match the current screen resolution.
Returns:
| Type | Description |
|---|---|
Any
|
A PIL Image object resized to the device screen dimensions. |
Source code in src/pymordial/core/blueprints/vision_device.py
15 16 17 18 19 20 21 22 23 | |
where_element()
abstractmethod
Finds the coordinates of a visual element.
Returns:
| Type | Description |
|---|---|
tuple[int, int] | None
|
A tuple of (x, y) coordinates if found, None otherwise. |
Source code in src/pymordial/core/blueprints/vision_device.py
34 35 36 37 38 39 40 41 | |
where_elements()
abstractmethod
Finds the coordinates of one of multiple visual elements.
Returns:
| Type | Description |
|---|---|
tuple[int, int] | None
|
A tuple of (x, y) coordinates if any element is found, None otherwise. |
Source code in src/pymordial/core/blueprints/vision_device.py
43 44 45 46 47 48 49 50 | |
Emulator Device
Bases: ABC
Abstract interface for controlling emulator software (e.g., BlueStacks).
Attributes:
| Name | Type | Description |
|---|---|---|
state |
StateMachine tracking the emulator's lifecycle. |
Source code in src/pymordial/core/blueprints/emulator_device.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
close()
abstractmethod
Closes or terminates the emulator software.
Returns:
| Type | Description |
|---|---|
|
True if the close command was successful, False otherwise. |
Source code in src/pymordial/core/blueprints/emulator_device.py
71 72 73 74 75 76 77 78 | |
is_ready()
abstractmethod
Checks if the emulator is currently ready to accept commands.
Returns:
| Type | Description |
|---|---|
|
True if the emulator is ready, False otherwise. |
Source code in src/pymordial/core/blueprints/emulator_device.py
62 63 64 65 66 67 68 69 | |
open()
abstractmethod
Opens the emulator software.
Returns:
| Type | Description |
|---|---|
|
True if the launch command was successful, False otherwise. |
Source code in src/pymordial/core/blueprints/emulator_device.py
44 45 46 47 48 49 50 51 | |
wait_for_load()
abstractmethod
Waits for the emulator to reach a ready state.
Returns:
| Type | Description |
|---|---|
|
True if proper loading was detected within timeout, False otherwise. |
Source code in src/pymordial/core/blueprints/emulator_device.py
53 54 55 56 57 58 59 60 | |
OCR Device
Bases: ABC
Abstract base class for OCR engines.
All OCR implementations must inherit from this class and implement the extract_text method.
Source code in src/pymordial/core/blueprints/ocr_device.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
contains_text(search_text, image_path)
Checks if image contains specific text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
search_text
|
str
|
The text string to search for. |
required |
image_path
|
Path | bytes | str | Any
|
The image source (file path, bytes, or numpy array). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the search text is found (case-insensitive), False otherwise. |
Source code in src/pymordial/core/blueprints/ocr_device.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
extract_lines(image_path)
Extracts text as individual lines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path
|
Path | bytes | str | Any
|
The image source (file path, bytes, or numpy array). |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of non-empty text lines extracted from the image. |
Source code in src/pymordial/core/blueprints/ocr_device.py
59 60 61 62 63 64 65 66 67 68 69 | |
extract_text(image_path)
abstractmethod
Extracts text from an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path
|
Path | bytes | str | Any
|
The image source (file path, bytes, or numpy array). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The raw text extracted from the image. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the image format is unsupported or cannot be processed. |
Source code in src/pymordial/core/blueprints/ocr_device.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
find_text(search_text, image_path)
abstractmethod
Finds the coordinates (center) of the specified text in the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
search_text
|
str
|
The text string to search for. |
required |
image_path
|
Any
|
The image source (file path, bytes, or numpy array). |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int] | None
|
A tuple of (x, y) coordinates for the center of the found text, |
tuple[int, int] | None
|
or None if the text is not found. |
Source code in src/pymordial/core/blueprints/ocr_device.py
30 31 32 33 34 35 36 37 38 39 40 41 42 | |