Devices API
ADB Device
pymordialdroid.devices.adb_device
Android Debug Bridge (ADB) device implementation for PymordialDroid.
AdbDevice
Bases: PymordialBridgeDevice
Handles Android device communication via pure Python ADB.
Fulfills the PymordialBridgeDevice contract with native package resolution, activity detection, focused window parsing, and resilient app lifecycle commands.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | |
capture_screenshot()
Captures a PNG screenshot, preferring the scrcpy headless feed.
Tries the frame provider first (fast path); falls back to pure 'screencap -p' so behavior never regresses when no feed is running.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | |
clear_frame_provider()
Removes the headless-feed frame provider.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
461 462 463 | |
close_all_apps(exclude=None)
Force stops all installed third-party/user packages to clear device state.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
close_app(package_name=None, app_name=None, timeout=5.0, wait_time=0.5)
Force stops an app and polls pidof to confirm closure.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
connect(auto_heal=True)
Connects to the Android device via TCP socket with RSA authentication.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
disconnect()
Disconnects the ADB device.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
148 149 150 151 152 153 154 155 156 157 158 159 160 | |
ensure_cli_endpoint()
Registers this endpoint with the CLI adb server (adb connect).
Required before launching scrcpy binaries / live-stream helpers,
which shell out to adb.exe and cannot see pure-Python
:class:AdbDeviceTcp sockets. Best-effort: never raises.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
find_package_by_keyword(keyword)
Finds an installed package matching a keyword using 'pm list packages'.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
215 216 217 218 219 220 221 222 223 224 225 226 227 | |
get_current_app()
Gets the package name of the currently focused application.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
368 369 370 371 372 373 | |
get_focused_app()
Parses 'dumpsys window' to detect the currently focused package and activity.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
get_latest_frame()
Retrieves the most recent frame bytes or captures a fresh screenshot.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
500 501 502 503 504 | |
get_launch_activity(package_name)
Queries Android's activity manager to determine the exact launchable activity.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
go_back()
Simulates Back button press.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
437 438 439 | |
go_home()
Simulates Home button press.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
433 434 435 | |
initialize(config=None)
Initializes the ADB device plugin.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
45 46 47 | |
install_apk(apk_path, update=True)
Pushes and installs an APK file via adb.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | |
is_app_running(package_name=None, app_name=None, max_retries=2, wait_time=1.0)
Checks if an app is actively running by querying process PID.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
is_connected()
Checks if ADB connection is currently active and responsive.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
144 145 146 | |
open_app(package_name, app_name=None, timeout=10.0, wait_time=1.0)
Launches an app via resolved Activity or Monkey fallback, verifying it started.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
parse_package_list(output)
staticmethod
Extracts package names from pm list packages output.
Only package:-prefixed lines are kept; device warnings (e.g.
Samsung multi-user SecurityException preambles) are ignored so
they can never match a keyword or be force-stopped.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
press_enter()
Simulates Enter key press.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
441 442 443 | |
press_esc()
Simulates Back / Escape key press.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
445 446 447 | |
rank_package(keyword, packages)
staticmethod
Ranks packages for a keyword: exact > component > substring.
- Case-insensitive exact match.
- Keyword equals a dot-separated component (
settingsmatchescom.android.settingsbut notcom.sec.usbsettings); ties break toward the shortest full name. - Plain substring match; ties break toward the shortest full name.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
run_command(command, decode=True)
Executes a shell command on the device.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
162 163 164 165 166 167 168 169 170 171 172 | |
set_frame_provider(provider)
Sets an optional headless-feed frame provider.
The provider is a zero-arg callable returning PNG bytes (or None).
Typically ScrcpyDevice.get_latest_frame. When set,
:meth:capture_screenshot tries it first for a high-FPS frame and
falls back to screencap -p on None/exception.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
451 452 453 454 455 456 457 458 459 | |
show_recent_apps()
Opens recent apps / overview.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
344 345 346 347 | |
shutdown()
Disconnects and cleans up resources.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
49 50 51 | |
start_stream()
Starts stream mode (tracks frames from screenshot captures).
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
492 493 494 | |
stop_stream()
Stops stream mode.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
496 497 498 | |
swipe(start_x, start_y, end_x, end_y, duration=300)
Performs a touch swipe gesture from start to end coordinates.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
401 402 403 404 405 406 407 408 409 410 411 412 413 | |
tap(coords, y=None, times=1)
Sends tap events to coordinates on screen.
Accepts either a tuple/list (x, y) or separate x, y integers.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | |
type_text(text, enter=False)
Types text into the focused input field, escaping shell characters.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/adb_device.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
BlueStacks Device
pymordialblue.devices.bluestacks_device
Controller for managing the BlueStacks emulator.
BluestacksDevice
Bases: PymordialEmulatorDevice
Controls the BlueStacks emulator.
Attributes:
| Name | Type | Description |
|---|---|---|
running_apps |
list[PymordialApp] | list
|
A list of currently running PymordialApp instances. |
state |
list[PymordialApp] | list
|
The state machine managing the BlueStacks lifecycle state. |
elements |
list[PymordialApp] | list
|
A container for BlueStacks UI elements. |
elements |
list[PymordialApp] | list
|
A container for BlueStacks UI elements. |
config |
The configuration dictionary for BlueStacks. |
Source code in src/pymordialblue/devices/bluestacks_device.py
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | |
filepath
property
writable
Gets the BlueStacks executable filepath.
Returns:
| Type | Description |
|---|---|
str | None
|
The absolute path to the HD-Player.exe file as a string, or None |
str | None
|
if it has not been determined. |
ref_window_size
property
writable
Gets the reference window size.
Returns:
| Type | Description |
|---|---|
tuple[int, int] | None
|
A tuple containing (width, height) in pixels, or None if not set. |
__init__(adb_bridge_device=None, vision_device=None, config=None)
Initializes the BluestacksDevice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adb_bridge_device
|
AdbDevice | None
|
The bridge device (e.g. AdbDevice) used for low-level ADB interactions. |
None
|
vision_device
|
AndroidUiDevice | None
|
The vision device used for screen analysis. |
None
|
config
|
BluestacksConfig | None
|
A TypedDict containing BlueStacks configuration options. Defaults to package defaults if None. |
None
|
Source code in src/pymordialblue/devices/bluestacks_device.py
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 | |
close()
Kills the Bluestacks controller process.
This will also disconnect the ADB bridge device.
Returns:
| Type | Description |
|---|---|
bool
|
True if the Bluestacks process was found and killed, or if no |
bool
|
process was found running. False if the process was found but |
bool
|
could not be killed. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an unexpected error occurs during the process killing routine. |
Source code in src/pymordialblue/devices/bluestacks_device.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | |
initialize(config)
Initializes the BlueStacks device plugin with configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
BlueConfig
|
Global Pymordial configuration dictionary. |
required |
Source code in src/pymordialblue/devices/bluestacks_device.py
90 91 92 93 94 95 96 | |
is_ready()
Checks if BlueStacks is in the READY state.
Returns:
| Type | Description |
|---|---|
bool
|
True if the current state is EmulatorState.READY, False otherwise. |
Source code in src/pymordialblue/devices/bluestacks_device.py
349 350 351 352 353 354 355 | |
open(max_retries=None, wait_time=None, timeout_s=None)
Opens the BlueStacks emulator application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_retries
|
int | None
|
The maximum number of attempts to detect the process after launching. Defaults to the configuration value. |
None
|
wait_time
|
int | None
|
The time in seconds to wait between detection attempts. Defaults to the configuration value. |
None
|
timeout_s
|
int | None
|
The maximum total time in seconds to wait for the process to appear before timing out. Defaults to the configuration value. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If BlueStacks fails to start due to an OS error. |
Exception
|
If the BlueStacks process window is not found after the specified retries or timeout period. |
Source code in src/pymordialblue/devices/bluestacks_device.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
open_settings()
Opens the Settings app using a verified activity name.
Returns:
| Type | Description |
|---|---|
bool
|
True if opened successfully, False otherwise. |
Source code in src/pymordialblue/devices/bluestacks_device.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
set_dependencies(adb_bridge_device, vision_device)
Sets external dependencies (dependency injection).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adb_bridge_device
|
AdbDevice
|
The ADB bridge device. |
required |
vision_device
|
AndroidUiDevice
|
The vision device. |
required |
Source code in src/pymordialblue/devices/bluestacks_device.py
98 99 100 101 102 103 104 105 106 107 108 109 110 | |
shutdown()
Kills the emulator process.
Source code in src/pymordialblue/devices/bluestacks_device.py
112 113 114 | |
wait_for_load(timeout_s=None)
Waits for Bluestacks to finish loading by polling the ADB connection.
This method blocks until the emulator is responsive via ADB or the timeout is reached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout_s
|
int | None
|
The maximum number of seconds to wait for the emulator to load. Defaults to the configuration value. |
None
|
Source code in src/pymordialblue/devices/bluestacks_device.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
UI Device
pymordialdroid.devices.ui_device
Vision and UI element detection implementing Pymordial's PymordialVisionDevice contract.
AndroidUiDevice
Bases: PymordialVisionDevice
Handles visual recognition tasks: template matching, pixel checks, and OCR.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/ui_device.py
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
check_pixel_color(pymordial_pixel=None, pymordial_screenshot=None, coords=None, expected_color=None, tolerance=10, screenshot=None)
Checks if a pixel matches the target color within tolerance.
Supports coordinate scaling when og_resolution is set on pymordial_pixel.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/ui_device.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
check_text(text_to_find, pymordial_screenshot=None, case_sensitive=False, strategy=None)
Checks if text is visible on screen using the OCR device.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/ui_device.py
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |
find_text(text_to_find, pymordial_screenshot=None, strategy=None)
Finds the center coordinates of specified text using the OCR device.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/ui_device.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
initialize(config=None)
Initializes the UI vision plugin.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/ui_device.py
40 41 42 | |
read_text(pymordial_screenshot=None, case_sensitive=False, strategy=None)
Reads text lines from the screen using the OCR device.
Lines are always returned verbatim as recognized; case_sensitive
is accepted for signature compatibility but no longer mutates the
output (case-insensitive matching belongs in :meth:check_text).
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/ui_device.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
scale_img_to_screen(image_path, screen_image, ref_resolution=None)
Scales a template image to match the device screen resolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path
|
str | Path
|
Path to the reference image. |
required |
screen_image
|
str | Image | bytes | ndarray
|
The current screen image. |
required |
ref_resolution
|
tuple[int, int] | None
|
Original resolution (width, height) the template was captured at. |
None
|
Returns:
| Type | Description |
|---|---|
Image
|
Scaled PIL Image. |
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/ui_device.py
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 | |
set_bridge_device(bridge_device)
Sets the underlying bridge device.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/ui_device.py
48 49 50 | |
set_ocr_device(ocr_device)
Sets the OCR device.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/ui_device.py
52 53 54 | |
shutdown()
Performs cleanup.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/ui_device.py
44 45 46 | |
where_element(element, screenshot=None, max_tries=1, set_position=False, set_size=False, wait_time=0.5, pymordial_screenshot=None)
Finds (center_x, center_y) coordinates of a UI element on screen.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/ui_device.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
where_elements(elements, screenshot=None, max_tries=1, pymordial_screenshot=None)
Finds the coordinates of the first matching element from a list.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/ui_device.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
Tesseract Device
pymordialdroid.devices.tesseract_device
Tesseract OCR device implementing Pymordial's PymordialOCRDevice contract.
TesseractDevice
Bases: PymordialOCRDevice
Optical Character Recognition device powered by Tesseract and OpenCV.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/tesseract_device.py
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
extract_text(image_path, strategy=None)
Extracts text from an image with optional preprocessing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path
|
Path | bytes | str | ndarray
|
Source image as Path, bytes, string, or numpy array. |
required |
strategy
|
PymordialExtractStrategy | None
|
Optional extraction strategy (defaults to DefaultExtractStrategy). |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Extracted text string. |
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/tesseract_device.py
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 | |
find_text(search_text, image_path, strategy=None)
Finds (center_x, center_y) coordinates of search_text in the source image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
search_text
|
str
|
Text keyword or substring to search for. |
required |
image_path
|
Path | bytes | str | ndarray
|
Source image as Path, bytes, string, or numpy array. |
required |
strategy
|
PymordialExtractStrategy | None
|
Optional preprocessing strategy. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[int, int] | None
|
(center_x, center_y) coordinates if located, None otherwise. |
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/tesseract_device.py
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
initialize(config=None)
Initializes the OCR device plugin.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/tesseract_device.py
43 44 45 | |
shutdown()
Cleans up resources.
Source code in .venv/lib/python3.13/site-packages/pymordialdroid/devices/tesseract_device.py
47 48 49 | |