Devices API
ADB Device
pymordialblue.devices.adb_device
Controller for ADB interactions.
PymordialAdbDevice
Bases: PymordialBridgeDevice
Handles Android device communication using adb-shell.
Configuration is loaded from default settings but can be overridden per instance by modifying the instance attributes after initialization.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The plugin name ("adb"). |
version |
str
|
The plugin version. |
host |
str
|
The address of the device; may be an IP address or a host name. |
port |
int
|
The device port to which we are connecting |
device |
AdbDeviceTcp
|
The adb_shell.AdbDeviceTcp instance. |
config |
AdbConfig
|
The configuration dictionary. |
Source code in src/pymordialblue/devices/adb_device.py
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 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 | |
is_streaming
property
Check if streaming is currently active.
Returns:
| Type | Description |
|---|---|
bool
|
True if streaming is active, False otherwise. |
__init__(host=None, port=None, config=None, adbshell_log_level=WARNING)
Initalizes PymordialAdbDevice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str | None
|
The address of the device; may be an IP address or a host name. |
None
|
port
|
int | None
|
The device port to which we are connecting. |
None
|
config
|
AdbConfig | None
|
A TypedDict containing ADB configuration. Defaults to package defaults. |
None
|
adbshell_log_level
|
int
|
The log level for adb-shell (e.g. logging.WARNING). |
WARNING
|
Source code in src/pymordialblue/devices/adb_device.py
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 | |
capture_screen()
Captures the current BlueStacks screen using the appropriate capture strategy.
Returns:
| Type | Description |
|---|---|
'bytes | np.ndarray | None'
|
The screenshot as bytes or numpy array, or None if failed. |
Source code in src/pymordialblue/devices/adb_device.py
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 | |
capture_screenshot()
Captures a screenshot of the device.
Returns:
| Type | Description |
|---|---|
bytes | None
|
The screenshot as bytes, or None if failed. |
Source code in src/pymordialblue/devices/adb_device.py
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 | |
close_all_apps(exclude=None)
Force stops all packages to clear the device state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exclude
|
list[str] | None
|
Optional list of package names to exclude from closing. |
None
|
Source code in src/pymordialblue/devices/adb_device.py
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 | |
close_app(package_name=None, app_name=None, timeout=5.0, wait_time=0.5)
Closes an app and verifies it stopped.
Provide either package_name (exact) or app_name (keyword search). If both provided, package_name takes priority.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str | None
|
Exact package name (e.g., 'com.revomon.vr'). |
None
|
app_name
|
str | None
|
Keyword to search for package (e.g., 'revomon'). |
None
|
timeout
|
float
|
Max seconds to wait for app to close. |
5.0
|
wait_time
|
float
|
Seconds between verification retries. |
0.5
|
Returns:
| Type | Description |
|---|---|
bool
|
True if app is confirmed closed, False otherwise. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither package_name nor app_name is provided. |
Source code in src/pymordialblue/devices/adb_device.py
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 | |
disconnect()
Disconnects the PymordialAdbDevice device.
Returns:
| Type | Description |
|---|---|
bool
|
True if disconnected (or already disconnected), False on error. |
Source code in src/pymordialblue/devices/adb_device.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
get_focused_app()
Gets information about the currently focused app.
Returns:
| Type | Description |
|---|---|
dict[str, str] | None
|
A dictionary with 'package' and 'activity', or None if failed. |
Source code in src/pymordialblue/devices/adb_device.py
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 | |
get_latest_frame()
Gets the latest decoded frame from the stream.
Returns:
| Type | Description |
|---|---|
ndarray | None
|
The latest frame as a numpy array (RGB), or None if no frame available. |
Source code in src/pymordialblue/devices/adb_device.py
667 668 669 670 671 672 673 674 675 676 | |
go_home()
Navigates to the home screen.
Returns:
| Type | Description |
|---|---|
bool
|
True if successful, False otherwise. |
Source code in src/pymordialblue/devices/adb_device.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | |
initialize(config)
Initializes the ADB device plugin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
'PymordialBlueConfig'
|
Global Pymordial configuration dictionary. |
required |
Source code in src/pymordialblue/devices/adb_device.py
85 86 87 88 89 90 91 92 93 | |
is_app_running(package_name=None, pymordial_app=None, app_name=None, max_retries=2, wait_time=1)
Checks if an app is running using pidof command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str | None
|
Direct package name (e.g., 'com.android.settings'). |
None
|
pymordial_app
|
'PymordialApp' | None
|
PymordialApp instance to extract package from. |
None
|
app_name
|
str | None
|
App name keyword to search for. |
None
|
max_retries
|
int
|
Number of retries. |
2
|
wait_time
|
int
|
Time to wait between retries. |
1
|
Returns:
| Type | Description |
|---|---|
bool
|
True if running, False otherwise. |
Priority: package_name > pymordial_app > app_name.
Source code in src/pymordialblue/devices/adb_device.py
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 | |
is_connected()
Checks if PymordialAdbDevice device is connected.
Returns:
| Type | Description |
|---|---|
bool
|
True if the device is connected, False otherwise. |
Source code in src/pymordialblue/devices/adb_device.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
open_app(app_name, package_name=None, timeout=10.0, wait_time=1.0)
Opens an app by name or package, with optional verification. Args: app_name: Name/keyword to search for the package if package_name not provided. package_name: Optional exact package name. timeout: Max seconds to wait for app to start (if verify=True). wait_time: Seconds between verification retries. Returns: True if launched, False otherwise.
Source code in src/pymordialblue/devices/adb_device.py
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 | |
press_enter()
Presses the Enter key.
Returns:
| Type | Description |
|---|---|
bool
|
True if successful, False otherwise. |
Source code in src/pymordialblue/devices/adb_device.py
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 | |
press_esc()
Presses the Esc key.
Returns:
| Type | Description |
|---|---|
bool
|
True if successful, False otherwise. |
Source code in src/pymordialblue/devices/adb_device.py
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 | |
run_command(command, decode=False)
Executes a shell command and returns the output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
The command to execute. |
required |
Returns:
| Type | Description |
|---|---|
bytes | None
|
The command output as bytes, or None if not connected. |
Source code in src/pymordialblue/devices/adb_device.py
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 | |
show_recent_apps()
Shows the recent apps drawer.
Returns:
| Type | Description |
|---|---|
bool
|
True if successful, False otherwise. |
Source code in src/pymordialblue/devices/adb_device.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | |
shutdown()
Disconnects and cleans up resources.
Source code in src/pymordialblue/devices/adb_device.py
95 96 97 | |
start_stream()
Starts screen streaming using adb-shell's streaming_shell with PyAV decoding.
Automatically detects resolution from a screenshot.
Returns:
| Type | Description |
|---|---|
bool
|
True if stream started successfully, False otherwise. |
Source code in src/pymordialblue/devices/adb_device.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 | |
stop_stream()
Stops the screen stream.
Source code in src/pymordialblue/devices/adb_device.py
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 | |
tap(x, y)
Performs a simple tap at (x, y).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int
|
X coordinate. |
required |
y
|
int
|
Y coordinate. |
required |
Source code in src/pymordialblue/devices/adb_device.py
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
type_text(text, enter=False)
Types text on the device. Args: text: The text to type. enter: Whether to press enter after typing. Returns: True if successful, False otherwise.
Source code in src/pymordialblue/devices/adb_device.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 | |
BlueStacks Device
pymordialblue.devices.bluestacks_device
Controller for managing the BlueStacks emulator.
PymordialBluestacksDevice
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 | |
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 PymordialBluestacksDevice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adb_bridge_device
|
PymordialAdbDevice | None
|
The bridge device (e.g. PymordialAdbDevice) used for low-level ADB interactions. |
None
|
vision_device
|
PymordialVisionDevice | 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
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 | |
initialize(config)
Initializes the BlueStacks device plugin with configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
PymordialBlueConfig
|
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
348 349 350 351 352 353 354 | |
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 | |
set_dependencies(adb_bridge_device, vision_device)
Sets external dependencies (dependency injection).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adb_bridge_device
|
PymordialAdbDevice
|
The ADB bridge device. |
required |
vision_device
|
PymordialVisionDevice
|
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
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 | |
UI Device
pymordialblue.devices.ui_device
Controller for image processing and element detection.
PymordialUiDevice
Bases: PymordialVisionDevice
Handles all visual recognition tasks.
This class consolidates image recognition (template matching), pixel color detection, and Optical Character Recognition (OCR) into a single interface. It routes element finding requests to the appropriate backend based on the element type (PymordialImage, PymordialPixel, or PymordialText).
Attributes:
| Name | Type | Description |
|---|---|---|
bridge_device |
Helper for underlying device operations (e.g., ADB). |
|
config |
VisionConfig
|
Configuration dictionary for vision settings (timeouts, retries). |
ocr_engine |
VisionConfig
|
The backend engine used for text extraction (e.g., Tesseract). |
Source code in src/pymordialblue/devices/ui_device.py
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 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 | |
__init__(bridge_device=None, config=None)
Initializes the PymordialUiDevice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bridge_device
|
PymordialBridgeDevice | None
|
Optional PymordialBridgeDevice for device interactions. If None, a new PymordialAdbDevice will be created. |
None
|
config
|
VisionConfig | None
|
Optional configuration dictionary. If None, loads defaults from the global configuration. |
None
|
Source code in src/pymordialblue/devices/ui_device.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
check_pixel_color(pymordial_pixel, pymordial_screenshot=None)
Checks if a specific pixel matches a target color within a given tolerance.
If a screenshot is not provided, one will be captured automatically from the connected device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pymordial_pixel
|
PymordialPixel
|
The pixel element definition containing coordinates, target color, and tolerance. |
required |
pymordial_screenshot
|
bytes | ndarray | None
|
Optional current screen content. Can be bytes or a numpy array. If None, a fresh screenshot is captured. |
None
|
Returns:
| Type | Description |
|---|---|
bool | None
|
True if the pixel at the specified coordinates matches the target |
bool | None
|
color within the tolerance. Returns None if the pixel element has |
bool | None
|
no position defined. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the screenshot cannot be captured, processed, or if the pixel definition is invalid (e.g., missing coordinates). |
Source code in src/pymordialblue/devices/ui_device.py
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 | |
check_text(text_to_find, pymordial_screenshot, case_sensitive=False, strategy=None)
Checks if specific text is present in the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text_to_find
|
str
|
The exact text string to search for. |
required |
pymordial_screenshot
|
Path | bytes | str | ndarray
|
The source image to search within. Can be a file path (str or Path), raw image bytes, or a numpy array. |
required |
case_sensitive
|
bool
|
If True, performs a case-sensitive search. Defaults to False. |
False
|
strategy
|
PymordialExtractStrategy | None
|
Optional preprocessing strategy to apply before OCR. This is currently only supported by PymordialTesseractDevice. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the text is found in the image, False otherwise. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the image cannot be loaded or processed. |
Source code in src/pymordialblue/devices/ui_device.py
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 | |
find_text(text_to_find, pymordial_screenshot, strategy=None)
Finds the coordinates of specific text in the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text_to_find
|
str
|
The text string to search for. |
required |
pymordial_screenshot
|
Path | bytes | str | ndarray
|
The source image to search within. Can be a file path (str or Path) or raw image bytes. |
required |
strategy
|
PymordialExtractStrategy | None
|
Optional preprocessing strategy to apply before OCR. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[int, int] | None
|
A tuple containing (x, y) coordinates of the found text center, or |
tuple[int, int] | None
|
None if the text was not found. |
Source code in src/pymordialblue/devices/ui_device.py
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 | |
initialize(config)
Initializes the UI device plugin with configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
PymordialBlueConfig
|
Global Pymordial configuration dictionary. |
required |
Source code in src/pymordialblue/devices/ui_device.py
70 71 72 73 74 75 76 77 | |
read_text(pymordial_screenshot, case_sensitive=False, strategy=None)
Reads and extracts text lines from an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pymordial_screenshot
|
Path | bytes | str | ndarray
|
The source image to read text from. Can be a file path (str or Path), raw image bytes, or a numpy array. |
required |
case_sensitive
|
bool
|
If True, preserves the original case of the text. If False, converts all text to lowercase. Defaults to False. |
False
|
strategy
|
PymordialExtractStrategy | None
|
Optional preprocessing strategy to apply before OCR. This is currently only supported by PymordialTesseractDevice. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of strings, where each string corresponds to a line of text |
list[str]
|
detected in the image. Empty lines and whitespace-only lines are |
list[str]
|
excluded. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the image cannot be loaded or processed by the OCR engine. |
Source code in src/pymordialblue/devices/ui_device.py
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 | |
scale_img_to_screen(image_path, screen_image, bluestacks_resolution)
Scales an image to match the current screen resolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path
|
str
|
The file path to the reference image (needle) to scale. |
required |
screen_image
|
str | Image | bytes | ndarray
|
The current screen content. Can be a file path, bytes, numpy array, or a PIL Image object. |
required |
bluestacks_resolution
|
tuple[int, int]
|
The reference resolution (width, height) that the image_path was originally captured at. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
A PIL Image object of the needle image, scaled to match the |
Image
|
dimensions of the provided screen_image. |
Source code in src/pymordialblue/devices/ui_device.py
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 | |
set_bridge_device(bridge_device)
Sets the bridge device (dependency injection).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bridge_device
|
PymordialBridgeDevice
|
The bridge device instance to use. |
required |
Source code in src/pymordialblue/devices/ui_device.py
79 80 81 82 83 84 85 | |
shutdown()
Cleans up resources.
Source code in src/pymordialblue/devices/ui_device.py
87 88 89 | |
where_element(pymordial_element, pymordial_screenshot=None, max_tries=None, set_position=False, set_size=False)
Finds the coordinates of a PymordialElement on the screen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pymordial_element
|
PymordialElement
|
The PymordialElement instance to locate. |
required |
pymordial_screenshot
|
bytes | ndarray | None
|
Optional pre-captured screenshot (bytes or numpy array) to search within. If None, a new screenshot will be captured. |
None
|
max_tries
|
int | None
|
Maximum number of attempts to find the element. If None, it will retry indefinitely (useful for waiting on loading screens). |
None
|
set_position
|
bool
|
If True, updates the element's |
False
|
set_size
|
bool
|
If True, updates the element's |
False
|
Returns:
| Type | Description |
|---|---|
tuple[int, int] | None
|
A tuple containing (x, y) coordinates of the element's center if found, |
tuple[int, int] | None
|
or None if the element was not found after the specified attempts. |
Note
If max_tries is None, this method loops indefinitely until the element is found.
Source code in src/pymordialblue/devices/ui_device.py
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 | |
where_elements(pymordial_elements, pymordial_screenshot=None, max_tries=None)
Finds the coordinates of the first found element from a list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pymordial_elements
|
list[PymordialElement]
|
A list of PymordialElement objects to search for. |
required |
pymordial_screenshot
|
bytes | ndarray | None
|
Optional pre-captured screenshot (bytes or numpy array) to avoid capturing a new one. |
None
|
max_tries
|
int | None
|
Maximum number of retries for each element in the list. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[int, int] | None
|
A tuple containing (x, y) coordinates of the first element successfully |
tuple[int, int] | None
|
located, or None if no elements from the list were found. |
Source code in src/pymordialblue/devices/ui_device.py
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 | |
Tesseract Device
pymordialblue.devices.tesseract_device
Tesseract OCR implementation (requires Tesseract installation).
PymordialTesseractDevice
Bases: PymordialOCRDevice
Tesseract OCR implementation.
Advantages: - Lightweight (~50MB) - Fast CPU-only inference - Good accuracy for clean text - Cross-platform
Attributes:
| Name | Type | Description |
|---|---|---|
config |
Tesseract configuration string. |
Source code in src/pymordialblue/devices/tesseract_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 | |
__init__(config=DEFAULT_CONFIG)
Initializes Tesseract OCR.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
str
|
Tesseract configuration string. |
DEFAULT_CONFIG
|
Source code in src/pymordialblue/devices/tesseract_device.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
extract_text(image_path, strategy=None)
Extracts text from an image using Tesseract with optional preprocessing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path
|
Path | bytes | str | ndarray
|
Path to image file, image bytes, numpy array, or a string path. |
required |
strategy
|
PymordialExtractStrategy | None
|
Optional PymordialExtractStrategy instance. If None, a DefaultExtractStrategy is used, providing generic preprocessing suitable for any image. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The extracted text. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the image cannot be processed. |
Source code in src/pymordialblue/devices/tesseract_device.py
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 | |
find_text(search_text, image_path, strategy=None)
Finds the coordinates (center) of the specified text in the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
search_text
|
str
|
Text to search for. |
required |
image_path
|
Path | bytes | str | ndarray
|
Path to image file, image bytes, or numpy array. |
required |
strategy
|
PymordialExtractStrategy | None
|
Optional preprocessing strategy. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[int, int] | None
|
(x, y) coordinates of the center of the found text, or None if not found. |
Source code in src/pymordialblue/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 | |