Issue 118478

Summary: To support getInvocationContext in Python scripts
Product: App Dev Reporter: hanya <hanya.runo>
Component: scriptingAssignee: kay.ramme
Status: CLOSED FIXED QA Contact:
Severity: Normal    
Priority: P5 (lowest) CC: arielch, issues
Version: 3.3.0 or older (OOo)   
Target Milestone: 4.0.0   
Hardware: PC   
OS: All   
Issue Type: PATCH Latest Confirmation in: ---
Developer Difficulty: ---
Attachments:
Description Flags
Add getInvocationContext function to pythonscript.py
none
Simple test for invocation context of python script
none
Patch reconstructed for AOO none

Description hanya 2011-10-03 09:57:17 UTC
Created attachment 76855 [details]
Add getInvocationContext function to pythonscript.py

When I try to execute a python script stored in the Text document as a form embedded in a Base document, script framework error causes.
The pythonscript.py has problem about invocation context. I made a patch to fix it.
Comment 1 hanya 2011-10-03 10:07:27 UTC
Created attachment 76856 [details]
Simple test for invocation context of python script

Attached file containes a form document which has two button on it. One for Python text and another for Java's example.
When Java button is pushed, getDocument method returns the object of Base docuemnt and getInvocationContext method returns the form document object. It should be the same in Python scripting.
When Python button is pushed, getDocument should be Base document and getInvocationContext should be Text document.

The test scripts are the same as follows: 
Python test
def hello(*args):
	doc = XSCRIPTCONTEXT.getDocument()
	inv = XSCRIPTCONTEXT.getInvocationContext()
	
	base_doc = doc.supportsService("com.sun.star.sdb.OfficeDatabaseDocument")
	text_doc = inv.supportsService("com.sun.star.text.TextDocument")
	
	text = inv.getText()
	text.setString(
	    "Python\n" + 
	    ("getDocument is Base Document?: %s\n" % base_doc) + 
	    ("getInvocationContext is Text Document?: %s" % text_doc))

Code for Java.
package test.macro;

import com.sun.star.awt.ActionEvent;
import com.sun.star.document.XScriptInvocationContext;
import com.sun.star.frame.XModel;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.script.provider.XScriptContext;
import com.sun.star.text.XText;
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.UnoRuntime;

public class Test {

	public static void test(XScriptContext xScriptContext, ActionEvent ev) {
		XModel doc = xScriptContext.getDocument();
		XScriptInvocationContext xInv = xScriptContext.getInvocationContext();
		XModel inv = UnoRuntime.queryInterface(XModel.class, xInv);
		
		boolean base_doc = UnoRuntime.queryInterface(XServiceInfo.class, doc).
			supportsService("com.sun.star.sdb.OfficeDatabaseDocument");
		boolean text_doc = UnoRuntime.queryInterface(XServiceInfo.class, inv).
			supportsService("com.sun.star.text.TextDocument");
		
		XTextDocument xTextDocument = UnoRuntime.queryInterface(XTextDocument.class, xInv);
		XText xText = xTextDocument.getText();
		xText.setString(
				"Java\n" + 
				"getDocument is Base Document?: " + base_doc + "\n"+ 
				"getInvocationContext is Text Document?: " + text_doc);
	}
	
	public static void main(String[] args) {
	}
}
Comment 2 Ariel Constenla-Haile 2012-05-25 12:21:57 UTC
@hanya: is the issue still present? If so, can you provide patches updated to AOO source?
Comment 3 hanya 2012-05-26 02:37:37 UTC
Created attachment 77603 [details]
Patch reconstructed for AOO

(In reply to comment #2)
> @hanya: is the issue still present? If so, can you provide patches updated
> to AOO source?

Still valid on AOO 3.4.0. new patch for recent revision 1342730.
Comment 4 Ariel Constenla-Haile 2012-05-30 04:09:24 UTC
Committed as Revision 1344092

@hanya: Many thanks for your contribution.
Comment 5 Oliver-Rainer Wittmann 2012-06-13 12:28:13 UTC
getting rid of value "enhancement" for field "severity".
For enhancement the field "issue type" shall be used.