从Actionscript调用python [英] Calling python from Actionscript

查看:121
本文介绍了从Actionscript调用python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个调用python脚本的Adobe Air程序。我不认为ActionScript 3.0可以正确调用。代码:

I have an Adobe Air Program that calls a python script. I dont' think the actionscript 3.0 is making the proper call. Code:

        var file:File;
        var args:Vector.<String> = new Vector.<String>;

            file = new File().resolvePath("/usr/bin/python");

            var pyScript:File;
            pyScript = File.applicationDirectory.resolvePath("python/mac/merge.py");

            var tempOutPath:String = File.applicationStorageDirectory.resolvePath("out.pdf").nativePath;
            args.push(pyScript.nativePath, "-w", "-o", tempOutPath, "-i");

            for(var x:int; x < numFilesToProcess; x++){

                var pdfPath:String = File(pdfs.getItemAt(x)).nativePath;

                args.push(pdfPath);

            }

            callNative(file, args);

在终端机(Mac)中,以下工作正常:

In terminal (Mac), the following works fine:

python merge.py -w -o out.pdf -i file1.pdf file2.pdf

args.push(pyScript.native ....行是有问题的。我希望获得一些帮助。

The args.push(pyScript.native.... line is the problematic one. I'd appreciate some assistance.

推荐答案

我在使用Air时遇到了类似的问题。我需要从Air应用程序打印到收据打印机。我无法从应用程序本身执行此操作,因此我使用了python RPC服务器为我完成工作并通过http。进行了讨论,下面是一个简化的版本,可以让您了解一下:

I have faced a similar problem using Air. I needed to print to a receipt printer from an Air app. I couldn't do it from the app itself so I used a python RPC server to do the work for me and talked to it over http. below is a simplified version to give you an idea:

python RPC服务器

The python RPC server

from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler

class RequestHandler(SimpleXMLRPCRequestHandler):
    rpc_paths = ('/','/RPC2')

server = SimpleXMLRPCServer(('localhost', 8123), requestHandler=RequestHandler)

def myService( arg0, arg1 ):
    #do the stuff
    return 0

server.register_function(myService)
server.serve_forever()

在空中,我将呼叫创建为XML字符串并提出请求。
我没有显示所有详细信息,因为我正在使用javascript而不是actionscript,因此请将此视为伪代码。

In Air I create the call as an XML string and make my request. I haven't shown all the details as I was using javascript not actionscript so please treat this as pseudocode.

// XML as a string
// possibly create the XML and toXMLString() it?
var data:String = '
<?xml version="1.0"?>
<methodCall>
    <methodName>myService</methodName>
    <params>
        <param>
            <string>file1.pdf</string>
        </param>
        <param>
            <string>file2.pdf</string>
        </param>
    </params>
</methodCall>';

var req:URLRequest = new URLRequest('localhost:8123');
rec.method = 'POST';
rec.data = data;
var loader:URLLoader = new URLLoader( req );
//etc

这篇关于从Actionscript调用python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆