Issue 118478 - To support getInvocationContext in Python scripts
To support getInvocationContext in Python scripts
Status: RESOLVED FIXED
Product: App Dev
Classification: Unclassified
Component: scripting
OOo 3.3 or older
PC All
: P5 normal
: 4.0.0
Assigned To: kay.ramme
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-10-03 09:57 UTC by hanya
Modified: 2013-07-11 12:43 UTC (History)
2 users (show)

See Also:
Issue Type: PATCH
Latest Confirmation on: ---
Developer Difficulty: ---


Attachments
Add getInvocationContext function to pythonscript.py (4.19 KB, patch)
2011-10-03 09:57 UTC, hanya
no flags Details | Diff
Simple test for invocation context of python script (14.00 KB, application/octet-stream)
2011-10-03 10:07 UTC, hanya
no flags Details
Patch reconstructed for AOO (4.13 KB, patch)
2012-05-26 02:37 UTC, hanya
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this issue.
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.