App Model API
pymordialblue.android_app
Core application logic for Pymordial.
PymordialAndroidApp
Bases: PymordialApp
Represents an Android application with lifecycle management.
The PymordialController reference is automatically set when this app is registered with a controller via PymordialController(apps=[...]) or controller.add_app(...).
Attributes:
| Name | Type | Description |
|---|---|---|
app_name |
The display name of the app. |
|
package_name |
str
|
The Android package name (e.g., com.example.app). |
pymordial_controller |
PymordialController | None
|
The controller managing this app. |
screens |
PymordialController | None
|
A dictionary of screens belonging to this app. |
app_state |
PymordialController | None
|
The state machine managing the app's lifecycle. |
ready_element |
PymordialController | None
|
Optional element to detect when app is fully loaded. When this element becomes visible, app automatically transitions to READY. |
Source code in src/pymordialblue/android_app.py
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
__init__(app_name, package_name, screens={}, ready_element=None)
Initializes a PymordialApp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
The display name of the app. |
required |
package_name
|
str
|
The Android package name. |
required |
screens
|
dict[str, PymordialScreen] | dict
|
Optional dictionary of screens. |
{}
|
ready_element
|
PymordialElement | None
|
Optional element that indicates app is ready. When this element becomes visible after opening the app, the state will automatically transition from LOADING to READY. Example: main menu button, game title text, etc. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If app_name or package_name are empty. |
Source code in src/pymordialblue/android_app.py
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 | |
check_ready(max_tries=None)
Check if ready_element is visible and transition to READY if so.
This is automatically called after open() if ready_element is defined. You can also manually poll this to check loading status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_tries
|
int
|
Maximum detection attempts (default: None). |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if transitioned to READY, False if still loading. |
Example
Manual polling in a loop
while app.is_loading(): if app.check_ready(): print("App is ready!") break time.sleep(0.5)
Source code in src/pymordialblue/android_app.py
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 92 93 | |
is_open()
Checks if the app is in the READY state.
Returns:
| Type | Description |
|---|---|
bool
|
True if the app is READY, False otherwise. |
Source code in src/pymordialblue/android_app.py
95 96 97 98 99 100 101 | |
is_loading()
Checks if the app is in the LOADING state.
Apps remain in LOADING until: 1. A ready_element becomes visible (automatic transition), or 2. You manually transition: app.app_state.transition_to(AppState.READY)
Returns:
| Type | Description |
|---|---|
bool
|
True if the app is LOADING, False otherwise. |
Source code in src/pymordialblue/android_app.py
103 104 105 106 107 108 109 110 111 112 113 | |
is_closed()
Checks if the app is in the CLOSED state.
Returns:
| Type | Description |
|---|---|
bool
|
True if the app is CLOSED, False otherwise. |
Source code in src/pymordialblue/android_app.py
115 116 117 118 119 120 121 | |
__repr__()
Returns a string representation of the app.
Source code in src/pymordialblue/android_app.py
123 124 125 126 127 128 129 130 | |