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

Uploaded Source

Built Distribution

File details

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

File metadata

File hashes

Hashes for java-access-bridge-wrapper-0.8.2.tar.gz
Algorithm Hash digest
SHA256 ea829780564d40cd161372b8fa03dd8c6b78aa879a3c19555fe189c89c77484f
MD5 513f232b25d3a8e279dc6fedf315bc0d
BLAKE2b-256 1f625e0b74d9bcfd0f17c38f92e5e63d8001042127a25eee10b1bd890e940b68

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for java_access_bridge_wrapper-0.8.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c633ca0af05587a969cffd755c92ef1d09d3dfa1a37dfc479bb061a668895c8a
MD5 eee61da22a7bdda28b9ae7a0b5af6485
BLAKE2b-256 f1c89321463341e187a8ca372abe8b70ee2fc7ad67fef9fdcd8fa1657c88cc53

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