Windows Java Access Bridge的Python封装器
项目描述
简介
Java访问桥/Windows访问桥的Python包装器。
要求
- 64位Windows
- Java >= 8 (https://docs.aws.amazon.com/corretto/latest/corretto-8-ug/downloads-list.html)
- 如果您正在进行开发,请安装JDK,否则JRE足够。
- Python >= 3.8 (https://pythonlang.cn/downloads/release/python-375/)
在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)
开发
先决条件
- 安装Invoke、Poetry和其他必需的依赖项,以便能够开发和打包库:
pip install -Ur requirements.txt
。- 如果您想将这些与其他项目隔离开来,不依赖于OS Python,请首先通过以下说明启用一个(pyenv)虚拟环境。
- 现在您可以使用
inv setup
首次设置Poetry。- 使用
-h
检查如何传递凭据以确保您的生产PyPI和CI DevPI都已配置。您可以在我们的 Robocorp > 共享 1Password中通过搜索关键词如“pypi”(我们建议使用个人令牌)和“devpi”来找到这些凭据。
- 使用
- 运行
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.tar.gz的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | 77b9e88d84a74794fa69fda486dc756a8b4f69442d3f51551eb51935d8be70ed |
|
MD5 | 10290394e8ff115d781dc1956af7895c |
|
BLAKE2b-256 | ff0ee4542f601a1e15c72c4e813a6f3e6d825a1297be3ee5e58d73be0919532e |
关闭
java_access_bridge_wrapper-1.2.0-py3-none-any.whl的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | a0875687a70e5dea48806db387de440ebacd02c9a84447a592aa42a0281bcfc1 |
|
MD5 | c8493a8042441ce00f401347e9346a06 |
|
BLAKE2b-256 | 8685ffd3f9e255f34d4b717d60c755b2934bbd8d8287483c4bedf9743b12c70e |