From: Noel R. <no...@ya...> - 2002-03-09 18:55:46
|
At 12:08 AM 3/9/02, you wrote: >I am looking for some Jython/ Swing sample code to code an utility. Any >links/ suggestions ? Here's another shameless plug... If you can wait a couple of weeks, _Jython Essentials_ has a full chapter with a number of Jython/Swing examples, and a lot of material on using Java Libraries in general. Hope this helps. Thanks, Noel _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com |
From: BillWorker 2. <bil...@in...> - 2002-03-11 05:00:45
|
From: Ype Kingma <yk...@xs...> Subject: Re: [Jython-users] Swing examples > Ahish, > > >This is more of what I learnt while working with Jython and Swings! > > > >First, if you want to use Swings and its MVC architecture, you have to > >remember Swing is designed to work it Java objects. For example, when > >working with JList, I wanted to implement my own ListModel so I extended the > >AbstractListModel and went about writing my implementations of > >getElementAt() and getSize(). It took me one whole day of fooling around to > >realize that the object returned by getElementAt() should be an instance > >java.lang.Object. > > I suppose the compiler did not allow you to override the return value > of getElementAt() to a java basic type like int or char? > In case you override in jython code, jython will try and convert the returned > python object to an appropriate java object, which works surprisingly > well. What do you mean by override jython code? Sure, an easy way to convert python object to java object is to inherit from java.lang.Object. or other similar class. This is what I wanted to mention. Since, I started out with Java and when we don't mention explicitly the base class it is automatically made java.lang.Object. This is one thing we forget while working in Jython, so I just wanted to have this thing mentioned in FAQ. It took me a day to realise that Python objects do not inherit from java.lang.Object unless explicitly mentioned. This would be a nice reminder to any Java programmers! Of course, the other option is to make sure the whatever we return from getElementAt() is wrapped by a Java object. > >If you remember this and have the looks at the bean section of the docs, > >then any Swing books is good. > > > >Somehow, you just don't remember that. The examples all use strings and that > >is automatically handled. > > > >Guess someone should add that section to the FAQ! > > I'm afraid I don't understand your problem well enough. > > >Oh, about the shameless plug for Jython Essentials, guess I will wait till > >it becomes available in my part of the world (Kathmandu, Nepal). If it ever > >comes :-( Since, I don't have International credit cards I can't do online > >shopping and I don't think I would really like to go through all the hassel > >at banks, getting permissions for making dollar payments .... In short, > >visits to multiple organisations! > > You only need the Swing API docs, the Swing examples from Sun, > and a few jython examples on using Swing to get going. All of > this is downloadable, no paper needed. Yup, I don't think I would by a Jython book to learn Swings. That I have all the docs I need. I would by Jython book to see how Python works with Java! Or rather how to write more Pythonlike (Pythonic??) code! > Have fun, That's exactly what I am doing! > Ype > > P.S. You replied in private, which is ok to me, but it might not > have been your intention. (My mail program does not by default > reply to the list, but to the original sender, so I always have > to cut and past the list address to return to the list.) > I just realised neither does mine! |
From: BillWorker 2. <bil...@in...> - 2002-03-15 08:15:54
|
Let me explain myself! In Java if I were to extend AbstractListModel and use an array internalArray to hold my data internally, then for getElementAt() I could do internalArray[i]. The object that I get from the array does not need to be converted to java.lang.Object as it ALWAYS inherits from java.lang.Object However, in Jython I have to either i. ensure that the object that I get from the array (list) is an instance of java.lang.Object or ii. wrap the Python object into a wrapper class that inherits from java.lang.Object This is not obivous to a new Jython programmer who has come from Java! Ashish |
From: Jeff E. <je...@ad...> - 2002-03-15 15:55:10
|
This works for me. No explicit java.lang.Objects in sight. from javax.swing import * class PythonClass: pass pythonInstance = PythonClass() pythonString = 'foo' pythonInt = 3 l = [pythonInstance, pythonString, pythonInt] class MyModel(AbstractListModel): def getElementAt(self, i): return l[i] def getSize(self): return len(l) model = MyModel() jlist = JList(model) frame = JFrame() frame.contentPane.add(jlist) frame.setSize(100,300) frame.show() Perhaps you should post an example that shows your problem. BillWorker 2i wrote: > Let me explain myself! > > In Java if I were to extend AbstractListModel and use an array internalArray > to hold my data internally, then for getElementAt() I could do > internalArray[i]. The object that I get from the array does not need to be > converted to java.lang.Object as it ALWAYS inherits from java.lang.Object > > However, in Jython I have to either > i. ensure that the object that I get from the array (list) is an instance of > java.lang.Object or > ii. wrap the Python object into a wrapper class that inherits from > java.lang.Object > > This is not obivous to a new Jython programmer who has come from Java! > > Ashish > > > > > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > |
From: BillWorker 2. <bil...@in...> - 2002-03-18 04:57:01
|
Okay, I just have modified your code to include a few more classes. If you run the script you will see that only for PyClass5, the one that inherits from java.lang.Object, the JList shows a proper string in the list. Ashish ---------- code --------- import java import javax.swing as swing class PyClass1: pass class PyClass2: def __repr__(self): return 'PyClass2' class PyClass3: def __str__(self): return 'PyClass3' class PyClass4: def toString(self): return 'PyClass4' class PyClass5(java.lang.Object): def toString(self): return 'PyClass5' class TestModel(swing.AbstractListModel): def __init__(self): self.classList = [PyClass1(), PyClass2(), PyClass3(), PyClass4(), PyClass5()] def getElementAt(self, i): return self.classList[i] def getSize(self): return len(self.classList) frame = swing.JFrame('test') jlist = swing.JList(TestModel()) frame.contentPane.add(jlist) frame.pack() frame.visible = 1 |
From: Brad C. <bc...@vi...> - 2002-03-19 16:17:08
|
I've just begun experimenting with jpython (just today). Hope to use it to replace velocity as the teacher-programmable component of the interactive learning environment at http://virtualschool.edu/jile. My first problem is that tutorial chapter on strings isn't working right (on Linux 7.0 Redhat) >>> "Hello world" "Hello world" >>> "Hello\ Syntax error: LexicalScanner Encountered <EOF> after \ This one is critical and preventing me from exploring deeper. Second problem is that command history isn't working. readline is definitely installed but isn't being recognized by the installer. Can someone please help? Sorry if these are faqs; I've not made it through all the docs yet. -- Brad Cox, PhD; bc...@vi... 703 361 4751 o For industrial age goods there were checks and credit cards. For everything else there is http://virtualschool.edu/mybank o Java Interactive Learning Environment http://virtualschool.edu/jile o Java Web Application Architecture: http://virtualschool.edu/jwaa |
From: Brian Z. <bri...@ya...> - 2002-03-19 22:51:21
|
Brad, Honored to have you here. Apparently you hit a known bug: http://sourceforge.net/tracker/index.php?func=detail&aid=222805&group_id=128 67&atid=112867 In Robert W. Bill's book, page 5 about Line Separators and Block Indentation Syntax: """ A Current Interactive Limitation One disclaimer concerning the interactive interpreter: The current implementation of Jython produces an error when employing backslashes, open enclosures, and triple-quotes in interactive mode despite it being legal syntax. This syntax does work in Jython files as well as in the interactive interpreter for CPython (Jython's counterpart implemented in C). It could be working in interactive mode as well by the time you read this, but if not, those examples with extended logical lines should be placed in a file and run as an argument to the Jython interpreter (such as jython example.py). """ Wonder how hard it is to fix? Any idea from the developers? -Brian ----- Original Message ----- From: "Brad Cox" <bc...@vi...> To: <jyt...@li...> Sent: Tuesday, March 19, 2002 8:16 AM Subject: [Jython-users] Newbie problems > I've just begun experimenting with jpython (just today). Hope to use > it to replace velocity as the teacher-programmable component of the > interactive learning environment at http://virtualschool.edu/jile. > > My first problem is that tutorial chapter on strings isn't working > right (on Linux 7.0 Redhat) > >>> "Hello world" > "Hello world" > > >>> "Hello\ > Syntax error: LexicalScanner Encountered <EOF> after \ > > This one is critical and preventing me from exploring deeper. > > Second problem is that command history isn't working. readline is > definitely installed but isn't being recognized by the installer. > > Can someone please help? Sorry if these are faqs; I've not made it > through all the docs yet. > -- > Brad Cox, PhD; bc...@vi... 703 361 4751 > o For industrial age goods there were checks and credit cards. > For everything else there is http://virtualschool.edu/mybank > o Java Interactive Learning Environment http://virtualschool.edu/jile > o Java Web Application Architecture: http://virtualschool.edu/jwaa > > > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > |
From: Jeff E. <je...@ad...> - 2002-03-22 16:44:17
|
Ashish, The default list cell renderer renders the objects in the list with the result of toString. Instances of Python classes do not return the result of __repr__ or __str__ for the Java toString method. You could write a replacement cell renderer that calls the __str__ method for PyInstances. Perhaps something like in Jython: class PyInstanceListCellRenderer(DefaultListCellRenderer): def getListCellRendererComponent(self,list, \ value, index, selected, focus): return DefaultListCellRenderer.getListCellRendererComponent(self,\ list,`value`,index,selected,focus) myList = JList(cellRenderer=PyInstanceListCellRenderer()) Jeff Emanuel BillWorker 2i wrote: > Okay, I just have modified your code to include a few more classes. If you > run the script you will see that only for PyClass5, the one that inherits > from java.lang.Object, the JList shows a proper string in the list. > > Ashish > > ---------- code --------- > import java > import javax.swing as swing > > class PyClass1: > pass > > class PyClass2: > def __repr__(self): > return 'PyClass2' > > class PyClass3: > def __str__(self): > return 'PyClass3' > > class PyClass4: > def toString(self): > return 'PyClass4' > > class PyClass5(java.lang.Object): > def toString(self): > return 'PyClass5' > > > class TestModel(swing.AbstractListModel): > def __init__(self): > self.classList = [PyClass1(), PyClass2(), PyClass3(), PyClass4(), > PyClass5()] > > def getElementAt(self, i): > return self.classList[i] > > def getSize(self): > return len(self.classList) > > > frame = swing.JFrame('test') > jlist = swing.JList(TestModel()) > frame.contentPane.add(jlist) > frame.pack() > frame.visible = 1 > > > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > |
From: Ype K. <yk...@xs...> - 2002-03-19 18:16:51
|
Brad, >I've just begun experimenting with jpython (just today). Hope to use it to replace velocity as the teacher-programmable component of the interactive learning environment at http://virtualschool.edu/jile. > >My first problem is that tutorial chapter on strings isn't working right (on Linux 7.0 Redhat) >>>> "Hello world" >"Hello world" > >>>> "Hello\ >Syntax error: LexicalScanner Encountered <EOF> after \ > >This one is critical and preventing me from exploring deeper. Use triple quotes around your string when you need it to contain newlines: """Hello world. """ > >Second problem is that command history isn't working. readline is definitely installed but isn't being recognized by the installer. Have a look at the registry file in the jython directory (where jython.jar is), and look for the readline option. It needs a java class that accesses the native readline lib that you may have to download iirc. There is also a simple Console.py in the demo dir that has an up arrow which is good enough for me. Regards, Ype -- |
From: Brad C. <bc...@vi...> - 2002-03-19 18:53:43
|
Thanks. But """ doesn't work either.... At 7:28 PM +0100 3/19/02, Ype Kingma wrote: > >I've just begun experimenting with jpython (just today). Hope to >use it to replace velocity as the teacher-programmable component of >the interactive learning environment at >http://virtualschool.edu/jile. >> >>My first problem is that tutorial chapter on strings isn't working >>right (on Linux 7.0 Redhat) >>>>> "Hello world" >>"Hello world" >> >>>>> "Hello\ >>Syntax error: LexicalScanner Encountered <EOF> after \ >> >>This one is critical and preventing me from exploring deeper. > >Use triple quotes around your string when you need it to contain >newlines: > >"""Hello >world. >""" >>> """Hello Traceback (innermost last): (no code object) at line 0 File "<console>", line 2 SyntaxError: Lexical error at line 2, column 0. Encountered: <EOF> after : "" >>> Any other suggestions? > > >>Second problem is that command history isn't working. readline is >>definitely installed but isn't being recognized by the installer. > >Have a look at the registry file in the jython directory (where >jython.jar is), and look for the readline option. >It needs a java class that accesses the native readline lib >that you may have to download iirc. Apparently readline isn't installed on mac osx (haven't tried this on linux yet). Will track it down and try again. Jython 2.1 on java1.3.1 (JIT: null) Exception in thread "main" java.lang.NoClassDefFoundError: org/gnu/readline/ReadlineLibrary at org.python.util.ReadlineConsole.<init>(ReadlineConsole.java) at org.python.util.ReadlineConsole.<init>(ReadlineConsole.java) at java.lang.Class.newInstance0(Native Method) at java.lang.Class.newInstance(Class.java:237) at org.python.util.jython.main(jython.java) >There is also a simple Console.py in the demo dir that has >an up arrow which is good enough for me. > >Regards, >Ype > >-- > >_______________________________________________ >Jython-users mailing list >Jyt...@li... >https://lists.sourceforge.net/lists/listinfo/jython-users -- Brad Cox, PhD; bc...@vi... 703 361 4751 o For industrial age goods there were checks and credit cards. For everything else there is http://virtualschool.edu/mybank o Java Interactive Learning Environment http://virtualschool.edu/jile o Java Web Application Architecture: http://virtualschool.edu/jwaa |
From: Kevin B. <kb...@ca...> - 2002-03-19 19:14:23
|
Brad Cox wrote: > Thanks. But """ doesn't work either.... This appears to be a bug in the parser in Jython's interactive interpreter: Jython 2.1 on java1.3.1_02 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> """hello Traceback (innermost last): (no code object) at line 0 File "<console>", line 2 SyntaxError: Lexical error at line 2, column 0. Encountered: <EOF> after : "" >>> print """hello Traceback (innermost last): (no code object) at line 0 File "<console>", line 2 SyntaxError: Lexical error at line 2, column 0. Encountered: <EOF> after : "" >>> def go(): ... print """Hello Traceback (innermost last): (no code object) at line 0 File "<console>", line 3 SyntaxError: Lexical error at line 3, column 0. Encountered: <EOF> after : "" >>> ^Z In contrast, with CPython: PYTHON:/e/work/cp$ python Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> """Hello ... world""" 'Hello\nworld' >>> ^Z If you create & execute a file, they both work identically: PYTHON:d:/temp$ cat >> hello.py print """Hello world""" PYTHON:d:/temp$ jython hello.py Hello world PYTHON:d:/temp$ python hello.py Hello world PYTHON:d:/temp$ kb |
From: Gerald G. <gu...@fn...> - 2002-03-11 15:05:26
|
Hi, This is a few years old, but it shows how to do some swing examples. http://home.fnal.gov/~gug/docs/jpython.ps Fermipython: ------------ FermiPython is a collection of scripts, modules and documents useful for demonstrating the use of python and jpython. The aim is to help provide information and demonstrate techniques to help a new user of these scripted languages get started programming. As of version 2_0, Fermipython now includes examples of how to use XML in JPython applications. The product can be downloaded from: ftp://ftp.fnal.gov/pub/fermipython/v2_0 and is released under the Fermi Software Tools Program: http://www.fnal.gov/fermitools/ > Message: 6 > Date: Sat, 09 Mar 2002 13:45:32 -0500 > To: R Datta <rd...@cr...>,jyt...@li... > From: Noel Rappin <no...@ya...> > Subject: Re: [Jython-users] Swing examples > > At 12:08 AM 3/9/02, you wrote: > > >I am looking for some Jython/ Swing sample code to code an utility. Any > >links/ suggestions ? > > Here's another shameless plug... If you can wait a couple of weeks, > _Jython Essentials_ has a full chapter with a number of Jython/Swing > examples, and a lot of material on using Java Libraries in general. > > Hope this helps. > > Thanks, > > Noel > > _________________________________________________________ > Do You Yahoo!? > Get your free @yahoo.com address at http://mail.yahoo.com > -- -Jerry-> gu...@fn... Pepe's Theory of everything: "Under the right circumstances, things happen." |