跳转到主要内容

Windows Java Access Bridge的Python封装器

项目描述

Version License

简介

Java访问桥/Windows访问桥的Python包装器。

要求

在Windows中启用Java访问桥

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

安装

pip install java-access-bridge-wrapper

如何使用

导入Java访问桥(JAB)包装器以及可选的上下文树

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

当JAB打开时,它创建一个虚拟GUI窗口。为了使JAB运行并从GUI接收事件,调用代码需要实现窗口消息泵并在循环中调用它。JABWrapper对象需要在同一线程中。

例如,可以通过在单独的线程中启动消息泵并初始化JAB对象来实现这一点。

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()

一旦JABWrapper对象初始化,将其附加到某个框架并可选地创建上下文树以获取应用程序的元素树。

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

开发

先决条件

  1. 安装Invoke、Poetry和其他必需的依赖项,以便能够开发和打包库: pip install -Ur requirements.txt
    • 如果您想将这些与其他项目隔离开来,不依赖于OS Python,请首先通过以下说明启用一个(pyenv)虚拟环境。
  2. 现在您可以使用inv setup首次设置Poetry。
    • 使用-h检查如何传递凭据以确保您的生产PyPI和CI DevPI都已配置。您可以在我们的 Robocorp > 共享 1Password中通过搜索关键词如“pypi”(我们建议使用个人令牌)和“devpi”来找到这些凭据。
  3. 运行inv update,以便库准备好开发。

测试

针对简单的Swing应用程序运行测试脚本。

设置环境变量

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

更新要求并以开发模式安装库

inv update

运行测试

inv 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 output

打包

检查代码风格

inv lint  # apply with '-a'

构建和发布

inv publish  # '-c' for DevPI

待办事项

  • 32位Java访问桥版本支持
  • 将其他实用功能实现到JABWrapper中

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

java_access_bridge_wrapper-1.2.0.tar.gz (29.4 kB 查看散列值)

上传时间 源代码

构建分发

java_access_bridge_wrapper-1.2.0-py3-none-any.whl (32.9 kB 查看散列值)

上传时间 Python 3

由以下提供支持