I integrated the Jython panel into my Java app and added a static hashtable
of the top-level parts of my system.
It's grown into quite a complex system, and has a Swing GUI. Anyhow, I
created a couple of objects using the GUI, and then had a fiddle with the
interpreter. Had to look up the syntax for imports, but then I did a get()
from the hashtable and a print - and there was the toString() version in the
output window!! Next I tried creating a new object in the interpreter - that
I'm reeling from this - a couple of days work (one of which was wasted
trying to be too clever with the layout of the interpreter) and the app I've
been working on for months now just gained a *massive* pile of new
So thanks for your help Paul, and major kudos for the Jython developers!
(now can anyone tell me the difference between
InteractiveInterpreter.runsource(String s) and PythonInterpreter.exec(String
<stuff> http://www.isacat.net </stuff>
>From: Paul Giotta [mailto:paul.giotta@...]
>Sent: 23 June 2002 12:08
>To: jython-users@...; Danny Ayers
>Subject: Re: [Jython-users] 2 newbie questions
>On Saturday 22 June 2002 21:05, jython-users-request@...
>> From: "Danny Ayers" <danny666@...>
>> To: "Jython" <jython-users@...>
>> Date: Sat, 22 Jun 2002 20:26:43 +0200
>> Subject: [Jython-users] 2 newbie questions
>> Hi folks,
>> I managed to get a simple interpreter console going in a JPanel
>> a JFrame), which I'm planning on embedding in an existing Java app. There
>> are a couple of things I'd like to be able to do, which from what I can
>> gather from the scant docs I've seen are probably doable, but
>> on Python, more so with Jython. So could anyone please tell me how to get
>> started with the following :
>> 1. Using the interpreter (how) can I manipulate instances of
>> created in the rest of my app?
>You can use any java object that you can get a reference to (more
>or less) as
>though it were a python object. Jython uses reflection to make this
>transparent. The only issue is getting an initiail reference to the java
>object that you are interested in from your Python code...
>> 2. If I load/run a .py file in the InteractiveInterpreter (runsource or
>> exec?), (how) can I get at objects created there with the rest of my app?
>... What I have done in the past is to have my java code place
>key objects into a hashtable in a singleton object. this singleton can be
>retrieved from your Python code running in the embedded
>interpreter. This is
>somewhat crude though, if you find a cleaner means to do this, you
>> Any refs to online docs relating to embedding Jython (apart from the page
>> in the Jython package) would be greatly appreciated.
>Bruce Eckel's online book "Thinking in Patterns with Java" has a chapter
>dedicated to embedded Jython (IIRC, the Interpreter 'pattern')
>Check here: http://www.mindview.net/Books/TIPatterns/
>> Bonus question - what on earth does "local name 'self' in 'startGrammar'
>> shadows use as global in nested scopes" mean??
>Not sure, but if you are using 'self' as an idenifier somewhere
>other than as
>the first parameter of an object method, then you should probably pick
>another name. 'self' is not reserved, but it is a convention to use it for