On Mon, May 14, 2012 at 7:41 PM, Josh Stratton <strattonbra...@gmail.com> wrote:
> After digging around with the pydev code I've been trying to write a
> simple eclipse plugin that can change the active python interpreter or
> alter the current project's python path programmatically.  For
> example, if I call PythonInterpreterManager.createInterpreterInfo(), I
> get the popup asking for which system libs to include on the path.
> With the info I get back, I can call addInterpreterInfo() to store it
> in the manager.  What I don't understand though is what happens with
> this stored data.  For example, if I call
> PythonInterpreterManager.getInterpreterInfos(), I don't get that new
> info I just added back.  Looking at the code, it seems to be doing
> something more complex than just pulling from a list.  I also don't
> see anything outside the preferences as to which interpreter is
> actually being used.  Is it the selected one?  Is there a way to query
> this without actually looking at the IPreferencePage?  Because we have
> several diferrent interpreters, I'd like to write a view plugin that
> can add/switch-between the various interpreters without having to open
> up the preferences window.  However, it seems that the preferences are
> intimately tied to the actual data, so I have to actually look at
> preferences pages instead of some function on a manager like
> getActiveInterpreter() or setActiveInterpreter().
>
> In a related vein, I'd like to be able to alter the pythonpath for a
> given project I'm working on.  For example, I might add a checkbox to
> my view and when it's toggled, it adds/removes some path from the
> project's python path.
>
> I was expecting some functions like addInterpreterPath() on some
> manager that adds that path to the interpreters preferences page.  Or
> getProjectPythonPath(IProject) or setProjectPythonPath(IProject,
> String) that could change the project's python path without dealing
> with the actual preference pages.  Just from my limited understanding
> of the code, however, a lot of the "model" state is actually in the UI
> itself instead of just in the managers.
>
> Is this functionality currently possible with the existing API without
> having to jump through a bunch of hoops?
>
> Thanks, Josh
>


Not sure if it was you, but see:
http://stackoverflow.com/questions/10587681/adding-python-interpreters-programmatically

As for the project, you should do:

nature = PythonNature.getPythonNature(IProject)
pythonPath = nature.getPythonPathNature()
pythonPath.setProjectSourcePath("/project/path1|/project/path2")

You can look at those (IPythonNature and IPythonPathNature for more
APIs for dealing with the project).

Cheers,

Fabio

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
pydev-code mailing list
pydev-code@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pydev-code

Reply via email to