Pythonとのインターフェイスが必要なXULRunnerベースのアプリケーションを作成する予定です。計画はPyXPCOMを使用することです。現在、私はPyXPCOMを使用し、Creating a Python XPCOM componentのサンプルコンポーネントdevelopmnetを試していますが、動作させることはできません。PyXPCOMコンポーネントがXULRunnerにロードされていません
私はUbuntuの11.04を使用していて、私の手順は以下の通りであった:アプリケーションディレクトリを作成し
と
xulrunner
サブディレクトリが正常にBuilding PyXPCOM次PyXPCOMをを建て、そこに私のXULRunner 5.xのバイナリディストリビューションをコピーします
PyXPCOMソース
README.txt
ファイルのインストール手順に続いて、直接私xulrunner
サブディレクトリにobj/dist/bin
ORYとxulrunner/chrome.manifest
ファイルに以下の行を追加しました:nsIPySimple.idl
ファイルを作成したmanifest components/pyxpcom.manifest
と私のアプリケーション
components
サブディレクトリに置か者:XPTファイルを作成した#include "nsISupports.idl" [scriptable, uuid(2b324e9d-a322-44a7-bd6e-0d8c83d94883)] interface nsIPySimple : nsISupports { attribute string yourName; void write(); void change(in string aValue); };
components
サブディレクトリの下のコマンドを実行します。[xul-sdk-path]/xpidl -m typelib -w -v -I [xul-sdk-path]/idl/ nsIPySimple.idl
私
作成さ
:
interfaces components/nsIPySimple.xpt component {607ebc50-b8ba-11e0-81d9-001cc4c794e3} components/nsIPySimple.py contract @mozilla.org/PySimple;1 {607ebc50-b8ba-11e0-81d9-001cc4c794e3}
はPythonのメソッドを呼び出すJavaScript関数を作成しました:
function showMore() { try { testComp = Components.classes["@mozilla.org/PySimple;1"].name; alert(testComp); testComp = Components.classes["@mozilla.org/PySimple;1"]. createInstance(Components.interfaces.nsIPySimple); testComp.write(); } catch (anError) { alert(anError); } }
chrome.manifest
ファイルに以下の行を追加することでPythonのコード登録私の
components
サブディレクトリに
nsIPySimple.py
from xpcom import components, verbose
class PySimple: #PythonTestComponent
_com_interfaces_ = components.interfaces.nsIPySimple
_reg_clsid_ = "{607ebc50-b8ba-11e0-81d9-001cc4c794e3}"
_reg_contractid_ = "@mozilla.org/PySimple;1"
def __init__(self):
self.yourName = "a default name" # or mName ?
def __del__(self):
if verbose:
print "PySimple: __del__ method called - object is destructing"
def write(self):
print self.yourName
def change(self, newName):
self.yourName = newName
PYXPCOM_CLASSES = [
PySimple,
]
しかし、Javascriptのコードは、次の例外がスローされます。
[Exception... "Component returned failure code: 0x80570015
(NS_ERROR_XPC_CI_RETURNED_FAILURE) [nsIJSCID.createInstance]"
nsresult: "0x80570015 (NS_ERROR_XPC_CI_RETURNED_FAILURE)"
location: "JS frame :: chrome://reader/content/main.js ::
showMore :: line 5" data: no]
起こったか、私が間違って何をしたか何任意のアイデアを?
ありがとうございました!
それでも、同じ例外がスローされます。しかし、良い人@ ActiveStateと協力して、問題がxulrunner-stubであることを知りました。私がスタブを使ってアプリケーションを実行したときに例外がスローされましたが、xulrunnerで直接実行した場合はすべて動作します! – rahmad
これを指摘してくれてありがとう、私はそれがリストであったことに気付かなかった。おそらく、サイト上の自動カラーコーディングのためです。あなたがそれを指摘するまで、私が見ることができるほど明確ではなかった。 – rahmad
xulrunner-stubがなぜxulrunner自体がなぜ例外を投げているのかを最後に理解しました。 xulrunner-stubが必要なライブラリlibxpcom.soとlibpyxpcom.soをロードしていませんでした。 dependentlibs.listファイルに2つのファイルをリストアップすると、xulrunner-stubとxulrunnerの両方が期待どおりに動作しました。 – rahmad