[Boudewijn Rempt]
>I've been hacking away at Console.py - I want to use it from
>my java app. But no matter what I do, I don't get any
>public methods. I've attached my version of Console.py. I want
>to call it with something like:
>
> Console console=new Console();
> JScrollPane pane=new JScrollPane(console.getTextPane());
> console.capturePythonOutput();
> console.textpane.requestFocus();
> console.newInput();
>
>Can anyone tell me what I'm doing wrong?
The @sig only works on classes that subclass java, not for standard
python classes. So if you don't want the Console class to subclass
something else, just use java.lang.Object:
@@ -18,7 +18,7 @@
from pawt import swing, colors
from java.awt.event.KeyEvent import VK_UP, VK_DOWN
from java.awt.event import ActionEvent
-from java.lang import Thread, System
+from java.lang import Thread, System, Object
from code import compile_command
import string, sys, re
@@ -33,7 +33,7 @@
def write(self, text):
self.console.write(text, self.stylename)
-class Console:
+class Console(Object):
def __init__(self):
"@sig public Console()"
>I'm trying to embed the Demo/swing/console in my Java
>application, and I was wondering whether I could get
>the instance variables like textpane without creating
>accessor functions. Is that at all possible?
No. You have to add accessor functions [*]. And when you add accessor
functions, these functions will also be called from the Console methods
themselfs. Ie. the line:
self.document = swing.text.DefaultStyledDocument(self.styles)
will try to assign a new value to the bean property created by the
existenceof the "getDocument()" method. If you also had a setDocument()
method, the line above would have called that method. This often end up
in an infinite recursion.
To avoid that, you will have to rename the instance variable name to
something else:
self._document = swing.text.DefaultStyledDocument(self.styles)
regards,
finn
[*] You can also use the Jython API. Then the textpane line becomes:
//console.textpane.requestFocus();
Py.java2py(console).__getattr__("textpane").invoke("requestFocus");
|