Skip to main content

Python wrapper for the Windows Java Access Bridge

Project description

Version License

Introduction

Python wrapper around the Java Access Bridge / Windows Access Bridge.

Requirements

Enable the Java Access Bridge in windows

C:\path\to\java\bin\jabswitch -enable

Install

pip install java-access-bridge-wrapper

How to use

Import the Java Access Bridge (JAB) wrapper and optionally the context tree

from JABWrapper.jab_wrapper import JavaAccessBridgeWrapper
from JABWrapper.context_tree import ContextNode, ContextTree, SearchElement

The JAB creates an virtual GUI window when it is opened. For the JAB to operate and receive events from the GUI, the calling code needs to implement the windows message pump and call it in a loop. The JABWrapper object needs to be in the same thread.

This can be achieved for example by starting the message pump in a separate thread, where the JAB object is also initialized.

GetMessage = ctypes.windll.user32.GetMessageW
TranslateMessage = ctypes.windll.user32.TranslateMessage
DispatchMessage = ctypes.windll.user32.DispatchMessageW

def pump_background(pipe: queue.Queue):
    try:
        jab_wrapper = JavaAccessBridgeWrapper()
        pipe.put(jab_wrapper)
        message = byref(wintypes.MSG())
        while GetMessage(message, 0, 0, 0) > 0:
            TranslateMessage(message)
            logging.debug("Dispatching msg={}".format(repr(message)))
            DispatchMessage(message)
    except Exception as err:
        pipe.put(None)

def main():
    pipe = queue.Queue()
        thread = threading.Thread(target=pump_background, daemon=True, args=[pipe])
        thread.start()
        jab_wrapper = pipe.get()
        if not jab_wrapper:
            raise Exception("Failed to initialize Java Access Bridge Wrapper")
        time.sleep(0.1) # Wait until the initial messages are parsed, before accessing frames

if __name__ == "__main__":
    main()

Once the JABWrapper object is initialized, attach to some frame and optionally create the context tree to get the element tree of the application.

jab_wrapper.switch_window_by_title("Frame title")
context_tree = ContextTree(jab_wrapper)

Development

Prerequisites

  1. Install Invoke, Poetry and the other required dependencies in order to be able to develop and package the library: pip install -Ur requirements.txt.
    • If you want to isolate these from the other projects and not rely on the OS Python, enable a (pyenv) virtual environment first by following these instructions.
  2. Now you're ready to set-up Poetry for the first time with inv setup.
    • Check with -h on how to pass credentials for ensuring that both your production PyPI and CI DevPI are configured. You'll find these in our Robocorp > Shared 1Password by searching for keywords like "pypi" (where we recommend a personal token instead) and "devpi".
  3. Run inv update so the library gets ready for development.

Testing

Run test script against a simple Swing application.

Set environment variable

set RC_JAVA_ACCESS_BRIDGE_DLL="C:\path\to\Java\bin\WindowsAccessBridge-64.dll"

Update requirements and install the library in development mode

inv update

Run tests

inv test

Packaging

Check linting

inv lint  # apply with '-a'

Building and publishing

inv publish  # '-c' for DevPI

TODO:

  • Support for 32-bit Java Access Bridge version
  • Implement rest of the utility functions to the JABWrapper

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

java_access_bridge_wrapper-1.0.0.tar.gz (29.0 kB view details)

Uploaded Source

Built Distribution

java_access_bridge_wrapper-1.0.0-py3-none-any.whl (32.6 kB view details)

Uploaded Python 3

File details

Details for the file java_access_bridge_wrapper-1.0.0.tar.gz.

File metadata

File hashes

Hashes for java_access_bridge_wrapper-1.0.0.tar.gz
Algorithm Hash digest
SHA256 979c05b9d625240abd55a9ce7aee516a115155ab68d98b42c58840271a9806f6
MD5 c54e921dd31bcda42816ceda9986099b
BLAKE2b-256 cafc2ddf4649f7c9b9d6ccbdf8cf4cde0a2effbd09e19f7a58a5fd1f3a692ceb

See more details on using hashes here.

File details

Details for the file java_access_bridge_wrapper-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for java_access_bridge_wrapper-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ecca6061be0775fb3f01ebc857b4160dae4c529e45d0593498f71cb746657a68
MD5 99c6add2bf3205efcf33b1c0c1276039
BLAKE2b-256 b70eaeb2147b394f09dc8c6e6a919d5ca4b894cf23ba39861386ea047a025c61

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page