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.

Prerequisites

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

Development prerequisites

Test

Run test script against simple Swing application

set environment variable

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

Run test with poetry

poetry run python tests\test.py

Packaging

poetry build
poetry publish

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-0.9.4.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

java_access_bridge_wrapper-0.9.4-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

Details for the file java-access-bridge-wrapper-0.9.4.tar.gz.

File metadata

File hashes

Hashes for java-access-bridge-wrapper-0.9.4.tar.gz
Algorithm Hash digest
SHA256 6bac676a70c2e4a4e29e1d282694f5cfea4f9e2e201083a60c16d8e1ed18af39
MD5 5cff292eaf5f35aff2e1984cb7a604c2
BLAKE2b-256 a50dfc79dbfdbd8821d76ab7f92a2d080092e6c7f0a554f72ba46abbdeace078

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for java_access_bridge_wrapper-0.9.4-py3-none-any.whl
Algorithm Hash digest
SHA256 274aa98c87bf380025206688303e95dfe1546bf6fdc6d599604f6dbe4469d9a4
MD5 3bce77dfc0098400c0daeb31c00fe53f
BLAKE2b-256 00945bc06bf6cd8f26bb01a1aaf022ebdc7cba399a544115dbc99a4ebde2899b

See more details on using hashes here.

Provenance

Supported by

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