跳转到主要内容

Python的Auto-Hotkey-JSON

项目描述

ahk-json

这是一个扩展包,旨在与Python ahk 包一起使用。

它提供了在AutoHotkey中处理JSON的接口,来自cocobelgica/AutoHotkey-JSON。此包中的扩展不提供任何额外的方法,而是提供了一个方便的方法将 Jxon.ahk 和/或 JSON.ahk 包含到其他扩展中。

此包提供了两个扩展: JXONJSON。它还注册了一个JSON消息类型(ahk_json.message.JsonResponseMessage

安装

使用 pip 安装此扩展

pip install ahk-json

使用方法

通常,您将其用作构建自己的扩展时的依赖项。

在以下示例中,创建了一个简单的扩展(my_extension)。它实现了AHK函数 MyTestFunction,该函数使用Python函数 my_test_function 注册到扩展中。

from ahk.extensions import Extension
from ahk import AHK

from ahk_json import JXON  # importing is necessary for ``extensions='auto'`` to work, even if this is not used

ext_script = '''\
MyTestFunction(ByRef command) {
    arg := command[2]
    obj := Object("test", arg)
    res := Jxon_Dump(obj) ; this is available thanks to the extension
    return FormatResponse("ahk_json.message.JsonResponseMessage", res)
}
'''

my_extension = Extension(script_text=ext_script)

@my_extension.register
def my_test_function(ahk: AHK, arg: str):
    return ahk.function_call('MyTestFunction', [arg])


def main():
    ahk = AHK(extensions='auto')  # automatically use all imported/created extensions
    # or use the extensions explicitly:
    # ahk = AHK(extensions=[JXON, my_extension])

    # now ``.my_test_function`` is a method on the `ahk` instance:
    assert ahk.my_test_function('foo') == {'test': 'foo'}

许可证

此作品受MIT许可证的许可。

此包包含大量来自原始AutoHotkey-JSON的部分。包含的AutoHotkey-JSON代码归其原始作者(们)所有并受版权保护,根据WTFPL条款使用/重新分发。

项目详情


下载文件

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

源代码分发

ahk-json-0.1.0rc2.tar.gz (11.0 kB 查看哈希值)

上传时间 源代码

构建分发

ahk_json-0.1.0rc2-py3-none-any.whl (11.5 kB 查看哈希值)

上传时间 Python 3

由以下支持