[Pydev-cvs] org.python.pydev.jython/src/org/python/pydev/jython JythonPlugin.java, 1.20, 1.21 Scrip
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-09-27 19:58:47
|
Update of /cvsroot/pydev/org.python.pydev.jython/src/org/python/pydev/jython In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20453/src/org/python/pydev/jython Modified Files: JythonPlugin.java ScriptOutput.java IPythonInterpreter.java ScriptingExtensionInitializer.java Log Message: Synching to latest changes: Pydev <ul> <li><strong>Editor</strong>: Cursor settings no longer overridden</li> <li><strong>Code-completion</strong>: If __all__ is defined with runtime elements (and not only in a single assign statement), it's ignored for code-completion purposes</li> <li><strong>Debugger</strong>: Pythonpath the same in debug and regular modes (sys.path[0] is the same directory as the file run)</li> <li><strong>Debugger</strong>: Persist choices done in the debugger when files from the debugger are not found</li> <li><strong>Interpreter config</strong>: "email" automatically added to the "forced builtins"</li> <li><strong>Parser</strong>: Correctly recognizing absolute import with 3 or more levels</li> <li><strong>Syntax check</strong>: Option to do only on active editor</li> </ul> Also: tabs changed for spaces Index: JythonPlugin.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.jython/src/org/python/pydev/jython/JythonPlugin.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** JythonPlugin.java 27 May 2007 13:25:43 -0000 1.20 --- JythonPlugin.java 27 Sep 2008 19:58:13 -0000 1.21 *************** *** 39,49 **** public class JythonPlugin extends AbstractUIPlugin { ! private static final boolean DEBUG = false; ! public static boolean DEBUG_RELOAD = true; /** * While in tests, errors are thrown even if we don't have a shared instance for JythonPlugin */ ! public static boolean IN_TESTS = false; private static String LOAD_FILE_SCRIPT = "" + --- 39,49 ---- public class JythonPlugin extends AbstractUIPlugin { ! private static final boolean DEBUG = false; ! public static boolean DEBUG_RELOAD = true; /** * While in tests, errors are thrown even if we don't have a shared instance for JythonPlugin */ ! public static boolean IN_TESTS = false; private static String LOAD_FILE_SCRIPT = "" + *************** *** 71,75 **** } ! // ----------------- SINGLETON THINGS ----------------------------- public static IBundleInfo info; public static IBundleInfo getBundleInfo(){ --- 71,75 ---- } ! // ----------------- SINGLETON THINGS ----------------------------- public static IBundleInfo info; public static IBundleInfo getBundleInfo(){ *************** *** 84,199 **** // ----------------- END BUNDLE INFO THINGS -------------------------- ! //The shared instance. ! private static JythonPlugin plugin; ! ! /** ! * The constructor. ! */ ! public JythonPlugin() { ! plugin = this; ! } ! ! ! ! // ------------------------------------------ ! /** ! * Classloader that knows about all the bundles... ! */ ! public static class AllBundleClassLoader extends ClassLoader { ! private Bundle[] bundles; ! public AllBundleClassLoader(Bundle[] bundles, ClassLoader parent) { ! super(parent); ! this.bundles = bundles; ! setPackageNames(bundles); ! } ! @SuppressWarnings("unchecked") ! public Class loadClass(String className) throws ClassNotFoundException { ! try { ! return super.loadClass(className); ! } catch (ClassNotFoundException e) { ! // Look for the class from the bundles. ! for (int i = 0; i < bundles.length; ++i) { ! try { if(bundles[i].getState() == Bundle.ACTIVE){ return bundles[i].loadClass(className); } ! } catch (Throwable e2) { ! } ! } ! // Didn't find the class anywhere, rethrow e. ! throw e; ! } ! } ! ! ! /** ! * The package names the bundles provide ! */ ! private String[] packageNames; ! ! /** ! * Set the package names available given the bundles that we can access ! */ ! private void setPackageNames(Bundle[] bundles) { ! List<String> names = new ArrayList<String>(); ! for (int i = 0; i < bundles.length; ++i) { ! String packages = (String) bundles[i].getHeaders().get("Provide-Package"); ! if (packages != null) { ! String[] pnames = packages.split(","); ! for (int j = 0; j < pnames.length; ++j) { ! names.add(pnames[j].trim()); ! } ! } ! packages = (String) bundles[i].getHeaders().get("Export-Package"); ! if (packages != null) { ! String[] pnames = packages.split(","); ! for (int j = 0; j < pnames.length; ++j) { ! names.add(pnames[j].trim()); ! } ! } ! } ! packageNames = (String[]) names.toArray(new String[names.size()]); ! } ! ! /** ! * @return the package names available for the passed bundles ! */ ! public String[] getPackageNames() { ! return packageNames; ! } ! } ! //------------------------------------------ ! AllBundleClassLoader allBundleClassLoader; ! /** ! * This method is called upon plug-in activation ! */ ! public void start(BundleContext context) throws Exception { ! super.start(context); ! //initialize the Jython runtime ! Properties prop2 = new Properties(); ! prop2.put("python.home", REF.getFileAbsolutePath(getPluginRootDir())); ! prop2.put("python.path", REF.getFileAbsolutePath(getJySrcDirFile())); ! prop2.put("python.security.respectJavaAccessibility", "false"); //don't respect java accessibility, so that we can access protected members on subclasses ! ! try { ! allBundleClassLoader = new AllBundleClassLoader(context.getBundles(), this.getClass().getClassLoader()); ! PySystemState.initialize(System.getProperties(), prop2, new String[0], allBundleClassLoader); ! String[] packageNames = getDefault().allBundleClassLoader.getPackageNames(); ! for (int i = 0; i < packageNames.length; ++i) { ! PySystemState.add_package(packageNames[i]); ! } ! } catch (Exception e) { ! Log.log(e); ! } ! } ! private File getPluginRootDir() { try { IPath relative = new Path("."); --- 84,199 ---- // ----------------- END BUNDLE INFO THINGS -------------------------- ! //The shared instance. ! private static JythonPlugin plugin; ! ! /** ! * The constructor. ! */ ! public JythonPlugin() { ! plugin = this; ! } ! ! ! ! // ------------------------------------------ ! /** ! * Classloader that knows about all the bundles... ! */ ! public static class AllBundleClassLoader extends ClassLoader { ! private Bundle[] bundles; ! public AllBundleClassLoader(Bundle[] bundles, ClassLoader parent) { ! super(parent); ! this.bundles = bundles; ! setPackageNames(bundles); ! } ! @SuppressWarnings("unchecked") ! public Class loadClass(String className) throws ClassNotFoundException { ! try { ! return super.loadClass(className); ! } catch (ClassNotFoundException e) { ! // Look for the class from the bundles. ! for (int i = 0; i < bundles.length; ++i) { ! try { if(bundles[i].getState() == Bundle.ACTIVE){ return bundles[i].loadClass(className); } ! } catch (Throwable e2) { ! } ! } ! // Didn't find the class anywhere, rethrow e. ! throw e; ! } ! } ! ! ! /** ! * The package names the bundles provide ! */ ! private String[] packageNames; ! ! /** ! * Set the package names available given the bundles that we can access ! */ ! private void setPackageNames(Bundle[] bundles) { ! List<String> names = new ArrayList<String>(); ! for (int i = 0; i < bundles.length; ++i) { ! String packages = (String) bundles[i].getHeaders().get("Provide-Package"); ! if (packages != null) { ! String[] pnames = packages.split(","); ! for (int j = 0; j < pnames.length; ++j) { ! names.add(pnames[j].trim()); ! } ! } ! packages = (String) bundles[i].getHeaders().get("Export-Package"); ! if (packages != null) { ! String[] pnames = packages.split(","); ! for (int j = 0; j < pnames.length; ++j) { ! names.add(pnames[j].trim()); ! } ! } ! } ! packageNames = (String[]) names.toArray(new String[names.size()]); ! } ! ! /** ! * @return the package names available for the passed bundles ! */ ! public String[] getPackageNames() { ! return packageNames; ! } ! } ! //------------------------------------------ ! AllBundleClassLoader allBundleClassLoader; ! /** ! * This method is called upon plug-in activation ! */ ! public void start(BundleContext context) throws Exception { ! super.start(context); ! //initialize the Jython runtime ! Properties prop2 = new Properties(); ! prop2.put("python.home", REF.getFileAbsolutePath(getPluginRootDir())); ! prop2.put("python.path", REF.getFileAbsolutePath(getJySrcDirFile())); ! prop2.put("python.security.respectJavaAccessibility", "false"); //don't respect java accessibility, so that we can access protected members on subclasses ! ! try { ! allBundleClassLoader = new AllBundleClassLoader(context.getBundles(), this.getClass().getClassLoader()); ! PySystemState.initialize(System.getProperties(), prop2, new String[0], allBundleClassLoader); ! String[] packageNames = getDefault().allBundleClassLoader.getPackageNames(); ! for (int i = 0; i < packageNames.length; ++i) { ! PySystemState.add_package(packageNames[i]); ! } ! } catch (Exception e) { ! Log.log(e); ! } ! } ! private File getPluginRootDir() { try { IPath relative = new Path("."); *************** *** 204,230 **** } /** ! * This method is called when the plug-in is stopped ! */ ! public void stop(BundleContext context) throws Exception { ! super.stop(context); ! plugin = null; ! } ! /** ! * Returns the shared instance. ! */ ! public static JythonPlugin getDefault() { ! return plugin; ! } ! ! public static File getJythonLibDir(){ ! try { ! IPath relative = new Path("Lib"); ! return getBundleInfo().getRelativePath(relative); ! } catch (Exception e) { ! throw new RuntimeException(e); ! } ! } ! public static File getFileWithinJySrc(String f){ try { IPath relative = new Path("jysrc").addTrailingSeparator().append(f); --- 204,230 ---- } /** ! * This method is called when the plug-in is stopped ! */ ! public void stop(BundleContext context) throws Exception { ! super.stop(context); ! plugin = null; ! } ! /** ! * Returns the shared instance. ! */ ! public static JythonPlugin getDefault() { ! return plugin; ! } ! ! public static File getJythonLibDir(){ ! try { ! IPath relative = new Path("Lib"); ! return getBundleInfo().getRelativePath(relative); ! } catch (Exception e) { ! throw new RuntimeException(e); ! } ! } ! public static File getFileWithinJySrc(String f){ try { IPath relative = new Path("jysrc").addTrailingSeparator().append(f); *************** *** 233,284 **** throw new RuntimeException(e); } ! } ! ! /** ! * @return the jysrc (org.python.pydev.jython/jysrc) directory ! */ ! public static File getJySrcDirFile() { ! try { ! IPath relative = new Path("jysrc"); ! return getBundleInfo().getRelativePath(relative); ! } catch (Exception e) { ! throw new RuntimeException(e); ! } ! } ! /** ! * This is a helper for: ! * - Loading a file from the filesystem with jython code ! * - Compiling it to a code object (that will remain in the 'code' local for the interpreter) ! * - Making a call to exec that code ! * - Returning the local in the interpreter regarded as jythonResult ! * ! * Additional notes: ! * - The code object will be regenerated only if: ! * - It still didn't exist (dought!!) ! * - The timestamp of the file changed ! * ! * @param locals Those are the locals that should be added to the interpreter before calling the actual code ! * @param fileToExec the file that should be executed (relative to the JythonPlugin jysrc folder) ! * @param interpreter the interpreter that should be used to execute the code ! * ! # @note If further info is needed (after the run), the interpreter itself should be checked for return values ! * @return any error that happened while executing the script ! * ! */ ! public static Throwable exec(HashMap<String, Object> locals, String fileToExec, IPythonInterpreter interpreter) { ! File fileWithinJySrc = JythonPlugin.getFileWithinJySrc(fileToExec); ! return exec(locals, interpreter, fileWithinJySrc, new File[]{fileWithinJySrc.getParentFile()}); ! } ! ! public static List<Throwable> execAll(HashMap<String, Object> locals, final String startingWith, IPythonInterpreter interpreter) { ! //exec files beneath jysrc in org.python.pydev.jython ! File jySrc = JythonPlugin.getJySrcDirFile(); ! File additionalScriptingLocation = JyScriptingPreferencesPage.getAdditionalScriptingLocation(); ! return execAll(locals, startingWith, interpreter, new File[]{jySrc, additionalScriptingLocation}); ! ! } /** --- 233,284 ---- throw new RuntimeException(e); } ! } ! ! /** ! * @return the jysrc (org.python.pydev.jython/jysrc) directory ! */ ! public static File getJySrcDirFile() { ! try { ! IPath relative = new Path("jysrc"); ! return getBundleInfo().getRelativePath(relative); ! } catch (Exception e) { ! throw new RuntimeException(e); ! } ! } ! /** ! * This is a helper for: ! * - Loading a file from the filesystem with jython code ! * - Compiling it to a code object (that will remain in the 'code' local for the interpreter) ! * - Making a call to exec that code ! * - Returning the local in the interpreter regarded as jythonResult ! * ! * Additional notes: ! * - The code object will be regenerated only if: ! * - It still didn't exist (dought!!) ! * - The timestamp of the file changed ! * ! * @param locals Those are the locals that should be added to the interpreter before calling the actual code ! * @param fileToExec the file that should be executed (relative to the JythonPlugin jysrc folder) ! * @param interpreter the interpreter that should be used to execute the code ! * ! # @note If further info is needed (after the run), the interpreter itself should be checked for return values ! * @return any error that happened while executing the script ! * ! */ ! public static Throwable exec(HashMap<String, Object> locals, String fileToExec, IPythonInterpreter interpreter) { ! File fileWithinJySrc = JythonPlugin.getFileWithinJySrc(fileToExec); ! return exec(locals, interpreter, fileWithinJySrc, new File[]{fileWithinJySrc.getParentFile()}); ! } ! ! public static List<Throwable> execAll(HashMap<String, Object> locals, final String startingWith, IPythonInterpreter interpreter) { ! //exec files beneath jysrc in org.python.pydev.jython ! File jySrc = JythonPlugin.getJySrcDirFile(); ! File additionalScriptingLocation = JyScriptingPreferencesPage.getAdditionalScriptingLocation(); ! return execAll(locals, startingWith, interpreter, new File[]{jySrc, additionalScriptingLocation}); ! ! } /** *************** *** 310,397 **** return errors; } ! /** ! * List all the 'target' scripts available beneath some folder. ! */ ! public static File[] getFilesBeneathFolder(final String startingWith, File jySrc) { ! File[] files = jySrc.listFiles(new FileFilter(){ ! public boolean accept(File pathname) { ! String name = pathname.getName(); if(name.startsWith(startingWith) && name.endsWith(".py")){ ! return true; ! } ! return false; ! } ! ! }); ! return files; ! } ! /** ! * Holds a cache with the name of the created code to a tuple with the file timestamp and the Code Object ! * that was generated with the contents of that timestamp. ! */ ! private static Map<File, Tuple<Long, Object>> codeCache = new HashMap<File,Tuple<Long, Object>>(); ! ! /** ! * @param pythonpathFolders folders that should be in the pythonpath when executing the script ! * @see JythonPlugin#exec(HashMap, String, PythonInterpreter) ! * Same as before but the file to execute is passed as a parameter ! */ ! public static synchronized Throwable exec(HashMap<String, Object> locals, IPythonInterpreter interpreter, File fileToExec, File[] pythonpathFolders) { if(locals == null){ locals = new HashMap<String, Object>(); } ! synchronized (codeCache) { //hold on there... one at a time... please? ! try { ! String fileName = fileToExec.getName(); ! if(!fileName.endsWith(".py")){ ! throw new RuntimeException("The script to be executed must be a python file. Name:"+fileName); ! } ! String codeObjName = "code"+fileName.substring(0, fileName.indexOf('.')); ! final String codeObjTimestampName = codeObjName+"Timestamp"; ! ! for (Map.Entry<String, Object> entry : locals.entrySet()) { ! interpreter.set(entry.getKey(), entry.getValue()); ! } ! ! boolean regenerate = false; ! Tuple<Long, Object> timestamp = codeCache.get(fileToExec); ! final long lastModified = fileToExec.lastModified(); ! if(timestamp == null || timestamp.o1 != lastModified){ ! //the file timestamp changed, so, we have to regenerate it ! regenerate = true; ! } ! ! if(!regenerate){ ! //if the 'code' object does not exist or if it's timestamp is outdated, we have to re-set it. ! PyObject obj = interpreter.get(codeObjName); ! PyObject pyTime = interpreter.get(codeObjTimestampName); ! if (obj == null || pyTime == null || !pyTime.__tojava__(Long.class).equals(timestamp.o1)){ ! if(DEBUG){ ! System.out.println("Resetting object: "+codeObjName); ! } ! interpreter.set(codeObjName, timestamp.o2); ! interpreter.set(codeObjTimestampName, timestamp.o1); ! } ! } ! ! if(regenerate){ ! if(DEBUG){ ! System.out.println("Regenerating: "+codeObjName); ! } ! String path = REF.getFileAbsolutePath(fileToExec); ! ! StringBuffer strPythonPathFolders = new StringBuffer(); ! strPythonPathFolders.append("["); ! for (File file : pythonpathFolders) { if (file != null){ ! strPythonPathFolders.append("r'"); ! strPythonPathFolders.append(REF.getFileAbsolutePath(file)); ! strPythonPathFolders.append("',"); } ! } ! strPythonPathFolders.append("]"); StringBuffer addToSysPath = new StringBuffer(); --- 310,397 ---- return errors; } ! /** ! * List all the 'target' scripts available beneath some folder. ! */ ! public static File[] getFilesBeneathFolder(final String startingWith, File jySrc) { ! File[] files = jySrc.listFiles(new FileFilter(){ ! public boolean accept(File pathname) { ! String name = pathname.getName(); if(name.startsWith(startingWith) && name.endsWith(".py")){ ! return true; ! } ! return false; ! } ! ! }); ! return files; ! } ! /** ! * Holds a cache with the name of the created code to a tuple with the file timestamp and the Code Object ! * that was generated with the contents of that timestamp. ! */ ! private static Map<File, Tuple<Long, Object>> codeCache = new HashMap<File,Tuple<Long, Object>>(); ! ! /** ! * @param pythonpathFolders folders that should be in the pythonpath when executing the script ! * @see JythonPlugin#exec(HashMap, String, PythonInterpreter) ! * Same as before but the file to execute is passed as a parameter ! */ ! public static synchronized Throwable exec(HashMap<String, Object> locals, IPythonInterpreter interpreter, File fileToExec, File[] pythonpathFolders) { if(locals == null){ locals = new HashMap<String, Object>(); } ! synchronized (codeCache) { //hold on there... one at a time... please? ! try { ! String fileName = fileToExec.getName(); ! if(!fileName.endsWith(".py")){ ! throw new RuntimeException("The script to be executed must be a python file. Name:"+fileName); ! } ! String codeObjName = "code"+fileName.substring(0, fileName.indexOf('.')); ! final String codeObjTimestampName = codeObjName+"Timestamp"; ! ! for (Map.Entry<String, Object> entry : locals.entrySet()) { ! interpreter.set(entry.getKey(), entry.getValue()); ! } ! ! boolean regenerate = false; ! Tuple<Long, Object> timestamp = codeCache.get(fileToExec); ! final long lastModified = fileToExec.lastModified(); ! if(timestamp == null || timestamp.o1 != lastModified){ ! //the file timestamp changed, so, we have to regenerate it ! regenerate = true; ! } ! ! if(!regenerate){ ! //if the 'code' object does not exist or if it's timestamp is outdated, we have to re-set it. ! PyObject obj = interpreter.get(codeObjName); ! PyObject pyTime = interpreter.get(codeObjTimestampName); ! if (obj == null || pyTime == null || !pyTime.__tojava__(Long.class).equals(timestamp.o1)){ ! if(DEBUG){ ! System.out.println("Resetting object: "+codeObjName); ! } ! interpreter.set(codeObjName, timestamp.o2); ! interpreter.set(codeObjTimestampName, timestamp.o1); ! } ! } ! ! if(regenerate){ ! if(DEBUG){ ! System.out.println("Regenerating: "+codeObjName); ! } ! String path = REF.getFileAbsolutePath(fileToExec); ! ! StringBuffer strPythonPathFolders = new StringBuffer(); ! strPythonPathFolders.append("["); ! for (File file : pythonpathFolders) { if (file != null){ ! strPythonPathFolders.append("r'"); ! strPythonPathFolders.append(REF.getFileAbsolutePath(file)); ! strPythonPathFolders.append("',"); } ! } ! strPythonPathFolders.append("]"); StringBuffer addToSysPath = new StringBuffer(); *************** *** 410,453 **** addToSysPath.append("\n"); ! String toExec = StringUtils.format(LOAD_FILE_SCRIPT, path, path, addToSysPath.toString()); ! interpreter.exec(toExec); ! String exec = StringUtils.format("%s = compile(toExec, r'%s', 'exec')", codeObjName, path); ! interpreter.exec(exec); ! //set its timestamp ! interpreter.set(codeObjTimestampName, lastModified); ! ! Object codeObj = interpreter.get(codeObjName); ! codeCache.put(fileToExec, new Tuple<Long, Object>(lastModified, codeObj)); ! } ! ! interpreter.exec(StringUtils.format("exec(%s)" , codeObjName)); ! } catch (Throwable e) { if(!IN_TESTS && JythonPlugin.getDefault() == null){ //it is already disposed return null; } ! //the user requested it to exit ! if(e instanceof ExitScriptException){ ! return null; ! } ! //actually, this is more likely to happen when raising an exception in jython ! if(e instanceof PyException){ ! PyException pE = (PyException) e; ! if (pE.type instanceof PyJavaClass){ ! PyJavaClass t = (PyJavaClass) pE.type; ! if(t.__name__ != null && t.__name__.equals("org.python.pydev.jython.ExitScriptException")){ ! return null; ! } ! } ! } ! ! if(JyScriptingPreferencesPage.getShowScriptingOutput()){ ! Log.log(IStatus.ERROR, "Error while executing:"+fileToExec, e); ! } return e; ! } ! } return null; ! } --- 410,453 ---- addToSysPath.append("\n"); ! String toExec = StringUtils.format(LOAD_FILE_SCRIPT, path, path, addToSysPath.toString()); ! interpreter.exec(toExec); ! String exec = StringUtils.format("%s = compile(toExec, r'%s', 'exec')", codeObjName, path); ! interpreter.exec(exec); ! //set its timestamp ! interpreter.set(codeObjTimestampName, lastModified); ! ! Object codeObj = interpreter.get(codeObjName); ! codeCache.put(fileToExec, new Tuple<Long, Object>(lastModified, codeObj)); ! } ! ! interpreter.exec(StringUtils.format("exec(%s)" , codeObjName)); ! } catch (Throwable e) { if(!IN_TESTS && JythonPlugin.getDefault() == null){ //it is already disposed return null; } ! //the user requested it to exit ! if(e instanceof ExitScriptException){ ! return null; ! } ! //actually, this is more likely to happen when raising an exception in jython ! if(e instanceof PyException){ ! PyException pE = (PyException) e; ! if (pE.type instanceof PyJavaClass){ ! PyJavaClass t = (PyJavaClass) pE.type; ! if(t.__name__ != null && t.__name__.equals("org.python.pydev.jython.ExitScriptException")){ ! return null; ! } ! } ! } ! ! if(JyScriptingPreferencesPage.getShowScriptingOutput()){ ! Log.log(IStatus.ERROR, "Error while executing:"+fileToExec, e); ! } return e; ! } ! } return null; ! } *************** *** 482,546 **** * Creates a new Python interpreter (with jython) and returns it. */ ! public static IPythonInterpreter newPythonInterpreter(boolean redirect) { ! PythonInterpreterWrapper interpreter = new PythonInterpreterWrapper(); if(redirect){ ! interpreter.setOut(new ScriptOutput(getBlack(), getConsole())); ! interpreter.setErr(new ScriptOutput(getRed(), getConsole())); } ! interpreter.set("False", 0); ! interpreter.set("True", 1); ! return interpreter; ! } ! ! static Color red; ! static Color black; static Color green; ! public static Color getRed() { ! if(red == null){ ! synchronized (Display.getDefault()) { ! Display.getDefault().syncExec(new Runnable(){ ! ! public void run() { ! red = Display.getDefault().getSystemColor(SWT.COLOR_RED); ! } ! }); ! } ! } ! return red; ! } ! ! public static Color getBlack() { ! if(black == null){ ! synchronized (Display.getDefault()) { ! Display.getDefault().syncExec(new Runnable(){ ! public void run() { ! black = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); ! } ! }); ! } ! } ! return black; ! } ! public static Color getGreen() { ! if(green == null){ ! synchronized (Display.getDefault()) { ! Display.getDefault().syncExec(new Runnable(){ ! ! public void run() { green = new Color(Display.getDefault(), 0, 200, 125); ! } ! }); ! } ! } ! return green; ! } public static IInteractiveConsole newInteractiveConsole() { return new InteractiveConsoleWrapper(); } ! } --- 482,546 ---- * Creates a new Python interpreter (with jython) and returns it. */ ! public static IPythonInterpreter newPythonInterpreter(boolean redirect) { ! PythonInterpreterWrapper interpreter = new PythonInterpreterWrapper(); if(redirect){ ! interpreter.setOut(new ScriptOutput(getBlack(), getConsole())); ! interpreter.setErr(new ScriptOutput(getRed(), getConsole())); } ! interpreter.set("False", 0); ! interpreter.set("True", 1); ! return interpreter; ! } ! ! static Color red; ! static Color black; static Color green; ! public static Color getRed() { ! if(red == null){ ! synchronized (Display.getDefault()) { ! Display.getDefault().syncExec(new Runnable(){ ! ! public void run() { ! red = Display.getDefault().getSystemColor(SWT.COLOR_RED); ! } ! }); ! } ! } ! return red; ! } ! ! public static Color getBlack() { ! if(black == null){ ! synchronized (Display.getDefault()) { ! Display.getDefault().syncExec(new Runnable(){ ! public void run() { ! black = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); ! } ! }); ! } ! } ! return black; ! } ! public static Color getGreen() { ! if(green == null){ ! synchronized (Display.getDefault()) { ! Display.getDefault().syncExec(new Runnable(){ ! ! public void run() { green = new Color(Display.getDefault(), 0, 200, 125); ! } ! }); ! } ! } ! return green; ! } public static IInteractiveConsole newInteractiveConsole() { return new InteractiveConsoleWrapper(); } ! } Index: ScriptOutput.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.jython/src/org/python/pydev/jython/ScriptOutput.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ScriptOutput.java 22 Mar 2006 01:42:15 -0000 1.2 --- ScriptOutput.java 27 Sep 2008 19:58:13 -0000 1.3 *************** *** 22,39 **** */ public class ScriptOutput extends OutputStream{ ! /** ! * Indicates whether we should write to the console or not ! */ ! private boolean writeToConsole; ! ! /** ! * Stream to the console we want to write ! */ ! private IOConsoleOutputStream out; ! ! /** ! * This is the color of the output ! */ ! private Color color; /** --- 22,39 ---- */ public class ScriptOutput extends OutputStream{ ! /** ! * Indicates whether we should write to the console or not ! */ ! private boolean writeToConsole; ! ! /** ! * Stream to the console we want to write ! */ ! private IOConsoleOutputStream out; ! ! /** ! * This is the color of the output ! */ ! private Color color; /** *************** *** 41,45 **** */ private IOConsole fConsole; ! /** * Constructor - the user is able to define whether he wants to write to the console or not. --- 41,45 ---- */ private IOConsole fConsole; ! /** * Constructor - the user is able to define whether he wants to write to the console or not. *************** *** 53,99 **** } ! /** ! * Constructor - Uses the properties from the JyScriptingPreferencesPage to know if we should write to * the console or not ! * ! * @param color the color of the output written ! */ ! public ScriptOutput(Color color, MessageConsole console){ this(color, console, JyScriptingPreferencesPage.getShowScriptingOutput()); ! IPropertyChangeListener listener = new Preferences.IPropertyChangeListener(){ ! public void propertyChange(PropertyChangeEvent event) { ! writeToConsole = JyScriptingPreferencesPage.getShowScriptingOutput(); ! } ! }; ! JythonPlugin.getDefault().getPluginPreferences().addPropertyChangeListener(listener); ! } ! ! /** ! * OutputStream interface ! */ ! @Override ! public void write(int b) throws IOException { ! if(writeToConsole){ ! IOConsoleOutputStream out = getOutputStream(); ! out.write(b); ! } ! } ! /** ! * @return the output stream to use ! */ ! private IOConsoleOutputStream getOutputStream() throws MalformedURLException { ! if(out == null){ ! out = fConsole.newOutputStream(); ! synchronized (Display.getDefault()) { ! Display.getDefault().syncExec(new Runnable(){ ! public void run() { ! out.setColor(color); ! } ! }); ! } ! } ! return out; ! } ! } \ No newline at end of file --- 53,99 ---- } ! /** ! * Constructor - Uses the properties from the JyScriptingPreferencesPage to know if we should write to * the console or not ! * ! * @param color the color of the output written ! */ ! public ScriptOutput(Color color, MessageConsole console){ this(color, console, JyScriptingPreferencesPage.getShowScriptingOutput()); ! IPropertyChangeListener listener = new Preferences.IPropertyChangeListener(){ ! public void propertyChange(PropertyChangeEvent event) { ! writeToConsole = JyScriptingPreferencesPage.getShowScriptingOutput(); ! } ! }; ! JythonPlugin.getDefault().getPluginPreferences().addPropertyChangeListener(listener); ! } ! ! /** ! * OutputStream interface ! */ ! @Override ! public void write(int b) throws IOException { ! if(writeToConsole){ ! IOConsoleOutputStream out = getOutputStream(); ! out.write(b); ! } ! } ! /** ! * @return the output stream to use ! */ ! private IOConsoleOutputStream getOutputStream() throws MalformedURLException { ! if(out == null){ ! out = fConsole.newOutputStream(); ! synchronized (Display.getDefault()) { ! Display.getDefault().syncExec(new Runnable(){ ! public void run() { ! out.setColor(color); ! } ! }); ! } ! } ! return out; ! } ! } \ No newline at end of file Index: ScriptingExtensionInitializer.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.jython/src/org/python/pydev/jython/ScriptingExtensionInitializer.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ScriptingExtensionInitializer.java 21 Mar 2006 23:20:05 -0000 1.2 --- ScriptingExtensionInitializer.java 27 Sep 2008 19:58:13 -0000 1.3 *************** *** 7,19 **** public class ScriptingExtensionInitializer extends AbstractPreferenceInitializer{ ! public static final String DEFAULT_SCOPE = "org.python.pydev.jython"; ! ! @Override ! public void initializeDefaultPreferences() { ! Preferences node = new DefaultScope().getNode(DEFAULT_SCOPE); node.putBoolean(JyScriptingPreferencesPage.SHOW_SCRIPTING_OUTPUT, JyScriptingPreferencesPage.DEFAULT_SHOW_SCRIPTING_OUTPUT); node.putBoolean(JyScriptingPreferencesPage.LOG_SCRIPTING_ERRORS, JyScriptingPreferencesPage.DEFAULT_LOG_SCRIPTING_ERRORS); ! } } --- 7,19 ---- public class ScriptingExtensionInitializer extends AbstractPreferenceInitializer{ ! public static final String DEFAULT_SCOPE = "org.python.pydev.jython"; ! ! @Override ! public void initializeDefaultPreferences() { ! Preferences node = new DefaultScope().getNode(DEFAULT_SCOPE); node.putBoolean(JyScriptingPreferencesPage.SHOW_SCRIPTING_OUTPUT, JyScriptingPreferencesPage.DEFAULT_SHOW_SCRIPTING_OUTPUT); node.putBoolean(JyScriptingPreferencesPage.LOG_SCRIPTING_ERRORS, JyScriptingPreferencesPage.DEFAULT_LOG_SCRIPTING_ERRORS); ! } } Index: IPythonInterpreter.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.jython/src/org/python/pydev/jython/IPythonInterpreter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** IPythonInterpreter.java 20 Oct 2007 19:30:28 -0000 1.5 --- IPythonInterpreter.java 27 Sep 2008 19:58:13 -0000 1.6 *************** *** 11,41 **** public interface IPythonInterpreter { ! /** ! * This method sets some variable in the interpreter ! * ! * @param key the variable name ! * @param value the variable value ! */ ! void set(String key, Object value); ! /** ! * Executes a piece of code ! * ! * @param exec The piece of code that should be executed ! */ ! void exec(String exec); ! /** ! * This method returns the variable that we want to get from the interpreter as a java object ! * ! * @param varName the variable that we want to get ! * @param class_ the java class that should be used as the return value ! * @return the object with the variable requested as a java object ! */ ! Object get(String varName, Class class_); ! /** ! * This method returns the variable that we want to get from the interpreter as a PyObject ! */ PyObject get(String varName); --- 11,41 ---- public interface IPythonInterpreter { ! /** ! * This method sets some variable in the interpreter ! * ! * @param key the variable name ! * @param value the variable value ! */ ! void set(String key, Object value); ! /** ! * Executes a piece of code ! * ! * @param exec The piece of code that should be executed ! */ ! void exec(String exec); ! /** ! * This method returns the variable that we want to get from the interpreter as a java object ! * ! * @param varName the variable that we want to get ! * @param class_ the java class that should be used as the return value ! * @return the object with the variable requested as a java object ! */ ! Object get(String varName, Class class_); ! /** ! * This method returns the variable that we want to get from the interpreter as a PyObject ! */ PyObject get(String varName); *************** *** 43,48 **** * Cleans the interpreter */ ! void cleanup(); ! void setOut(OutputStream output); --- 43,48 ---- * Cleans the interpreter */ ! void cleanup(); ! void setOut(OutputStream output); |