From: Rasjid W. <ra...@gm...> - 2010-01-25 23:29:52
|
Hi all, All the examples I can find for Jython applets are for Jython 2.1. Are there any examples on how to create Applets with Jython 2.5? I'd really like to be able to use Python in the web-browser, and I'd prefer to use Jython and Java Applets than IronPython and Silverlight/Moonlight, since I suspect the JVM is more likely to be installed on Linux machines than Moonlight. Cheers, Rasjid. |
From: Francis P. <fr...@qm...> - 2010-01-26 04:54:36
|
Hi Rasjid, You can download the example I have created in that blog: http://fraka6.blogspot.com/2010/01/power-of-python-within-tomcat-for.html Let me know if you have problems. Thanks, Fran6 http://fraka6.blogspot.com 2010/1/25 Rasjid Wilcox <ra...@gm...> > Hi all, > > All the examples I can find for Jython applets are for Jython 2.1. Are > there any examples on how to create Applets with Jython 2.5? I'd really > like to be able to use Python in the web-browser, and I'd prefer to use > Jython and Java Applets than IronPython and Silverlight/Moonlight, since I > suspect the JVM is more likely to be installed on Linux machines than > Moonlight. > > Cheers, > > Rasjid. > > > > ------------------------------------------------------------------------------ > The Planet: dedicated and managed hosting, cloud storage, colocation > Stay online with enterprise data centers and the best network in the > business > Choose flexible plans and management services without long-term contracts > Personal 24x7 support from experience hosting pros just a phone call away. > http://p.sf.net/sfu/theplanet-com > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > -- Francis Piéraut, eng. M.A.Sc. Senior Software engineer/Machine Learning Consultant http://francispieraut.com/ |
From: Rasjid W. <ra...@gm...> - 2010-01-26 11:08:47
|
2010/1/26 Francis Pieraut <fr...@qm...> > Hi Rasjid, > > You can download the example I have created in that blog: > http://fraka6.blogspot.com/2010/01/power-of-python-within-tomcat-for.html > Let me know if you have problems. > > Thanks Francis, but (unless I'm mistaken) that is for a servlet (I think that is the right terminology - I'm not from the Java world) to run within tomcat, where as I'm after an example of running a Jython applet in a browser (the code runs client side in the browser, not server side in tomcat). http://www.jython.org/applets/ says the page has been retired. The docs for Jython 2.1 are at http://www.jython.org/archive/21/applets/index.html but I have no idea if the approach given for Jython 2.1 still holds for Jython 2.5. Cheers, Rasjid. |
From: Josh J. <jun...@gm...> - 2010-01-26 12:10:14
|
Rasjid- Although coding traditional applets in Jython 2.5.x is not yet possible, it is easy to develop Java web start applications using the latest version of Jython. The development of applets using Jython requires a compiler such as jythonc. The jythonc compiler has not been brought forward into 2.5.x due incompatibilities with some of the newer language features. However, web start applications are a viable alternative to applets, although they will not run directly within the web browser. For more information on how to get started, you may wish to take a look here: http://jythonpodcast.hostjava.net/jythonbook/chapter13.html#applets-and-java-web-start Hope this helps. Best Josh Juneau jun...@gm... http://jj-blogger.blogspot.com http://www.jythonpodcast.com Twitter ID: javajuneau On Tue, Jan 26, 2010 at 5:08 AM, Rasjid Wilcox <ra...@gm...> wrote: > 2010/1/26 Francis Pieraut <fr...@qm...> > > Hi Rasjid, >> >> You can download the example I have created in that blog: >> http://fraka6.blogspot.com/2010/01/power-of-python-within-tomcat-for.html >> Let me know if you have problems. >> >> > Thanks Francis, but (unless I'm mistaken) that is for a servlet (I think > that is the right terminology - I'm not from the Java world) to run within > tomcat, where as I'm after an example of running a Jython applet in a > browser (the code runs client side in the browser, not server side in > tomcat). > > http://www.jython.org/applets/ says the page has been retired. The docs > for Jython 2.1 are at http://www.jython.org/archive/21/applets/index.htmlbut I have no idea if the approach given for Jython 2.1 still holds for > Jython 2.5. > > Cheers, > > Rasjid. > > > > > > ------------------------------------------------------------------------------ > The Planet: dedicated and managed hosting, cloud storage, colocation > Stay online with enterprise data centers and the best network in the > business > Choose flexible plans and management services without long-term contracts > Personal 24x7 support from experience hosting pros just a phone call away. > http://p.sf.net/sfu/theplanet-com > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > |
From: Rasjid W. <ra...@gm...> - 2010-01-26 13:01:38
|
2010/1/26 Josh Juneau <jun...@gm...> > Although coding traditional applets in Jython 2.5.x is not yet possible, it > is easy to develop Java web start applications using the latest version of > Jython. The development of applets using Jython requires a compiler such as > jythonc. The jythonc compiler has not been brought forward into 2.5.x > due incompatibilities with some of the newer language features. However, > web start applications are a viable alternative to applets, although they > will not run directly within the web browser. For more information on how > to get started, you may wish to take a look here: > http://jythonpodcast.hostjava.net/jythonbook/chapter13.html#applets-and-java-web-start > > Ah. I don't think webstart will do what I had in mind in this instance. I'll keep it in mind for other things though. So thanks for the info, even if it is not what I wanted to hear. :-) Cheers, Rasjid. |
From: Marcos S. P. <msa...@gr...> - 2010-01-26 14:04:10
|
Hi there But you can use a pythoninterpreter in your applet classes, can't you? You just have to include your py sources as resources. I have a test applet that adds 2+2 and show sys.version. In theory, you could add your jython java object factory to this mix... By the way, what is the minimal set of permissions for jython to work? I am testing with grant { permission java.security.AllPermission; }; Rasjid, is that close to what you wanted? El mar, 26-01-2010 a las 23:39 +1100, Rasjid Wilcox escribió: > 2010/1/26 Josh Juneau <jun...@gm...> > Although coding traditional applets in Jython 2.5.x is not yet > possible, it is easy to develop Java web start applications > using the latest version of Jython. The development of > applets using Jython requires a compiler such as jythonc. The > jythonc compiler has not been brought forward into 2.5.x > due incompatibilities with some of the newer language > features. However, web start applications are a viable > alternative to applets, although they will not run directly > within the web browser. For more information on how to get > started, you may wish to take a look here: > http://jythonpodcast.hostjava.net/jythonbook/chapter13.html#applets-and-java-web-start > > > > Ah. I don't think webstart will do what I had in mind in this > instance. I'll keep it in mind for other things though. > > So thanks for the info, even if it is not what I wanted to hear. :-) > > Cheers, Rasjid. > > > ------------------------------------------------------------------------------ > The Planet: dedicated and managed hosting, cloud storage, colocation > Stay online with enterprise data centers and the best network in the business > Choose flexible plans and management services without long-term contracts > Personal 24x7 support from experience hosting pros just a phone call away. > http://p.sf.net/sfu/theplanet-com > _______________________________________________ Jython-users mailing list Jyt...@li... https://lists.sourceforge.net/lists/listinfo/jython-users |
From: Marcos S. P. <msa...@gr...> - 2010-01-26 14:41:34
|
Actually, we could have a template project in which to add python implementation files. The jars (jython+jython_applet) would be alwauys the same (and cached, I guess); the concrete application files would be dynamically downloaded... El mar, 26-01-2010 a las 15:03 +0100, Marcos Sánchez Provencio escribió: > Hi there > > But you can use a pythoninterpreter in your applet classes, can't you? > You just have to include your py sources as resources. I have a test > applet that adds 2+2 and show sys.version. In theory, you could add your > jython java object factory to this mix... > > By the way, what is the minimal set of permissions for jython to work? I > am testing with > grant { > permission java.security.AllPermission; > }; > > Rasjid, is that close to what you wanted? > > El mar, 26-01-2010 a las 23:39 +1100, Rasjid Wilcox escribió: > > 2010/1/26 Josh Juneau <jun...@gm...> > > Although coding traditional applets in Jython 2.5.x is not yet > > possible, it is easy to develop Java web start applications > > using the latest version of Jython. The development of > > applets using Jython requires a compiler such as jythonc. The > > jythonc compiler has not been brought forward into 2.5.x > > due incompatibilities with some of the newer language > > features. However, web start applications are a viable > > alternative to applets, although they will not run directly > > within the web browser. For more information on how to get > > started, you may wish to take a look here: > > http://jythonpodcast.hostjava.net/jythonbook/chapter13.html#applets-and-java-web-start > > > > > > > > Ah. I don't think webstart will do what I had in mind in this > > instance. I'll keep it in mind for other things though. > > > > So thanks for the info, even if it is not what I wanted to hear. :-) > > > > Cheers, Rasjid. > > > > > > ------------------------------------------------------------------------------ > > The Planet: dedicated and managed hosting, cloud storage, colocation > > Stay online with enterprise data centers and the best network in the business > > Choose flexible plans and management services without long-term contracts > > Personal 24x7 support from experience hosting pros just a phone call away. > > http://p.sf.net/sfu/theplanet-com > > _______________________________________________ Jython-users mailing list Jyt...@li... https://lists.sourceforge.net/lists/listinfo/jython-users > > > > ------------------------------------------------------------------------------ > The Planet: dedicated and managed hosting, cloud storage, colocation > Stay online with enterprise data centers and the best network in the business > Choose flexible plans and management services without long-term contracts > Personal 24x7 support from experience hosting pros just a phone call away. > http://p.sf.net/sfu/theplanet-com > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > |
From: Rasjid W. <ra...@gm...> - 2010-01-26 22:48:18
|
2010/1/27 Marcos Sánchez Provencio <msa...@gr...> > But you can use a pythoninterpreter in your applet classes, can't you? > You just have to include your py sources as resources. I have a test > applet that adds 2+2 and show sys.version. In theory, you could add your > jython java object factory to this mix... > > By the way, what is the minimal set of permissions for jython to work? I > am testing with > grant { > permission java.security.AllPermission; > }; > > Rasjid, is that close to what you wanted? > > Yes, this approach occurred to me late last night. If you can share your test applet, that would be great, since I'd be kind of working it out from scratch. (I have minimal exposure to Java.) Cheers, Rasjid. |
From: Josh J. <jun...@gm...> - 2010-01-27 12:58:47
|
Rasjid/Marcos- This approach has also crossed my mind. I'd really like to implement something in the PlyJy project that would allow for one to create a Jython applet without worrying about the object factory design. I started an implementation some time ago, but was never really able to embed the resulting applet into a webpage and make it work. Perhaps with a little more time we can come up with a variant of my implementation that would make this approach usable. So far, I've created a "test" facade which is actually a Java applet class which invokes the PythonInterpreter from within the init() method. Basically, the Jython code is not really an applet in this approach, but rather just swing code that is added to this applet facade. In the end, the facade would be the embedded applet and it would call to the Jython code to create the actual GUI. The implementation I've started is not reusable and we'd have to take it a step further in order to make it so, but it is a start. AppletFacade.java - This is the actual (likely reusable at some point) applet that will become part of PlyJy. In this hard-coded implementation I am instantiating a Jython module named "Ouch" which simply places a button on the applet. Maybe this could be an abstract class in a reusable implementation. package org.plyjy.facade; import java.util.ArrayList; import java.util.List; import javax.swing.JApplet; import javax.swing.SwingUtilities; import javax.swing.JLabel; import org.plyjy.factory.JythonObjectFactory; import org.plyjy.factory.PySystemObjectFactory; import org.plyjy.interfaces.AppletType; public class AppletFacade extends JApplet { private String appletClass = "Ouch"; private List argList = new ArrayList(); //Called when this applet is loaded into the browser. @Override public void init() { // Add a reference to this applet into our list...this will be passed to the Jython code this.argList.add(this); //Execute a job on the event-dispatching thread; creating this applet's GUI. try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { PySystemObjectFactory factory = new PySystemObjectFactory( AppletType.class, appletClass, appletClass); AppletType app = (AppletType) factory.createObject(); app.run_applet(argList); } }); } catch (Exception e) { System.err.println("createGUI didn't complete successfully " + e); } } public void setArgList(){ // Empty method to override...perhaps use to load values in reusable case? } } AppletType.java - This is the interface which all Jython GUI code will need to implement in our solution package org.plyjy.interfaces; import java.util.List; public interface AppletType { public void run_applet(List args); } Ouch.py - Adds a button to the applet. We can create a GUI here and simply add it to the applet object which is passed in via the argList. import javax.swing as swing from org.plyjy.interfaces import AppletType class Ouch (AppletType): def init(self): # Probably do something else here....just a test self.frame = None self.button = None def print_message(self, event): print "Ouch!" def run_applet(self, *args): arrayList = args[0] self.frame = arrayList.get(0) self.button=swing.JButton("Push Me!", actionPerformed=self.print_message) self.frame.contentPane.add(self.button) Like I said, this approach runs fine on my desktop, but it doesn't work when I embed it into an HTML page. Perhaps I just need to work a bit with it to make it happen. I haven't committed this code to PlyJy as I wanted to make it function properly first. However, perhaps it would be desirable for me to commit it so that others can work on it as well. :) Is this the idea you had in mind Marcos? Best Josh Juneau jun...@gm... http://jj-blogger.blogspot.com http://www.jythonpodcast.com Twitter ID: javajuneau 2010/1/26 Rasjid Wilcox <ra...@gm...> > 2010/1/27 Marcos Sánchez Provencio <msa...@gr...> > > But you can use a pythoninterpreter in your applet classes, can't you? >> You just have to include your py sources as resources. I have a test >> applet that adds 2+2 and show sys.version. In theory, you could add your >> jython java object factory to this mix... >> >> By the way, what is the minimal set of permissions for jython to work? I >> am testing with >> grant { >> permission java.security.AllPermission; >> }; >> >> Rasjid, is that close to what you wanted? >> >> > Yes, this approach occurred to me late last night. If you can share your > test applet, that would be great, since I'd be kind of working it out from > scratch. (I have minimal exposure to Java.) > > Cheers, Rasjid. > > |
From: Marcos S. P. <msa...@gr...> - 2010-01-27 14:00:21
|
You beat me with posting the actual code :-) I am going to try to package your applet to use it from a browser. El mié, 27-01-2010 a las 06:52 -0600, Josh Juneau escribió: > Rasjid/Marcos- > > > This approach has also crossed my mind. I'd really like to implement > something in the PlyJy project that would allow for one to create a > Jython applet without worrying about the object factory design. I > started an implementation some time ago, but was never really able to > embed the resulting applet into a webpage and make it work. Perhaps > with a little more time we can come up with a variant of my > implementation that would make this approach usable. > > > So far, I've created a "test" facade which is actually a Java applet > class which invokes the PythonInterpreter from within the init() > method. Basically, the Jython code is not really an applet in this > approach, but rather just swing code that is added to this applet > facade. In the end, the facade would be the embedded applet and it > would call to the Jython code to create the actual GUI. The > implementation I've started is not reusable and we'd have to take it a > step further in order to make it so, but it is a start. > > > AppletFacade.java - This is the actual (likely reusable at some point) > applet that will become part of PlyJy. In this hard-coded > implementation I am instantiating a Jython module named "Ouch" which > simply places a button on the applet. Maybe this could be an abstract > class in a reusable implementation. > > > package org.plyjy.facade; > > > import java.util.ArrayList; > import java.util.List; > import javax.swing.JApplet; > import javax.swing.SwingUtilities; > import javax.swing.JLabel; > import org.plyjy.factory.JythonObjectFactory; > import org.plyjy.factory.PySystemObjectFactory; > import org.plyjy.interfaces.AppletType; > > > public class AppletFacade extends JApplet { > > > private String appletClass = "Ouch"; > private List argList = new ArrayList(); > > > //Called when this applet is loaded into the browser. > @Override > public void init() { > > // Add a reference to this applet into our list...this will be > passed to the Jython code > this.argList.add(this); > //Execute a job on the event-dispatching thread; creating this > applet's GUI. > try { > SwingUtilities.invokeAndWait(new Runnable() { > public void run() { > PySystemObjectFactory factory = new > PySystemObjectFactory( > AppletType.class, appletClass, appletClass); > > > AppletType app = (AppletType) > factory.createObject(); > > > app.run_applet(argList); > } > }); > > } catch (Exception e) { > System.err.println("createGUI didn't complete successfully > " + e); > } > } > > > public void setArgList(){ > // Empty method to override...perhaps use to load values in > reusable case? > } > } > > > > > AppletType.java - This is the interface which all Jython GUI code will > need to implement in our solution > > > package org.plyjy.interfaces; > > > import java.util.List; > > > public interface AppletType { > public void run_applet(List args); > } > > > > > Ouch.py - Adds a button to the applet. We can create a GUI here and > simply add it to the applet object which is passed in via the argList. > > > import javax.swing as swing > from org.plyjy.interfaces import AppletType > > > class Ouch (AppletType): > > > def init(self): > # Probably do something else here....just a test > self.frame = None > self.button = None > > def print_message(self, event): > print "Ouch!" > > > def run_applet(self, *args): > arrayList = args[0] > self.frame = arrayList.get(0) > self.button=swing.JButton("Push Me!", > actionPerformed=self.print_message) > self.frame.contentPane.add(self.button) > > > > > Like I said, this approach runs fine on my desktop, but it doesn't > work when I embed it into an HTML page. Perhaps I just need to work a > bit with it to make it happen. I haven't committed this code to PlyJy > as I wanted to make it function properly first. However, perhaps it > would be desirable for me to commit it so that others can work on it > as well. :) > > > Is this the idea you had in mind Marcos? > > > Best > > > Josh Juneau > jun...@gm... > http://jj-blogger.blogspot.com > http://www.jythonpodcast.com > Twitter ID: javajuneau > > > 2010/1/26 Rasjid Wilcox <ra...@gm...> > 2010/1/27 Marcos Sánchez Provencio <msa...@gr...> > > But you can use a pythoninterpreter in your applet > classes, can't you? > You just have to include your py sources as resources. > I have a test > applet that adds 2+2 and show sys.version. In theory, > you could add your > jython java object factory to this mix... > > By the way, what is the minimal set of permissions for > jython to work? I > am testing with > grant { > permission java.security.AllPermission; > }; > > Rasjid, is that close to what you wanted? > > > Yes, this approach occurred to me late last night. If you can > share your test applet, that would be great, since I'd be kind > of working it out from scratch. (I have minimal exposure to > Java.) > > Cheers, Rasjid. > > > |