You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Edgar Merino <do...@gmail.com> on 2011/05/24 21:28:39 UTC

Python scripts in BXML

Hello:

     Long time since the last time I used pivot (back when it was in 
incubation), now I've got a new project where Pivot will come in handy, 
however I'd like to try using python for UI logic instead of javascript, 
however I'm having some problems with this:

     Following the Scripting tutorial in the pivot homepage, I tried to 
port the code to use it with python, however I get this exception when 
running the code:
javax.script.ScriptException: 
sun.org.mozilla.javascript.EvaluatorException: missing ; before 
statement (<Unknown source>#2) in <Unknown source> at line number 2

                     from org.apache.pivot.wtk import Prompt

                     def buttonPressend(button):
                         Prompt.promp("PYTHON", button.getWindow())

This is the bxml source:

<Window title="Hello BXML!" maximized="true"
     xmlns:bxml="http://pivot.apache.org/bxml"
     xmlns="org.apache.pivot.wtk">

<BoxPane orientation="vertical" styles="{padding:6}">
<PushButton buttonData="Click Me!">
<buttonPressListeners>
                     from org.apache.pivot.wtk import Prompt

                     def buttonPressend(button):
                         Prompt.promp("PYTHON", button.getWindow())

</buttonPressListeners>
</PushButton>
</BoxPane>
</Window>

     The above is trying to run the code using the javascript engine, so 
I tried to put this in an external file and include it in bxml source 
like this:

<Window title="Hello BXML!" maximized="true"
     xmlns:bxml="http://pivot.apache.org/bxml"
     xmlns="org.apache.pivot.wtk">

<bxml:script src="test.py" language="python" />

<BoxPane orientation="vertical" styles="{padding:6}">
<PushButton buttonData="No, Click Me!"
                 
ButtonPressListener.buttonPressed="buttonClicked(arguments[0])"/>

</BoxPane>
</Window>

test.py:
from org.apache.pivot.wtk import Prompt

def buttonClicked(button):
     Prompt.promp("PYTHON", button.getWindow())

     But then I get this exception:
javax.script.ScriptException: sun.org.mozilla.javascript.EcmaError: 
TypeError: buttonClicked is not a function, it is object. (<Unknown 
source>#1) in <Unknown source> at line number 1
buttonClicked(arguments[0])

     Which tells me it's still trying to use the javascript engine to 
run the code, how can I tell pivot to use a different engine? The 
"language" attribute for the tag <bxml:script> seems to do nothing.


Thanks in advance!
Edgar Merino

Re: Python scripts in BXML

Posted by Edgar Merino <do...@gmail.com>.
Ah! That did the trick, thank you Greg!


El 24/05/11 14:37, Greg Brown escribió:
> Sorry, that wasn't clear. What you need to do is add this:
>
> <?language python?>
>
> at the beginning of your file. That tells the serializer what language you want to use in your BXML file.
>
>
> On May 24, 2011, at 3:32 PM, Greg Brown wrote:
>
>>>    Which tells me it's still trying to use the javascript engine to run the code, how can I tell pivot to use a different engine? The "language" attribute for the tag<bxml:script>  seems to do nothing.
>> The language attribute actually defines the language that is used in the attribute-based event handlers. If you want to use Python code in your handlers, you'll need to include this.
>>
>>

Re: Python scripts in BXML

Posted by Greg Brown <gk...@verizon.net>.
Sorry, that wasn't clear. What you need to do is add this:

<?language python?>

at the beginning of your file. That tells the serializer what language you want to use in your BXML file.


On May 24, 2011, at 3:32 PM, Greg Brown wrote:

>>   Which tells me it's still trying to use the javascript engine to run the code, how can I tell pivot to use a different engine? The "language" attribute for the tag <bxml:script> seems to do nothing.
> 
> The language attribute actually defines the language that is used in the attribute-based event handlers. If you want to use Python code in your handlers, you'll need to include this.
> 
> 


Re: Python scripts in BXML

Posted by Greg Brown <gk...@verizon.net>.
>    Which tells me it's still trying to use the javascript engine to run the code, how can I tell pivot to use a different engine? The "language" attribute for the tag <bxml:script> seems to do nothing.

The language attribute actually defines the language that is used in the attribute-based event handlers. If you want to use Python code in your handlers, you'll need to include this.