use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class PySelectInterpreter method run.
@Override
public void run(IAction action) {
try {
PyEdit editor = getPyEdit();
IPythonNature nature = editor.getPythonNature();
if (nature != null) {
IInterpreterManager interpreterManager = nature.getRelatedInterpreterManager();
final IInterpreterInfo[] interpreterInfos = interpreterManager.getInterpreterInfos();
if (interpreterInfos == null || interpreterInfos.length == 0) {
PyDialogHelpers.openWarning("No interpreters available", "Unable to change default interpreter because no interpreters are available (add more interpreters in the related preferences page).");
return;
}
if (interpreterInfos.length == 1) {
PyDialogHelpers.openWarning("Only 1 interpreters available", "Unable to change default interpreter because only 1 interpreter is configured (add more interpreters in the related preferences page).");
return;
}
// Ok, more than 1 found.
IWorkbenchWindow workbenchWindow = EditorUtils.getActiveWorkbenchWindow();
Assert.isNotNull(workbenchWindow);
SelectionDialog listDialog = AbstractInterpreterPreferencesPage.createChooseIntepreterInfoDialog(workbenchWindow, interpreterInfos, "Select interpreter to be made the default.", false);
int open = listDialog.open();
if (open != ListDialog.OK || listDialog.getResult().length != 1) {
return;
}
Object[] result = listDialog.getResult();
if (result == null || result.length == 0) {
return;
}
final IInterpreterInfo selectedInterpreter = ((IInterpreterInfo) result[0]);
if (selectedInterpreter != interpreterInfos[0]) {
// Ok, some interpreter (which wasn't already the default) was selected.
Arrays.sort(interpreterInfos, (a, b) -> {
if (a == selectedInterpreter) {
return -1;
}
if (b == selectedInterpreter) {
return 1;
}
// Don't change order for the others.
return 0;
});
Shell shell = EditorUtils.getShell();
setInterpreterInfosWithProgressDialog(interpreterManager, interpreterInfos, shell);
}
}
} catch (Exception e) {
Log.log(e);
}
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class AbstractInterpreterPreferencesPage method performOk.
/**
* Applies changes (if any)
*
* @see org.eclipse.jface.preference.IPreferencePage#performOk()
*/
@Override
public boolean performOk() {
// IMPORTANT: we must call the perform before restoring the modules because this
// info is going to be used when restoring them.
super.performOk();
// we need to update the tree so that the environment variables stay correct.
pathEditor.updateTree();
IInterpreterManager interpreterManager = getInterpreterManager();
String newStringToPersist = AbstractInterpreterManager.getStringToPersist(pathEditor.getExesList());
String oldStringToPersist = AbstractInterpreterManager.getStringToPersist(interpreterManager.getInterpreterInfos());
boolean changed;
if (!newStringToPersist.equals(oldStringToPersist)) {
changed = true;
} else {
changed = false;
}
if (changed || inApply) {
// If the user just presses 'apply' and nothing changed, he'll be asked to restore information on one of
// the current interpreters.
restoreInterpreterInfos(changed);
}
if (!inApply) {
// re-enable "configure interpreter" dialogs, but only upon exiting the wizard
PyDialogHelpers.enableAskInterpreterStep(true);
}
return true;
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class SyncSystemModulesManager method synchronizeManagerToNameToInfoPythonpath.
public void synchronizeManagerToNameToInfoPythonpath(IProgressMonitor monitor, ManagerInfoToUpdate localManagerToNameToInfo, IInterpreterInfoBuilder builder) {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
if (builder == null) {
builder = (IInterpreterInfoBuilder) ExtensionHelper.getParticipant(ExtensionHelper.PYDEV_INTERPRETER_INFO_BUILDER, false);
if (builder == null) {
Log.log("Expecting at least one " + ExtensionHelper.PYDEV_INTERPRETER_INFO_BUILDER + ".");
return;
}
}
// Ok, all is Ok in the PYTHONPATH, so, check if something changed inside the interpreter info
// and not on the PYTHONPATH.
Tuple<IInterpreterManager, IInterpreterInfo>[] managerAndInfos = localManagerToNameToInfo.getManagerAndInfos();
for (Tuple<IInterpreterManager, IInterpreterInfo> tuple : managerAndInfos) {
// If it was changed or not, we must check the internal structure too!
InterpreterInfo info = (InterpreterInfo) tuple.o2;
if (info == null) {
Log.log("Info null when synchronizing info.");
continue;
}
if (DEBUG) {
System.out.println("Synchronizing PYTHONPATH info: " + info.getNameForUI());
}
long initial = System.currentTimeMillis();
builder.syncInfoToPythonPath(monitor, info);
if (DEBUG) {
System.out.println("End Synchronizing PYTHONPATH info (" + (System.currentTimeMillis() - initial) / 1000.0 + " secs.)");
}
}
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class SyncSystemModulesManager method applySelectedChangesToInterpreterInfosPythonpath.
public void applySelectedChangesToInterpreterInfosPythonpath(final DataAndImageTreeNode root, List<TreeNode> selectElements, IProgressMonitor monitor) {
List<IInterpreterInfo> changedInfos = computeChanges(root, selectElements);
if (changedInfos.size() > 0) {
IInterpreterManager[] allInterpreterManagers = InterpreterManagersAPI.getAllInterpreterManagers();
for (IInterpreterManager manager : allInterpreterManagers) {
if (manager == null) {
continue;
}
Map<String, IInterpreterInfo> changedInterpreterNameToInterpreter = new HashMap<>();
for (IInterpreterInfo info : changedInfos) {
changedInterpreterNameToInterpreter.put(info.getName(), info);
}
IInterpreterInfo[] allInfos = manager.getInterpreterInfos();
List<Object> newInfos = new ArrayList<>(allInfos.length);
Set<String> changedNames = new HashSet<>();
// Important: keep the order in which the user configured the interpreters.
for (IInterpreterInfo info : allInfos) {
IInterpreterInfo changedInfo = changedInterpreterNameToInterpreter.remove(info.getName());
if (changedInfo != null) {
// Override with the ones that should be changed.
newInfos.add(changedInfo);
changedNames.add(changedInfo.getExecutableOrJar());
} else {
newInfos.add(info);
}
}
if (changedNames.size() > 0) {
if (DEBUG) {
System.out.println("Updating interpreters: " + changedNames);
}
manager.setInfos(newInfos.toArray(new IInterpreterInfo[newInfos.size()]), changedNames, monitor);
}
}
}
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class SyncSystemModulesManagerScheduler method stop.
/**
* Stops the synchronization.
*/
public void stop() {
job.cancel();
IInterpreterManager[] managers = InterpreterManagersAPI.getAllInterpreterManagers();
synchronized (lockSetInfos) {
for (IInterpreterManager iInterpreterManager : managers) {
if (iInterpreterManager != null) {
stopTrack(iInterpreterManager, pathWatch);
}
}
}
pathWatch.dispose();
}
Aggregations