[IronPython] Having problems calling javascript from ironpython in silverlight

Vineet Jain (gmail) vinjvinj at gmail.com
Tue Apr 8 04:27:52 CEST 2008


I can call from javascript to python but cannot call from python to
javascript. I get the error on my onload function that 

I'm trying to access a property (callToJsWithString) which does not exist.
I've included a test template for python and

javascript code. Any help would be appreciated. 

 

Python Code:------------------------>

 

        import clr

        clr.AddReference("Scriptable, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=null")

        

        from Scriptable import (

            Scriptable, ScriptableForString, 

            ScriptableEvent, ScriptableEventArgs

        )

        

        import sys

        from System.Windows.Browser.HtmlPage import Document

        import System.Windows.Browser.HtmlPage as HtmlPage

        

        #calling javascript function from python

        callToJsWithString = ScriptableEvent()

        

        #calling python from javascript

        class CallFromJs(ScriptableForString):

            def _method(self, code):

                Document.value_from_python.innerHTML = code

        callFromJs = CallFromJs()

        

        class CallFromJs2(ScriptableForString):

            def _method(self, code):

                args = ScriptableEventArgs()

                args.code = "calling javascript from python"

                callToJsWithString.OnEvent(args)

        callFromJs2 = CallFromJs2()

        

        HtmlPage.RegisterScriptableObject("callFromJs", callFromJs)

        HtmlPage.RegisterScriptableObject("callFromJs2", callFromJs2)

        HtmlPage.RegisterScriptableObject("callToJsWithString",
callToJsWithString)

 

 

Javascript Code:------------------------>

 

        function callToJsWithString(s, e) {

            alert(e.code);

        };

 

      function onload() {

 
$('#value_from_python').html("after 1");

 
alert(document.getElementById("SilverlightControl").Content);

 
document.getElementById("SilverlightControl").Content.callToJsWithString.Eve
nt = callToJsWithString;


 
$('#value_from_python').val("after 2");

      };

                                var controlID = "SilverlightControl"

                                Silverlight.createObjectEx({

                                    source: "app.xap",

                                    parentElement:
document.getElementById("SilverlightControlHost"),

                                    id: controlID,

                                    properties: {

                                                    width:'1',

                                                    height:'1',

                                                    inplaceInstallPrompt:
false,

                                                    isWindowless: 'True',

                                                    version:'1.1'

                                    },

        events:{

            onError:null,               // OnError property value --
event-handler function name.

            onLoad:'onload'},            // OnLoad property value --
event-handler function name.

                                    initParams: "start=scan.py, debug=true"

                                });

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080407/ad55fc92/attachment.html>


More information about the Ironpython-users mailing list