Thread: [Pydev-users] [Users] How to write commands to pydev console
Brought to you by:
fabioz
From: SourceForge.net <no...@so...> - 2011-04-21 16:21:17
|
The following forum message was posted by at http://sourceforge.net/projects/pydev/forums/forum/293649/topic/4498666: Hello, I am trying to send python commands to the pydev console inside an eclipse plugin. I have tried this: MessageConsole console = findConsole ("Pydev Console [0]"); // finds the associated console MessageConsoleStream out = console.newMessageStream(); out.println("print 8"); // nothing happens Which does not seem to do anything. I probably need to use a different class somewhere in pydev to do this but I'm not sure where. Thanks, Brian |
From: SourceForge.net <no...@so...> - 2011-04-21 23:48:06
|
The following forum message was posted by fabioz at http://sourceforge.net/projects/pydev/forums/forum/293649/topic/4498666: I haven't checked this, but I think it goes something like ... get the ScriptConsolePage ... scriptConsolePage.getViewer().getDocument().replace(offset, length, text) <-- just make sure to always only add content to the end of the document (adding to other places may have bad repercussions) -- whenever you add a new line, that line will be evaluated. Also, not sure exactly what you plan to do, but if you add content while it's waiting for a response of the server I'm not sure what will happen (it'll probably just ignore what you've written, but I may be wrong there). Cheers, Fabio |
From: SourceForge.net <no...@so...> - 2011-05-25 19:35:46
|
The following forum message was posted by at http://sourceforge.net/projects/pydev/forums/forum/293649/topic/4498666: FYI, This is what i did to solve this problem and it seems to work (I created the console first, but there must be a way to get the console after it has been created). [code] final ICallback<Object, InterpreterResponse> onResponseReceived = new ICallback<Object, InterpreterResponse>(){ public Object call(final InterpreterResponse arg){ //When we receive the response, we must handle it in the UI thread. RunInUiThread.async(new Runnable(){ public void run(){ } }); return null; } }; try { PydevConsoleFactory factory = new PydevConsoleFactory(); PydevConsoleInterpreter interp = PydevConsoleFactory .createDefaultPydevInterpreter(); factory.createConsole(interp, "x=1;print x\n"); interp.exec ("y=2\n", onResponseReceived); } catch (Exception e) { e.printStackTrace(); }[/code] Brian |