You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by jo...@barclays.com on 2013/08/14 22:53:28 UTC

Pivot + Jython

Hello Pivot users,

Does anyone have experience using Pivot with JVM scripting languages like JRuby or Jython? I looked around and some time back someone asked a similar question for JRuby and hit the same problem as I did.

My code:

#!/usr/bin/env jython
from org.apache.pivot.beans import BXMLSerializer
from org.apache.pivot.collections import Map
from org.apache.pivot.wtk import Application
from org.apache.pivot.wtk import Display
from org.apache.pivot.wtk import Window
from org.apache.pivot.wtk import DesktopApplicationContext
from java.lang import Runnable, Exception as Ex
from javax.swing import SwingUtilities
import sys,subprocess,os,re, traceback

class Test(Application):
        def __init__(self):
                self.window = None
                self.bxmlSerializer = BXMLSerializer()
        def startup(self, display, properties):
                self.window = self.bxmlSerializer.readObject("file:///home/myuser/test.bxml")
                self.window.open(display)
        def shutdown(self, optional):
                if self.window != null:
                        window.close()
                return False
        def suspend(self):
                pass
        def resume(self):
                pass

class Task(Runnable):
        def __init__(self, argv):
                self.argv = argv
        def run(self):
                DesktopApplicationContext.main(Test, self.argv)

if __name__ == "__main__":
        try:
                SwingUtilities.invokeAndWait(Task(sys.argv[1:]))
        except:
                traceback.print_exc(file=sys.stderr)
                sys.exit(192)

Throws an exception:

java.lang.ClassNotFoundException: org.python.proxies.__main__$Test$1
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:186)
        at org.apache.pivot.wtk.DesktopApplicationContext.main(DesktopApplicationContext.java:606)
        at org.apache.pivot.wtk.DesktopApplicationContext.main(DesktopApplicationContext.java:881)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:186)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:204)
        at org.python.core.PyObject.__call__(PyObject.java:404)
        at org.python.core.PyObject.__call__(PyObject.java:408)
        at org.python.pycode._pyx0.run$9(/home/jnunezzu/pivot.py:39)
        at org.python.pycode._pyx0.call_function(/home/myuser/pivot.py)

Any help will be greatly appreciated.

Thanks,

--Jose

_______________________________________________

This message is for information purposes only, it is not a recommendation, advice, offer or solicitation to buy or sell a product or service nor an official confirmation of any transaction. It is directed at persons who are professionals and is not intended for retail customer use. Intended for recipient only. This message is subject to the terms at: www.barclays.com/emaildisclaimer.

For important disclosures, please see: www.barclays.com/salesandtradingdisclaimer regarding market commentary from Barclays Sales and/or Trading, who are active market participants; and in respect of Barclays Research, including disclosures relating to specific issuers, please see http://publicresearch.barclays.com.

_______________________________________________

Re: Pivot + Jython

Posted by Sandro Martini <sa...@gmail.com>.
Hi all, under
http://svn.codespot.com/a/apache-extras.org/pivot-stuff/trunk/pivot-stuff-common-groovy/
you can find a Groovy version of this problem ... under the test
folder there are some Groovy Scripts, with some of them containing
Groovy classes defined inside (inline in the script, but just for
convenience), because otherwise it seems that currently Pivot won't be
able to work with these scripts.
We have already (since many time) some features that let Pivot to work
better with scripts, and should go in Pivot 2.1 ... for examples those
related to Classloaders.

Note that if using Groovy classes (instead of Groovy Scripts) all
should be ok, and asap I'll try to put here even some sample for that
... or refactor existing inner classes to standard external Groovy
classes and provide updated scripts to test them in a simple way.


Anyway next week I plan to continue some work on Jython Scripts with
Pivot (like here) ...

As always, for suggestions, comments (and maybe even help :-) ) we are here.

Bye,
Sandro

RE: Pivot + Jython

Posted by jo...@barclays.com.
Hello Sandro; I tried your suggestion but I still got an exception complaining about not being able to locate an inner class:

java.lang.ClassNotFoundException: org.python.proxies.__main__$HelloBXML$1
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
        at java.lang.Class.forName0(Native Method)

I created a JIRA and attached as much information as possible, including the small script I used to test this:

https://issues.apache.org/jira/browse/PIVOT-917

I can help with some examples for Jython, but I first I need to get passed the 'hello world' issue :-)

Thanks for looking into this!

--Jose

-----Original Message-----
From: Sandro Martini [mailto:sandro.martini@gmail.com] 
Sent: Sunday, August 18, 2013 1:05 PM
To: Users - Apache Pivot
Cc: Nunez Zuleta, Jose V: IT (NYK)
Subject: Re: Pivot + Jython

Hi Jose, sorry for the delay ...

I haven't experience with JRuby and Jython (only tried them few times), and probably even other Pivot developers.
You found some of our subprojects at Apache-Extras I created some time ago, where to put all additional stuff, from us and even by our users, but as you can see some of them are near-empty due to lack of time (and probably lack of interest from users).

Your error seems to be related to the loading of bxml file:
> self.window = 
> self.bxmlSerializer.readObject("file:///home/myuser/test.bxml")
try with a relative path for the bxml file, starting from the package of your main class ... for example start to put it in the same folder of your application main class, and move it later.
I can suggest to take a minimal sample, like our "Hello BXML" ( http://pivot.apache.org/tutorials/hello-bxml.html ) and try to convert it to Jython ... and this could then be put somewhere under pivot-contrib if you are interested.
As minimal sample, take a look at:
http://svn.codespot.com/a/apache-extras.org/pivot-stuff/trunk/scala-use-pivot2/


Anyway, if you are interested in help us improving Pivot usage with Jython (and maybe even JRuby), could you create a jira issue in Pivot usual Bug tracker (or if you prefer, an issue under pivot-multilang), and attach there a minimal project (if possible an eclipse, or a maven, or gradle) project ?
What release of OS , Java, Jython are you using ? If you add an issue, please write even there.
Or at least, attach here that minimal sample, but in a zip (or it won't be accepted by our mailing lists) ...

As soon as I'll find some time I could take a look at it, and even improve my Scala examples/support files, and even a Groovy example there.


Thank you very much,
Sandro
_______________________________________________

This message is for information purposes only, it is not a recommendation, advice, offer or solicitation to buy or sell a product or service nor an official confirmation of any transaction. It is directed at persons who are professionals and is not intended for retail customer use. Intended for recipient only. This message is subject to the terms at: www.barclays.com/emaildisclaimer.

For important disclosures, please see: www.barclays.com/salesandtradingdisclaimer regarding market commentary from Barclays Sales and/or Trading, who are active market participants; and in respect of Barclays Research, including disclosures relating to specific issuers, please see http://publicresearch.barclays.com.

_______________________________________________

Re: Pivot + Jython

Posted by Sandro Martini <sa...@gmail.com>.
Hi Jose, sorry for the delay ...

I haven't experience with JRuby and Jython (only tried them few
times), and probably even other Pivot developers.
You found some of our subprojects at Apache-Extras I created some time
ago, where to put all additional stuff, from us and even by our users,
but as you can see some of them are near-empty due to lack of time
(and probably lack of interest from users).

Your error seems to be related to the loading of bxml file:
> self.window = self.bxmlSerializer.readObject("file:///home/myuser/test.bxml")
try with a relative path for the bxml file, starting from the package
of your main class ... for example start to put it in the same folder
of your application main class, and move it later.
I can suggest to take a minimal sample, like our "Hello BXML" (
http://pivot.apache.org/tutorials/hello-bxml.html ) and try to convert
it to Jython ... and this could then be put somewhere under
pivot-contrib if you are interested.
As minimal sample, take a look at:
http://svn.codespot.com/a/apache-extras.org/pivot-stuff/trunk/scala-use-pivot2/


Anyway, if you are interested in help us improving Pivot usage with
Jython (and maybe even JRuby), could you create a jira issue in Pivot
usual Bug tracker (or if you prefer, an issue under pivot-multilang),
and attach there a minimal project (if possible an eclipse, or a
maven, or gradle) project ?
What release of OS , Java, Jython are you using ? If you add an issue,
please write even there.
Or at least, attach here that minimal sample, but in a zip (or it
won't be accepted by our mailing lists) ...

As soon as I'll find some time I could take a look at it, and even
improve my Scala examples/support files, and even a Groovy example
there.


Thank you very much,
Sandro

RE: Pivot + Jython

Posted by jo...@barclays.com.
Also checked http://svn.codespot.com/a/apache-extras.org/pivot-multilang/trunk/, but found not much in there.

--Jose

-----Original Message-----
From: Nunez Zuleta, Jose V: IT (NYK) 
Sent: Wednesday, August 14, 2013 4:53 PM
To: 'user@pivot.apache.org'
Subject: Pivot + Jython

Hello Pivot users,

Does anyone have experience using Pivot with JVM scripting languages like JRuby or Jython? I looked around and some time back someone asked a similar question for JRuby and hit the same problem as I did.

My code:

#!/usr/bin/env jython
from org.apache.pivot.beans import BXMLSerializer from org.apache.pivot.collections import Map from org.apache.pivot.wtk import Application from org.apache.pivot.wtk import Display from org.apache.pivot.wtk import Window from org.apache.pivot.wtk import DesktopApplicationContext from java.lang import Runnable, Exception as Ex from javax.swing import SwingUtilities import sys,subprocess,os,re, traceback

class Test(Application):
        def __init__(self):
                self.window = None
                self.bxmlSerializer = BXMLSerializer()
        def startup(self, display, properties):
                self.window = self.bxmlSerializer.readObject("file:///home/myuser/test.bxml")
                self.window.open(display)
        def shutdown(self, optional):
                if self.window != null:
                        window.close()
                return False
        def suspend(self):
                pass
        def resume(self):
                pass

class Task(Runnable):
        def __init__(self, argv):
                self.argv = argv
        def run(self):
                DesktopApplicationContext.main(Test, self.argv)

if __name__ == "__main__":
        try:
                SwingUtilities.invokeAndWait(Task(sys.argv[1:]))
        except:
                traceback.print_exc(file=sys.stderr)
                sys.exit(192)

Throws an exception:

java.lang.ClassNotFoundException: org.python.proxies.__main__$Test$1
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:186)
        at org.apache.pivot.wtk.DesktopApplicationContext.main(DesktopApplicationContext.java:606)
        at org.apache.pivot.wtk.DesktopApplicationContext.main(DesktopApplicationContext.java:881)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:186)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:204)
        at org.python.core.PyObject.__call__(PyObject.java:404)
        at org.python.core.PyObject.__call__(PyObject.java:408)
        at org.python.pycode._pyx0.run$9(/home/jnunezzu/pivot.py:39)
        at org.python.pycode._pyx0.call_function(/home/myuser/pivot.py)

Any help will be greatly appreciated.

Thanks,

--Jose

_______________________________________________

This message is for information purposes only, it is not a recommendation, advice, offer or solicitation to buy or sell a product or service nor an official confirmation of any transaction. It is directed at persons who are professionals and is not intended for retail customer use. Intended for recipient only. This message is subject to the terms at: www.barclays.com/emaildisclaimer.

For important disclosures, please see: www.barclays.com/salesandtradingdisclaimer regarding market commentary from Barclays Sales and/or Trading, who are active market participants; and in respect of Barclays Research, including disclosures relating to specific issuers, please see http://publicresearch.barclays.com.

_______________________________________________