Python wrapper for the Windows Java Access Bridge
Project description
Introduction
Python wrapper around the Java Access Bridge / Windows Access Bridge.
Prerequisites
- 64-bit Windows
- Java >= 8 (https://docs.aws.amazon.com/corretto/latest/corretto-8-ug/downloads-list.html)
- If you are doing development install JDK, otherwise JRE is enough
- Python >= 3.7 (https://www.python.org/downloads/release/python-375/)
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
- Install poetry: https://python-poetry.org/docs/
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"
Initialize poetry
poetry intall
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for java_access_bridge_wrapper-0.14.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ee085b6257b23037e84c0572821e636402b14450ec7d396b0b04ab85ce40476 |
|
MD5 | 115dadd4a2c6ad36cd9195c0b8b1c2a6 |
|
BLAKE2b-256 | c5d8ef958309b153f4ebc1996d4777d128c9fd346bfd532262955c7add5d08ea |
Hashes for java_access_bridge_wrapper-0.14.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e3a5afbb5a42a50d33b355ad74b7fe1e1109c4f7a90c363ec49542fcd605806 |
|
MD5 | 88a8ef85e7429fd8cdbb114ec620fafc |
|
BLAKE2b-256 | ac398ae188c521273523010f6b298dab4746ff1ba692325e2543e0fa658129f9 |