Package: java-access-bridge-wrapper
IntroductionPython wrapper around the Java Access Bridge / Windows Access Bridge.Requirements64-bit WindowsJava >= 8 (https://docs.aws.amazon.com/corretto/latest/corretto-8-ug/downloads-list.html)If you are doing development install JDK, otherwise JRE is enoughPython >= 3.8 (https://www.python.org/downloads/release/python-375/)Enable the Java Access Bridge in windowsC:\path\to\java\bin\jabswitch -enableInstallpip install java-access-bridge-wrapperHow to useImport the Java Access Bridge (JAB) wrapper and optionally the context treefrom JABWrapper.jab_wrapper import JavaAccessBridgeWrapper
from JABWrapper.context_tree import ContextNode, ContextTree, SearchElementThe 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)DevelopmentPrerequisitesInstall 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 theseinstructions.Now you're ready to set-up Poetry for the first time withinv setup.Check with-hon how to pass credentials for ensuring that both your production  PyPI and CI DevPI are
configured. You'll find these in ourRobocorp>Shared1Password by searching for keywords like "pypi"
(where we recommend a personaltokeninstead) and "devpi".Runinv updateso the library gets ready for development.TestingRun test script against a simple Swing application.Set environment variableset RC_JAVA_ACCESS_BRIDGE_DLL="C:\path\to\Java\bin\WindowsAccessBridge-64.dll"Update requirements and install the library in development modeinv updateRun testsinv test  # runs all the tests in all scenarios
inv test -s -t test_jab_wrapper.py  # runs all the tests from a file in one simple common scenario
inv test -s -c -t test_jab_wrapper.py::test_depth  # as above, but specific test and captures outputPackagingCheck lintinginv lint  # apply with '-a'Building and publishinginv publish  # '-c' for DevPITODO:Support for 32-bit Java Access Bridge versionImplement rest of the utility functions to the JABWrapper