Révision 3583

TXM/trunk/org.txm.groovy.core/src/java/org/txm/groovy/core/GroovyScriptedImportEngine.java (revision 3583)
132 132
			}
133 133
			
134 134
			ExecTimer.start();
135
			Log.info(NLS.bind("Compiling {0} import module...", project.getImportModuleName()));
135
			Log.info(NLS.bind("Compiling the \"{0}\" import module scripts...", project.getImportModuleName()));
136 136
			Script s = gse.createScript(mainScript.toURI().toURL().toString(), binding);
137 137
			Log.info(NLS.bind(GroovyMessages.startingTheP0importModule, project.getImportModuleName()));
138 138
			s.run(); // run the groovy import script
......
182 182
		catch (Exception e) {
183 183
			// System.out.println(NLS.bind(TXMUIMessages.errorWhileRunningScriptColonP0, e));
184 184
			Log.printStackTrace(e);
185
			Log.warning("Import failed.");
185
			Log.warning("Import failed: "+e);
186 186
			return new Status(Status.ERROR, "org.txm.groovy.core", e.getMessage());
187 187
		}
188 188
		finally {
TXM/trunk/org.txm.specificities.rcp/src/org/txm/specificities/rcp/editors/SpecificitiesEditor.java (revision 3583)
34 34
import org.eclipse.jface.viewers.TableViewer;
35 35
import org.eclipse.osgi.util.NLS;
36 36
import org.eclipse.swt.SWT;
37
import org.eclipse.swt.events.MouseEvent;
38
import org.eclipse.swt.events.MouseListener;
37 39
import org.eclipse.swt.layout.GridData;
38 40
import org.eclipse.swt.layout.GridLayout;
39 41
import org.eclipse.swt.widgets.Composite;
......
61 63
import org.txm.searchengine.cqp.corpus.WordProperty;
62 64
import org.txm.specificities.core.functions.Specificities;
63 65
import org.txm.specificities.core.preferences.SpecificitiesPreferences;
66
import org.txm.specificities.rcp.handlers.ComputeSpecifictiesSelectionChart;
64 67
import org.txm.specificities.rcp.messages.SpecificitiesUIMessages;
65 68
import org.txm.statsengine.core.StatException;
66 69
import org.txm.statsengine.r.core.messages.RCoreMessages;
......
191 194
			
192 195
			specificitesTable.setHeaderVisible(true);
193 196
			
197
			specificitesTable.addMouseListener(new MouseListener() {
198
				
199
				@Override
200
				public void mouseUp(MouseEvent e) { }
201
				
202
				@Override
203
				public void mouseDown(MouseEvent e) { }
204
				
205
				@Override
206
				public void mouseDoubleClick(MouseEvent e) {
207
					
208
					ComputeSpecifictiesSelectionChart.open(SpecificitiesEditor.this);
209
				}
210
			});
211
			
194 212
			// Horizontal bar on second table takes up a little extra space.
195 213
			// To keep vertical scroll bars in sink, force table1 to end above
196 214
			// horizontal scrollbar
TXM/trunk/org.txm.specificities.rcp/src/org/txm/specificities/rcp/handlers/ComputeSpecifictiesSelectionChart.java (revision 3583)
16 16
import org.txm.specificities.core.functions.SpecificitiesSelection;
17 17
import org.txm.specificities.rcp.editors.SpecifLine;
18 18
import org.txm.specificities.rcp.editors.SpecificitiesEditor;
19
import org.txm.utils.logger.Log;
19 20

  
20 21

  
21 22

  
......
40 41
		if (selection instanceof SpecificitiesSelection && CorporaView.isActive()) { // test if the corpora view is active (otherwise, if a SpecificitiesSelection is selected, the creation from table
41 42
																					 // lines bugs )
42 43
			specificitiesSelection = (SpecificitiesSelection) selection;
44
			open(specificitiesSelection);
43 45
		}
44 46
		// Creates from SpecificitiesEditor selected table lines
45 47
		else {
......
48 50
				IWorkbenchPage iwp = iww.getActivePage();
49 51
				IEditorPart editor = iwp.getActiveEditor();
50 52
				if (!(editor instanceof SpecificitiesEditor)) {
51
					System.out.println("Editor is not a SpecificitiesEditor: " + editor.getClass());
53
					Log.warning("Editor is not a SpecificitiesEditor: " + editor.getClass());
52 54
					return null;
53 55
				}
54 56
				
55
				Specificities specificities = ((SpecificitiesEditor) editor).getResult();
56
				
57
				IStructuredSelection tableSelection = (IStructuredSelection) ((SpecificitiesEditor) editor).getTableSelection();
58
				Object[] tableLines = tableSelection.toArray();
59
				
60
				// no line selected
61
				if (tableSelection.isEmpty()) {
62
					return null;
63
				}
64
				
65
				final String[] selectedTypeNames = new String[tableLines.length];
66
				String[] partNames = specificities.getColumnsNames();
67
				final double[][] selectedSpecificitiesIndices = new double[tableLines.length][partNames.length];
68
				for (int i = 0; i < tableLines.length; i++) {
69
					Object o = tableLines[i];
70
					SpecifLine line = (SpecifLine)o;
71
					selectedTypeNames[i] = line.name;
72
					selectedSpecificitiesIndices[i] = line.specifs;
73
				}
74
				
75
				specificitiesSelection = new SpecificitiesSelection(specificities);
76
				
77
				// Set the data to focus on
78
				specificitiesSelection.setSelectedTypeNames(Arrays.asList(selectedTypeNames));
57
				open((SpecificitiesEditor) editor);
79 58
			}
80 59
			catch (Exception e) {
81 60
				System.out.println("Error while computing specificities bar chart: " + e.getLocalizedMessage());
......
83 62
			}
84 63
		}
85 64
		
65
		return null;
66
	}
67
	
68
	public static void open(SpecificitiesEditor editor) {
86 69
		
87
		ChartEditor.openEditor(specificitiesSelection);
70
		try {
71
			
72
			Specificities specificities = editor.getResult();
73
			
74
			IStructuredSelection tableSelection = (IStructuredSelection) ((SpecificitiesEditor) editor).getTableSelection();
75
			Object[] tableLines = tableSelection.toArray();
76
			
77
			// no line selected
78
			if (tableSelection.isEmpty()) {
79
				return;
80
			}
81
			
82
			final String[] selectedTypeNames = new String[tableLines.length];
83
			String[] partNames = specificities.getColumnsNames();
84
			final double[][] selectedSpecificitiesIndices = new double[tableLines.length][partNames.length];
85
			for (int i = 0; i < tableLines.length; i++) {
86
				Object o = tableLines[i];
87
				SpecifLine line = (SpecifLine)o;
88
				selectedTypeNames[i] = line.name;
89
				selectedSpecificitiesIndices[i] = line.specifs;
90
			}
91
			
92
			SpecificitiesSelection specificitiesSelection = new SpecificitiesSelection(specificities);
93
			
94
			// Set the data to focus on
95
			specificitiesSelection.setSelectedTypeNames(Arrays.asList(selectedTypeNames));
96
			
97
			open(specificitiesSelection);
98
		}
99
		catch (Exception e) {
100
			System.out.println("Error while computing specificities bar chart: " + e.getLocalizedMessage());
101
			org.txm.utils.logger.Log.printStackTrace(e);
102
		}
88 103
		
89
		return null;
90 104
	}
91 105
	
106
	public static void open(SpecificitiesSelection specificitiesSelection) {
107
		
108
		ChartEditor.openEditor(specificitiesSelection);
109
	}
110
	
92 111
}
TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteScript.java (revision 3583)
64 64
import org.txm.rcp.messages.TXMUIMessages;
65 65
import org.txm.rcp.preferences.RCPPreferences;
66 66
import org.txm.rcp.swt.dialog.LastOpened;
67
import org.txm.utils.logger.Log;
67 68
// TODO: Auto-generated Javadoc
68 69
/**
69 70
 * Execute a script. It uses the file extension to execute it as Groovy or R
......
200 201
		if ("groovy".equals(ext)) { // TODO make Groovy a script engine //$NON-NLS-1$
201 202
			return ExecuteGroovyScript.executeScript(scriptpath, page, selection);
202 203
		} else {
203
			ScriptEngine se = (ScriptEngine) Toolbox.getEngineManager(EngineType.SCRIPT).getEngine(ext);
204
			ScriptEnginesManager sem = (ScriptEnginesManager) Toolbox.getEngineManager(EngineType.SCRIPT);
205
			ScriptEngine se = (ScriptEngine) sem.getEngineForExtension(ext);
204 206
			if (se != null) {
205 207
				HashMap<String, Object> env = new HashMap<String, Object>();
206 208
				env.put("page", page); // selection //$NON-NLS-1$
207 209
				env.put("selection", selection); // selection //$NON-NLS-1$
208 210
				return se.executeScript(script, env, stringArgs);
209 211
			} else {
210
				System.out.println(TXMUIMessages.noInterpreterFoundForScriptFileExtension+script.getName());
212
				Log.warning(TXMUIMessages.noInterpreterFoundForScriptFileExtension+script.getName());
211 213
			}
212 214
		}
213 215
		
TXM/trunk/org.txm.python.rcp/src/org/txm/python/rcp/PythonPreferencesPage.java (revision 3583)
31 31
		
32 32
		this.addField(new StringFieldEditor(PythonPreferences.HOME, "HOME", this.getFieldEditorParent()));
33 33
		
34
		this.addField(new StringFieldEditor(PythonPreferences.EXECUTABLE_NAME, "PERL executable name", this.getFieldEditorParent()));
34
		this.addField(new StringFieldEditor(PythonPreferences.EXECUTABLE_NAME, "PYTHON executable path", this.getFieldEditorParent()));
35 35
		
36
		this.addField(new StringFieldEditor(PythonPreferences.ADDITIONAL_PARAMETERS, "PERL executable additional parameters", this.getFieldEditorParent()));
36
		this.addField(new StringFieldEditor(PythonPreferences.ADDITIONAL_PARAMETERS, "PYTHON executable additional parameters", this.getFieldEditorParent()));
37 37
	}
38 38
}
TXM/trunk/org.txm.python.core/src/org/txm/python/core/PythonScriptEngine.java (revision 3583)
17 17
import org.python.util.PythonInterpreter;
18 18
import org.txm.Toolbox;
19 19
import org.txm.core.engines.ScriptEngine;
20
import org.txm.utils.logger.Log;
20 21

  
21 22
public class PythonScriptEngine extends ScriptEngine {
22 23

  
......
74 75

  
75 76
	private static IStatus runJython(ArrayList<String> cmd, HashMap<String, Object> env) {
76 77

  
77
		PySystemState sys = Py.getSystemState();
78
		sys.path.append(new PyString(Toolbox.getTxmHomePath()+"/scripts/python"));
79
		sys.prefix = new PyString(Toolbox.getTxmHomePath()+"/scripts/python");
80
		PythonInterpreter interpreter = new PythonInterpreter(null, sys);
81
		
82
		for (String s : env.keySet()) {
83
			interpreter.set(s, env.get(s));
78
		try {
79
			PySystemState sys = Py.getSystemState();
80
			//if (sys.path == null || !sys.path.asString().contains(Toolbox.getTxmHomePath()+"/scripts/python")) {
81
			File sysdir = new File(Toolbox.getTxmHomePath()+"/scripts/python");
82
			sysdir.mkdirs();
83
				sys.path.append(new PyString(Toolbox.getTxmHomePath()+"/scripts/python"));
84
			//}
85
			//if (!sys.prefix.asString().equals(Toolbox.getTxmHomePath()+"/scripts/python")) {
86
				sys.prefix = new PyString(Toolbox.getTxmHomePath()+"/scripts/python");
87
			//}
88
			
89
			PythonInterpreter interpreter = new PythonInterpreter();
90
			
91
			for (String s : env.keySet()) {
92
				interpreter.set(s, env.get(s));
93
			}
94
			if (cmd.get(0).equals("-c")) {
95
				interpreter.exec(cmd.get(1));
96
			} else {
97
				interpreter.execfile(cmd.get(0));
98
			}
99
			interpreter.close();
100
			return Status.OK_STATUS;
84 101
		}
85
		if (cmd.get(0).equals("-c")) {
86
			interpreter.exec(cmd.get(1));
87
		} else {
88
			interpreter.execfile(cmd.get(0));
102
		catch (Throwable e) {
103
			Log.warning("Jython error: "+e);
104
			e.printStackTrace();
105
			return Status.CANCEL_STATUS;
89 106
		}
90
		interpreter.close();
91
		return Status.OK_STATUS;
107
		
92 108
	}
93 109

  
94 110
	private static IStatus runPython(ArrayList<String> cmd, HashMap<String, Object> env) {
......
131 147
			}
132 148
			System.out.println("Done.");
133 149
		} catch (Exception e) {
134
			e.printStackTrace();
150
			Log.warning("Python error: "+e);
151
			Log.printStackTrace(e);
135 152
			return Status.CANCEL_STATUS;
136 153
		}
137 154
		return Status.OK_STATUS;

Formats disponibles : Unified diff