<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openoffice.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Hanya</id>
	<title>Apache OpenOffice Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openoffice.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Hanya"/>
	<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/wiki/Special:Contributions/Hanya"/>
	<updated>2026-05-25T03:36:17Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.14</generator>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=236881</id>
		<title>Python/Transfer from Basic to Python</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=236881"/>
		<updated>2015-11-15T15:18:24Z</updated>

		<summary type="html">&lt;p&gt;Hanya: /* Input Box */ Set label to no label on the input box&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Transfer from Basic to Python}}&lt;br /&gt;
&lt;br /&gt;
Translation [[ES/Manuales/GuiaAOO/TemasAvanzados/Macros/Python/BasicAPython| Español]]&lt;br /&gt;
&lt;br /&gt;
If you feel some displeasure at StarBasic/OpenOffice Basic or you meet requirement of custom UNO component, now it is the time to transfer coding environment from Basic to Python.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, there are some runtime function provides shortcut to do something. But using Python-UNO bridge, you have to do such task by API ways.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s start with Python&amp;#039;s tutorial and return back to here when you have learned a bit about Python language.&lt;br /&gt;
&lt;br /&gt;
== Macro Location ==&lt;br /&gt;
On the current version, script organizer for Python do not provide the way to manage script files. So you have to manage yourself. Macros written in Python should be placed in the specific directory under your user&amp;#039;s profile, shared profile or script directory of your document.&lt;br /&gt;
&lt;br /&gt;
The python directory (in all lowercase) should be created in Scripts directory and you can put your python scripts that contain python code.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
path_to_directory/Scripts/python/your_file.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can make subdirectories to put macro files in them under Scripts/python directory.&lt;br /&gt;
&lt;br /&gt;
You have to add &amp;quot;py&amp;quot; file extension to your file name.&lt;br /&gt;
&lt;br /&gt;
== Macro Editor ==&lt;br /&gt;
&lt;br /&gt;
There is no built-in editor dedicated to code in Python. But you can choose your favorite text editor application to edit your Python script.&lt;br /&gt;
&lt;br /&gt;
This is discussed in another page.&lt;br /&gt;
&lt;br /&gt;
== Short Example ==&lt;br /&gt;
&lt;br /&gt;
Here is a small example written in Python.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello():&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Each callable function is the executable unit of Python macro (you can choose which function should be listed in the GUI, see other document).&lt;br /&gt;
&lt;br /&gt;
You can access the current document through getDocument method of XSCRIPTCONTEXT variable of the module. And it changes the document content to &amp;quot;Hello!&amp;quot; of the Writer document.&lt;br /&gt;
&lt;br /&gt;
== Usable Modules ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 import unohelper&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Script Context ==&lt;br /&gt;
&lt;br /&gt;
StarBasic is embedded runtime and it always works with living instance of the office. So the context is always the match with the office&amp;#039;s one. But Python-UNO bridge provides the way to work as RPC client. At that time, remote Python instance does have different context from the office instance. Therefore you have to use correct component context to tell to the multi component factory to instantiate a service.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you have no matching object provided.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039; macro, you have to use &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; module variable that provides &amp;lt;idl&amp;gt;com.sun.star.script.provider.XScriptContext&amp;lt;/idl&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XModel&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDocument()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current document object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.document.XScriptInvocationContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getInvocationContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns invocation dependent object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XDesktop&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDesktop()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns instance of &amp;lt;idl&amp;gt;com.sun.star.frame.Desktop&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.uno.XComponentContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getComponentContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current component context that is used to tell the which context is.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; variable is defined in module level and it is not provided to imported modules from your script.&lt;br /&gt;
&lt;br /&gt;
== Component Context ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get component context as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = GetDefaultContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But you do not need to access to it until you need to get singletons.&lt;br /&gt;
&lt;br /&gt;
In Python, you can get access to the component context through the script context.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need this value to instantiate services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service Manager ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get service manager as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 smgr = GetProcessServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But not so many people having to access to it.&lt;br /&gt;
&lt;br /&gt;
In Python, this instance is most important value to instantiate services to work with the office APIs.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need both the component context and the service manager to instantiate services.&lt;br /&gt;
&lt;br /&gt;
== Service Instance ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can instantiate services by built-in function as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 sfa = CreateUnoService(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or with initialize arguments: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 arg = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = CreateUnoServiceWithArguments(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, Array(arg))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Python, you have to work with com.sun.star.lang.XMultiComponentFactory interface as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
 sfa = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;, ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to initialize the instance, use createInstanceWithArgumentsAndContext method: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = smgr.createInstanceWithArgumentsAndContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, (FILESAVE_SIMPLE,) ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or initialize after the instantiation: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 file_picker = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, ctx)&lt;br /&gt;
 file_picker.initialize((FILESAVE_SIMPLE,))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service with Constructor ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can call service construct from its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 shell_execute = com.sun.star.system.SystemShellExecute.create()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you have to instantiate it with XMultiComponentFactory::createInstanceWithArgumentsAndContext method with initial arguments or instantiate after the instantiation.&lt;br /&gt;
&lt;br /&gt;
The constructor calling does type checking before to pass arguments to createInstanceWithArgumentsAndContext method.&lt;br /&gt;
&lt;br /&gt;
== Current Document ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ThisComponent runtime function provides access to the current document: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = ThisComponent&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Its return value is bound to the macro location. If the macro stored in a document, the result of ThisComponent is the document that the storage of the macro belongs to. And if your macro is stored in application wide, the returned value is the document model of currently active frame, this is the same result taken from StarDesktop.&amp;#039;&amp;#039;&amp;#039;getCurrentComponent()&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can access to the current document through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If your macro is &amp;#039;&amp;#039;&amp;#039;embedded in the document&amp;#039;&amp;#039;&amp;#039;, the document model is match with the document that the macro stored in. If your macro is stored in user or shared location, the document object is from active frame.&lt;br /&gt;
&lt;br /&gt;
== Desktop ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, StarDesktop runtime function is provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = StarDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can get access to the desktop through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = XSCRIPTCONTEXT.getDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Struct Instance ==&lt;br /&gt;
&lt;br /&gt;
In Basic, instance of struct can be instantiated in two ways: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Dim a As New com.sun.star.awt.Point&lt;br /&gt;
 a = CreateUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
With Dim statement and New keyword, you can instantiate a struct or array of structs. Or CreateUnoStruct method provides the way to instantiate a struct at runtime. You can not initialize the instance at the creation, you have to set its value of members.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can use the following ways to instantiate a struct. Import struct class and call it.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.awt import Point&lt;br /&gt;
&lt;br /&gt;
 a = Point()         # instantiate with default values, X=0, Y=0&lt;br /&gt;
 b = Point(100, 200) # initialize with initial values, X=100, Y=200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Calling the class to create new instance of the struct, you can empty its arguments or you have to pass values for all fields. In other words, you can not pass insufficient number of arguments to initialize. And its order should be match with definition of the struct in its IDL. For example, instance of struct b having X=100 and Y=200 in the above piece of code.&lt;br /&gt;
&lt;br /&gt;
You can initialize without to import the class of your target struct with uno.createUnoStruct function as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 a = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
 b = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This makes the same result with the above example. The first parameter of the createUnoStruct method is the name of the struct to initialize. The following arguments are initial values for new instance.&lt;br /&gt;
&lt;br /&gt;
== Enum ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can access to the module of the enum as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ITALIC = com.sun.star.awt.FontSlant.ITALIC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following ways can be used: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontSlant import ITALIC&lt;br /&gt;
 ITALIC = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontSlant.ITALIC&amp;quot;)&lt;br /&gt;
 ITALIC = uno.Enum(&amp;quot;com.sun.star.awt.FontSlant&amp;quot;, &amp;quot;ITALIC&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
All of the way results the instance of uno.Enum class.&lt;br /&gt;
&lt;br /&gt;
== Constants ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get access to constants through its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 BOLD = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways are provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontWeight import BOLD&lt;br /&gt;
 BOLD = uno.getConstantsByName(&amp;quot;com.sun.star.awt.FontWeight.BOLD&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sequence ==&lt;br /&gt;
&lt;br /&gt;
The sequence is sequential value of the same type.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, array is used.&lt;br /&gt;
&lt;br /&gt;
In Python, tuple is chosen to represent UNO&amp;#039;s sequence. Note, list is not allowed to pass as sequence value.&lt;br /&gt;
&lt;br /&gt;
== Boolean ==&lt;br /&gt;
&lt;br /&gt;
In Python, True or False.&lt;br /&gt;
&lt;br /&gt;
== String ==&lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;s string can contain over 64K bytes.&lt;br /&gt;
&lt;br /&gt;
If you have to write non Ascii 7 bit characters in your script, write magic comment at the head of your file. This is standard Python instructions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # -*- coding: utf_8 -*-&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please read Python&amp;#039;s documentation for more detail.&lt;br /&gt;
&lt;br /&gt;
You have to use unicode string to write some unicode characters in Python 2.X. And strings coming from UNO is decoded in unicode in Python 2.X.&lt;br /&gt;
&lt;br /&gt;
== Char ==&lt;br /&gt;
&lt;br /&gt;
There is no dedicated value for char type in StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, uno.Char class is defined for char type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 c = uno.Char(&amp;quot;a&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Type ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Type&amp;quot; type is meta type of UNO that represents type of UNO.&lt;br /&gt;
Since 3.4, if you pass string value to method as an argument that should be type, the bridge of Basic read it as type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
oMap = com.sun.star.container.EnumerableMap.create(&amp;quot;string&amp;quot;, &amp;quot;string&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways can be used to create new valu of type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 t = uno.getTypeByName(&amp;quot;string&amp;quot;)&lt;br /&gt;
 t = uno.Type(&amp;quot;string&amp;quot;, uno.Enum(&amp;quot;com.sun.star.uno.TypeClass&amp;quot;, &amp;quot;STRING&amp;quot;))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Byte Sequence ==&lt;br /&gt;
&lt;br /&gt;
The byte sequence is sequence of byte type.&lt;br /&gt;
&lt;br /&gt;
In Basic, array of byte is used to represent it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, it is represented by str wrapped by uno.ByteSequence class. If you takes some byte sequences from UNO, they are the instance of uno.ByteSequence. If you need to get real value of them, refer its &amp;#039;&amp;#039;value&amp;#039;&amp;#039; instance variable.&lt;br /&gt;
&lt;br /&gt;
== Exception ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you get thrown exception as some error. And On Error statement is used to catch it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub ErrorExample&lt;br /&gt;
&lt;br /&gt;
   On Error GoTo Handler&lt;br /&gt;
&lt;br /&gt;
   &amp;#039; ... error&lt;br /&gt;
&lt;br /&gt;
   Exit Sub&lt;br /&gt;
&lt;br /&gt;
   Handler: &lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
And you can not throw any exceptions from StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, the exception thrown in UNO world can be treated as normal Python&amp;#039;s exception. Here is an example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.container import IndexOutOfBoundsException&lt;br /&gt;
&lt;br /&gt;
 try:&lt;br /&gt;
     obj.getByIndex(100) # raises IndexOutOfBoundsException&lt;br /&gt;
 except IndexOutOfBoundsException as e:&lt;br /&gt;
     print(e)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If getByIndex method raises IndexOutOfBoundsException, it can be caught in except statement because all exceptions inherit Python&amp;#039;s Exception class.&lt;br /&gt;
&lt;br /&gt;
And also you can throw UNO&amp;#039;s exception from your Python code as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.uno import RuntimeException&lt;br /&gt;
 raise RuntimeException(&amp;quot;Some message&amp;quot;, None)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Empty Value ==&lt;br /&gt;
&lt;br /&gt;
In Basic, there are some situations to meet variables that they do not contain any value (this is not correct). Null, empty, missing, nothing and so on.&lt;br /&gt;
&lt;br /&gt;
In Python, None is used. If a method defined as void return value in its IDL, it results None if you call it. If you need to pass invalid interface as an argument for the method that takes some interface, pass None for it. The result of this behavior is fully dependent to the implementation of the method.&lt;br /&gt;
&lt;br /&gt;
== Listener and Interface ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can create new listener using CreateUnoListener runtime function with some subroutines or functions.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub Add&lt;br /&gt;
&lt;br /&gt;
   d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
   listener = CreateUnoListener(&amp;quot;ActionListener&amp;quot;, &amp;quot;com.sun.star.awt.XActionListener&amp;quot;)&lt;br /&gt;
   d.getControl(&amp;quot;CommandButton1&amp;quot;).addActionListener(listener)&lt;br /&gt;
   d.execute()&lt;br /&gt;
   d.dispose()&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 Sub ActionListener_actionPerformed(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 Sub ActionListener_disposing(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you have to define your own class with desired interfaces. With helper class, you can define easily as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import unohelper&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt import XActionListener&lt;br /&gt;
&lt;br /&gt;
 class ActionListener(unohelper.Base, XActionListener):&lt;br /&gt;
     def __init__(self):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def disposing(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def actionPerformed(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
unohelper.Base class provides required interface for UNO components.&lt;br /&gt;
&lt;br /&gt;
== Containers ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, container object provides the way to access to its contents in sequentially.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, there is no shortcut provided. &lt;br /&gt;
&lt;br /&gt;
If you need to access to elements of indexed container, use range function to generate sequential indexes.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 for i in range(container.getCount()):&lt;br /&gt;
     obj = container.getByIndex(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== URL and System Path ==&lt;br /&gt;
&lt;br /&gt;
If you work with a file stored in your local file system, you have to get its corresponding URL.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ConvertToURL runtime function is prepared for this task. And there is ConvertFromURL runtime function for reverse conversion.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following functions are defined in uno module for such task.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 path = &amp;quot;/home/foo/Documents/file.odt&amp;quot;&lt;br /&gt;
 url = uno.sytemPathToFileUrl(path)&lt;br /&gt;
 path = uno.fileUrlToSystemPath(url)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments and Return Value ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, mode of the first argument of parseStrict method is &amp;quot;inout&amp;quot; in the following code: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 aURL = CreateUnoStruct(&amp;quot;com.sun.star.util.URL&amp;quot;)&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 CreateUnoService(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;).parseStrict(aURL)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The content of aURL variable is updated after calling the method.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, out mode parameter is returned as part of return value.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.util import URL&lt;br /&gt;
&lt;br /&gt;
 aURL = URL()&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 dummy, aURL = smgr.createInstanceWithContext(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;, ctx).parseStrict(aURL)&lt;br /&gt;
 # Definition of com.sun.star.util.XURLTransformer::parseStrict method: &lt;br /&gt;
 # void parseStrict([inout] com.sun.star.util.URL aURL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If a method has out mode in its parameters, its return is always tuple that contains original return value and values for out parameters.&lt;br /&gt;
&lt;br /&gt;
Here is a potential example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # boolean getSomeValue([in] string aName, [out] short aNum, [inout] long aNum2);&lt;br /&gt;
 result, num, num2 = obj.getSomeValue(&amp;quot;foo&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above example, &amp;#039;&amp;#039;result&amp;#039;&amp;#039; variable takes original return value, &amp;#039;&amp;#039;num&amp;#039;&amp;#039; takes output value for second parameter and &amp;#039;&amp;#039;num2&amp;#039;&amp;#039; takes output value for third parameter. The method takes 100 as the second parameter but it is not used as input of value. No entry in returned tuple for in mode parameter.&lt;br /&gt;
&lt;br /&gt;
== Functions to be Executed ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can not choose routines to be executed by users.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, define &amp;#039;&amp;#039;&amp;#039;g_exportedScripts&amp;#039;&amp;#039;&amp;#039; variable that contains tuple of callable in your macro file.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def func_a(): pass&lt;br /&gt;
 def func_b(): pass&lt;br /&gt;
 def func_hidden(): pass # not shown in the UI&lt;br /&gt;
 &lt;br /&gt;
 g_exportedScripts = func_a, func_b&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above code, func_hidden is not shown in execution dialog of macros.&lt;br /&gt;
&lt;br /&gt;
== Importing Modules ==&lt;br /&gt;
In Basic, you can call subroutines defined in other modules or other libraries that has been loaded.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
BasicLibraries.loadLibrary(&amp;quot;Library1&amp;quot;)&lt;br /&gt;
Library1.Foo()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you can import some modules that can be found in sys.path list. If you want to import your own module placed inside Scripts/python directory, put your module in pythonpath directory nearby your script file.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 - Scripts/&lt;br /&gt;
   - python/&lt;br /&gt;
     - macro.py&lt;br /&gt;
     - pythonpath/  # this directory is added automatically before your macro executed&lt;br /&gt;
       - your_module.py  # this module can be found&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When you execute the macro from your script file, the internal executor adds the pythonpath/ directory to sys.path list to be used as one of lookup location.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, the name of module conflict each other if you have the same named module in the some location, this is the standard python mechanism of importing modules, put your each modules in differently named library to avoid the name conflict.&lt;br /&gt;
&lt;br /&gt;
== Dialog ==&lt;br /&gt;
In Basic, there is CreateUnoDialog runtime function to instantiate the dialog.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 DialogLibraries.loadLibrary(&amp;quot;Standard&amp;quot;)&lt;br /&gt;
 dialog = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
 dialog.execute()&lt;br /&gt;
 dialog.dispose()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, such shortcut function is not provided but you can easily instantiate your dialog using &amp;lt;idl&amp;gt;com.sun.star.awt.DialogProvider&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def dialog_example():&lt;br /&gt;
     ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
     smgr = ctx.getServiceManager()&lt;br /&gt;
     dp = smgr.createInstanceWithContext(&amp;quot;com.sun.star.awt.DialogProvider&amp;quot;, ctx)&lt;br /&gt;
     dialog = dp.createDialog(&amp;quot;vnd.sun.star.script:Standard.Dialog1?location=user&amp;quot;)&lt;br /&gt;
     dialog.execute()&lt;br /&gt;
     dialog.dispose()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Message Box ==&lt;br /&gt;
In Basic, you can use MsgBox runtime function to show some message to the users.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
  Msgbox &amp;quot;Hello.&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, no shortcut function is provided but you can use &amp;lt;idl&amp;gt;com.sun.star.awt.XMessageBoxFactory&amp;lt;/idl&amp;gt; interface through the toolkit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
def messagebox(ctx, parent, message, title, message_type, buttons):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Show message in message box. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    toolkit = parent.getToolkit()&lt;br /&gt;
    older_imple = check_method_parameter(&lt;br /&gt;
        ctx, &amp;quot;com.sun.star.awt.XMessageBoxFactory&amp;quot;, &amp;quot;createMessageBox&amp;quot;, &lt;br /&gt;
        1, &amp;quot;com.sun.star.awt.Rectangle&amp;quot;)&lt;br /&gt;
    if older_imple:&lt;br /&gt;
        msgbox = toolkit.createMessageBox(&lt;br /&gt;
            parent, Rectangle(), message_type, buttons, title, message)&lt;br /&gt;
    else:&lt;br /&gt;
        message_type = uno.getConstantByName(&amp;quot;com.sun.star.awt.MessageBoxType.&amp;quot; + {&lt;br /&gt;
            &amp;quot;messbox&amp;quot;: &amp;quot;MESSAGEBOX&amp;quot;, &amp;quot;infobox&amp;quot;: &amp;quot;INFOBOX&amp;quot;, &lt;br /&gt;
            &amp;quot;warningbox&amp;quot;: &amp;quot;WARNINGBOX&amp;quot;, &amp;quot;errorbox&amp;quot;: &amp;quot;ERRORBOX&amp;quot;, &lt;br /&gt;
            &amp;quot;querybox&amp;quot;: &amp;quot;QUERYBOX&amp;quot;}[message_type])&lt;br /&gt;
        msgbox = toolkit.createMessageBox(&lt;br /&gt;
            parent, message_type, buttons, title, message)&lt;br /&gt;
    n = msgbox.execute()&lt;br /&gt;
    msgbox.dispose()&lt;br /&gt;
    return n&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def check_method_parameter(ctx, interface_name, method_name, param_index, param_type):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Check the method has specific type parameter at the specific position. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    cr = create_service(ctx, &amp;quot;com.sun.star.reflection.CoreReflection&amp;quot;)&lt;br /&gt;
    try:&lt;br /&gt;
        idl = cr.forName(interface_name)&lt;br /&gt;
        m = idl.getMethod(method_name)&lt;br /&gt;
        if m:&lt;br /&gt;
            info = m.getParameterInfos()[param_index]&lt;br /&gt;
            return info.aType.getName() == param_type&lt;br /&gt;
    except:&lt;br /&gt;
        pass&lt;br /&gt;
    return False&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Input Box ==&lt;br /&gt;
&lt;br /&gt;
No function provided for Python, you have to make your own one. Here is an example: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;def inputbox(message, title=&amp;quot;&amp;quot;, default=&amp;quot;&amp;quot;, x=None, y=None):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Shows dialog with input box.&lt;br /&gt;
        @param message message to show on the dialog&lt;br /&gt;
        @param title window title&lt;br /&gt;
        @param default default value&lt;br /&gt;
        @param x dialog positio in twips, pass y also&lt;br /&gt;
        @param y dialog position in twips, pass y also&lt;br /&gt;
        @return string if OK button pushed, otherwise zero length string&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    WIDTH = 600&lt;br /&gt;
    HORI_MARGIN = VERT_MARGIN = 8&lt;br /&gt;
    BUTTON_WIDTH = 100&lt;br /&gt;
    BUTTON_HEIGHT = 26&lt;br /&gt;
    HORI_SEP = VERT_SEP = 8&lt;br /&gt;
    LABEL_HEIGHT = BUTTON_HEIGHT * 2 + 5&lt;br /&gt;
    EDIT_HEIGHT = 24&lt;br /&gt;
    HEIGHT = VERT_MARGIN * 2 + LABEL_HEIGHT + VERT_SEP + EDIT_HEIGHT&lt;br /&gt;
    import uno&lt;br /&gt;
    from com.sun.star.awt.PosSize import POS, SIZE, POSSIZE&lt;br /&gt;
    from com.sun.star.awt.PushButtonType import OK, CANCEL&lt;br /&gt;
    from com.sun.star.util.MeasureUnit import TWIP&lt;br /&gt;
    ctx = uno.getComponentContext()&lt;br /&gt;
    def create(name):&lt;br /&gt;
        return ctx.getServiceManager().createInstanceWithContext(name, ctx)&lt;br /&gt;
    dialog = create(&amp;quot;com.sun.star.awt.UnoControlDialog&amp;quot;)&lt;br /&gt;
    dialog_model = create(&amp;quot;com.sun.star.awt.UnoControlDialogModel&amp;quot;)&lt;br /&gt;
    dialog.setModel(dialog_model)&lt;br /&gt;
    dialog.setVisible(False)&lt;br /&gt;
    dialog.setTitle(title)&lt;br /&gt;
    dialog.setPosSize(0, 0, WIDTH, HEIGHT, SIZE)&lt;br /&gt;
    def add(name, type, x_, y_, width_, height_, props):&lt;br /&gt;
        model = dialog_model.createInstance(&amp;quot;com.sun.star.awt.UnoControl&amp;quot; + type + &amp;quot;Model&amp;quot;)&lt;br /&gt;
        dialog_model.insertByName(name, model)&lt;br /&gt;
        control = dialog.getControl(name)&lt;br /&gt;
        control.setPosSize(x_, y_, width_, height_, POSSIZE)&lt;br /&gt;
        for key, value in props.items():&lt;br /&gt;
            setattr(model, key, value)&lt;br /&gt;
    label_width = WIDTH - BUTTON_WIDTH - HORI_SEP - HORI_MARGIN * 2&lt;br /&gt;
    add(&amp;quot;label&amp;quot;, &amp;quot;FixedText&amp;quot;, HORI_MARGIN, VERT_MARGIN, label_width, LABEL_HEIGHT, &lt;br /&gt;
        {&amp;quot;Label&amp;quot;: str(message), &amp;quot;NoLabel&amp;quot;: True})&lt;br /&gt;
    add(&amp;quot;btn_ok&amp;quot;, &amp;quot;Button&amp;quot;, HORI_MARGIN + label_width + HORI_SEP, VERT_MARGIN, &lt;br /&gt;
            BUTTON_WIDTH, BUTTON_HEIGHT, {&amp;quot;PushButtonType&amp;quot;: OK, &amp;quot;DefaultButton&amp;quot;: True})&lt;br /&gt;
    add(&amp;quot;btn_cancel&amp;quot;, &amp;quot;Button&amp;quot;, HORI_MARGIN + label_width + HORI_SEP, VERT_MARGIN + BUTTON_HEIGHT + 5, &lt;br /&gt;
            BUTTON_WIDTH, BUTTON_HEIGHT, {&amp;quot;PushButtonType&amp;quot;: CANCEL})&lt;br /&gt;
    add(&amp;quot;edit&amp;quot;, &amp;quot;Edit&amp;quot;, HORI_MARGIN, LABEL_HEIGHT + VERT_MARGIN + VERT_SEP, &lt;br /&gt;
            WIDTH - HORI_MARGIN * 2, EDIT_HEIGHT, {&amp;quot;Text&amp;quot;: str(default)})&lt;br /&gt;
    frame = create(&amp;quot;com.sun.star.frame.Desktop&amp;quot;).getCurrentFrame()&lt;br /&gt;
    window = frame.getContainerWindow() if frame else None&lt;br /&gt;
    dialog.createPeer(create(&amp;quot;com.sun.star.awt.Toolkit&amp;quot;), window)&lt;br /&gt;
    if not x is None and not y is None:&lt;br /&gt;
        ps = dialog.convertSizeToPixel(uno.createUnoStruct(&amp;quot;com.sun.star.awt.Size&amp;quot;, x, y), TWIP)&lt;br /&gt;
        _x, _y = ps.Width, ps.Height&lt;br /&gt;
    elif window:&lt;br /&gt;
        ps = window.getPosSize()&lt;br /&gt;
        _x = ps.Width / 2 - WIDTH / 2&lt;br /&gt;
        _y = ps.Height / 2 - HEIGHT / 2&lt;br /&gt;
    dialog.setPosSize(_x, _y, 0, 0, POS)&lt;br /&gt;
    edit = dialog.getControl(&amp;quot;edit&amp;quot;)&lt;br /&gt;
    edit.setSelection(uno.createUnoStruct(&amp;quot;com.sun.star.awt.Selection&amp;quot;, 0, len(str(default))))&lt;br /&gt;
    edit.setFocus()&lt;br /&gt;
    ret = edit.getModel().Text if dialog.execute() else &amp;quot;&amp;quot;&lt;br /&gt;
    dialog.dispose()&lt;br /&gt;
    return ret&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function can be called as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
inputbox(&amp;quot;Please input some value&amp;quot;, &amp;quot;Input&amp;quot;, &amp;quot;Default value&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Executing Macros from Toolbar Buttons ==&lt;br /&gt;
In Basic, you can call any subroutines or functions through toolbar buttons. &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
Sub WriteHello()&lt;br /&gt;
  ThisComponent.getText().getEnd().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, you have to define your Python function with an argument (or variable length arguments) to take an argument passed when the function executed through assigned toolbar button.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
def writeHello(*args):&lt;br /&gt;
    # writeHello(arg): is also ok but if you want to call this function &lt;br /&gt;
    # by some ways, define your function takes variable arguments.&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().getEnd().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=236880</id>
		<title>Python/Transfer from Basic to Python</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=236880"/>
		<updated>2015-11-15T15:08:53Z</updated>

		<summary type="html">&lt;p&gt;Hanya: /* Input Box */ Add example about input box&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Transfer from Basic to Python}}&lt;br /&gt;
&lt;br /&gt;
Translation [[ES/Manuales/GuiaAOO/TemasAvanzados/Macros/Python/BasicAPython| Español]]&lt;br /&gt;
&lt;br /&gt;
If you feel some displeasure at StarBasic/OpenOffice Basic or you meet requirement of custom UNO component, now it is the time to transfer coding environment from Basic to Python.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, there are some runtime function provides shortcut to do something. But using Python-UNO bridge, you have to do such task by API ways.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s start with Python&amp;#039;s tutorial and return back to here when you have learned a bit about Python language.&lt;br /&gt;
&lt;br /&gt;
== Macro Location ==&lt;br /&gt;
On the current version, script organizer for Python do not provide the way to manage script files. So you have to manage yourself. Macros written in Python should be placed in the specific directory under your user&amp;#039;s profile, shared profile or script directory of your document.&lt;br /&gt;
&lt;br /&gt;
The python directory (in all lowercase) should be created in Scripts directory and you can put your python scripts that contain python code.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
path_to_directory/Scripts/python/your_file.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can make subdirectories to put macro files in them under Scripts/python directory.&lt;br /&gt;
&lt;br /&gt;
You have to add &amp;quot;py&amp;quot; file extension to your file name.&lt;br /&gt;
&lt;br /&gt;
== Macro Editor ==&lt;br /&gt;
&lt;br /&gt;
There is no built-in editor dedicated to code in Python. But you can choose your favorite text editor application to edit your Python script.&lt;br /&gt;
&lt;br /&gt;
This is discussed in another page.&lt;br /&gt;
&lt;br /&gt;
== Short Example ==&lt;br /&gt;
&lt;br /&gt;
Here is a small example written in Python.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello():&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Each callable function is the executable unit of Python macro (you can choose which function should be listed in the GUI, see other document).&lt;br /&gt;
&lt;br /&gt;
You can access the current document through getDocument method of XSCRIPTCONTEXT variable of the module. And it changes the document content to &amp;quot;Hello!&amp;quot; of the Writer document.&lt;br /&gt;
&lt;br /&gt;
== Usable Modules ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 import unohelper&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Script Context ==&lt;br /&gt;
&lt;br /&gt;
StarBasic is embedded runtime and it always works with living instance of the office. So the context is always the match with the office&amp;#039;s one. But Python-UNO bridge provides the way to work as RPC client. At that time, remote Python instance does have different context from the office instance. Therefore you have to use correct component context to tell to the multi component factory to instantiate a service.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you have no matching object provided.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039; macro, you have to use &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; module variable that provides &amp;lt;idl&amp;gt;com.sun.star.script.provider.XScriptContext&amp;lt;/idl&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XModel&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDocument()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current document object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.document.XScriptInvocationContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getInvocationContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns invocation dependent object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XDesktop&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDesktop()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns instance of &amp;lt;idl&amp;gt;com.sun.star.frame.Desktop&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.uno.XComponentContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getComponentContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current component context that is used to tell the which context is.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; variable is defined in module level and it is not provided to imported modules from your script.&lt;br /&gt;
&lt;br /&gt;
== Component Context ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get component context as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = GetDefaultContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But you do not need to access to it until you need to get singletons.&lt;br /&gt;
&lt;br /&gt;
In Python, you can get access to the component context through the script context.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need this value to instantiate services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service Manager ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get service manager as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 smgr = GetProcessServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But not so many people having to access to it.&lt;br /&gt;
&lt;br /&gt;
In Python, this instance is most important value to instantiate services to work with the office APIs.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need both the component context and the service manager to instantiate services.&lt;br /&gt;
&lt;br /&gt;
== Service Instance ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can instantiate services by built-in function as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 sfa = CreateUnoService(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or with initialize arguments: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 arg = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = CreateUnoServiceWithArguments(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, Array(arg))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Python, you have to work with com.sun.star.lang.XMultiComponentFactory interface as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
 sfa = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;, ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to initialize the instance, use createInstanceWithArgumentsAndContext method: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = smgr.createInstanceWithArgumentsAndContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, (FILESAVE_SIMPLE,) ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or initialize after the instantiation: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 file_picker = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, ctx)&lt;br /&gt;
 file_picker.initialize((FILESAVE_SIMPLE,))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service with Constructor ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can call service construct from its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 shell_execute = com.sun.star.system.SystemShellExecute.create()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you have to instantiate it with XMultiComponentFactory::createInstanceWithArgumentsAndContext method with initial arguments or instantiate after the instantiation.&lt;br /&gt;
&lt;br /&gt;
The constructor calling does type checking before to pass arguments to createInstanceWithArgumentsAndContext method.&lt;br /&gt;
&lt;br /&gt;
== Current Document ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ThisComponent runtime function provides access to the current document: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = ThisComponent&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Its return value is bound to the macro location. If the macro stored in a document, the result of ThisComponent is the document that the storage of the macro belongs to. And if your macro is stored in application wide, the returned value is the document model of currently active frame, this is the same result taken from StarDesktop.&amp;#039;&amp;#039;&amp;#039;getCurrentComponent()&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can access to the current document through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If your macro is &amp;#039;&amp;#039;&amp;#039;embedded in the document&amp;#039;&amp;#039;&amp;#039;, the document model is match with the document that the macro stored in. If your macro is stored in user or shared location, the document object is from active frame.&lt;br /&gt;
&lt;br /&gt;
== Desktop ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, StarDesktop runtime function is provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = StarDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can get access to the desktop through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = XSCRIPTCONTEXT.getDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Struct Instance ==&lt;br /&gt;
&lt;br /&gt;
In Basic, instance of struct can be instantiated in two ways: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Dim a As New com.sun.star.awt.Point&lt;br /&gt;
 a = CreateUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
With Dim statement and New keyword, you can instantiate a struct or array of structs. Or CreateUnoStruct method provides the way to instantiate a struct at runtime. You can not initialize the instance at the creation, you have to set its value of members.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can use the following ways to instantiate a struct. Import struct class and call it.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.awt import Point&lt;br /&gt;
&lt;br /&gt;
 a = Point()         # instantiate with default values, X=0, Y=0&lt;br /&gt;
 b = Point(100, 200) # initialize with initial values, X=100, Y=200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Calling the class to create new instance of the struct, you can empty its arguments or you have to pass values for all fields. In other words, you can not pass insufficient number of arguments to initialize. And its order should be match with definition of the struct in its IDL. For example, instance of struct b having X=100 and Y=200 in the above piece of code.&lt;br /&gt;
&lt;br /&gt;
You can initialize without to import the class of your target struct with uno.createUnoStruct function as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 a = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
 b = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This makes the same result with the above example. The first parameter of the createUnoStruct method is the name of the struct to initialize. The following arguments are initial values for new instance.&lt;br /&gt;
&lt;br /&gt;
== Enum ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can access to the module of the enum as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ITALIC = com.sun.star.awt.FontSlant.ITALIC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following ways can be used: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontSlant import ITALIC&lt;br /&gt;
 ITALIC = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontSlant.ITALIC&amp;quot;)&lt;br /&gt;
 ITALIC = uno.Enum(&amp;quot;com.sun.star.awt.FontSlant&amp;quot;, &amp;quot;ITALIC&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
All of the way results the instance of uno.Enum class.&lt;br /&gt;
&lt;br /&gt;
== Constants ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get access to constants through its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 BOLD = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways are provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontWeight import BOLD&lt;br /&gt;
 BOLD = uno.getConstantsByName(&amp;quot;com.sun.star.awt.FontWeight.BOLD&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sequence ==&lt;br /&gt;
&lt;br /&gt;
The sequence is sequential value of the same type.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, array is used.&lt;br /&gt;
&lt;br /&gt;
In Python, tuple is chosen to represent UNO&amp;#039;s sequence. Note, list is not allowed to pass as sequence value.&lt;br /&gt;
&lt;br /&gt;
== Boolean ==&lt;br /&gt;
&lt;br /&gt;
In Python, True or False.&lt;br /&gt;
&lt;br /&gt;
== String ==&lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;s string can contain over 64K bytes.&lt;br /&gt;
&lt;br /&gt;
If you have to write non Ascii 7 bit characters in your script, write magic comment at the head of your file. This is standard Python instructions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # -*- coding: utf_8 -*-&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please read Python&amp;#039;s documentation for more detail.&lt;br /&gt;
&lt;br /&gt;
You have to use unicode string to write some unicode characters in Python 2.X. And strings coming from UNO is decoded in unicode in Python 2.X.&lt;br /&gt;
&lt;br /&gt;
== Char ==&lt;br /&gt;
&lt;br /&gt;
There is no dedicated value for char type in StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, uno.Char class is defined for char type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 c = uno.Char(&amp;quot;a&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Type ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Type&amp;quot; type is meta type of UNO that represents type of UNO.&lt;br /&gt;
Since 3.4, if you pass string value to method as an argument that should be type, the bridge of Basic read it as type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
oMap = com.sun.star.container.EnumerableMap.create(&amp;quot;string&amp;quot;, &amp;quot;string&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways can be used to create new valu of type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 t = uno.getTypeByName(&amp;quot;string&amp;quot;)&lt;br /&gt;
 t = uno.Type(&amp;quot;string&amp;quot;, uno.Enum(&amp;quot;com.sun.star.uno.TypeClass&amp;quot;, &amp;quot;STRING&amp;quot;))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Byte Sequence ==&lt;br /&gt;
&lt;br /&gt;
The byte sequence is sequence of byte type.&lt;br /&gt;
&lt;br /&gt;
In Basic, array of byte is used to represent it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, it is represented by str wrapped by uno.ByteSequence class. If you takes some byte sequences from UNO, they are the instance of uno.ByteSequence. If you need to get real value of them, refer its &amp;#039;&amp;#039;value&amp;#039;&amp;#039; instance variable.&lt;br /&gt;
&lt;br /&gt;
== Exception ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you get thrown exception as some error. And On Error statement is used to catch it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub ErrorExample&lt;br /&gt;
&lt;br /&gt;
   On Error GoTo Handler&lt;br /&gt;
&lt;br /&gt;
   &amp;#039; ... error&lt;br /&gt;
&lt;br /&gt;
   Exit Sub&lt;br /&gt;
&lt;br /&gt;
   Handler: &lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
And you can not throw any exceptions from StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, the exception thrown in UNO world can be treated as normal Python&amp;#039;s exception. Here is an example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.container import IndexOutOfBoundsException&lt;br /&gt;
&lt;br /&gt;
 try:&lt;br /&gt;
     obj.getByIndex(100) # raises IndexOutOfBoundsException&lt;br /&gt;
 except IndexOutOfBoundsException as e:&lt;br /&gt;
     print(e)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If getByIndex method raises IndexOutOfBoundsException, it can be caught in except statement because all exceptions inherit Python&amp;#039;s Exception class.&lt;br /&gt;
&lt;br /&gt;
And also you can throw UNO&amp;#039;s exception from your Python code as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.uno import RuntimeException&lt;br /&gt;
 raise RuntimeException(&amp;quot;Some message&amp;quot;, None)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Empty Value ==&lt;br /&gt;
&lt;br /&gt;
In Basic, there are some situations to meet variables that they do not contain any value (this is not correct). Null, empty, missing, nothing and so on.&lt;br /&gt;
&lt;br /&gt;
In Python, None is used. If a method defined as void return value in its IDL, it results None if you call it. If you need to pass invalid interface as an argument for the method that takes some interface, pass None for it. The result of this behavior is fully dependent to the implementation of the method.&lt;br /&gt;
&lt;br /&gt;
== Listener and Interface ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can create new listener using CreateUnoListener runtime function with some subroutines or functions.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub Add&lt;br /&gt;
&lt;br /&gt;
   d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
   listener = CreateUnoListener(&amp;quot;ActionListener&amp;quot;, &amp;quot;com.sun.star.awt.XActionListener&amp;quot;)&lt;br /&gt;
   d.getControl(&amp;quot;CommandButton1&amp;quot;).addActionListener(listener)&lt;br /&gt;
   d.execute()&lt;br /&gt;
   d.dispose()&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 Sub ActionListener_actionPerformed(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 Sub ActionListener_disposing(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you have to define your own class with desired interfaces. With helper class, you can define easily as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import unohelper&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt import XActionListener&lt;br /&gt;
&lt;br /&gt;
 class ActionListener(unohelper.Base, XActionListener):&lt;br /&gt;
     def __init__(self):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def disposing(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def actionPerformed(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
unohelper.Base class provides required interface for UNO components.&lt;br /&gt;
&lt;br /&gt;
== Containers ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, container object provides the way to access to its contents in sequentially.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, there is no shortcut provided. &lt;br /&gt;
&lt;br /&gt;
If you need to access to elements of indexed container, use range function to generate sequential indexes.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 for i in range(container.getCount()):&lt;br /&gt;
     obj = container.getByIndex(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== URL and System Path ==&lt;br /&gt;
&lt;br /&gt;
If you work with a file stored in your local file system, you have to get its corresponding URL.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ConvertToURL runtime function is prepared for this task. And there is ConvertFromURL runtime function for reverse conversion.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following functions are defined in uno module for such task.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 path = &amp;quot;/home/foo/Documents/file.odt&amp;quot;&lt;br /&gt;
 url = uno.sytemPathToFileUrl(path)&lt;br /&gt;
 path = uno.fileUrlToSystemPath(url)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments and Return Value ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, mode of the first argument of parseStrict method is &amp;quot;inout&amp;quot; in the following code: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 aURL = CreateUnoStruct(&amp;quot;com.sun.star.util.URL&amp;quot;)&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 CreateUnoService(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;).parseStrict(aURL)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The content of aURL variable is updated after calling the method.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, out mode parameter is returned as part of return value.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.util import URL&lt;br /&gt;
&lt;br /&gt;
 aURL = URL()&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 dummy, aURL = smgr.createInstanceWithContext(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;, ctx).parseStrict(aURL)&lt;br /&gt;
 # Definition of com.sun.star.util.XURLTransformer::parseStrict method: &lt;br /&gt;
 # void parseStrict([inout] com.sun.star.util.URL aURL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If a method has out mode in its parameters, its return is always tuple that contains original return value and values for out parameters.&lt;br /&gt;
&lt;br /&gt;
Here is a potential example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # boolean getSomeValue([in] string aName, [out] short aNum, [inout] long aNum2);&lt;br /&gt;
 result, num, num2 = obj.getSomeValue(&amp;quot;foo&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above example, &amp;#039;&amp;#039;result&amp;#039;&amp;#039; variable takes original return value, &amp;#039;&amp;#039;num&amp;#039;&amp;#039; takes output value for second parameter and &amp;#039;&amp;#039;num2&amp;#039;&amp;#039; takes output value for third parameter. The method takes 100 as the second parameter but it is not used as input of value. No entry in returned tuple for in mode parameter.&lt;br /&gt;
&lt;br /&gt;
== Functions to be Executed ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can not choose routines to be executed by users.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, define &amp;#039;&amp;#039;&amp;#039;g_exportedScripts&amp;#039;&amp;#039;&amp;#039; variable that contains tuple of callable in your macro file.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def func_a(): pass&lt;br /&gt;
 def func_b(): pass&lt;br /&gt;
 def func_hidden(): pass # not shown in the UI&lt;br /&gt;
 &lt;br /&gt;
 g_exportedScripts = func_a, func_b&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above code, func_hidden is not shown in execution dialog of macros.&lt;br /&gt;
&lt;br /&gt;
== Importing Modules ==&lt;br /&gt;
In Basic, you can call subroutines defined in other modules or other libraries that has been loaded.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
BasicLibraries.loadLibrary(&amp;quot;Library1&amp;quot;)&lt;br /&gt;
Library1.Foo()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you can import some modules that can be found in sys.path list. If you want to import your own module placed inside Scripts/python directory, put your module in pythonpath directory nearby your script file.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 - Scripts/&lt;br /&gt;
   - python/&lt;br /&gt;
     - macro.py&lt;br /&gt;
     - pythonpath/  # this directory is added automatically before your macro executed&lt;br /&gt;
       - your_module.py  # this module can be found&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When you execute the macro from your script file, the internal executor adds the pythonpath/ directory to sys.path list to be used as one of lookup location.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, the name of module conflict each other if you have the same named module in the some location, this is the standard python mechanism of importing modules, put your each modules in differently named library to avoid the name conflict.&lt;br /&gt;
&lt;br /&gt;
== Dialog ==&lt;br /&gt;
In Basic, there is CreateUnoDialog runtime function to instantiate the dialog.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 DialogLibraries.loadLibrary(&amp;quot;Standard&amp;quot;)&lt;br /&gt;
 dialog = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
 dialog.execute()&lt;br /&gt;
 dialog.dispose()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, such shortcut function is not provided but you can easily instantiate your dialog using &amp;lt;idl&amp;gt;com.sun.star.awt.DialogProvider&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def dialog_example():&lt;br /&gt;
     ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
     smgr = ctx.getServiceManager()&lt;br /&gt;
     dp = smgr.createInstanceWithContext(&amp;quot;com.sun.star.awt.DialogProvider&amp;quot;, ctx)&lt;br /&gt;
     dialog = dp.createDialog(&amp;quot;vnd.sun.star.script:Standard.Dialog1?location=user&amp;quot;)&lt;br /&gt;
     dialog.execute()&lt;br /&gt;
     dialog.dispose()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Message Box ==&lt;br /&gt;
In Basic, you can use MsgBox runtime function to show some message to the users.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
  Msgbox &amp;quot;Hello.&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, no shortcut function is provided but you can use &amp;lt;idl&amp;gt;com.sun.star.awt.XMessageBoxFactory&amp;lt;/idl&amp;gt; interface through the toolkit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
def messagebox(ctx, parent, message, title, message_type, buttons):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Show message in message box. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    toolkit = parent.getToolkit()&lt;br /&gt;
    older_imple = check_method_parameter(&lt;br /&gt;
        ctx, &amp;quot;com.sun.star.awt.XMessageBoxFactory&amp;quot;, &amp;quot;createMessageBox&amp;quot;, &lt;br /&gt;
        1, &amp;quot;com.sun.star.awt.Rectangle&amp;quot;)&lt;br /&gt;
    if older_imple:&lt;br /&gt;
        msgbox = toolkit.createMessageBox(&lt;br /&gt;
            parent, Rectangle(), message_type, buttons, title, message)&lt;br /&gt;
    else:&lt;br /&gt;
        message_type = uno.getConstantByName(&amp;quot;com.sun.star.awt.MessageBoxType.&amp;quot; + {&lt;br /&gt;
            &amp;quot;messbox&amp;quot;: &amp;quot;MESSAGEBOX&amp;quot;, &amp;quot;infobox&amp;quot;: &amp;quot;INFOBOX&amp;quot;, &lt;br /&gt;
            &amp;quot;warningbox&amp;quot;: &amp;quot;WARNINGBOX&amp;quot;, &amp;quot;errorbox&amp;quot;: &amp;quot;ERRORBOX&amp;quot;, &lt;br /&gt;
            &amp;quot;querybox&amp;quot;: &amp;quot;QUERYBOX&amp;quot;}[message_type])&lt;br /&gt;
        msgbox = toolkit.createMessageBox(&lt;br /&gt;
            parent, message_type, buttons, title, message)&lt;br /&gt;
    n = msgbox.execute()&lt;br /&gt;
    msgbox.dispose()&lt;br /&gt;
    return n&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def check_method_parameter(ctx, interface_name, method_name, param_index, param_type):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Check the method has specific type parameter at the specific position. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    cr = create_service(ctx, &amp;quot;com.sun.star.reflection.CoreReflection&amp;quot;)&lt;br /&gt;
    try:&lt;br /&gt;
        idl = cr.forName(interface_name)&lt;br /&gt;
        m = idl.getMethod(method_name)&lt;br /&gt;
        if m:&lt;br /&gt;
            info = m.getParameterInfos()[param_index]&lt;br /&gt;
            return info.aType.getName() == param_type&lt;br /&gt;
    except:&lt;br /&gt;
        pass&lt;br /&gt;
    return False&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Input Box ==&lt;br /&gt;
&lt;br /&gt;
No function provided for Python, you have to make your own one. Here is an example: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;def inputbox(message, title=&amp;quot;&amp;quot;, default=&amp;quot;&amp;quot;, x=None, y=None):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Shows dialog with input box.&lt;br /&gt;
        @param message message to show on the dialog&lt;br /&gt;
        @param title window title&lt;br /&gt;
        @param default default value&lt;br /&gt;
        @param x dialog positio in twips, pass y also&lt;br /&gt;
        @param y dialog position in twips, pass y also&lt;br /&gt;
        @return string if OK button pushed, otherwise zero length string&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    WIDTH = 600&lt;br /&gt;
    HORI_MARGIN = VERT_MARGIN = 8&lt;br /&gt;
    BUTTON_WIDTH = 100&lt;br /&gt;
    BUTTON_HEIGHT = 26&lt;br /&gt;
    HORI_SEP = VERT_SEP = 8&lt;br /&gt;
    LABEL_HEIGHT = BUTTON_HEIGHT * 2 + 5&lt;br /&gt;
    EDIT_HEIGHT = 24&lt;br /&gt;
    HEIGHT = VERT_MARGIN * 2 + LABEL_HEIGHT + VERT_SEP + EDIT_HEIGHT&lt;br /&gt;
    import uno&lt;br /&gt;
    from com.sun.star.awt.PosSize import POS, SIZE, POSSIZE&lt;br /&gt;
    from com.sun.star.awt.PushButtonType import OK, CANCEL&lt;br /&gt;
    from com.sun.star.util.MeasureUnit import TWIP&lt;br /&gt;
    ctx = uno.getComponentContext()&lt;br /&gt;
    def create(name):&lt;br /&gt;
        return ctx.getServiceManager().createInstanceWithContext(name, ctx)&lt;br /&gt;
    dialog = create(&amp;quot;com.sun.star.awt.UnoControlDialog&amp;quot;)&lt;br /&gt;
    dialog_model = create(&amp;quot;com.sun.star.awt.UnoControlDialogModel&amp;quot;)&lt;br /&gt;
    dialog.setModel(dialog_model)&lt;br /&gt;
    dialog.setVisible(False)&lt;br /&gt;
    dialog.setTitle(title)&lt;br /&gt;
    dialog.setPosSize(0, 0, WIDTH, HEIGHT, SIZE)&lt;br /&gt;
    def add(name, type, x_, y_, width_, height_, props):&lt;br /&gt;
        model = dialog_model.createInstance(&amp;quot;com.sun.star.awt.UnoControl&amp;quot; + type + &amp;quot;Model&amp;quot;)&lt;br /&gt;
        dialog_model.insertByName(name, model)&lt;br /&gt;
        control = dialog.getControl(name)&lt;br /&gt;
        control.setPosSize(x_, y_, width_, height_, POSSIZE)&lt;br /&gt;
        for key, value in props.items():&lt;br /&gt;
            setattr(model, key, value)&lt;br /&gt;
    label_width = WIDTH - BUTTON_WIDTH - HORI_SEP - HORI_MARGIN * 2&lt;br /&gt;
    add(&amp;quot;label&amp;quot;, &amp;quot;FixedText&amp;quot;, HORI_MARGIN, VERT_MARGIN, label_width, LABEL_HEIGHT, {&amp;quot;Label&amp;quot;: str(message)})&lt;br /&gt;
    add(&amp;quot;btn_ok&amp;quot;, &amp;quot;Button&amp;quot;, HORI_MARGIN + label_width + HORI_SEP, VERT_MARGIN, &lt;br /&gt;
            BUTTON_WIDTH, BUTTON_HEIGHT, {&amp;quot;PushButtonType&amp;quot;: OK, &amp;quot;DefaultButton&amp;quot;: True})&lt;br /&gt;
    add(&amp;quot;btn_cancel&amp;quot;, &amp;quot;Button&amp;quot;, HORI_MARGIN + label_width + HORI_SEP, VERT_MARGIN + BUTTON_HEIGHT + 5, &lt;br /&gt;
            BUTTON_WIDTH, BUTTON_HEIGHT, {&amp;quot;PushButtonType&amp;quot;: CANCEL})&lt;br /&gt;
    add(&amp;quot;edit&amp;quot;, &amp;quot;Edit&amp;quot;, HORI_MARGIN, LABEL_HEIGHT + VERT_MARGIN + VERT_SEP, &lt;br /&gt;
            WIDTH - HORI_MARGIN * 2, EDIT_HEIGHT, {&amp;quot;Text&amp;quot;: str(default)})&lt;br /&gt;
    frame = create(&amp;quot;com.sun.star.frame.Desktop&amp;quot;).getCurrentFrame()&lt;br /&gt;
    window = frame.getContainerWindow() if frame else None&lt;br /&gt;
    dialog.createPeer(create(&amp;quot;com.sun.star.awt.Toolkit&amp;quot;), window)&lt;br /&gt;
    if not x is None and not y is None:&lt;br /&gt;
        ps = dialog.convertSizeToPixel(uno.createUnoStruct(&amp;quot;com.sun.star.awt.Size&amp;quot;, x, y), TWIP)&lt;br /&gt;
        _x, _y = ps.Width, ps.Height&lt;br /&gt;
    elif window:&lt;br /&gt;
        ps = window.getPosSize()&lt;br /&gt;
        _x = ps.Width / 2 - WIDTH / 2&lt;br /&gt;
        _y = ps.Height / 2 - HEIGHT / 2&lt;br /&gt;
    dialog.setPosSize(_x, _y, 0, 0, POS)&lt;br /&gt;
    edit = dialog.getControl(&amp;quot;edit&amp;quot;)&lt;br /&gt;
    edit.setSelection(uno.createUnoStruct(&amp;quot;com.sun.star.awt.Selection&amp;quot;, 0, len(str(default))))&lt;br /&gt;
    edit.setFocus()&lt;br /&gt;
    ret = edit.getModel().Text if dialog.execute() else &amp;quot;&amp;quot;&lt;br /&gt;
    dialog.dispose()&lt;br /&gt;
    return ret&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This function can be called as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
inputbox(&amp;quot;Please input some value&amp;quot;, &amp;quot;Input&amp;quot;, &amp;quot;Default value&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Executing Macros from Toolbar Buttons ==&lt;br /&gt;
In Basic, you can call any subroutines or functions through toolbar buttons. &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
Sub WriteHello()&lt;br /&gt;
  ThisComponent.getText().getEnd().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, you have to define your Python function with an argument (or variable length arguments) to take an argument passed when the function executed through assigned toolbar button.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
def writeHello(*args):&lt;br /&gt;
    # writeHello(arg): is also ok but if you want to call this function &lt;br /&gt;
    # by some ways, define your function takes variable arguments.&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().getEnd().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/Part_of_Build_Tools&amp;diff=235794</id>
		<title>User:Hanya/Part of Build Tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/Part_of_Build_Tools&amp;diff=235794"/>
		<updated>2015-01-05T09:41:27Z</updated>

		<summary type="html">&lt;p&gt;Hanya: /* Other */ Fix about rsc&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There are some executable and scripts used while building the office. Here is the part of them that I wanted to know.&lt;br /&gt;
&lt;br /&gt;
== Localization ==&lt;br /&gt;
For localization. See [[Localization_AOO]].&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! Module&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| cfgex&lt;br /&gt;
| l10ntools&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| gsicheck&lt;br /&gt;
| l10ntools&lt;br /&gt;
| Checks SDF file&lt;br /&gt;
|-&lt;br /&gt;
| helpex&lt;br /&gt;
| l10ntools&lt;br /&gt;
| Generates SDF file from help files&lt;br /&gt;
|-&lt;br /&gt;
| HelpLinker&lt;br /&gt;
| l10ntools&lt;br /&gt;
| Generates ht, db and key files&lt;br /&gt;
|-&lt;br /&gt;
| tralay&lt;br /&gt;
| l10ntools&lt;br /&gt;
| Merge XML file into SDF file&lt;br /&gt;
|- &lt;br /&gt;
| transex3&lt;br /&gt;
| l10ntools&lt;br /&gt;
| translation frontend&lt;br /&gt;
|-&lt;br /&gt;
| ulfex&lt;br /&gt;
| l10ntools&lt;br /&gt;
| &lt;br /&gt;
|- &lt;br /&gt;
| xrmex&lt;br /&gt;
| l10ntools&lt;br /&gt;
| For xrm files&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
It seems some tools are not used.&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! Module&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| bmp&lt;br /&gt;
| svtools/bmpmaker&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| bmpsum&lt;br /&gt;
| svtools/bmpmaker&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| g2g&lt;br /&gt;
| svtools/bmpmaker&lt;br /&gt;
| graphic to graphic conversion&lt;br /&gt;
|-&lt;br /&gt;
| rsc&lt;br /&gt;
| rsc&lt;br /&gt;
| Compiles resource files into srs file&lt;br /&gt;
|-&lt;br /&gt;
| rsc2&lt;br /&gt;
| rsc&lt;br /&gt;
| Called from rsc&lt;br /&gt;
|-&lt;br /&gt;
| rscdep&lt;br /&gt;
| tools/bootstrp&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| rscpp&lt;br /&gt;
| rsc&lt;br /&gt;
| Called from rsc&lt;br /&gt;
|-&lt;br /&gt;
| sp2bv&lt;br /&gt;
| cpputools/source/sp2bv&lt;br /&gt;
| Convert system path to URL&lt;br /&gt;
|-&lt;br /&gt;
| srvdepy&lt;br /&gt;
| xml2cmp&lt;br /&gt;
| Find dependencies for XML files of component descriptions&lt;br /&gt;
|-&lt;br /&gt;
| sspretty&lt;br /&gt;
| tools/bootstrp&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| svidl&lt;br /&gt;
| idl/source/prj&lt;br /&gt;
| StarView IDL compiler&lt;br /&gt;
|-&lt;br /&gt;
| ulfconv&lt;br /&gt;
| setup_native/source/ulfconv&lt;br /&gt;
| Convert ulf file according to passed encoding table&lt;br /&gt;
|-&lt;br /&gt;
| xml2cmp&lt;br /&gt;
| xml2cmp&lt;br /&gt;
| &lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/Part_of_Build_Tools&amp;diff=235792</id>
		<title>User:Hanya/Part of Build Tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/Part_of_Build_Tools&amp;diff=235792"/>
		<updated>2015-01-05T09:27:44Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add initial content&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There are some executable and scripts used while building the office. Here is the part of them that I wanted to know.&lt;br /&gt;
&lt;br /&gt;
== Localization ==&lt;br /&gt;
For localization. See [[Localization_AOO]].&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! Module&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| cfgex&lt;br /&gt;
| l10ntools&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| gsicheck&lt;br /&gt;
| l10ntools&lt;br /&gt;
| Checks SDF file&lt;br /&gt;
|-&lt;br /&gt;
| helpex&lt;br /&gt;
| l10ntools&lt;br /&gt;
| Generates SDF file from help files&lt;br /&gt;
|-&lt;br /&gt;
| HelpLinker&lt;br /&gt;
| l10ntools&lt;br /&gt;
| Generates ht, db and key files&lt;br /&gt;
|-&lt;br /&gt;
| tralay&lt;br /&gt;
| l10ntools&lt;br /&gt;
| Merge XML file into SDF file&lt;br /&gt;
|- &lt;br /&gt;
| transex3&lt;br /&gt;
| l10ntools&lt;br /&gt;
| translation frontend&lt;br /&gt;
|-&lt;br /&gt;
| ulfex&lt;br /&gt;
| l10ntools&lt;br /&gt;
| &lt;br /&gt;
|- &lt;br /&gt;
| xrmex&lt;br /&gt;
| l10ntools&lt;br /&gt;
| For xrm files&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
It seems some tools are not used.&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
! Name&lt;br /&gt;
! Module&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| bmp&lt;br /&gt;
| svtools/bmpmaker&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| bmpsum&lt;br /&gt;
| svtools/bmpmaker&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| g2g&lt;br /&gt;
| svtools/bmpmaker&lt;br /&gt;
| graphic to graphic conversion&lt;br /&gt;
|-&lt;br /&gt;
| rsc&lt;br /&gt;
| rsc&lt;br /&gt;
| Compiles rsc file to res file&lt;br /&gt;
|-&lt;br /&gt;
| rsc2&lt;br /&gt;
| rsc&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| rscdep&lt;br /&gt;
| tools/bootstrp&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| rscpp&lt;br /&gt;
| rsc&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| sp2bv&lt;br /&gt;
| cpputools/source/sp2bv&lt;br /&gt;
| Convert system path to URL&lt;br /&gt;
|-&lt;br /&gt;
| srvdepy&lt;br /&gt;
| xml2cmp&lt;br /&gt;
| Find dependencies for XML files of component descriptions&lt;br /&gt;
|-&lt;br /&gt;
| sspretty&lt;br /&gt;
| tools/bootstrp&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| svidl&lt;br /&gt;
| idl/source/prj&lt;br /&gt;
| StarView IDL compiler&lt;br /&gt;
|-&lt;br /&gt;
| ulfconv&lt;br /&gt;
| setup_native/source/ulfconv&lt;br /&gt;
| Convert ulf file according to passed encoding table&lt;br /&gt;
|-&lt;br /&gt;
| xml2cmp&lt;br /&gt;
| xml2cmp&lt;br /&gt;
| &lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya&amp;diff=235791</id>
		<title>User:Hanya</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya&amp;diff=235791"/>
		<updated>2015-01-05T08:20:15Z</updated>

		<summary type="html">&lt;p&gt;Hanya: /* Notes */ Add link to new page about build tool&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ICLA submitted.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
* [[/Tracked_API_Changes]]&lt;br /&gt;
* [[/Hyperlink_Control_on_Dialog_Editor]]&lt;br /&gt;
* [[/Distribute_SymbolStyles_by_Extension]]&lt;br /&gt;
* [[/External_Libraries]]&lt;br /&gt;
* [[/API Changes on 4.0 since 3.4]]&lt;br /&gt;
* [[/Translation_Review]]&lt;br /&gt;
* [[/New_Field_on_Writer]]&lt;br /&gt;
* [[/Iif_Problem]]&lt;br /&gt;
* [[/Python_Test_Executor]]&lt;br /&gt;
* [[/Part_of_Build_Tools]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/Python_Test_Executor&amp;diff=235789</id>
		<title>User:Hanya/Python Test Executor</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/Python_Test_Executor&amp;diff=235789"/>
		<updated>2014-12-27T16:09:09Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add description about how to execute bundled test cases of Python standard libraries from Python macro&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;If new version of Python is introduced as shipped Python, bundled test cases should be executed to check standard libraries work well. &lt;br /&gt;
There are a few problems to execute these test cases from Python macro. Here is Python script having some settings that avoids errors.&lt;br /&gt;
&lt;br /&gt;
Store the following content into $(user)/Scripts/python/test.py and execute test_all or test_ function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import uno&lt;br /&gt;
import sys&lt;br /&gt;
import os.path&lt;br /&gt;
import platform&lt;br /&gt;
import locale&lt;br /&gt;
import builtins&lt;br /&gt;
&lt;br /&gt;
STORE_IN_LOGFILE = False&lt;br /&gt;
LOG_PATH = None&lt;br /&gt;
LOGGER = None&lt;br /&gt;
&lt;br /&gt;
# some tests have problem with the uno importer function, &lt;br /&gt;
# so use default import function in regression test&lt;br /&gt;
_default_importer = uno._g_delegatee&lt;br /&gt;
_uno_importer = uno._uno_import&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def _set_default_importer():&lt;br /&gt;
    builtins.__dict__[&amp;quot;__import__&amp;quot;] = _default_importer&lt;br /&gt;
&lt;br /&gt;
def _set_uno_importer():&lt;br /&gt;
    builtins.__dict__[&amp;quot;__import__&amp;quot;] = _uno_importer&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class LogWriter:&lt;br /&gt;
    def write(self, s):&lt;br /&gt;
        if LOG_PATH:&lt;br /&gt;
            with open(LOG_PATH, &amp;quot;a&amp;quot;) as f:&lt;br /&gt;
                f.seek(0, whence=2)&lt;br /&gt;
                f.write(s)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def create(script_context, name):&lt;br /&gt;
    ctx = script_context.getComponentContext()&lt;br /&gt;
    return ctx.getServiceManager().createInstanceWithContext(name, ctx)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def _set_io():&lt;br /&gt;
    if STORE_IN_LOGFILE:&lt;br /&gt;
        global LOG_PATH&lt;br /&gt;
        if LOG_PATH is None:&lt;br /&gt;
            LOG_PATH = uno.fileUrlToSystemPath(&lt;br /&gt;
                create(XSCRIPTCONTEXT, &amp;quot;com.sun.star.util.PathSubstitution&amp;quot;).substituteVariables(&lt;br /&gt;
                                        &amp;quot;$(user)/Scripts/python/test.log&amp;quot;))&lt;br /&gt;
            global LOGGER = LogWriter()&lt;br /&gt;
    sys.stdout = LOGGER&lt;br /&gt;
    sys.stderr = LOGGER&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def _reset_io():&lt;br /&gt;
    sys.stdout = sys.__stdout__&lt;br /&gt;
    sys.stderr = sys.__stderr__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def _set_vars():&lt;br /&gt;
    python_name = &amp;quot;python.exe&amp;quot; if platform.system() == &amp;quot;Windows&amp;quot; else &amp;quot;python&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    office_dir = create(XSCRIPTCONTEXT, &amp;quot;com.sun.star.util.OfficeInstallationDirectories&amp;quot;).getOfficeInstallationDirectoryURL()&lt;br /&gt;
    python_path = os.path.join(uno.fileUrlToSystemPath(office_dir), &amp;quot;program&amp;quot;, python_name)&lt;br /&gt;
    &lt;br /&gt;
    # set parameters for test through command line arguments&lt;br /&gt;
    sys.argv = [&amp;quot;-r&amp;quot;, &amp;quot;-w&amp;quot;, &amp;quot;-n&amp;quot;, &amp;quot;-u&amp;quot; &amp;quot;all&amp;quot;]#&amp;quot;all,-largefile,-audio,-gui&amp;quot;]&lt;br /&gt;
    # set executable path because not executable path has been set&lt;br /&gt;
    sys.executable = python_path&lt;br /&gt;
    &lt;br /&gt;
    # for some modules such as datetime&lt;br /&gt;
    locale.setlocale(locale.LC_ALL, &amp;quot;C&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def test_all():&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Execute all regression test. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    if STORE_IN_LOGFILE:&lt;br /&gt;
        _set_io()&lt;br /&gt;
    _set_vars()&lt;br /&gt;
    _set_default_importer()&lt;br /&gt;
    try:&lt;br /&gt;
        import test.__main__&lt;br /&gt;
    except:&lt;br /&gt;
        pass&lt;br /&gt;
    finally:&lt;br /&gt;
        _set_uno_importer()&lt;br /&gt;
        if STORE_IN_LOGFILE:&lt;br /&gt;
            _reset_io()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class TestEnv:&lt;br /&gt;
    def __init__(self, module):&lt;br /&gt;
        self.module = module&lt;br /&gt;
    &lt;br /&gt;
    def __enter__(self):&lt;br /&gt;
        _set_vars()&lt;br /&gt;
        _set_default_importer()&lt;br /&gt;
        return self&lt;br /&gt;
    &lt;br /&gt;
    def __exit__(self, *args):&lt;br /&gt;
        _set_uno_importer()&lt;br /&gt;
        return False&lt;br /&gt;
    &lt;br /&gt;
    def start(self):&lt;br /&gt;
        _exec_test(self.module)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def _exec_test(module):&lt;br /&gt;
    module.test_main()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def test_():&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Execute selected test. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    import test.test_ssl as module&lt;br /&gt;
    with TestEnv(module) as t:&lt;br /&gt;
        t.start()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
g_exportedScripts = test_all, test_,&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya&amp;diff=235788</id>
		<title>User:Hanya</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya&amp;diff=235788"/>
		<updated>2014-12-27T16:02:51Z</updated>

		<summary type="html">&lt;p&gt;Hanya: /* Notes */ Add link to new page about the way to execute test cases of Python&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ICLA submitted.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
* [[/Tracked_API_Changes]]&lt;br /&gt;
* [[/Hyperlink_Control_on_Dialog_Editor]]&lt;br /&gt;
* [[/Distribute_SymbolStyles_by_Extension]]&lt;br /&gt;
* [[/External_Libraries]]&lt;br /&gt;
* [[/API Changes on 4.0 since 3.4]]&lt;br /&gt;
* [[/Translation_Review]]&lt;br /&gt;
* [[/New_Field_on_Writer]]&lt;br /&gt;
* [[/Iif_Problem]]&lt;br /&gt;
* [[/Python_Test_Executor]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/Iif_Problem&amp;diff=235773</id>
		<title>User:Hanya/Iif Problem</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/Iif_Problem&amp;diff=235773"/>
		<updated>2014-12-22T08:48:05Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add the way to obtain disassembled code&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Issue: https://issues.apache.org/ooo/show_bug.cgi?id=63614&lt;br /&gt;
&lt;br /&gt;
Error code 87302 is produced when some code is modified contains Iif runtime function.&lt;br /&gt;
&lt;br /&gt;
== How to Obtain Disassembled Code ==&lt;br /&gt;
The compile for Basic contains the code to write disassembled code into a file. Change some part like the following and recompile it. &lt;br /&gt;
Change aFile variable to match with your desired location to store the result. If this code is enabled, you get disassembled code every compilation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Index: basic/source/comp/sbcomp.cxx&lt;br /&gt;
===================================================================&lt;br /&gt;
--- basic/source/comp/sbcomp.cxx	(Revision 1634275)&lt;br /&gt;
+++ basic/source/comp/sbcomp.cxx	(Working Copy)&lt;br /&gt;
@@ -908,7 +908,7 @@&lt;br /&gt;
 &lt;br /&gt;
 //==========================================================================&lt;br /&gt;
 // For debugging only&lt;br /&gt;
-//#define DBG_SAVE_DISASSEMBLY&lt;br /&gt;
+#define DBG_SAVE_DISASSEMBLY&lt;br /&gt;
 &lt;br /&gt;
 #ifdef DBG_SAVE_DISASSEMBLY&lt;br /&gt;
 static bool dbg_bDisassemble = true;&lt;br /&gt;
@@ -920,7 +920,7 @@&lt;br /&gt;
 #include &amp;lt;com/sun/star/io/XActiveDataSource.hpp&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 using namespace comphelper;&lt;br /&gt;
-using namespace rtl;&lt;br /&gt;
+//using namespace rtl;&lt;br /&gt;
 using namespace com::sun::star::uno;&lt;br /&gt;
 using namespace com::sun::star::lang;&lt;br /&gt;
 using namespace com::sun::star::ucb;&lt;br /&gt;
@@ -931,7 +931,7 @@&lt;br /&gt;
     bool bDisassemble = dbg_bDisassemble;&lt;br /&gt;
     if( bDisassemble )&lt;br /&gt;
 	{&lt;br /&gt;
-		Reference&amp;lt; XSimpleFileAccess3 &amp;gt; xSFI;&lt;br /&gt;
+		//Reference&amp;lt; XSimpleFileAccess3 &amp;gt; xSFI;&lt;br /&gt;
 		Reference&amp;lt; XTextOutputStream &amp;gt; xTextOut;&lt;br /&gt;
 		Reference&amp;lt; XOutputStream &amp;gt; xOut;&lt;br /&gt;
 		Reference&amp;lt; XMultiServiceFactory &amp;gt; xSMgr = getProcessServiceFactory();&lt;br /&gt;
@@ -938,10 +938,10 @@&lt;br /&gt;
 		if( xSMgr.is() )&lt;br /&gt;
 		{&lt;br /&gt;
 			Reference&amp;lt; XSimpleFileAccess3 &amp;gt; xSFI = Reference&amp;lt; XSimpleFileAccess3 &amp;gt;( xSMgr-&amp;gt;createInstance&lt;br /&gt;
-				( OUString::createFromAscii( &amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot; ) ), UNO_QUERY );&lt;br /&gt;
+				( ::rtl::OUString::createFromAscii( &amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot; ) ), UNO_QUERY );&lt;br /&gt;
 			if( xSFI.is() )&lt;br /&gt;
 			{&lt;br /&gt;
-				String aFile( RTL_CONSTASCII_USTRINGPARAM(&amp;quot;file:///d:/zBasic.Asm/Asm_&amp;quot;) );&lt;br /&gt;
+				String aFile( RTL_CONSTASCII_USTRINGPARAM(&amp;quot;file:///home/foo/a&amp;quot;) );&lt;br /&gt;
 				StarBASIC* pBasic = (StarBASIC*)pModule-&amp;gt;GetParent();&lt;br /&gt;
 				if( pBasic )&lt;br /&gt;
 				{&lt;br /&gt;
@@ -955,7 +955,7 @@&lt;br /&gt;
 				if( xSFI-&amp;gt;exists( aFile ) )&lt;br /&gt;
 					xSFI-&amp;gt;kill( aFile );&lt;br /&gt;
 				xOut = xSFI-&amp;gt;openFileWrite( aFile );&lt;br /&gt;
-				Reference&amp;lt; XInterface &amp;gt; x = xSMgr-&amp;gt;createInstance( OUString::createFromAscii( &amp;quot;com.sun.star.io.TextOutputStream&amp;quot; ) );&lt;br /&gt;
+				Reference&amp;lt; XInterface &amp;gt; x = xSMgr-&amp;gt;createInstance( ::rtl::OUString::createFromAscii( &amp;quot;com.sun.star.io.TextOutputStream&amp;quot; ) );&lt;br /&gt;
 				Reference&amp;lt; XActiveDataSource &amp;gt; xADS( x, UNO_QUERY );&lt;br /&gt;
 				xADS-&amp;gt;setOutputStream( xOut );&lt;br /&gt;
 				xTextOut = Reference&amp;lt; XTextOutputStream &amp;gt;( x, UNO_QUERY );&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Disassembled Original ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sub Main&lt;br /&gt;
IIf(true, 1.0, &amp;quot;&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Position Op Op1      Op2        OpStr   &lt;br /&gt;
-----------------------------------------&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000  // Label&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, 1.0, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	     // new argv&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 40 00000004          	NUMBER	&amp;quot;1&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000005          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Disassembled with Problem ==&lt;br /&gt;
Second argument for IIf function is changed from 1.0 to &amp;quot;&amp;quot;. &lt;br /&gt;
Execute the code after the change -&amp;gt; strange error.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sub Main&lt;br /&gt;
IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000002 	RTL	IIf	; Integer, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Disassembled without Problem after Restarting ==&lt;br /&gt;
After the modification and error mentioned above, restart the office. &lt;br /&gt;
And then execute the code, no error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences ==&lt;br /&gt;
With the same code, different operation codes are generated for IIf function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Position Op Op1      Op2        OpStr   &lt;br /&gt;
-----------------------------------------&lt;br /&gt;
// with problem&lt;br /&gt;
0000002E 80 00008003 00000002 	RTL	IIf	; Integer, Args&lt;br /&gt;
// restarted&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Op2 is type for this OpCode: &lt;br /&gt;
&amp;lt;pre&amp;gt;// SbiDisas::TypeOp&lt;br /&gt;
pTypes[][13] = {&lt;br /&gt;
  &amp;quot;Empty&amp;quot;,&amp;quot;Null&amp;quot;,&amp;quot;Integer&amp;quot;,&amp;quot;Long&amp;quot;,&amp;quot;Single&amp;quot;,&amp;quot;Double&amp;quot;,&lt;br /&gt;
  &amp;quot;Currency&amp;quot;,&amp;quot;Date&amp;quot;,&amp;quot;String&amp;quot;,&amp;quot;Object&amp;quot;,&amp;quot;Error&amp;quot;,&amp;quot;Boolean&amp;quot;,&lt;br /&gt;
  &amp;quot;Variant&amp;quot; };&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The error code 87302 is set in SbxValue::SetType (t is not equal to aData.eType) method. &lt;br /&gt;
Therefore the problem is caused by the wrong compilation when the code is modified.&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC &lt;br /&gt;
// SbiExprList::Gen in exprgen.cxx&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV &lt;br /&gt;
// SbiExprList::Gen in exprgen.cxx&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV &lt;br /&gt;
// SbiExprNode::GenElement in exprgen.cxx&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET &lt;br /&gt;
// SbiParser::Symbol in parser.cxx&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE &lt;br /&gt;
// SbiParser::DefProc in dim.cxx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In SbiParser::CheckRTLForSym method, pVar-&amp;gt;GetType() call should return SbxEMPTY for rSym == &amp;quot;IIf&amp;quot;. But SbxINTEGER is returned when the problem was happen. The return value of the function, instance of SbiSymDef gets wrong type. The return type depends on the arguments of the Iif function that called first time. &lt;br /&gt;
Then the wrong type is passed to new SbiExprNode instance in SbiExpression::Term method.&lt;br /&gt;
When I change the second argument from &amp;quot;&amp;quot; to false, I got SbxSTRING for the type.&lt;br /&gt;
&lt;br /&gt;
While first compilation, SbxObject::Find( rName, t ) returns NULL in SbiStdObject::Find method for rName = &amp;quot;IIf&amp;quot;. &lt;br /&gt;
IIf function was found in pMethods in SbxObject::Find at second compilation. When the function is registerd in SbxObject::pMethods variable of runtime. The method instance is registerd by SbxObject::Make method called in SbiStdObject::Find method after searching the runtime function in the table. &lt;br /&gt;
&lt;br /&gt;
The type of return value is set at first execution of the runtime function. Iif is defined as RTLFUNC(Iif) (SbRtl_Iif function is generated by the macro) in basic/source/runtime/methods1.cxx file. &lt;br /&gt;
If Iif is called like: Iif(true, 1, &amp;quot;&amp;quot;), the return type is going to be SbxINTEGER from the second argument in *rPar.Get(0) = *rPar.Get(2); line. In SbxValue::operator= function called at assignment of the return value, last Put method call set the type of return value of the function.&lt;br /&gt;
&lt;br /&gt;
After the first execution of the code that contains Iif function call, the method instance having return type is used to obtain the return type while the second compilation. The type of return value of Iif function depends on each function call and cause type miss match.&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/Iif_Problem&amp;diff=235772</id>
		<title>User:Hanya/Iif Problem</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/Iif_Problem&amp;diff=235772"/>
		<updated>2014-12-21T10:12:06Z</updated>

		<summary type="html">&lt;p&gt;Hanya: /* Code */ Add description about the cause of the wrong type&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Issue: https://issues.apache.org/ooo/show_bug.cgi?id=63614&lt;br /&gt;
&lt;br /&gt;
Error code 87302 is produced when some code is modified contains Iif runtime function.&lt;br /&gt;
&lt;br /&gt;
== Disassembled Original ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sub Main&lt;br /&gt;
IIf(true, 1.0, &amp;quot;&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Position Op Op1      Op2        OpStr   &lt;br /&gt;
-----------------------------------------&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000  // Label&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, 1.0, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	     // new argv&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 40 00000004          	NUMBER	&amp;quot;1&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000005          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Disassembled with Problem ==&lt;br /&gt;
Second argument for IIf function is changed from 1.0 to &amp;quot;&amp;quot;. &lt;br /&gt;
Execute the code after the change -&amp;gt; strange error.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sub Main&lt;br /&gt;
IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000002 	RTL	IIf	; Integer, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Disassembled without Problem after Restarting ==&lt;br /&gt;
After the modification and error mentioned above, restart the office. &lt;br /&gt;
And then execute the code, no error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences ==&lt;br /&gt;
With the same code, different operation codes are generated for IIf function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Position Op Op1      Op2        OpStr   &lt;br /&gt;
-----------------------------------------&lt;br /&gt;
// with problem&lt;br /&gt;
0000002E 80 00008003 00000002 	RTL	IIf	; Integer, Args&lt;br /&gt;
// restarted&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Op2 is type for this OpCode: &lt;br /&gt;
&amp;lt;pre&amp;gt;// SbiDisas::TypeOp&lt;br /&gt;
pTypes[][13] = {&lt;br /&gt;
  &amp;quot;Empty&amp;quot;,&amp;quot;Null&amp;quot;,&amp;quot;Integer&amp;quot;,&amp;quot;Long&amp;quot;,&amp;quot;Single&amp;quot;,&amp;quot;Double&amp;quot;,&lt;br /&gt;
  &amp;quot;Currency&amp;quot;,&amp;quot;Date&amp;quot;,&amp;quot;String&amp;quot;,&amp;quot;Object&amp;quot;,&amp;quot;Error&amp;quot;,&amp;quot;Boolean&amp;quot;,&lt;br /&gt;
  &amp;quot;Variant&amp;quot; };&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The error code 87302 is set in SbxValue::SetType (t is not equal to aData.eType) method. &lt;br /&gt;
Therefore the problem is caused by the wrong compilation when the code is modified.&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC &lt;br /&gt;
// SbiExprList::Gen in exprgen.cxx&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV &lt;br /&gt;
// SbiExprList::Gen in exprgen.cxx&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV &lt;br /&gt;
// SbiExprNode::GenElement in exprgen.cxx&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET &lt;br /&gt;
// SbiParser::Symbol in parser.cxx&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE &lt;br /&gt;
// SbiParser::DefProc in dim.cxx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In SbiParser::CheckRTLForSym method, pVar-&amp;gt;GetType() call should return SbxEMPTY for rSym == &amp;quot;IIf&amp;quot;. But SbxINTEGER is returned when the problem was happen. The return value of the function, instance of SbiSymDef gets wrong type. The return type depends on the arguments of the Iif function that called first time. &lt;br /&gt;
Then the wrong type is passed to new SbiExprNode instance in SbiExpression::Term method.&lt;br /&gt;
When I change the second argument from &amp;quot;&amp;quot; to false, I got SbxSTRING for the type.&lt;br /&gt;
&lt;br /&gt;
While first compilation, SbxObject::Find( rName, t ) returns NULL in SbiStdObject::Find method for rName = &amp;quot;IIf&amp;quot;. &lt;br /&gt;
IIf function was found in pMethods in SbxObject::Find at second compilation. When the function is registerd in SbxObject::pMethods variable of runtime. The method instance is registerd by SbxObject::Make method called in SbiStdObject::Find method after searching the runtime function in the table. &lt;br /&gt;
&lt;br /&gt;
The type of return value is set at first execution of the runtime function. Iif is defined as RTLFUNC(Iif) (SbRtl_Iif function is generated by the macro) in basic/source/runtime/methods1.cxx file. &lt;br /&gt;
If Iif is called like: Iif(true, 1, &amp;quot;&amp;quot;), the return type is going to be SbxINTEGER from the second argument in *rPar.Get(0) = *rPar.Get(2); line. In SbxValue::operator= function called at assignment of the return value, last Put method call set the type of return value of the function.&lt;br /&gt;
&lt;br /&gt;
After the first execution of the code that contains Iif function call, the method instance having return type is used to obtain the return type while the second compilation. The type of return value of Iif function depends on each function call and cause type miss match.&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/Iif_Problem&amp;diff=235771</id>
		<title>User:Hanya/Iif Problem</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/Iif_Problem&amp;diff=235771"/>
		<updated>2014-12-20T17:53:06Z</updated>

		<summary type="html">&lt;p&gt;Hanya: /* Code */ IIf is found in list of methods hold by the runtime&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Issue: https://issues.apache.org/ooo/show_bug.cgi?id=63614&lt;br /&gt;
&lt;br /&gt;
Error code 87302 is produced when some code is modified contains Iif runtime function.&lt;br /&gt;
&lt;br /&gt;
== Disassembled Original ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sub Main&lt;br /&gt;
IIf(true, 1.0, &amp;quot;&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Position Op Op1      Op2        OpStr   &lt;br /&gt;
-----------------------------------------&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000  // Label&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, 1.0, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	     // new argv&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 40 00000004          	NUMBER	&amp;quot;1&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000005          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Disassembled with Problem ==&lt;br /&gt;
Second argument for IIf function is changed from 1.0 to &amp;quot;&amp;quot;. &lt;br /&gt;
Execute the code after the change -&amp;gt; strange error.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sub Main&lt;br /&gt;
IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000002 	RTL	IIf	; Integer, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Disassembled without Problem after Restarting ==&lt;br /&gt;
After the modification and error mentioned above, restart the office. &lt;br /&gt;
And then execute the code, no error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences ==&lt;br /&gt;
With the same code, different operation codes are generated for IIf function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Position Op Op1      Op2        OpStr   &lt;br /&gt;
-----------------------------------------&lt;br /&gt;
// with problem&lt;br /&gt;
0000002E 80 00008003 00000002 	RTL	IIf	; Integer, Args&lt;br /&gt;
// restarted&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Op2 is type for this OpCode: &lt;br /&gt;
&amp;lt;pre&amp;gt;// SbiDisas::TypeOp&lt;br /&gt;
pTypes[][13] = {&lt;br /&gt;
  &amp;quot;Empty&amp;quot;,&amp;quot;Null&amp;quot;,&amp;quot;Integer&amp;quot;,&amp;quot;Long&amp;quot;,&amp;quot;Single&amp;quot;,&amp;quot;Double&amp;quot;,&lt;br /&gt;
  &amp;quot;Currency&amp;quot;,&amp;quot;Date&amp;quot;,&amp;quot;String&amp;quot;,&amp;quot;Object&amp;quot;,&amp;quot;Error&amp;quot;,&amp;quot;Boolean&amp;quot;,&lt;br /&gt;
  &amp;quot;Variant&amp;quot; };&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The error code 87302 is set in SbxValue::SetType (t is not equal to aData.eType) method. &lt;br /&gt;
Therefore the problem is caused by the wrong compilation when the code is modified.&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC &lt;br /&gt;
// SbiExprList::Gen in exprgen.cxx&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV &lt;br /&gt;
// SbiExprList::Gen in exprgen.cxx&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV &lt;br /&gt;
// SbiExprNode::GenElement in exprgen.cxx&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET &lt;br /&gt;
// SbiParser::Symbol in parser.cxx&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE &lt;br /&gt;
// SbiParser::DefProc in dim.cxx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In SbiParser::CheckRTLForSym method, pVar-&amp;gt;GetType() call should return SbxEMPTY for rSym == &amp;quot;IIf&amp;quot;. But SbxINTEGER is returned when the problem was happen. The return value of the function, instance of SbiSymDef gets wrong type. &lt;br /&gt;
Then the wrong type is passed to new SbiExprNode instance in SbiExpression::Term method.&lt;br /&gt;
When I change the second argument from &amp;quot;&amp;quot; to false, I got SbxSTRING for the type.&lt;br /&gt;
&lt;br /&gt;
While first compilation, SbxObject::Find( rName, t ) returns NULL in SbiStdObject::Find method for rName = &amp;quot;IIf&amp;quot;. &lt;br /&gt;
But the second compilation, the call returns something. Who does define IIf as something in the runtime?&lt;br /&gt;
&lt;br /&gt;
IIf function was found in pMethods in SbxObject::Find at second compilation. The function is defined as user defined function with just calling as runtime function, it seems. When the function is registerd in SbxObject::pMethods variable of runtime.&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/Iif_Problem&amp;diff=235770</id>
		<title>User:Hanya/Iif Problem</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/Iif_Problem&amp;diff=235770"/>
		<updated>2014-12-20T17:43:04Z</updated>

		<summary type="html">&lt;p&gt;Hanya: /* Code */ Add description about wrong findings of the function information&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Issue: https://issues.apache.org/ooo/show_bug.cgi?id=63614&lt;br /&gt;
&lt;br /&gt;
Error code 87302 is produced when some code is modified contains Iif runtime function.&lt;br /&gt;
&lt;br /&gt;
== Disassembled Original ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sub Main&lt;br /&gt;
IIf(true, 1.0, &amp;quot;&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Position Op Op1      Op2        OpStr   &lt;br /&gt;
-----------------------------------------&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000  // Label&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, 1.0, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	     // new argv&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 40 00000004          	NUMBER	&amp;quot;1&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000005          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Disassembled with Problem ==&lt;br /&gt;
Second argument for IIf function is changed from 1.0 to &amp;quot;&amp;quot;. &lt;br /&gt;
Execute the code after the change -&amp;gt; strange error.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sub Main&lt;br /&gt;
IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000002 	RTL	IIf	; Integer, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Disassembled without Problem after Restarting ==&lt;br /&gt;
After the modification and error mentioned above, restart the office. &lt;br /&gt;
And then execute the code, no error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences ==&lt;br /&gt;
With the same code, different operation codes are generated for IIf function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Position Op Op1      Op2        OpStr   &lt;br /&gt;
-----------------------------------------&lt;br /&gt;
// with problem&lt;br /&gt;
0000002E 80 00008003 00000002 	RTL	IIf	; Integer, Args&lt;br /&gt;
// restarted&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Op2 is type for this OpCode: &lt;br /&gt;
&amp;lt;pre&amp;gt;// SbiDisas::TypeOp&lt;br /&gt;
pTypes[][13] = {&lt;br /&gt;
  &amp;quot;Empty&amp;quot;,&amp;quot;Null&amp;quot;,&amp;quot;Integer&amp;quot;,&amp;quot;Long&amp;quot;,&amp;quot;Single&amp;quot;,&amp;quot;Double&amp;quot;,&lt;br /&gt;
  &amp;quot;Currency&amp;quot;,&amp;quot;Date&amp;quot;,&amp;quot;String&amp;quot;,&amp;quot;Object&amp;quot;,&amp;quot;Error&amp;quot;,&amp;quot;Boolean&amp;quot;,&lt;br /&gt;
  &amp;quot;Variant&amp;quot; };&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The error code 87302 is set in SbxValue::SetType (t is not equal to aData.eType) method. &lt;br /&gt;
Therefore the problem is caused by the wrong compilation when the code is modified.&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC &lt;br /&gt;
// SbiExprList::Gen in exprgen.cxx&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV &lt;br /&gt;
// SbiExprList::Gen in exprgen.cxx&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV &lt;br /&gt;
// SbiExprNode::GenElement in exprgen.cxx&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET &lt;br /&gt;
// SbiParser::Symbol in parser.cxx&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE &lt;br /&gt;
// SbiParser::DefProc in dim.cxx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In SbiParser::CheckRTLForSym method, pVar-&amp;gt;GetType() call should return SbxEMPTY for rSym == &amp;quot;IIf&amp;quot;. But SbxINTEGER is returned when the problem was happen. The return value of the function, instance of SbiSymDef gets wrong type. &lt;br /&gt;
Then the wrong type is passed to new SbiExprNode instance in SbiExpression::Term method.&lt;br /&gt;
When I change the second argument from &amp;quot;&amp;quot; to false, I got SbxSTRING for the type.&lt;br /&gt;
&lt;br /&gt;
While first compilation, SbxObject::Find( rName, t ) returns NULL in SbiStdObject::Find method for rName = &amp;quot;IIf&amp;quot;. &lt;br /&gt;
But the second compilation, the call returns something. Who does define IIf as something in the runtime?&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/Iif_Problem&amp;diff=235769</id>
		<title>User:Hanya/Iif Problem</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/Iif_Problem&amp;diff=235769"/>
		<updated>2014-12-20T17:19:11Z</updated>

		<summary type="html">&lt;p&gt;Hanya: /* Differences */ Add some description with code location&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Issue: https://issues.apache.org/ooo/show_bug.cgi?id=63614&lt;br /&gt;
&lt;br /&gt;
Error code 87302 is produced when some code is modified contains Iif runtime function.&lt;br /&gt;
&lt;br /&gt;
== Disassembled Original ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sub Main&lt;br /&gt;
IIf(true, 1.0, &amp;quot;&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Position Op Op1      Op2        OpStr   &lt;br /&gt;
-----------------------------------------&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000  // Label&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, 1.0, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	     // new argv&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 40 00000004          	NUMBER	&amp;quot;1&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000005          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Disassembled with Problem ==&lt;br /&gt;
Second argument for IIf function is changed from 1.0 to &amp;quot;&amp;quot;. &lt;br /&gt;
Execute the code after the change -&amp;gt; strange error.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sub Main&lt;br /&gt;
IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000002 	RTL	IIf	; Integer, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Disassembled without Problem after Restarting ==&lt;br /&gt;
After the modification and error mentioned above, restart the office. &lt;br /&gt;
And then execute the code, no error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences ==&lt;br /&gt;
With the same code, different operation codes are generated for IIf function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Position Op Op1      Op2        OpStr   &lt;br /&gt;
-----------------------------------------&lt;br /&gt;
// with problem&lt;br /&gt;
0000002E 80 00008003 00000002 	RTL	IIf	; Integer, Args&lt;br /&gt;
// restarted&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Op2 is type for this OpCode: &lt;br /&gt;
&amp;lt;pre&amp;gt;// SbiDisas::TypeOp&lt;br /&gt;
pTypes[][13] = {&lt;br /&gt;
  &amp;quot;Empty&amp;quot;,&amp;quot;Null&amp;quot;,&amp;quot;Integer&amp;quot;,&amp;quot;Long&amp;quot;,&amp;quot;Single&amp;quot;,&amp;quot;Double&amp;quot;,&lt;br /&gt;
  &amp;quot;Currency&amp;quot;,&amp;quot;Date&amp;quot;,&amp;quot;String&amp;quot;,&amp;quot;Object&amp;quot;,&amp;quot;Error&amp;quot;,&amp;quot;Boolean&amp;quot;,&lt;br /&gt;
  &amp;quot;Variant&amp;quot; };&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The error code 87302 is set in SbxValue::SetType (t is not equal to aData.eType) method. &lt;br /&gt;
Therefore the problem is caused by the wrong compilation when the code is modified.&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC &lt;br /&gt;
// SbiExprList::Gen in exprgen.cxx&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV &lt;br /&gt;
// SbiExprList::Gen in exprgen.cxx&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV &lt;br /&gt;
// SbiExprNode::GenElement in exprgen.cxx&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET &lt;br /&gt;
// SbiParser::Symbol in parser.cxx&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE &lt;br /&gt;
// SbiParser::DefProc in dim.cxx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In SbiParser::CheckRTLForSym method, pVar-&amp;gt;GetType() call should return SbxEMPTY for rSym == &amp;quot;IIf&amp;quot;. But SbxINTEGER is returned when the problem was happen. The return value of the function, instance of SbiSymDef gets wrong type. &lt;br /&gt;
Then the wrong type is passed to new SbiExprNode instance in SbiExpression::Term method.&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/Iif_Problem&amp;diff=235768</id>
		<title>User:Hanya/Iif Problem</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/Iif_Problem&amp;diff=235768"/>
		<updated>2014-12-20T09:30:16Z</updated>

		<summary type="html">&lt;p&gt;Hanya: /* Differences */ Add about Op2 code&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Issue: https://issues.apache.org/ooo/show_bug.cgi?id=63614&lt;br /&gt;
&lt;br /&gt;
Error code 87302 is produced when some code is modified contains Iif runtime function.&lt;br /&gt;
&lt;br /&gt;
== Disassembled Original ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sub Main&lt;br /&gt;
IIf(true, 1.0, &amp;quot;&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Position Op Op1      Op2        OpStr   &lt;br /&gt;
-----------------------------------------&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000  // Label&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, 1.0, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	     // new argv&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 40 00000004          	NUMBER	&amp;quot;1&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000005          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Disassembled with Problem ==&lt;br /&gt;
Second argument for IIf function is changed from 1.0 to &amp;quot;&amp;quot;. &lt;br /&gt;
Execute the code after the change -&amp;gt; strange error.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sub Main&lt;br /&gt;
IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000002 	RTL	IIf	; Integer, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Disassembled without Problem after Restarting ==&lt;br /&gt;
After the modification and error mentioned above, restart the office. &lt;br /&gt;
And then execute the code, no error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences ==&lt;br /&gt;
With the same code, different operation codes are generated for IIf function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Position Op Op1      Op2        OpStr   &lt;br /&gt;
-----------------------------------------&lt;br /&gt;
// with problem&lt;br /&gt;
0000002E 80 00008003 00000002 	RTL	IIf	; Integer, Args&lt;br /&gt;
// restarted&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Op2 is type for this OpCode: &lt;br /&gt;
&amp;lt;pre&amp;gt;// SbiDisas::TypeOp&lt;br /&gt;
pTypes[][13] = {&lt;br /&gt;
  &amp;quot;Empty&amp;quot;,&amp;quot;Null&amp;quot;,&amp;quot;Integer&amp;quot;,&amp;quot;Long&amp;quot;,&amp;quot;Single&amp;quot;,&amp;quot;Double&amp;quot;,&lt;br /&gt;
  &amp;quot;Currency&amp;quot;,&amp;quot;Date&amp;quot;,&amp;quot;String&amp;quot;,&amp;quot;Object&amp;quot;,&amp;quot;Error&amp;quot;,&amp;quot;Boolean&amp;quot;,&lt;br /&gt;
  &amp;quot;Variant&amp;quot; };&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The error code 87302 is set in SbxValue::SetType (t is not equal to aData.eType) method. &lt;br /&gt;
Therefore the problem is caused by the wrong compilation when the code is modified.&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/Iif_Problem&amp;diff=235767</id>
		<title>User:Hanya/Iif Problem</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/Iif_Problem&amp;diff=235767"/>
		<updated>2014-12-20T09:27:03Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Fix section tags&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Issue: https://issues.apache.org/ooo/show_bug.cgi?id=63614&lt;br /&gt;
&lt;br /&gt;
Error code 87302 is produced when some code is modified contains Iif runtime function.&lt;br /&gt;
&lt;br /&gt;
== Disassembled Original ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sub Main&lt;br /&gt;
IIf(true, 1.0, &amp;quot;&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Position Op Op1      Op2        OpStr   &lt;br /&gt;
-----------------------------------------&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000  // Label&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, 1.0, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	     // new argv&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 40 00000004          	NUMBER	&amp;quot;1&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000005          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Disassembled with Problem ==&lt;br /&gt;
Second argument for IIf function is changed from 1.0 to &amp;quot;&amp;quot;. &lt;br /&gt;
Execute the code after the change -&amp;gt; strange error.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sub Main&lt;br /&gt;
IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000002 	RTL	IIf	; Integer, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Disassembled without Problem after Restarting ==&lt;br /&gt;
After the modification and error mentioned above, restart the office. &lt;br /&gt;
And then execute the code, no error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Differences ==&lt;br /&gt;
With the same code, different operation codes are generated for IIf function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// with problem&lt;br /&gt;
0000002E 80 00008003 00000002 	RTL	IIf	; Integer, Args&lt;br /&gt;
// restarted&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The error code 87302 is set in SbxValue::SetType (t is not equal to aData.eType) method. &lt;br /&gt;
Therefore the problem is caused by the wrong compilation when the code is modified.&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/Iif_Problem&amp;diff=235766</id>
		<title>User:Hanya/Iif Problem</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/Iif_Problem&amp;diff=235766"/>
		<updated>2014-12-20T09:25:33Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add initial content of this page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Issue: https://issues.apache.org/ooo/show_bug.cgi?id=63614&lt;br /&gt;
&lt;br /&gt;
Error code 87302 is produced when some code is modified contains Iif runtime function.&lt;br /&gt;
&lt;br /&gt;
** Disassembled Original&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sub Main&lt;br /&gt;
IIf(true, 1.0, &amp;quot;&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Position Op Op1      Op2        OpStr   &lt;br /&gt;
-----------------------------------------&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000  // Label&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, 1.0, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	     // new argv&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 40 00000004          	NUMBER	&amp;quot;1&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000005          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
** Disassembled with Problem&lt;br /&gt;
Second argument for IIf function is changed from 1.0 to &amp;quot;&amp;quot;. &lt;br /&gt;
Execute the code after the change -&amp;gt; strange error.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Sub Main&lt;br /&gt;
IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000002 	RTL	IIf	; Integer, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
** Disassembled without Problem after Restarting&lt;br /&gt;
After the modification and error mentioned above, restart the office. &lt;br /&gt;
And then execute the code, no error.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00000000                            Lbl00000000:&lt;br /&gt;
00000000 45 00000000          	JUMP	Lbl0000&lt;br /&gt;
; Sub Main&lt;br /&gt;
00000005                            Main:&lt;br /&gt;
00000005 87 00000003 00000000 	STMNT	3,0 (For-Level: 0)&lt;br /&gt;
; IIf(true, &amp;quot;&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
0000000E 87 00000004 00000000 	STMNT	4,0 (For-Level: 0)&lt;br /&gt;
00000017 18                   	ARGC	&lt;br /&gt;
00000018 80 00000002 0000000C 	RTL	true	; Variant&lt;br /&gt;
00000021 19                   	ARGV	&lt;br /&gt;
00000022 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
00000027 19                   	ARGV	&lt;br /&gt;
00000028 41 00000004          	STRING	&amp;quot;&amp;quot;&lt;br /&gt;
0000002D 19                   	ARGV	&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
00000037 1C                   	GET	&lt;br /&gt;
; End Sub&lt;br /&gt;
00000038 87 00000005 00000000 	STMNT	5,0 (For-Level: 0)&lt;br /&gt;
00000041 2B                   	LEAVE	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
** Differences&lt;br /&gt;
With the same code, different operation codes are generated for IIf function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// with problem&lt;br /&gt;
0000002E 80 00008003 00000002 	RTL	IIf	; Integer, Args&lt;br /&gt;
// restarted&lt;br /&gt;
0000002E 80 00008003 00000000 	RTL	IIf	; Empty, Args&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The error code 87302 is set in SbxValue::SetType (t is not equal to aData.eType) method. &lt;br /&gt;
Therefore the problem is caused by the wrong compilation when the code is modified.&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya&amp;diff=235765</id>
		<title>User:Hanya</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya&amp;diff=235765"/>
		<updated>2014-12-20T07:43:35Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add link to Iif problem page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ICLA submitted.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
* [[/Tracked_API_Changes]]&lt;br /&gt;
* [[/Hyperlink_Control_on_Dialog_Editor]]&lt;br /&gt;
* [[/Distribute_SymbolStyles_by_Extension]]&lt;br /&gt;
* [[/External_Libraries]]&lt;br /&gt;
* [[/API Changes on 4.0 since 3.4]]&lt;br /&gt;
* [[/Translation_Review]]&lt;br /&gt;
* [[/New_Field_on_Writer]]&lt;br /&gt;
* [[/Iif_Problem]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/New_Field_on_Writer&amp;diff=235026</id>
		<title>User:Hanya/New Field on Writer</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/New_Field_on_Writer&amp;diff=235026"/>
		<updated>2014-05-16T12:06:13Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add note when adding new field on Writer&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
On Fields dialog of Writer document, the order of sub types for ExtUser fields should be match with SwExtUserSubType enum values. If not match with them, illegal value would be taken.&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya&amp;diff=235025</id>
		<title>User:Hanya</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya&amp;diff=235025"/>
		<updated>2014-05-16T12:03:43Z</updated>

		<summary type="html">&lt;p&gt;Hanya: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ICLA submitted.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
* [[/Tracked_API_Changes]]&lt;br /&gt;
* [[/Hyperlink_Control_on_Dialog_Editor]]&lt;br /&gt;
* [[/Distribute_SymbolStyles_by_Extension]]&lt;br /&gt;
* [[/External_Libraries]]&lt;br /&gt;
* [[/API Changes on 4.0 since 3.4]]&lt;br /&gt;
* [[/Translation_Review]]&lt;br /&gt;
* [[/New_Field_on_Writer]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Documentation/DevGuide/OfficeDev/XML_Filter_Detection&amp;diff=234505</id>
		<title>Documentation/DevGuide/OfficeDev/XML Filter Detection</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Documentation/DevGuide/OfficeDev/XML_Filter_Detection&amp;diff=234505"/>
		<updated>2014-02-11T15:06:09Z</updated>

		<summary type="html">&lt;p&gt;Hanya: i21766 Data property can not contain new line&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Documentation/DevGuide/OfficeDevTOC&lt;br /&gt;
|OfficeDev2b=block&lt;br /&gt;
|OfficeDevInteg=block&lt;br /&gt;
|OfficeDevXMLFilter=block&lt;br /&gt;
|ShowPrevNext=block&lt;br /&gt;
|PrevPage=Documentation/DevGuide/OfficeDev/The Exporter&lt;br /&gt;
|NextPage=Documentation/DevGuide/OfficeDev/Number Formats&lt;br /&gt;
}}&lt;br /&gt;
{{Documentation/DevGuideLanguages|Documentation/DevGuide/OfficeDev/{{SUBPAGENAME}}}} &lt;br /&gt;
 {{DISPLAYTITLE:XML Filter Detection}}&lt;br /&gt;
__NOTOC__&lt;br /&gt;
&amp;lt;!--&amp;lt;idltopic&amp;gt;com.sun.star.document.ExtendedTypeDetection&amp;lt;/idltopic&amp;gt;--&amp;gt;&lt;br /&gt;
The number of XML files that conform to differing DTD specifications means that a single filter and file type definition is insufficient to handle all of the possible formats available. In order to allow {{PRODUCTNAME}} to handle multiple filter definitions and implementations, it is necessary to implement an additional filter detection module that is capable of determining the type of XML file being read, based on its &amp;lt;code&amp;gt;DocType&amp;lt;/code&amp;gt; declaration.&lt;br /&gt;
&lt;br /&gt;
To accomplish this, a filter detection service &amp;lt;idl&amp;gt;com.sun.star.document.ExtendedTypeDetection&amp;lt;/idl&amp;gt; can be implemented, which is capable of handling and distinguishing between many different XML based file formats. This type of service supersedes the basic &amp;#039;&amp;#039;flat&amp;#039;&amp;#039; detection, which uses the file&amp;#039;s suffix to determine the Type, and instead, carries out a &amp;#039;&amp;#039;deep&amp;#039;&amp;#039; detection which uses the file&amp;#039;s internal structure and content to detect its true type.&lt;br /&gt;
&lt;br /&gt;
=== Requirements for Deep Detection ===&lt;br /&gt;
&lt;br /&gt;
There are three requirements for implementing a deep detection module that is capable of identifying one or more unique XML types. These include:&lt;br /&gt;
&lt;br /&gt;
* An extended type definition for describing the format in more detail (&amp;#039;&amp;#039;TypeDetection.xcu&amp;#039;&amp;#039;).&lt;br /&gt;
* A &amp;lt;code&amp;gt;DetectService&amp;lt;/code&amp;gt; implementation.&lt;br /&gt;
* A &amp;lt;code&amp;gt;DetectService&amp;lt;/code&amp;gt; definition (&amp;#039;&amp;#039;TypeDetection.xcu&amp;#039;&amp;#039;).&lt;br /&gt;
&lt;br /&gt;
=== Extending the File Type Definition ===&lt;br /&gt;
&lt;br /&gt;
Since many different XML files can conform to different DTDs, the type definition of a particular XML file needs to be extended. To do this, some or all of the &amp;lt;code&amp;gt;DocType&amp;lt;/code&amp;gt; information can be contained as part of the file type definition. This information is held as part of the &amp;lt;code&amp;gt;ClipboardFormat&amp;lt;/code&amp;gt; property of the type node. A unique namespace or preface identifies the string at this point in the sequence as being a &amp;lt;code&amp;gt;DocType&amp;lt;/code&amp;gt; declaration.&lt;br /&gt;
&lt;br /&gt;
==== Sample Type definition: ====&lt;br /&gt;
 &amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;node oor:name=&amp;quot;writer_DocBook_File&amp;quot; oor:op=&amp;quot;replace&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;prop oor:name=&amp;quot;UIName&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;value XML:lang=&amp;quot;en-US&amp;quot;&amp;gt;DocBook&amp;lt;/value&amp;gt;&lt;br /&gt;
      &amp;lt;/prop&amp;gt;&lt;br /&gt;
      &amp;lt;prop oor:name=&amp;quot;Data&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;value&amp;gt;0,,doctype:-//OASIS//DTD DocBook XML V4.1.2//EN,,XML,20002,&amp;lt;/value&amp;gt;&lt;br /&gt;
      &amp;lt;/prop&amp;gt;&lt;br /&gt;
  &amp;lt;/node&amp;gt;&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
=== The ExtendedTypeDetection Service Implementation ===&lt;br /&gt;
&lt;br /&gt;
In order for the type detection code to function as an &amp;lt;code&amp;gt;ExtendedTypeDetection&amp;lt;/code&amp;gt; service, you must implement the &amp;lt;code&amp;gt;detect()&amp;lt;/code&amp;gt; method as defined by the &amp;lt;idl&amp;gt;com.sun.star.document.XExtendedFilterDetection&amp;lt;/idl&amp;gt; interface definition:&lt;br /&gt;
 &amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
  string detect( [inout]sequence&amp;lt;com::sun::star::beans::PropertyValue &amp;gt; Descriptor );&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
This method supplies you with a sequence of &amp;lt;code&amp;gt;PropertyValue&amp;lt;/code&amp;gt;s from which you can use to extract the current &amp;lt;code&amp;gt;TypeName&amp;lt;/code&amp;gt; and the &amp;lt;code&amp;gt;URL&amp;lt;/code&amp;gt; of the file being loaded:&lt;br /&gt;
 &amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
  ::rtl::OUString SAL_CALL FilterDetect::detect(com::sun::star::uno::Sequence&amp;lt; com::sun::star::beans::PropertyValue &amp;gt;&amp;amp; aArguments ) throw (com::sun::star::uno::RuntimeException) &lt;br /&gt;
  {&lt;br /&gt;
  const PropertyValue * pValue = aArguments.getConstArray();&lt;br /&gt;
  sal_Int32 nLength;&lt;br /&gt;
  ::rtl::OString resultString;&lt;br /&gt;
  nLength = aArguments.getLength();&lt;br /&gt;
  for (sal_Int32 i = 0; i &amp;lt; nLength; i++) {&lt;br /&gt;
          if (pValue[i].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(&amp;quot;TypeName&amp;quot;))) {&lt;br /&gt;
          }&lt;br /&gt;
          else if (pValue[i].Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(&amp;quot;URL&amp;quot;))) {&lt;br /&gt;
                  pValue[i].Value &amp;gt;&amp;gt;= sUrl;&lt;br /&gt;
          }&lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
Once you have the URL of the file, you can then use it to create a &amp;lt;code&amp;gt;::ucb::Content&amp;lt;/code&amp;gt; from which you can open an &amp;lt;code&amp;gt;XInputStream&amp;lt;/code&amp;gt; to the file:&lt;br /&gt;
 &amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
  Reference&amp;lt; com::sun::star::ucb::XCommandEnvironment &amp;gt; xEnv;&lt;br /&gt;
  ::ucb::Content aContent(sUrl,xEnv);&lt;br /&gt;
  xInStream = aContent.openStream();&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
You can now use this &amp;lt;code&amp;gt;XInputStream&amp;lt;/code&amp;gt; to read the header of the file being loaded. Because the exact location of the &amp;lt;code&amp;gt;DocType&amp;lt;/code&amp;gt; information within the file is not known, the first 1000 bytes of information will be read:&lt;br /&gt;
 &amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
  ::rtl::OString resultString;&lt;br /&gt;
  com::sun::star::uno::Sequence&amp;lt; sal_Int8 &amp;gt; aData;&lt;br /&gt;
  long bytestRead = xInStream-&amp;gt;readBytes (aData, 1000);&lt;br /&gt;
  resultString = ::rtl::OString( (const sal_Char *)aData.getConstArray(), bytestRead);&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
Once you have this information, you can start looking for a type that describes the file being loaded. In order to do this, you need to get a list of the types currently supported:&lt;br /&gt;
 &amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
  Reference &amp;lt;XNameAccess&amp;gt; xTypeCont(mxMSF-&amp;gt;createInstance(OUString::createFromAscii(&lt;br /&gt;
                                  &amp;quot;com.sun.star.document.TypeDetection&amp;quot; )),UNO_QUERY);&lt;br /&gt;
  Sequence &amp;lt;::rtl::OUString&amp;gt; myTypes= xTypeCont-&amp;gt;getElementNames();&lt;br /&gt;
  nLength = myTypes.getLength();&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
For each of these types, you must first determine whether the &amp;lt;code&amp;gt;ClipboardFormat&amp;lt;/code&amp;gt; property contains a DocType:&lt;br /&gt;
 &amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
  Loc_of_ClipboardFormat=...;&lt;br /&gt;
  Sequence&amp;lt;::rtl::OUString&amp;gt; ClipboardFormatSeq;&lt;br /&gt;
  Type_Props[Loc_of_ClipboardFormat].Value &amp;gt;&amp;gt;=ClipboardFormatSeq ;&lt;br /&gt;
  while() {&lt;br /&gt;
          if(ClipboardFormatSeq.match(OUString::createFromAscii(&amp;quot;doctype:&amp;quot;) {&lt;br /&gt;
                      //if it contains a DocType, start to compare to header&lt;br /&gt;
          }&lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
All of the possible &amp;lt;code&amp;gt;DocType&amp;lt;/code&amp;gt; declarations of the file types can be checked to determine a match. If a match is found, the type corresponding to the match is returned. If no match is found, an empty string is returned. This will force {{PRODUCTNAME}} into flat detection mode.&lt;br /&gt;
&lt;br /&gt;
=== TypeDetection.xcu DetectServices Entry ===&lt;br /&gt;
&lt;br /&gt;
Now that you have created the &amp;lt;code&amp;gt;ExtendedTypeDetection&amp;lt;/code&amp;gt; service implementation, you need to tell {{PRODUCTNAME}} when to use this service.&lt;br /&gt;
&lt;br /&gt;
First create a &amp;lt;code&amp;gt;DetectServices&amp;lt;/code&amp;gt; node, unless one already exists, and then add the information specific to the detection service that has been implemented, that is, the name of the service and the file types that use it.&lt;br /&gt;
 &amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;node oor:name=&amp;quot;DetectServices&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;node oor:name=&amp;quot;com.sun.star.comp.filters.XMLDetect&amp;quot; oor:op=&amp;quot;replace&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;prop oor:name=&amp;quot;ServiceName&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;value XML:lang=&amp;quot;en-US&amp;quot;&amp;gt;com.sun.star.comp.filters.XMLDetect&amp;lt;/value&amp;gt;&lt;br /&gt;
          &amp;lt;/prop&amp;gt;&lt;br /&gt;
          &amp;lt;prop oor:name=&amp;quot;Types&amp;quot;&amp;gt;&lt;br /&gt;
                  &amp;lt;value&amp;gt;writer_DocBook_File&amp;lt;/value&amp;gt;&lt;br /&gt;
                  &amp;lt;value&amp;gt;writer_Flat_XML_File&amp;lt;/value&amp;gt;&lt;br /&gt;
          &amp;lt;/prop&amp;gt;&lt;br /&gt;
  &amp;lt;/node&amp;gt;&lt;br /&gt;
  &amp;lt;/node&amp;gt;&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
{{PDL1}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation/Developer&amp;#039;s Guide/Office Development]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Documentation/DevGuide/Scripting/Writing_Macros&amp;diff=232984</id>
		<title>Documentation/DevGuide/Scripting/Writing Macros</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Documentation/DevGuide/Scripting/Writing_Macros&amp;diff=232984"/>
		<updated>2014-02-03T06:36:07Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add description about manifest entries when Java macro embedded in document&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Documentation/DevGuide/ScriptingTOC&lt;br /&gt;
|ShowPrevNext=block&lt;br /&gt;
|PrevPage=Documentation/DevGuide/Scripting/Macro Recording&lt;br /&gt;
|NextPage=Documentation/DevGuide/Scripting/How the Scripting Framework Works&lt;br /&gt;
}}&lt;br /&gt;
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Scripting/{{SUBPAGENAME}}}} &lt;br /&gt;
 {{DISPLAYTITLE:Writing Macros}}&lt;br /&gt;
__NOTOC__&lt;br /&gt;
=== The HelloWorld macro ===&lt;br /&gt;
Here is a comparison of HelloWorld macros in the different script languages available in {{PRODUCTNAME}}.&lt;br /&gt;
&lt;br /&gt;
==== Basic ====&lt;br /&gt;
 &amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Sub writeHelloWorld()&lt;br /&gt;
Dim oDoc As Object, xText As Object, xTextRange As Object&lt;br /&gt;
&lt;br /&gt;
oDoc = ThisComponent&lt;br /&gt;
xText = oDoc.getText()&lt;br /&gt;
xTextRange = xText.getEnd()&lt;br /&gt;
xTextRange.CharBackColor = 1234567&lt;br /&gt;
xTextRange.CharHeight = 16.0&lt;br /&gt;
&amp;#039; CharUnderline receives a group constant&lt;br /&gt;
xTextRange.CharUnderline = com.sun.star.awt.FontUnderline.WAVE&lt;br /&gt;
&amp;#039; CharPosture receives an enum&lt;br /&gt;
xTextRange.CharPosture = com.sun.star.awt.FontSlant.ITALIC&lt;br /&gt;
xTextRange.setString( &amp;quot;Hello World (in Basic)&amp;quot; )&lt;br /&gt;
End Sub&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
Basic interprets pairs of get and set methods at UNO objects as object properties if they follow this pattern:&lt;br /&gt;
&lt;br /&gt;
  SomeType getSomeProperty()&lt;br /&gt;
  void setSomeProperty(SomeType aValue)&lt;br /&gt;
&lt;br /&gt;
Using these facilities some lines can be simplified:&lt;br /&gt;
 &amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
xText = oDoc.Text&lt;br /&gt;
xTextRange = xText.End&lt;br /&gt;
xTextRange.String = &amp;quot;Hello World (in Basic)&amp;quot;&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Service properties can be directly accessed in Basic, it is not necessary to use &amp;lt;code&amp;gt;getPropertyValue&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;setPropertyValue&amp;lt;/code&amp;gt; methods.&lt;br /&gt;
&lt;br /&gt;
==== BeanShell ====&lt;br /&gt;
As BeanShell accepts typeless variables, the code is simplified compared to Java.&lt;br /&gt;
 &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import com.sun.star.uno.UnoRuntime;&lt;br /&gt;
import com.sun.star.text.XTextDocument;&lt;br /&gt;
import com.sun.star.text.XText;&lt;br /&gt;
import com.sun.star.text.XTextRange;&lt;br /&gt;
import com.sun.star.beans.XPropertySet;&lt;br /&gt;
import com.sun.star.awt.FontSlant;&lt;br /&gt;
import com.sun.star.awt.FontUnderline;&lt;br /&gt;
&lt;br /&gt;
oDoc = XSCRIPTCONTEXT.getDocument();&lt;br /&gt;
&lt;br /&gt;
xTextDoc = UnoRuntime.queryInterface(XTextDocument.class,oDoc);&lt;br /&gt;
xText = xTextDoc.getText();&lt;br /&gt;
xTextRange = xText.getEnd();&lt;br /&gt;
pv = UnoRuntime.queryInterface(XPropertySet.class, xTextRange);&lt;br /&gt;
&lt;br /&gt;
pv.setPropertyValue(&amp;quot;CharBackColor&amp;quot;, 1234567);&lt;br /&gt;
pv.setPropertyValue(&amp;quot;CharHeight&amp;quot;, 16.0);&lt;br /&gt;
// CharUnderline receives a group constant&lt;br /&gt;
pv.setPropertyValue(&amp;quot;CharUnderline&amp;quot;, com.sun.star.awt.FontUnderline.WAVE);&lt;br /&gt;
// CharPosture receives an enum&lt;br /&gt;
pv.setPropertyValue(&amp;quot;CharPosture&amp;quot;, com.sun.star.awt.FontSlant.ITALIC) ;&lt;br /&gt;
&lt;br /&gt;
xTextRange.setString( &amp;quot;Hello World (in BeanShell)&amp;quot; );&lt;br /&gt;
return 0;&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
BeanShell interprets pairs of get and set methods at UNO objects as object properties if they follow this pattern:&lt;br /&gt;
&lt;br /&gt;
  SomeType getSomeProperty()&lt;br /&gt;
  void setSomeProperty(SomeType aValue)&lt;br /&gt;
&lt;br /&gt;
Using these facilities some lines can be simplified:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
  xText = xTextDoc.Text;&lt;br /&gt;
  xTextRange = xText.End;&lt;br /&gt;
  xTextRange.String = &amp;quot;Hello World (in BeanShell)&amp;quot;;&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Service properties are only accessed with &amp;lt;code&amp;gt;getPropertyValue&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;setPropertyValue&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== JavaScript ====&lt;br /&gt;
As JavaScript accepts typeless variables, the code is simplified compared to Java.&lt;br /&gt;
 &amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
importClass(Packages.com.sun.star.uno.UnoRuntime)&lt;br /&gt;
importClass(Packages.com.sun.star.text.XTextDocument)&lt;br /&gt;
importClass(Packages.com.sun.star.text.XText)&lt;br /&gt;
importClass(Packages.com.sun.star.text.XTextRange)&lt;br /&gt;
importClass(Packages.com.sun.star.beans.XPropertySet)&lt;br /&gt;
importClass(Packages.com.sun.star.awt.FontSlant)&lt;br /&gt;
importClass(Packages.com.sun.star.awt.FontUnderline)&lt;br /&gt;
&lt;br /&gt;
oDoc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
xTextDoc = UnoRuntime.queryInterface(XTextDocument,oDoc)&lt;br /&gt;
xText = xTextDoc.getText()&lt;br /&gt;
xTextRange = xText.getEnd()&lt;br /&gt;
pv = UnoRuntime.queryInterface(XPropertySet, xTextRange)&lt;br /&gt;
&lt;br /&gt;
pv.setPropertyValue(&amp;quot;CharHeight&amp;quot;, 16.0) // Double&lt;br /&gt;
// CharBackColor receives an Integer&lt;br /&gt;
pv.setPropertyValue(&amp;quot;CharBackColor&amp;quot;, new java.lang.Integer(1234567))&lt;br /&gt;
// CharUnderline receives a group constant&lt;br /&gt;
pv.setPropertyValue(&amp;quot;CharUnderline&amp;quot;,&lt;br /&gt;
   new java.lang.Short(Packages.com.sun.star.awt.FontUnderline.WAVE))&lt;br /&gt;
// CharPosture receives an enum&lt;br /&gt;
pv.setPropertyValue(&amp;quot;CharPosture&amp;quot;, Packages.com.sun.star.awt.FontSlant.ITALIC) &lt;br /&gt;
xTextRange.setString( &amp;quot;Hello World (in JavaScript)&amp;quot; )&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
JavaScript does not accept the simplifications seen in Basic and BeanShell.&lt;br /&gt;
&lt;br /&gt;
Setting an integer value to a property requires to use a java class.&lt;br /&gt;
&lt;br /&gt;
==== Java ====&lt;br /&gt;
Other sections of this document provide numerous Java examples. Here is the HelloWorld provided in {{PRODUCTNAME}}&lt;br /&gt;
 &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
  import com.sun.star.uno.UnoRuntime;&lt;br /&gt;
  import com.sun.star.frame.XModel;&lt;br /&gt;
  import com.sun.star.text.XTextDocument;&lt;br /&gt;
  import com.sun.star.text.XTextRange;&lt;br /&gt;
  import com.sun.star.text.XText;&lt;br /&gt;
  import com.sun.star.script.provider.XScriptContext;&lt;br /&gt;
  &lt;br /&gt;
  public class HelloWorld {&lt;br /&gt;
      public static void printHW(XScriptContext xScriptContext)&lt;br /&gt;
      {&lt;br /&gt;
          XModel xDocModel = xScriptContext.getDocument();&lt;br /&gt;
    &lt;br /&gt;
          // getting the text document object&lt;br /&gt;
          XTextDocument xtextdocument = (XTextDocument) UnoRuntime.queryInterface(&lt;br /&gt;
              XTextDocument.class, xDocModel);&lt;br /&gt;
      &lt;br /&gt;
          XText xText = xtextdocument.getText();&lt;br /&gt;
          XTextRange xTextRange = xText.getEnd();&lt;br /&gt;
          xTextRange.setString( &amp;quot;Hello World (in Java)&amp;quot; );&lt;br /&gt;
      }&lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Compiling and Deploying Java macros =====&lt;br /&gt;
&lt;br /&gt;
Because Java is a compiled language it is not possible to execute Java source code as a macro directly from within {{PRODUCTNAME}}. The code must first be compiled and then deployed within a {{PRODUCTNAME}} installation or document. The following steps show how to create a Java macro using the HelloWorld example code:&lt;br /&gt;
&lt;br /&gt;
* Create a &amp;#039;&amp;#039;HelloWorld&amp;#039;&amp;#039; directory for your macro&lt;br /&gt;
* Create a &amp;#039;&amp;#039;HelloWorld.java&amp;#039;&amp;#039; file using the HelloWorld source code&lt;br /&gt;
* Compile the &amp;#039;&amp;#039;HelloWorld.java&amp;#039;&amp;#039; file. The following jar files from the &amp;#039;&amp;#039;program/classes&amp;#039;&amp;#039; directory of a {{PRODUCTNAME}} installation must be in the classpath: &amp;#039;&amp;#039;ridl.jar&amp;#039;&amp;#039;, &amp;#039;&amp;#039;unoil.jar&amp;#039;&amp;#039;, &amp;#039;&amp;#039;jurt.jar&amp;#039;&amp;#039;&lt;br /&gt;
* Create a &amp;#039;&amp;#039;HelloWorld.jar&amp;#039;&amp;#039; file containing the &amp;#039;&amp;#039;HelloWorld.class&amp;#039;&amp;#039; file&lt;br /&gt;
* Create a &amp;#039;&amp;#039;parcel-descriptor.xml&amp;#039;&amp;#039; file for your macro&lt;br /&gt;
 &amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;lt;parcel language=&amp;quot;Java&amp;quot; xmlns:parcel=&amp;quot;scripting.dtd&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;script language=&amp;quot;Java&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;locale lang=&amp;quot;en&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;displayname value=&amp;quot;HelloWorld&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;description&amp;gt;&lt;br /&gt;
          Prints &amp;quot;Hello World&amp;quot;.&lt;br /&gt;
        &amp;lt;/description&amp;gt;&lt;br /&gt;
      &amp;lt;/locale&amp;gt;&lt;br /&gt;
      &amp;lt;functionname value=&amp;quot;HelloWorld.printHW&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;logicalname value=&amp;quot;HelloWorld.printHW&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;languagedepprops&amp;gt;&lt;br /&gt;
          &amp;lt;prop name=&amp;quot;classpath&amp;quot; value=&amp;quot;HelloWorld.jar&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;/languagedepprops&amp;gt;&lt;br /&gt;
    &amp;lt;/script&amp;gt;&lt;br /&gt;
  &amp;lt;/parcel&amp;gt;&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
The &amp;#039;&amp;#039;parcel-descriptor.xml&amp;#039;&amp;#039; file is used by the Scripting Framework to find macros. The functionname element indicates the name of the Java method which should be executed as a macro. The classpath element can be used to indicate any jar or class files which are used by the macro. If the classpath element is not included, then the directory in which the &amp;#039;&amp;#039;parcel-desciptor.xml&amp;#039;&amp;#039; file is found and any jar files in that directory will be used as the classpath. The necessary Java UNO classes are available automatically.&lt;br /&gt;
&lt;br /&gt;
* Copy the HelloWorld directory into the &amp;#039;&amp;#039;share/Scripts/java&amp;#039;&amp;#039; (or &amp;#039;&amp;#039;basis/share/Scripts/java&amp;#039;&amp;#039;) directory of a {{PRODUCTNAME}} installation or into the &amp;#039;&amp;#039;user/Scripts/java&amp;#039;&amp;#039; directory of a user installation. If you want to deploy the macro to a document you need to place it in a &amp;#039;&amp;#039;Scripts/java&amp;#039;&amp;#039; directory within the document zip file.&lt;br /&gt;
* If {{PRODUCTNAME}} is running, you will need to restart it in order for the macro to appear in the Macro Selector dialog.&lt;br /&gt;
&lt;br /&gt;
{{Documentation/Note|The &amp;#039;&amp;#039;parcel-descriptor.xml&amp;#039;&amp;#039; file is also used to detect BeanShell and JavaScript macros. It is created automatically when creating macros using the Organizer dialogs for BeanShell and JavaScript.}}&lt;br /&gt;
&lt;br /&gt;
If these files are embedded in document file, they have to be registered in META-INF/manifest.xml: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;manifest:file-entry manifest:media-type=&amp;quot;text/xml&amp;quot; manifest:full-path=&amp;quot;Scripts/java/Test/parcel-descriptor.xml&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;manifest:file-entry manifest:media-type=&amp;quot;application/binary&amp;quot; manifest:full-path=&amp;quot;Scripts/java/Test/test.jar&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;manifest:file-entry manifest:media-type=&amp;quot;&amp;quot; manifest:full-path=&amp;quot;Scripts/java/Test/&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;manifest:file-entry manifest:media-type=&amp;quot;&amp;quot; manifest:full-path=&amp;quot;Scripts/java/&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;manifest:file-entry manifest:media-type=&amp;quot;&amp;quot; manifest:full-path=&amp;quot;Scripts/&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Python ====&lt;br /&gt;
&lt;br /&gt;
A Python module may contain several scripts.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def HelloPython( ):&lt;br /&gt;
import uno&lt;br /&gt;
&lt;br /&gt;
def HelloPython( ):&lt;br /&gt;
    oDoc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
    xText = oDoc.getText()&lt;br /&gt;
    xTextRange = xText.getEnd()&lt;br /&gt;
    &lt;br /&gt;
    xTextRange.CharHeight = 16.0&lt;br /&gt;
    xTextRange.CharBackColor = 1234567&lt;br /&gt;
    # CharUnderline receives a group constant&lt;br /&gt;
    xTextRange.CharUnderline = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontUnderline.WAVE&amp;quot;)&lt;br /&gt;
    # CharPosture receives an enum&lt;br /&gt;
    xTextRange.CharPosture = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontSlant.ITALIC&amp;quot;)&lt;br /&gt;
    &lt;br /&gt;
    xTextRange.setString( &amp;quot;Hello World (in Python)&amp;quot; )&lt;br /&gt;
    return None&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Python interprets pairs of get and set methods at UNO objects as object properties if they follow this pattern:&lt;br /&gt;
&lt;br /&gt;
  SomeType getSomeProperty()&lt;br /&gt;
  void setSomeProperty(SomeType aValue)&lt;br /&gt;
&lt;br /&gt;
Using these facilities some lines can be simplified:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
    xText = oDoc.Text&lt;br /&gt;
    xTextRange = xText.End&lt;br /&gt;
    xTextRange.String = &amp;quot;Hello World (in Python)&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Service properties can be directly accessed in Python, no need to use &amp;lt;code&amp;gt;getPropertyValue&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;setPropertyValue&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Features of script languages supported by {{PRODUCTNAME}} ===&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;1&amp;quot; cellpadding=4 style=&amp;quot;border-collapse:collapse;&amp;quot;&lt;br /&gt;
|-bgcolor=#EDEDED&lt;br /&gt;
!Language feature &lt;br /&gt;
!Basic &lt;br /&gt;
!BeanShell &lt;br /&gt;
!JavaScript &lt;br /&gt;
!Java macro&lt;br /&gt;
!Python &lt;br /&gt;
|-&lt;br /&gt;
|Interpreted &lt;br /&gt;
|Yes &lt;br /&gt;
|Yes &lt;br /&gt;
|Yes&lt;br /&gt;
|No&lt;br /&gt;
|Yes &lt;br /&gt;
|-&lt;br /&gt;
|Integrated editor &lt;br /&gt;
|Yes, colored&lt;br /&gt;
|Yes &lt;br /&gt;
|Yes &lt;br /&gt;
|No &lt;br /&gt;
|No &lt;br /&gt;
|-&lt;br /&gt;
|Integrated debugger &lt;br /&gt;
|Yes &lt;br /&gt;
|No&lt;br /&gt;
|Yes &lt;br /&gt;
|No &lt;br /&gt;
|No &lt;br /&gt;
|-&lt;br /&gt;
|Script organizer &lt;br /&gt;
|Yes &lt;br /&gt;
|Yes&lt;br /&gt;
|Yes &lt;br /&gt;
|No &lt;br /&gt;
|No &lt;br /&gt;
|-&lt;br /&gt;
|Script encryption &lt;br /&gt;
|Possible &lt;br /&gt;
|No &lt;br /&gt;
|No &lt;br /&gt;
|No &lt;br /&gt;
|No &lt;br /&gt;
|-&lt;br /&gt;
|Typeless variables &lt;br /&gt;
|Yes: Variant &lt;br /&gt;
|Yes &lt;br /&gt;
|Yes&lt;br /&gt;
|No&lt;br /&gt;
|Yes&lt;br /&gt;
|-&lt;br /&gt;
|Getter/Setter &lt;br /&gt;
|Yes &lt;br /&gt;
|Yes &lt;br /&gt;
|No &lt;br /&gt;
|No &lt;br /&gt;
|Yes &lt;br /&gt;
|-&lt;br /&gt;
|Direct property access &lt;br /&gt;
|Yes &lt;br /&gt;
|No &lt;br /&gt;
|No &lt;br /&gt;
|No &lt;br /&gt;
|Yes &lt;br /&gt;
|-&lt;br /&gt;
|Function for Calc formula &lt;br /&gt;
|Yes &lt;br /&gt;
|No &lt;br /&gt;
|No &lt;br /&gt;
|No &lt;br /&gt;
|No &lt;br /&gt;
|-&lt;br /&gt;
|UNO component creation &lt;br /&gt;
|No &lt;br /&gt;
|No &lt;br /&gt;
|No &lt;br /&gt;
|Yes &lt;br /&gt;
|Yes &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Using the {{PRODUCTNAME}} API from macros ===&lt;br /&gt;
&lt;br /&gt;
BeanShell, JavaScript, Java, Python macros are supplied with a variable of type &amp;lt;idl&amp;gt;com.sun.star.script.provider.XScriptContext&amp;lt;/idl&amp;gt; which can be used to access the {{PRODUCTNAME}} API. This interface has three methods:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XModel&amp;lt;/idl&amp;gt; &amp;lt;code&amp;gt;getDocument( )&amp;lt;/code&amp;gt;&lt;br /&gt;
:Returns the &amp;lt;code&amp;gt;XModel&amp;lt;/code&amp;gt; interface of the document for which the macro was invoked (see [[Documentation/DevGuide/OfficeDev/Using the Component Framework|Using the Component Framework]])&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XDesktop&amp;lt;/idl&amp;gt; &amp;lt;code&amp;gt;getDesktop( )&amp;lt;/code&amp;gt;&lt;br /&gt;
:Returns the &amp;lt;code&amp;gt;XDesktop&amp;lt;/code&amp;gt; interface for the application which can be used to access open document, and load documents (see [[Documentation/DevGuide/OfficeDev/Using the Desktop|Using the Desktop]])&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.uno.XComponentContext&amp;lt;/idl&amp;gt; &amp;lt;code&amp;gt;getComponentContext( )&amp;lt;/code&amp;gt;&lt;br /&gt;
:Returns the &amp;lt;code&amp;gt;XComponentContext&amp;lt;/code&amp;gt; interface which is used to create instances of services (see [[Documentation/DevGuide/ProUNO/Service Manager and Component Context|Service Manager and Component Context]])&lt;br /&gt;
&lt;br /&gt;
Depending on the language the macro accesses &amp;lt;code&amp;gt;XScriptContext&amp;lt;/code&amp;gt; in different ways:&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;BeanShell&amp;#039;&amp;#039;&amp;#039;: Using the global variable &amp;lt;code&amp;gt;XSCRIPTCONTEXT&amp;lt;/code&amp;gt;&lt;br /&gt;
  oDoc = XSCRIPTCONTEXT.getDocument();&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;JavaScript&amp;#039;&amp;#039;&amp;#039;: Using the global variable &amp;lt;code&amp;gt;XSCRIPTCONTEXT&amp;lt;/code&amp;gt;&lt;br /&gt;
  oDoc = XSCRIPTCONTEXT.getDocument();&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Java&amp;#039;&amp;#039;&amp;#039;: The first parameter passed to the macro method is always of type &amp;lt;code&amp;gt;XScriptContext&amp;lt;/code&amp;gt;&lt;br /&gt;
  Xmodel xDocModel = xScriptContext.getDocument();&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Python&amp;#039;&amp;#039;&amp;#039;: Using the global variable &amp;lt;code&amp;gt;XSCRIPTCONTEXT&amp;lt;/code&amp;gt;&lt;br /&gt;
  oDoc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
&lt;br /&gt;
=== Handling arguments passed to macros ===&lt;br /&gt;
&lt;br /&gt;
In certain cases arguments may be passed to macros, for example, when a macro is assigned to a button in a document. In this case the arguments are passed to the macro as follows:&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;BeanShell&amp;#039;&amp;#039;&amp;#039;: In the global &amp;lt;code&amp;gt;Object[]&amp;lt;/code&amp;gt; variable &amp;lt;code&amp;gt;ARGUMENTS&amp;lt;/code&amp;gt;&lt;br /&gt;
  event = (ActionEvent) ARGUMENTS[0];&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;JavaScript&amp;#039;&amp;#039;&amp;#039;: In the global &amp;lt;code&amp;gt;Object[]&amp;lt;/code&amp;gt; variable &amp;lt;code&amp;gt;ARGUMENTS&amp;lt;/code&amp;gt;&lt;br /&gt;
  event = ARGUMENTS[0];&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Java&amp;#039;&amp;#039;&amp;#039;: The arguments are passed as an &amp;lt;code&amp;gt;Object[]&amp;lt;/code&amp;gt; in the second parameter to the macro method&lt;br /&gt;
  public void handleButtonPress(&lt;br /&gt;
      XScriptContext xScriptContext, Object[] args)&lt;br /&gt;
&lt;br /&gt;
Each of the arguments in the &amp;lt;code&amp;gt;Object[]&amp;lt;/code&amp;gt; are of the UNO type Any. For more information on how the Any type is used in Java see [[Documentation/DevGuide/ProUNO/Java/Type Mappings|Type Mappings]].&lt;br /&gt;
&lt;br /&gt;
The ButtonPressHandler macros in the Highlight library of a {{PRODUCTNAME}} installation show how a macro can handle arguments.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Python&amp;#039;&amp;#039;&amp;#039;: The arguments are passed as parameters of the called function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Creating dialogs from macros ===&lt;br /&gt;
&lt;br /&gt;
Dialogs which have been built in the Dialog Editor can be loaded by macros using the &amp;lt;idl&amp;gt;com.sun.star.awt.XDialogProvider&amp;lt;/idl&amp;gt; API. The method &amp;lt;code&amp;gt;createDialog()&amp;lt;/code&amp;gt; from interface &amp;lt;code&amp;gt;XDialogProvider&amp;lt;/code&amp;gt; uses a string as a parameter. This string is the URL to the dialog. It is formed as follows:&lt;br /&gt;
&lt;br /&gt;
  vnd.sun.star.script:DIALOGREF?location=[application|document]&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;DIALOGREF&amp;lt;/code&amp;gt; is the name of the dialog that you want to create, and location is either application or document depending on where the dialog is stored.&lt;br /&gt;
&lt;br /&gt;
For example if you wanted to load dialog called MyDialog, which is in a Dialog Library called MyDialogLibrary in the {{PRODUCTNAME}} dialogs area of your installation then the URL would be:&lt;br /&gt;
&lt;br /&gt;
  vnd.sun.star.script:MyDialogLibrary.MyDialog?location=application&lt;br /&gt;
&lt;br /&gt;
If you wanted to load a dialog called MyDocumentDialog which in a library called MyDocumentLibrary which is located in a document then the URL would be:&lt;br /&gt;
&lt;br /&gt;
  vnd.sun.star.script:MyDocumentLibrary.MyDocumentDialog?location=document&lt;br /&gt;
&lt;br /&gt;
The following code shows how to create a dialog from a Java macro:&lt;br /&gt;
 &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
  public XDialog getDialog(XScriptContext context)&lt;br /&gt;
  {&lt;br /&gt;
      XDialog theDialog;&lt;br /&gt;
  &lt;br /&gt;
      // We must pass the XModel of the current document when creating a DialogProvider object&lt;br /&gt;
      Object[] args = { context.getDocument() };&lt;br /&gt;
    &lt;br /&gt;
      Object obj;&lt;br /&gt;
      try {&lt;br /&gt;
          obj = xmcf.createInstanceWithArgumentsAndContext(&lt;br /&gt;
              &amp;quot;com.sun.star.awt.DialogProvider&amp;quot;, args, context.getComponentContext());&lt;br /&gt;
      }&lt;br /&gt;
      catch (com.sun.star.uno.Exception e) {&lt;br /&gt;
          System.err.println(&amp;quot;Error getting DialogProvider object&amp;quot;);&lt;br /&gt;
          return null;&lt;br /&gt;
      }&lt;br /&gt;
  &lt;br /&gt;
      XDialogProvider xDialogProvider = (XDialogProvider)&lt;br /&gt;
          UnoRuntime.queryInterface(XDialogProvider.class, obj);&lt;br /&gt;
      &lt;br /&gt;
      // Got DialogProvider, now get dialog &lt;br /&gt;
      try {&lt;br /&gt;
          theDialog = xDialogProvider.createDialog(&lt;br /&gt;
              &amp;quot;vnd.sun.star.script:MyDialogLibrary.MyDialog?location=application&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
      catch (java.lang.Exception e) {&lt;br /&gt;
          System.err.println(&amp;quot;Got exception on first creating dialog: &amp;quot; + e.getMessage());&lt;br /&gt;
      }&lt;br /&gt;
      return theDialog;&lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Calling a macro with the Scripting Framework ===&lt;br /&gt;
&lt;br /&gt;
The service &amp;lt;idl&amp;gt;com.sun.star.script.provider.ScriptProvider&amp;lt;/idl&amp;gt; exports interface &amp;lt;idls&amp;gt;com.sun.star.script.provider.XScriptProvider&amp;lt;/idls&amp;gt; which offers method &amp;lt;code&amp;gt;getScript( )&amp;lt;/code&amp;gt;. This method returns an interface &amp;lt;idls&amp;gt;com.sun.star.script.provider.XScript&amp;lt;/idls&amp;gt; which offers the method &amp;lt;code&amp;gt;invoke( )&amp;lt;/code&amp;gt; which will call the script with parameters if necessary.&lt;br /&gt;
&lt;br /&gt;
The identity and location of the called script is contained in an URI, which follows a [[Documentation/DevGuide/Scripting/Scripting_Framework_URI_Specification|particular syntax]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here are links to some code examples written by the community:&lt;br /&gt;
* [http://codesnippets.services.openoffice.org/Office/Office.HowToCallJavaProgramUsingScriptingFramework.snip Java calling a Java script]&lt;br /&gt;
* [http://www.oooforum.org/forum/viewtopic.phtml?t=69328 Java calling a Basic macro]&lt;br /&gt;
* [http://www.oooforum.org/forum/viewtopic.phtml?t=59534 Basic macro calling a Python script]&lt;br /&gt;
* [http://www.oooforum.org/forum/viewtopic.phtml?t=69350 Python script calling a Basic macro]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{PDL1}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation/Developer&amp;#039;s Guide/Scripting]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=232466</id>
		<title>Python/Transfer from Basic to Python</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=232466"/>
		<updated>2013-12-19T03:03:54Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Fix Executing Macros from Toolbar Buttons section to be heading&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Transfer from Basic to Python}}&lt;br /&gt;
&lt;br /&gt;
Translation [[ES/Manuales/GuiaAOO/TemasAvanzados/Macros/Python/BasicAPython| Español]]&lt;br /&gt;
&lt;br /&gt;
If you feel some displeasure at StarBasic/OpenOffice Basic or you meet requirement of custom UNO component, now it is the time to transfer coding environment from Basic to Python.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, there are some runtime function provides shortcut to do something. But using Python-UNO bridge, you have to do such task by API ways.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s start with Python&amp;#039;s tutorial and return back to here when you have learned a bit about Python language.&lt;br /&gt;
&lt;br /&gt;
== Macro Location ==&lt;br /&gt;
On the current version, script organizer for Python do not provide the way to manage script files. So you have to manage yourself. Macros written in Python should be placed in the specific directory under your user&amp;#039;s profile, shared profile or script directory of your document.&lt;br /&gt;
&lt;br /&gt;
The python directory (in all lowercase) should be created in Scripts directory and you can put your python scripts that contain python code.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
path_to_directory/Scripts/python/your_file.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can make subdirectories to put macro files in them under Scripts/python directory.&lt;br /&gt;
&lt;br /&gt;
You have to add &amp;quot;py&amp;quot; file extension to your file name.&lt;br /&gt;
&lt;br /&gt;
== Macro Editor ==&lt;br /&gt;
&lt;br /&gt;
There is no built-in editor dedicated to code in Python. But you can choose your favorite text editor application to edit your Python script.&lt;br /&gt;
&lt;br /&gt;
This is discussed in another page.&lt;br /&gt;
&lt;br /&gt;
== Short Example ==&lt;br /&gt;
&lt;br /&gt;
Here is a small example written in Python.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello():&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Each callable function is the executable unit of Python macro (you can choose which function should be listed in the GUI, see other document).&lt;br /&gt;
&lt;br /&gt;
You can access the current document through getDocument method of XSCRIPTCONTEXT variable of the module. And it changes the document content to &amp;quot;Hello!&amp;quot; of the Writer document.&lt;br /&gt;
&lt;br /&gt;
== Usable Modules ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 import unohelper&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Script Context ==&lt;br /&gt;
&lt;br /&gt;
StarBasic is embedded runtime and it always works with living instance of the office. So the context is always the match with the office&amp;#039;s one. But Python-UNO bridge provides the way to work as RPC client. At that time, remote Python instance does have different context from the office instance. Therefore you have to use correct component context to tell to the multi component factory to instantiate a service.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you have no matching object provided.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039; macro, you have to use &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; module variable that provides &amp;lt;idl&amp;gt;com.sun.star.script.provider.XScriptContext&amp;lt;/idl&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XModel&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDocument()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current document object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.document.XScriptInvocationContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getInvocationContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns invocation dependent object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XDesktop&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDesktop()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns instance of &amp;lt;idl&amp;gt;com.sun.star.frame.Desktop&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.uno.XComponentContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getComponentContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current component context that is used to tell the which context is.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; variable is defined in module level and it is not provided to imported modules from your script.&lt;br /&gt;
&lt;br /&gt;
== Component Context ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get component context as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = GetDefaultContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But you do not need to access to it until you need to get singletons.&lt;br /&gt;
&lt;br /&gt;
In Python, you can get access to the component context through the script context.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need this value to instantiate services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service Manager ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get service manager as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 smgr = GetProcessServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But not so many people having to access to it.&lt;br /&gt;
&lt;br /&gt;
In Python, this instance is most important value to instantiate services to work with the office APIs.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need both the component context and the service manager to instantiate services.&lt;br /&gt;
&lt;br /&gt;
== Service Instance ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can instantiate services by built-in function as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 sfa = CreateUnoService(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or with initialize arguments: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 arg = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = CreateUnoServiceWithArguments(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, Array(arg))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Python, you have to work with com.sun.star.lang.XMultiComponentFactory interface as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
 sfa = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;, ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to initialize the instance, use createInstanceWithArgumentsAndContext method: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = smgr.createInstanceWithArgumentsAndContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, (FILESAVE_SIMPLE,) ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or initialize after the instantiation: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 file_picker = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, ctx)&lt;br /&gt;
 file_picker.initialize((FILESAVE_SIMPLE,))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service with Constructor ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can call service construct from its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 shell_execute = com.sun.star.system.SystemShellExecute.create()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you have to instantiate it with XMultiComponentFactory::createInstanceWithArgumentsAndContext method with initial arguments or instantiate after the instantiation.&lt;br /&gt;
&lt;br /&gt;
The constructor calling does type checking before to pass arguments to createInstanceWithArgumentsAndContext method.&lt;br /&gt;
&lt;br /&gt;
== Current Document ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ThisComponent runtime function provides access to the current document: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = ThisComponent&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Its return value is bound to the macro location. If the macro stored in a document, the result of ThisComponent is the document that the storage of the macro belongs to. And if your macro is stored in application wide, the returned value is the document model of currently active frame, this is the same result taken from StarDesktop.&amp;#039;&amp;#039;&amp;#039;getCurrentComponent()&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can access to the current document through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If your macro is &amp;#039;&amp;#039;&amp;#039;embedded in the document&amp;#039;&amp;#039;&amp;#039;, the document model is match with the document that the macro stored in. If your macro is stored in user or shared location, the document object is from active frame.&lt;br /&gt;
&lt;br /&gt;
== Desktop ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, StarDesktop runtime function is provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = StarDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can get access to the desktop through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = XSCRIPTCONTEXT.getDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Struct Instance ==&lt;br /&gt;
&lt;br /&gt;
In Basic, instance of struct can be instantiated in two ways: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Dim a As New com.sun.star.awt.Point&lt;br /&gt;
 a = CreateUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
With Dim statement and New keyword, you can instantiate a struct or array of structs. Or CreateUnoStruct method provides the way to instantiate a struct at runtime. You can not initialize the instance at the creation, you have to set its value of members.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can use the following ways to instantiate a struct. Import struct class and call it.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.awt import Point&lt;br /&gt;
&lt;br /&gt;
 a = Point()         # instantiate with default values, X=0, Y=0&lt;br /&gt;
 b = Point(100, 200) # initialize with initial values, X=100, Y=200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Calling the class to create new instance of the struct, you can empty its arguments or you have to pass values for all fields. In other words, you can not pass insufficient number of arguments to initialize. And its order should be match with definition of the struct in its IDL. For example, instance of struct b having X=100 and Y=200 in the above piece of code.&lt;br /&gt;
&lt;br /&gt;
You can initialize without to import the class of your target struct with uno.createUnoStruct function as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 a = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
 b = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This makes the same result with the above example. The first parameter of the createUnoStruct method is the name of the struct to initialize. The following arguments are initial values for new instance.&lt;br /&gt;
&lt;br /&gt;
== Enum ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can access to the module of the enum as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ITALIC = com.sun.star.awt.FontSlant.ITALIC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following ways can be used: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontSlant import ITALIC&lt;br /&gt;
 ITALIC = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontSlant.ITALIC&amp;quot;)&lt;br /&gt;
 ITALIC = uno.Enum(&amp;quot;com.sun.star.awt.FontSlant&amp;quot;, &amp;quot;ITALIC&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
All of the way results the instance of uno.Enum class.&lt;br /&gt;
&lt;br /&gt;
== Constants ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get access to constants through its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 BOLD = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways are provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontWeight import BOLD&lt;br /&gt;
 BOLD = uno.getConstantsByName(&amp;quot;com.sun.star.awt.FontWeight.BOLD&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sequence ==&lt;br /&gt;
&lt;br /&gt;
The sequence is sequential value of the same type.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, array is used.&lt;br /&gt;
&lt;br /&gt;
In Python, tuple is chosen to represent UNO&amp;#039;s sequence. Note, list is not allowed to pass as sequence value.&lt;br /&gt;
&lt;br /&gt;
== Boolean ==&lt;br /&gt;
&lt;br /&gt;
In Python, True or False.&lt;br /&gt;
&lt;br /&gt;
== String ==&lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;s string can contain over 64K bytes.&lt;br /&gt;
&lt;br /&gt;
If you have to write non Ascii 7 bit characters in your script, write magic comment at the head of your file. This is standard Python instructions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # -*- coding: utf_8 -*-&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please read Python&amp;#039;s documentation for more detail.&lt;br /&gt;
&lt;br /&gt;
You have to use unicode string to write some unicode characters in Python 2.X. And strings coming from UNO is decoded in unicode in Python 2.X.&lt;br /&gt;
&lt;br /&gt;
== Char ==&lt;br /&gt;
&lt;br /&gt;
There is no dedicated value for char type in StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, uno.Char class is defined for char type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 c = uno.Char(&amp;quot;a&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Type ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Type&amp;quot; type is meta type of UNO that represents type of UNO.&lt;br /&gt;
Since 3.4, if you pass string value to method as an argument that should be type, the bridge of Basic read it as type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
oMap = com.sun.star.container.EnumerableMap.create(&amp;quot;string&amp;quot;, &amp;quot;string&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways can be used to create new valu of type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 t = uno.getTypeByName(&amp;quot;string&amp;quot;)&lt;br /&gt;
 t = uno.Type(&amp;quot;string&amp;quot;, uno.Enum(&amp;quot;com.sun.star.uno.TypeClass&amp;quot;, &amp;quot;STRING&amp;quot;))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Byte Sequence ==&lt;br /&gt;
&lt;br /&gt;
The byte sequence is sequence of byte type.&lt;br /&gt;
&lt;br /&gt;
In Basic, array of byte is used to represent it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, it is represented by str wrapped by uno.ByteSequence class. If you takes some byte sequences from UNO, they are the instance of uno.ByteSequence. If you need to get real value of them, refer its &amp;#039;&amp;#039;value&amp;#039;&amp;#039; instance variable.&lt;br /&gt;
&lt;br /&gt;
== Exception ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you get thrown exception as some error. And On Error statement is used to catch it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub ErrorExample&lt;br /&gt;
&lt;br /&gt;
   On Error GoTo Handler&lt;br /&gt;
&lt;br /&gt;
   &amp;#039; ... error&lt;br /&gt;
&lt;br /&gt;
   Exit Sub&lt;br /&gt;
&lt;br /&gt;
   Handler: &lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
And you can not throw any exceptions from StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, the exception thrown in UNO world can be treated as normal Python&amp;#039;s exception. Here is an example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.container import IndexOutOfBoundsException&lt;br /&gt;
&lt;br /&gt;
 try:&lt;br /&gt;
     obj.getByIndex(100) # raises IndexOutOfBoundsException&lt;br /&gt;
 except IndexOutOfBoundsException as e:&lt;br /&gt;
     print(e)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If getByIndex method raises IndexOutOfBoundsException, it can be caught in except statement because all exceptions inherit Python&amp;#039;s Exception class.&lt;br /&gt;
&lt;br /&gt;
And also you can throw UNO&amp;#039;s exception from your Python code as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.uno import RuntimeException&lt;br /&gt;
 raise RuntimeException(&amp;quot;Some message&amp;quot;, None)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Empty Value ==&lt;br /&gt;
&lt;br /&gt;
In Basic, there are some situations to meet variables that they do not contain any value (this is not correct). Null, empty, missing, nothing and so on.&lt;br /&gt;
&lt;br /&gt;
In Python, None is used. If a method defined as void return value in its IDL, it results None if you call it. If you need to pass invalid interface as an argument for the method that takes some interface, pass None for it. The result of this behavior is fully dependent to the implementation of the method.&lt;br /&gt;
&lt;br /&gt;
== Listener and Interface ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can create new listener using CreateUnoListener runtime function with some subroutines or functions.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub Add&lt;br /&gt;
&lt;br /&gt;
   d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
   listener = CreateUnoListener(&amp;quot;ActionListener&amp;quot;, &amp;quot;com.sun.star.awt.XActionListener&amp;quot;)&lt;br /&gt;
   d.getControl(&amp;quot;CommandButton1&amp;quot;).addActionListener(listener)&lt;br /&gt;
   d.execute()&lt;br /&gt;
   d.dispose()&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 Sub ActionListener_actionPerformed(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 Sub ActionListener_disposing(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you have to define your own class with desired interfaces. With helper class, you can define easily as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import unohelper&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt import XActionListener&lt;br /&gt;
&lt;br /&gt;
 class ActionListener(unohelper.Base, XActionListener):&lt;br /&gt;
     def __init__(self):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def disposing(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def actionPerformed(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
unohelper.Base class provides required interface for UNO components.&lt;br /&gt;
&lt;br /&gt;
== Containers ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, container object provides the way to access to its contents in sequentially.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, there is no shortcut provided. &lt;br /&gt;
&lt;br /&gt;
If you need to access to elements of indexed container, use range function to generate sequential indexes.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 for i in range(container.getCount()):&lt;br /&gt;
     obj = container.getByIndex(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== URL and System Path ==&lt;br /&gt;
&lt;br /&gt;
If you work with a file stored in your local file system, you have to get its corresponding URL.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ConvertToURL runtime function is prepared for this task. And there is ConvertFromURL runtime function for reverse conversion.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following functions are defined in uno module for such task.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 path = &amp;quot;/home/foo/Documents/file.odt&amp;quot;&lt;br /&gt;
 url = uno.sytemPathToFileUrl(path)&lt;br /&gt;
 path = uno.fileUrlToSystemPath(url)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments and Return Value ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, mode of the first argument of parseStrict method is &amp;quot;inout&amp;quot; in the following code: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 aURL = CreateUnoStruct(&amp;quot;com.sun.star.util.URL&amp;quot;)&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 CreateUnoService(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;).parseStrict(aURL)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The content of aURL variable is updated after calling the method.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, out mode parameter is returned as part of return value.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.util import URL&lt;br /&gt;
&lt;br /&gt;
 aURL = URL()&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 dummy, aURL = smgr.createInstanceWithContext(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;, ctx).parseStrict(aURL)&lt;br /&gt;
 # Definition of com.sun.star.util.XURLTransformer::parseStrict method: &lt;br /&gt;
 # void parseStrict([inout] com.sun.star.util.URL aURL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If a method has out mode in its parameters, its return is always tuple that contains original return value and values for out parameters.&lt;br /&gt;
&lt;br /&gt;
Here is a potential example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # boolean getSomeValue([in] string aName, [out] short aNum, [inout] long aNum2);&lt;br /&gt;
 result, num, num2 = obj.getSomeValue(&amp;quot;foo&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above example, &amp;#039;&amp;#039;result&amp;#039;&amp;#039; variable takes original return value, &amp;#039;&amp;#039;num&amp;#039;&amp;#039; takes output value for second parameter and &amp;#039;&amp;#039;num2&amp;#039;&amp;#039; takes output value for third parameter. The method takes 100 as the second parameter but it is not used as input of value. No entry in returned tuple for in mode parameter.&lt;br /&gt;
&lt;br /&gt;
== Functions to be Executed ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can not choose routines to be executed by users.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, define &amp;#039;&amp;#039;&amp;#039;g_exportedScripts&amp;#039;&amp;#039;&amp;#039; variable that contains tuple of callable in your macro file.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def func_a(): pass&lt;br /&gt;
 def func_b(): pass&lt;br /&gt;
 def func_hidden(): pass # not shown in the UI&lt;br /&gt;
 &lt;br /&gt;
 g_exportedScripts = func_a, func_b&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above code, func_hidden is not shown in execution dialog of macros.&lt;br /&gt;
&lt;br /&gt;
== Importing Modules ==&lt;br /&gt;
In Basic, you can call subroutines defined in other modules or other libraries that has been loaded.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
BasicLibraries.loadLibrary(&amp;quot;Library1&amp;quot;)&lt;br /&gt;
Library1.Foo()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you can import some modules that can be found in sys.path list. If you want to import your own module placed inside Scripts/python directory, put your module in pythonpath directory nearby your script file.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 - Scripts/&lt;br /&gt;
   - python/&lt;br /&gt;
     - macro.py&lt;br /&gt;
     - pythonpath/  # this directory is added automatically before your macro executed&lt;br /&gt;
       - your_module.py  # this module can be found&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When you execute the macro from your script file, the internal executor adds the pythonpath/ directory to sys.path list to be used as one of lookup location.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, the name of module conflict each other if you have the same named module in the some location, this is the standard python mechanism of importing modules, put your each modules in differently named library to avoid the name conflict.&lt;br /&gt;
&lt;br /&gt;
== Dialog ==&lt;br /&gt;
In Basic, there is CreateUnoDialog runtime function to instantiate the dialog.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 DialogLibraries.loadLibrary(&amp;quot;Standard&amp;quot;)&lt;br /&gt;
 dialog = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
 dialog.execute()&lt;br /&gt;
 dialog.dispose()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, such shortcut function is not provided but you can easily instantiate your dialog using &amp;lt;idl&amp;gt;com.sun.star.awt.DialogProvider&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def dialog_example():&lt;br /&gt;
     ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
     smgr = ctx.getServiceManager()&lt;br /&gt;
     dp = smgr.createInstanceWithContext(&amp;quot;com.sun.star.awt.DialogProvider&amp;quot;, ctx)&lt;br /&gt;
     dialog = dp.createDialog(&amp;quot;vnd.sun.star.script:Standard.Dialog1?location=user&amp;quot;)&lt;br /&gt;
     dialog.execute()&lt;br /&gt;
     dialog.dispose()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Message Box ==&lt;br /&gt;
In Basic, you can use MsgBox runtime function to show some message to the users.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
  Msgbox &amp;quot;Hello.&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, no shortcut function is provided but you can use &amp;lt;idl&amp;gt;com.sun.star.awt.XMessageBoxFactory&amp;lt;/idl&amp;gt; interface through the toolkit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
def messagebox(ctx, parent, message, title, message_type, buttons):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Show message in message box. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    toolkit = parent.getToolkit()&lt;br /&gt;
    older_imple = check_method_parameter(&lt;br /&gt;
        ctx, &amp;quot;com.sun.star.awt.XMessageBoxFactory&amp;quot;, &amp;quot;createMessageBox&amp;quot;, &lt;br /&gt;
        1, &amp;quot;com.sun.star.awt.Rectangle&amp;quot;)&lt;br /&gt;
    if older_imple:&lt;br /&gt;
        msgbox = toolkit.createMessageBox(&lt;br /&gt;
            parent, Rectangle(), message_type, buttons, title, message)&lt;br /&gt;
    else:&lt;br /&gt;
        message_type = uno.getConstantByName(&amp;quot;com.sun.star.awt.MessageBoxType.&amp;quot; + {&lt;br /&gt;
            &amp;quot;messbox&amp;quot;: &amp;quot;MESSAGEBOX&amp;quot;, &amp;quot;infobox&amp;quot;: &amp;quot;INFOBOX&amp;quot;, &lt;br /&gt;
            &amp;quot;warningbox&amp;quot;: &amp;quot;WARNINGBOX&amp;quot;, &amp;quot;errorbox&amp;quot;: &amp;quot;ERRORBOX&amp;quot;, &lt;br /&gt;
            &amp;quot;querybox&amp;quot;: &amp;quot;QUERYBOX&amp;quot;}[message_type])&lt;br /&gt;
        msgbox = toolkit.createMessageBox(&lt;br /&gt;
            parent, message_type, buttons, title, message)&lt;br /&gt;
    n = msgbox.execute()&lt;br /&gt;
    msgbox.dispose()&lt;br /&gt;
    return n&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def check_method_parameter(ctx, interface_name, method_name, param_index, param_type):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Check the method has specific type parameter at the specific position. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    cr = create_service(ctx, &amp;quot;com.sun.star.reflection.CoreReflection&amp;quot;)&lt;br /&gt;
    try:&lt;br /&gt;
        idl = cr.forName(interface_name)&lt;br /&gt;
        m = idl.getMethod(method_name)&lt;br /&gt;
        if m:&lt;br /&gt;
            info = m.getParameterInfos()[param_index]&lt;br /&gt;
            return info.aType.getName() == param_type&lt;br /&gt;
    except:&lt;br /&gt;
        pass&lt;br /&gt;
    return False&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Input Box ==&lt;br /&gt;
&lt;br /&gt;
No function provided for Python, you have to make your own one.&lt;br /&gt;
&lt;br /&gt;
== Executing Macros from Toolbar Buttons ==&lt;br /&gt;
In Basic, you can call any subroutines or functions through toolbar buttons. &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
Sub WriteHello()&lt;br /&gt;
  ThisComponent.getText().getEnd().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, you have to define your Python function with an argument (or variable length arguments) to take an argument passed when the function executed through assigned toolbar button.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
def writeHello(*args):&lt;br /&gt;
    # writeHello(arg): is also ok but if you want to call this function &lt;br /&gt;
    # by some ways, define your function takes variable arguments.&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().getEnd().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=232436</id>
		<title>Python/Transfer from Basic to Python</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=232436"/>
		<updated>2013-12-17T08:35:00Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Added Executing Macros from Toolbar Buttons section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Transfer from Basic to Python}}&lt;br /&gt;
&lt;br /&gt;
Translation [[ES/Manuales/GuiaAOO/TemasAvanzados/Macros/Python/BasicAPython| Español]]&lt;br /&gt;
&lt;br /&gt;
If you feel some displeasure at StarBasic/OpenOffice Basic or you meet requirement of custom UNO component, now it is the time to transfer coding environment from Basic to Python.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, there are some runtime function provides shortcut to do something. But using Python-UNO bridge, you have to do such task by API ways.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s start with Python&amp;#039;s tutorial and return back to here when you have learned a bit about Python language.&lt;br /&gt;
&lt;br /&gt;
== Macro Location ==&lt;br /&gt;
On the current version, script organizer for Python do not provide the way to manage script files. So you have to manage yourself. Macros written in Python should be placed in the specific directory under your user&amp;#039;s profile, shared profile or script directory of your document.&lt;br /&gt;
&lt;br /&gt;
The python directory (in all lowercase) should be created in Scripts directory and you can put your python scripts that contain python code.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
path_to_directory/Scripts/python/your_file.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can make subdirectories to put macro files in them under Scripts/python directory.&lt;br /&gt;
&lt;br /&gt;
You have to add &amp;quot;py&amp;quot; file extension to your file name.&lt;br /&gt;
&lt;br /&gt;
== Macro Editor ==&lt;br /&gt;
&lt;br /&gt;
There is no built-in editor dedicated to code in Python. But you can choose your favorite text editor application to edit your Python script.&lt;br /&gt;
&lt;br /&gt;
This is discussed in another page.&lt;br /&gt;
&lt;br /&gt;
== Short Example ==&lt;br /&gt;
&lt;br /&gt;
Here is a small example written in Python.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello():&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Each callable function is the executable unit of Python macro (you can choose which function should be listed in the GUI, see other document).&lt;br /&gt;
&lt;br /&gt;
You can access the current document through getDocument method of XSCRIPTCONTEXT variable of the module. And it changes the document content to &amp;quot;Hello!&amp;quot; of the Writer document.&lt;br /&gt;
&lt;br /&gt;
== Usable Modules ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 import unohelper&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Script Context ==&lt;br /&gt;
&lt;br /&gt;
StarBasic is embedded runtime and it always works with living instance of the office. So the context is always the match with the office&amp;#039;s one. But Python-UNO bridge provides the way to work as RPC client. At that time, remote Python instance does have different context from the office instance. Therefore you have to use correct component context to tell to the multi component factory to instantiate a service.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you have no matching object provided.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039; macro, you have to use &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; module variable that provides &amp;lt;idl&amp;gt;com.sun.star.script.provider.XScriptContext&amp;lt;/idl&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XModel&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDocument()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current document object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.document.XScriptInvocationContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getInvocationContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns invocation dependent object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XDesktop&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDesktop()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns instance of &amp;lt;idl&amp;gt;com.sun.star.frame.Desktop&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.uno.XComponentContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getComponentContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current component context that is used to tell the which context is.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; variable is defined in module level and it is not provided to imported modules from your script.&lt;br /&gt;
&lt;br /&gt;
== Component Context ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get component context as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = GetDefaultContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But you do not need to access to it until you need to get singletons.&lt;br /&gt;
&lt;br /&gt;
In Python, you can get access to the component context through the script context.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need this value to instantiate services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service Manager ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get service manager as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 smgr = GetProcessServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But not so many people having to access to it.&lt;br /&gt;
&lt;br /&gt;
In Python, this instance is most important value to instantiate services to work with the office APIs.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need both the component context and the service manager to instantiate services.&lt;br /&gt;
&lt;br /&gt;
== Service Instance ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can instantiate services by built-in function as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 sfa = CreateUnoService(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or with initialize arguments: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 arg = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = CreateUnoServiceWithArguments(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, Array(arg))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Python, you have to work with com.sun.star.lang.XMultiComponentFactory interface as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
 sfa = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;, ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to initialize the instance, use createInstanceWithArgumentsAndContext method: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = smgr.createInstanceWithArgumentsAndContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, (FILESAVE_SIMPLE,) ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or initialize after the instantiation: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 file_picker = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, ctx)&lt;br /&gt;
 file_picker.initialize((FILESAVE_SIMPLE,))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service with Constructor ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can call service construct from its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 shell_execute = com.sun.star.system.SystemShellExecute.create()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you have to instantiate it with XMultiComponentFactory::createInstanceWithArgumentsAndContext method with initial arguments or instantiate after the instantiation.&lt;br /&gt;
&lt;br /&gt;
The constructor calling does type checking before to pass arguments to createInstanceWithArgumentsAndContext method.&lt;br /&gt;
&lt;br /&gt;
== Current Document ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ThisComponent runtime function provides access to the current document: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = ThisComponent&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Its return value is bound to the macro location. If the macro stored in a document, the result of ThisComponent is the document that the storage of the macro belongs to. And if your macro is stored in application wide, the returned value is the document model of currently active frame, this is the same result taken from StarDesktop.&amp;#039;&amp;#039;&amp;#039;getCurrentComponent()&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can access to the current document through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If your macro is &amp;#039;&amp;#039;&amp;#039;embedded in the document&amp;#039;&amp;#039;&amp;#039;, the document model is match with the document that the macro stored in. If your macro is stored in user or shared location, the document object is from active frame.&lt;br /&gt;
&lt;br /&gt;
== Desktop ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, StarDesktop runtime function is provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = StarDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can get access to the desktop through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = XSCRIPTCONTEXT.getDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Struct Instance ==&lt;br /&gt;
&lt;br /&gt;
In Basic, instance of struct can be instantiated in two ways: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Dim a As New com.sun.star.awt.Point&lt;br /&gt;
 a = CreateUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
With Dim statement and New keyword, you can instantiate a struct or array of structs. Or CreateUnoStruct method provides the way to instantiate a struct at runtime. You can not initialize the instance at the creation, you have to set its value of members.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can use the following ways to instantiate a struct. Import struct class and call it.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.awt import Point&lt;br /&gt;
&lt;br /&gt;
 a = Point()         # instantiate with default values, X=0, Y=0&lt;br /&gt;
 b = Point(100, 200) # initialize with initial values, X=100, Y=200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Calling the class to create new instance of the struct, you can empty its arguments or you have to pass values for all fields. In other words, you can not pass insufficient number of arguments to initialize. And its order should be match with definition of the struct in its IDL. For example, instance of struct b having X=100 and Y=200 in the above piece of code.&lt;br /&gt;
&lt;br /&gt;
You can initialize without to import the class of your target struct with uno.createUnoStruct function as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 a = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
 b = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This makes the same result with the above example. The first parameter of the createUnoStruct method is the name of the struct to initialize. The following arguments are initial values for new instance.&lt;br /&gt;
&lt;br /&gt;
== Enum ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can access to the module of the enum as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ITALIC = com.sun.star.awt.FontSlant.ITALIC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following ways can be used: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontSlant import ITALIC&lt;br /&gt;
 ITALIC = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontSlant.ITALIC&amp;quot;)&lt;br /&gt;
 ITALIC = uno.Enum(&amp;quot;com.sun.star.awt.FontSlant&amp;quot;, &amp;quot;ITALIC&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
All of the way results the instance of uno.Enum class.&lt;br /&gt;
&lt;br /&gt;
== Constants ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get access to constants through its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 BOLD = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways are provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontWeight import BOLD&lt;br /&gt;
 BOLD = uno.getConstantsByName(&amp;quot;com.sun.star.awt.FontWeight.BOLD&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sequence ==&lt;br /&gt;
&lt;br /&gt;
The sequence is sequential value of the same type.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, array is used.&lt;br /&gt;
&lt;br /&gt;
In Python, tuple is chosen to represent UNO&amp;#039;s sequence. Note, list is not allowed to pass as sequence value.&lt;br /&gt;
&lt;br /&gt;
== Boolean ==&lt;br /&gt;
&lt;br /&gt;
In Python, True or False.&lt;br /&gt;
&lt;br /&gt;
== String ==&lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;s string can contain over 64K bytes.&lt;br /&gt;
&lt;br /&gt;
If you have to write non Ascii 7 bit characters in your script, write magic comment at the head of your file. This is standard Python instructions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # -*- coding: utf_8 -*-&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please read Python&amp;#039;s documentation for more detail.&lt;br /&gt;
&lt;br /&gt;
You have to use unicode string to write some unicode characters in Python 2.X. And strings coming from UNO is decoded in unicode in Python 2.X.&lt;br /&gt;
&lt;br /&gt;
== Char ==&lt;br /&gt;
&lt;br /&gt;
There is no dedicated value for char type in StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, uno.Char class is defined for char type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 c = uno.Char(&amp;quot;a&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Type ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Type&amp;quot; type is meta type of UNO that represents type of UNO.&lt;br /&gt;
Since 3.4, if you pass string value to method as an argument that should be type, the bridge of Basic read it as type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
oMap = com.sun.star.container.EnumerableMap.create(&amp;quot;string&amp;quot;, &amp;quot;string&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways can be used to create new valu of type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 t = uno.getTypeByName(&amp;quot;string&amp;quot;)&lt;br /&gt;
 t = uno.Type(&amp;quot;string&amp;quot;, uno.Enum(&amp;quot;com.sun.star.uno.TypeClass&amp;quot;, &amp;quot;STRING&amp;quot;))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Byte Sequence ==&lt;br /&gt;
&lt;br /&gt;
The byte sequence is sequence of byte type.&lt;br /&gt;
&lt;br /&gt;
In Basic, array of byte is used to represent it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, it is represented by str wrapped by uno.ByteSequence class. If you takes some byte sequences from UNO, they are the instance of uno.ByteSequence. If you need to get real value of them, refer its &amp;#039;&amp;#039;value&amp;#039;&amp;#039; instance variable.&lt;br /&gt;
&lt;br /&gt;
== Exception ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you get thrown exception as some error. And On Error statement is used to catch it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub ErrorExample&lt;br /&gt;
&lt;br /&gt;
   On Error GoTo Handler&lt;br /&gt;
&lt;br /&gt;
   &amp;#039; ... error&lt;br /&gt;
&lt;br /&gt;
   Exit Sub&lt;br /&gt;
&lt;br /&gt;
   Handler: &lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
And you can not throw any exceptions from StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, the exception thrown in UNO world can be treated as normal Python&amp;#039;s exception. Here is an example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.container import IndexOutOfBoundsException&lt;br /&gt;
&lt;br /&gt;
 try:&lt;br /&gt;
     obj.getByIndex(100) # raises IndexOutOfBoundsException&lt;br /&gt;
 except IndexOutOfBoundsException as e:&lt;br /&gt;
     print(e)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If getByIndex method raises IndexOutOfBoundsException, it can be caught in except statement because all exceptions inherit Python&amp;#039;s Exception class.&lt;br /&gt;
&lt;br /&gt;
And also you can throw UNO&amp;#039;s exception from your Python code as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.uno import RuntimeException&lt;br /&gt;
 raise RuntimeException(&amp;quot;Some message&amp;quot;, None)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Empty Value ==&lt;br /&gt;
&lt;br /&gt;
In Basic, there are some situations to meet variables that they do not contain any value (this is not correct). Null, empty, missing, nothing and so on.&lt;br /&gt;
&lt;br /&gt;
In Python, None is used. If a method defined as void return value in its IDL, it results None if you call it. If you need to pass invalid interface as an argument for the method that takes some interface, pass None for it. The result of this behavior is fully dependent to the implementation of the method.&lt;br /&gt;
&lt;br /&gt;
== Listener and Interface ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can create new listener using CreateUnoListener runtime function with some subroutines or functions.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub Add&lt;br /&gt;
&lt;br /&gt;
   d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
   listener = CreateUnoListener(&amp;quot;ActionListener&amp;quot;, &amp;quot;com.sun.star.awt.XActionListener&amp;quot;)&lt;br /&gt;
   d.getControl(&amp;quot;CommandButton1&amp;quot;).addActionListener(listener)&lt;br /&gt;
   d.execute()&lt;br /&gt;
   d.dispose()&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 Sub ActionListener_actionPerformed(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 Sub ActionListener_disposing(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you have to define your own class with desired interfaces. With helper class, you can define easily as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import unohelper&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt import XActionListener&lt;br /&gt;
&lt;br /&gt;
 class ActionListener(unohelper.Base, XActionListener):&lt;br /&gt;
     def __init__(self):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def disposing(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def actionPerformed(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
unohelper.Base class provides required interface for UNO components.&lt;br /&gt;
&lt;br /&gt;
== Containers ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, container object provides the way to access to its contents in sequentially.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, there is no shortcut provided. &lt;br /&gt;
&lt;br /&gt;
If you need to access to elements of indexed container, use range function to generate sequential indexes.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 for i in range(container.getCount()):&lt;br /&gt;
     obj = container.getByIndex(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== URL and System Path ==&lt;br /&gt;
&lt;br /&gt;
If you work with a file stored in your local file system, you have to get its corresponding URL.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ConvertToURL runtime function is prepared for this task. And there is ConvertFromURL runtime function for reverse conversion.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following functions are defined in uno module for such task.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 path = &amp;quot;/home/foo/Documents/file.odt&amp;quot;&lt;br /&gt;
 url = uno.sytemPathToFileUrl(path)&lt;br /&gt;
 path = uno.fileUrlToSystemPath(url)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments and Return Value ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, mode of the first argument of parseStrict method is &amp;quot;inout&amp;quot; in the following code: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 aURL = CreateUnoStruct(&amp;quot;com.sun.star.util.URL&amp;quot;)&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 CreateUnoService(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;).parseStrict(aURL)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The content of aURL variable is updated after calling the method.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, out mode parameter is returned as part of return value.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.util import URL&lt;br /&gt;
&lt;br /&gt;
 aURL = URL()&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 dummy, aURL = smgr.createInstanceWithContext(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;, ctx).parseStrict(aURL)&lt;br /&gt;
 # Definition of com.sun.star.util.XURLTransformer::parseStrict method: &lt;br /&gt;
 # void parseStrict([inout] com.sun.star.util.URL aURL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If a method has out mode in its parameters, its return is always tuple that contains original return value and values for out parameters.&lt;br /&gt;
&lt;br /&gt;
Here is a potential example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # boolean getSomeValue([in] string aName, [out] short aNum, [inout] long aNum2);&lt;br /&gt;
 result, num, num2 = obj.getSomeValue(&amp;quot;foo&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above example, &amp;#039;&amp;#039;result&amp;#039;&amp;#039; variable takes original return value, &amp;#039;&amp;#039;num&amp;#039;&amp;#039; takes output value for second parameter and &amp;#039;&amp;#039;num2&amp;#039;&amp;#039; takes output value for third parameter. The method takes 100 as the second parameter but it is not used as input of value. No entry in returned tuple for in mode parameter.&lt;br /&gt;
&lt;br /&gt;
== Functions to be Executed ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can not choose routines to be executed by users.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, define &amp;#039;&amp;#039;&amp;#039;g_exportedScripts&amp;#039;&amp;#039;&amp;#039; variable that contains tuple of callable in your macro file.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def func_a(): pass&lt;br /&gt;
 def func_b(): pass&lt;br /&gt;
 def func_hidden(): pass # not shown in the UI&lt;br /&gt;
 &lt;br /&gt;
 g_exportedScripts = func_a, func_b&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above code, func_hidden is not shown in execution dialog of macros.&lt;br /&gt;
&lt;br /&gt;
== Importing Modules ==&lt;br /&gt;
In Basic, you can call subroutines defined in other modules or other libraries that has been loaded.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
BasicLibraries.loadLibrary(&amp;quot;Library1&amp;quot;)&lt;br /&gt;
Library1.Foo()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you can import some modules that can be found in sys.path list. If you want to import your own module placed inside Scripts/python directory, put your module in pythonpath directory nearby your script file.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 - Scripts/&lt;br /&gt;
   - python/&lt;br /&gt;
     - macro.py&lt;br /&gt;
     - pythonpath/  # this directory is added automatically before your macro executed&lt;br /&gt;
       - your_module.py  # this module can be found&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When you execute the macro from your script file, the internal executor adds the pythonpath/ directory to sys.path list to be used as one of lookup location.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, the name of module conflict each other if you have the same named module in the some location, this is the standard python mechanism of importing modules, put your each modules in differently named library to avoid the name conflict.&lt;br /&gt;
&lt;br /&gt;
== Dialog ==&lt;br /&gt;
In Basic, there is CreateUnoDialog runtime function to instantiate the dialog.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 DialogLibraries.loadLibrary(&amp;quot;Standard&amp;quot;)&lt;br /&gt;
 dialog = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
 dialog.execute()&lt;br /&gt;
 dialog.dispose()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, such shortcut function is not provided but you can easily instantiate your dialog using &amp;lt;idl&amp;gt;com.sun.star.awt.DialogProvider&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def dialog_example():&lt;br /&gt;
     ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
     smgr = ctx.getServiceManager()&lt;br /&gt;
     dp = smgr.createInstanceWithContext(&amp;quot;com.sun.star.awt.DialogProvider&amp;quot;, ctx)&lt;br /&gt;
     dialog = dp.createDialog(&amp;quot;vnd.sun.star.script:Standard.Dialog1?location=user&amp;quot;)&lt;br /&gt;
     dialog.execute()&lt;br /&gt;
     dialog.dispose()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Message Box ==&lt;br /&gt;
In Basic, you can use MsgBox runtime function to show some message to the users.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
  Msgbox &amp;quot;Hello.&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, no shortcut function is provided but you can use &amp;lt;idl&amp;gt;com.sun.star.awt.XMessageBoxFactory&amp;lt;/idl&amp;gt; interface through the toolkit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
def messagebox(ctx, parent, message, title, message_type, buttons):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Show message in message box. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    toolkit = parent.getToolkit()&lt;br /&gt;
    older_imple = check_method_parameter(&lt;br /&gt;
        ctx, &amp;quot;com.sun.star.awt.XMessageBoxFactory&amp;quot;, &amp;quot;createMessageBox&amp;quot;, &lt;br /&gt;
        1, &amp;quot;com.sun.star.awt.Rectangle&amp;quot;)&lt;br /&gt;
    if older_imple:&lt;br /&gt;
        msgbox = toolkit.createMessageBox(&lt;br /&gt;
            parent, Rectangle(), message_type, buttons, title, message)&lt;br /&gt;
    else:&lt;br /&gt;
        message_type = uno.getConstantByName(&amp;quot;com.sun.star.awt.MessageBoxType.&amp;quot; + {&lt;br /&gt;
            &amp;quot;messbox&amp;quot;: &amp;quot;MESSAGEBOX&amp;quot;, &amp;quot;infobox&amp;quot;: &amp;quot;INFOBOX&amp;quot;, &lt;br /&gt;
            &amp;quot;warningbox&amp;quot;: &amp;quot;WARNINGBOX&amp;quot;, &amp;quot;errorbox&amp;quot;: &amp;quot;ERRORBOX&amp;quot;, &lt;br /&gt;
            &amp;quot;querybox&amp;quot;: &amp;quot;QUERYBOX&amp;quot;}[message_type])&lt;br /&gt;
        msgbox = toolkit.createMessageBox(&lt;br /&gt;
            parent, message_type, buttons, title, message)&lt;br /&gt;
    n = msgbox.execute()&lt;br /&gt;
    msgbox.dispose()&lt;br /&gt;
    return n&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def check_method_parameter(ctx, interface_name, method_name, param_index, param_type):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Check the method has specific type parameter at the specific position. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    cr = create_service(ctx, &amp;quot;com.sun.star.reflection.CoreReflection&amp;quot;)&lt;br /&gt;
    try:&lt;br /&gt;
        idl = cr.forName(interface_name)&lt;br /&gt;
        m = idl.getMethod(method_name)&lt;br /&gt;
        if m:&lt;br /&gt;
            info = m.getParameterInfos()[param_index]&lt;br /&gt;
            return info.aType.getName() == param_type&lt;br /&gt;
    except:&lt;br /&gt;
        pass&lt;br /&gt;
    return False&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Input Box ==&lt;br /&gt;
&lt;br /&gt;
No function provided for Python, you have to make your own one.&lt;br /&gt;
&lt;br /&gt;
== Executing Macros from Toolbar Buttons&lt;br /&gt;
In Basic, you can call any subroutines or functions through toolbar buttons. &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
Sub WriteHello()&lt;br /&gt;
  ThisComponent.getText().getEnd().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, you have to define your Python function with an argument (or variable length arguments) to take an argument passed when the function executed through assigned toolbar button.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
def writeHello(*args):&lt;br /&gt;
    # writeHello(arg): is also ok but if you want to call this function &lt;br /&gt;
    # by some ways, define your function takes variable arguments.&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().getEnd().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Using_Python_on_Windows&amp;diff=232413</id>
		<title>Using Python on Windows</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Using_Python_on_Windows&amp;diff=232413"/>
		<updated>2013-12-12T06:22:18Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add description about recent installer&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Extensions}}&lt;br /&gt;
===Introduction to Python on OOo=== &lt;br /&gt;
&lt;br /&gt;
You need OpenOffice.org installed with its Python-UNO bridge. &lt;br /&gt;
&lt;br /&gt;
If you do not customize the installation, Python-UNO bridge is installed as default on recent version. &lt;br /&gt;
Install OpenOffice.org. If you are installing it for the first time, then be sure to do a Custom install and install the Python-UNO bridge under Optional Components. &lt;br /&gt;
&lt;br /&gt;
If you already have OpenOffice.org installed, then go into your OOo folder and run Setup. Pick Modify, click Next. Under Optional Components, be sure to install the Python-UNO bridge. &lt;br /&gt;
&lt;br /&gt;
In order to use the python-uno bridge, the python code must run from the Python that comes with OOo 1.1.0. There is apparently some issue with the standard C library. The Python 2.2.2 that comes with OOo has been compiled using the StdCLib that OOo uses rather than the one that python would normally be compiled with. &lt;br /&gt;
&lt;br /&gt;
If you want an interactive Python command shell right now, go into your OOo\program subfolder and run the batch file named &amp;#039;&amp;#039;python.bat&amp;#039;&amp;#039;. You get a python shell. You can then use the statement Code:&lt;br /&gt;
   import uno&lt;br /&gt;
You can now connect to any OOo that will accept a remote UNO connection. &lt;br /&gt;
&lt;br /&gt;
I suppose that leads us to the next issue.... Configuring OOo to listen for UNO connections. &lt;br /&gt;
&lt;br /&gt;
It is also possible to write a component in Python and install it into the office. It is my understanding (but I have not tried yet) that when you do this you do NOT need to configure OOo to listen for uno connections. &lt;br /&gt;
&lt;br /&gt;
Therefore, the two ways to use Python are... &lt;br /&gt;
* Outside of OOo -- with a remote uno connection. &lt;br /&gt;
* Inside of OOo -- as an installed component. &lt;br /&gt;
&lt;br /&gt;
Approach 1 is the quick and easy way to write and debug code. &lt;br /&gt;
&lt;br /&gt;
Approach 2 is a great way to _deliver_ finished code to a user. &lt;br /&gt;
&lt;br /&gt;
See this for more information about the Python-UNO bridge in OOo. &lt;br /&gt;
http://udk.openoffice.org/python/python-bridge.html&lt;br /&gt;
&lt;br /&gt;
===Configuring OOo to listen for UNO connections===&lt;br /&gt;
&lt;br /&gt;
If you write programs in Java or Python and run them external to OOo, then you need to configure OOo to listen for a uno connection. &lt;br /&gt;
&lt;br /&gt;
It is possible to run your program on computer A, and connect to computer B which is running OOo, and have your program at A manipulate the OOo running on B. In fact, A and B can even be running different operating systems. I have done this personally using Java. With Python, I have only run my program on the same computer as OOo -- but it should work the same way. &lt;br /&gt;
&lt;br /&gt;
In the past, it was necessary to either &lt;br /&gt;
* launch OOo with a special parameter to make it listen &lt;br /&gt;
* hand edit one of OOo&amp;#039;s configuration files &lt;br /&gt;
&lt;br /&gt;
Both of the above options I explained here previously. &lt;br /&gt;
http://www.oooforum.org/forum/viewtopic.php?p=12370#12370 &lt;br /&gt;
&lt;br /&gt;
You can hand edit an XML file for version 1.0 of OOo, or an XCU file for version 1.1 of OOo (the current version). &lt;br /&gt;
&lt;br /&gt;
Later, I developed a macro to do this editing and announced it here. &lt;br /&gt;
http://www.oooforum.org/forum/viewtopic.php?t=3754 &lt;br /&gt;
&lt;br /&gt;
My &amp;#039;&amp;#039;&amp;#039;UnoConnectionListener document&amp;#039;&amp;#039;&amp;#039; can be obtained from OOoMacros.org. &lt;br /&gt;
&lt;br /&gt;
http://ooomacros.org/files.php?type=macro#UNOConnectionListener &lt;br /&gt;
&lt;br /&gt;
http://sourceforge.net/project/showfiles.php?group_id=87718&amp;amp;package_id=100069 &lt;br /&gt;
&lt;br /&gt;
Just download the document. Open it. Configure text boxes to taste. (Read the text of the above post if necessary.) Then click a button. Quit OOo. Re-launch OOo and it should henceforth (until you reconfigure it again) always listen for Uno connections. You can configure it to listen to connections only from localhost, or from any other computer.&lt;br /&gt;
[[Category:Extensions]]&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231618</id>
		<title>Python/Transfer from Basic to Python</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231618"/>
		<updated>2013-10-03T09:28:10Z</updated>

		<summary type="html">&lt;p&gt;Hanya: /* Input Box */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Transfer from Basic to Python}}&lt;br /&gt;
&lt;br /&gt;
Translation [[ES/Manuales/GuiaAOO/TemasAvanzados/Macros/Python/BasicAPython| Español]]&lt;br /&gt;
&lt;br /&gt;
If you feel some displeasure at StarBasic/OpenOffice Basic or you meet requirement of custom UNO component, now it is the time to transfer coding environment from Basic to Python.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, there are some runtime function provides shortcut to do something. But using Python-UNO bridge, you have to do such task by API ways.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s start with Python&amp;#039;s tutorial and return back to here when you have learned a bit about Python language.&lt;br /&gt;
&lt;br /&gt;
== Macro Location ==&lt;br /&gt;
On the current version, script organizer for Python do not provide the way to manage script files. So you have to manage yourself. Macros written in Python should be placed in the specific directory under your user&amp;#039;s profile, shared profile or script directory of your document.&lt;br /&gt;
&lt;br /&gt;
The python directory (in all lowercase) should be created in Scripts directory and you can put your python scripts that contain python code.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
path_to_directory/Scripts/python/your_file.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can make subdirectories to put macro files in them under Scripts/python directory.&lt;br /&gt;
&lt;br /&gt;
You have to add &amp;quot;py&amp;quot; file extension to your file name.&lt;br /&gt;
&lt;br /&gt;
== Macro Editor ==&lt;br /&gt;
&lt;br /&gt;
There is no built-in editor dedicated to code in Python. But you can choose your favorite text editor application to edit your Python script.&lt;br /&gt;
&lt;br /&gt;
This is discussed in another page.&lt;br /&gt;
&lt;br /&gt;
== Short Example ==&lt;br /&gt;
&lt;br /&gt;
Here is a small example written in Python.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello():&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Each callable function is the executable unit of Python macro (you can choose which function should be listed in the GUI, see other document).&lt;br /&gt;
&lt;br /&gt;
You can access the current document through getDocument method of XSCRIPTCONTEXT variable of the module. And it changes the document content to &amp;quot;Hello!&amp;quot; of the Writer document.&lt;br /&gt;
&lt;br /&gt;
== Usable Modules ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 import unohelper&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Script Context ==&lt;br /&gt;
&lt;br /&gt;
StarBasic is embedded runtime and it always works with living instance of the office. So the context is always the match with the office&amp;#039;s one. But Python-UNO bridge provides the way to work as RPC client. At that time, remote Python instance does have different context from the office instance. Therefore you have to use correct component context to tell to the multi component factory to instantiate a service.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you have no matching object provided.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039; macro, you have to use &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; module variable that provides &amp;lt;idl&amp;gt;com.sun.star.script.provider.XScriptContext&amp;lt;/idl&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XModel&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDocument()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current document object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.document.XScriptInvocationContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getInvocationContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns invocation dependent object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XDesktop&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDesktop()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns instance of &amp;lt;idl&amp;gt;com.sun.star.frame.Desktop&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.uno.XComponentContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getComponentContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current component context that is used to tell the which context is.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; variable is defined in module level and it is not provided to imported modules from your script.&lt;br /&gt;
&lt;br /&gt;
== Component Context ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get component context as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = GetDefaultContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But you do not need to access to it until you need to get singletons.&lt;br /&gt;
&lt;br /&gt;
In Python, you can get access to the component context through the script context.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need this value to instantiate services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service Manager ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get service manager as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 smgr = GetProcessServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But not so many people having to access to it.&lt;br /&gt;
&lt;br /&gt;
In Python, this instance is most important value to instantiate services to work with the office APIs.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need both the component context and the service manager to instantiate services.&lt;br /&gt;
&lt;br /&gt;
== Service Instance ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can instantiate services by built-in function as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 sfa = CreateUnoService(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or with initialize arguments: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 arg = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = CreateUnoServiceWithArguments(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, Array(arg))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Python, you have to work with com.sun.star.lang.XMultiComponentFactory interface as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
 sfa = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;, ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to initialize the instance, use createInstanceWithArgumentsAndContext method: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = smgr.createInstanceWithArgumentsAndContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, (FILESAVE_SIMPLE,) ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or initialize after the instantiation: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 file_picker = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, ctx)&lt;br /&gt;
 file_picker.initialize((FILESAVE_SIMPLE,))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service with Constructor ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can call service construct from its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 shell_execute = com.sun.star.system.SystemShellExecute.create()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you have to instantiate it with XMultiComponentFactory::createInstanceWithArgumentsAndContext method with initial arguments or instantiate after the instantiation.&lt;br /&gt;
&lt;br /&gt;
The constructor calling does type checking before to pass arguments to createInstanceWithArgumentsAndContext method.&lt;br /&gt;
&lt;br /&gt;
== Current Document ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ThisComponent runtime function provides access to the current document: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = ThisComponent&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Its return value is bound to the macro location. If the macro stored in a document, the result of ThisComponent is the document that the storage of the macro belongs to. And if your macro is stored in application wide, the returned value is the document model of currently active frame, this is the same result taken from StarDesktop.&amp;#039;&amp;#039;&amp;#039;getCurrentComponent()&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can access to the current document through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If your macro is &amp;#039;&amp;#039;&amp;#039;embedded in the document&amp;#039;&amp;#039;&amp;#039;, the document model is match with the document that the macro stored in. If your macro is stored in user or shared location, the document object is from active frame.&lt;br /&gt;
&lt;br /&gt;
== Desktop ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, StarDesktop runtime function is provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = StarDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can get access to the desktop through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = XSCRIPTCONTEXT.getDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Struct Instance ==&lt;br /&gt;
&lt;br /&gt;
In Basic, instance of struct can be instantiated in two ways: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Dim a As New com.sun.star.awt.Point&lt;br /&gt;
 a = CreateUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
With Dim statement and New keyword, you can instantiate a struct or array of structs. Or CreateUnoStruct method provides the way to instantiate a struct at runtime. You can not initialize the instance at the creation, you have to set its value of members.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can use the following ways to instantiate a struct. Import struct class and call it.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.awt import Point&lt;br /&gt;
&lt;br /&gt;
 a = Point()         # instantiate with default values, X=0, Y=0&lt;br /&gt;
 b = Point(100, 200) # initialize with initial values, X=100, Y=200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Calling the class to create new instance of the struct, you can empty its arguments or you have to pass values for all fields. In other words, you can not pass insufficient number of arguments to initialize. And its order should be match with definition of the struct in its IDL. For example, instance of struct b having X=100 and Y=200 in the above piece of code.&lt;br /&gt;
&lt;br /&gt;
You can initialize without to import the class of your target struct with uno.createUnoStruct function as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 a = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
 b = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This makes the same result with the above example. The first parameter of the createUnoStruct method is the name of the struct to initialize. The following arguments are initial values for new instance.&lt;br /&gt;
&lt;br /&gt;
== Enum ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can access to the module of the enum as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ITALIC = com.sun.star.awt.FontSlant.ITALIC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following ways can be used: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontSlant import ITALIC&lt;br /&gt;
 ITALIC = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontSlant.ITALIC&amp;quot;)&lt;br /&gt;
 ITALIC = uno.Enum(&amp;quot;com.sun.star.awt.FontSlant&amp;quot;, &amp;quot;ITALIC&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
All of the way results the instance of uno.Enum class.&lt;br /&gt;
&lt;br /&gt;
== Constants ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get access to constants through its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 BOLD = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways are provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontWeight import BOLD&lt;br /&gt;
 BOLD = uno.getConstantsByName(&amp;quot;com.sun.star.awt.FontWeight.BOLD&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sequence ==&lt;br /&gt;
&lt;br /&gt;
The sequence is sequential value of the same type.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, array is used.&lt;br /&gt;
&lt;br /&gt;
In Python, tuple is chosen to represent UNO&amp;#039;s sequence. Note, list is not allowed to pass as sequence value.&lt;br /&gt;
&lt;br /&gt;
== Boolean ==&lt;br /&gt;
&lt;br /&gt;
In Python, True or False.&lt;br /&gt;
&lt;br /&gt;
== String ==&lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;s string can contain over 64K bytes.&lt;br /&gt;
&lt;br /&gt;
If you have to write non Ascii 7 bit characters in your script, write magic comment at the head of your file. This is standard Python instructions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # -*- coding: utf_8 -*-&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please read Python&amp;#039;s documentation for more detail.&lt;br /&gt;
&lt;br /&gt;
You have to use unicode string to write some unicode characters in Python 2.X. And strings coming from UNO is decoded in unicode in Python 2.X.&lt;br /&gt;
&lt;br /&gt;
== Char ==&lt;br /&gt;
&lt;br /&gt;
There is no dedicated value for char type in StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, uno.Char class is defined for char type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 c = uno.Char(&amp;quot;a&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Type ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Type&amp;quot; type is meta type of UNO that represents type of UNO.&lt;br /&gt;
Since 3.4, if you pass string value to method as an argument that should be type, the bridge of Basic read it as type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
oMap = com.sun.star.container.EnumerableMap.create(&amp;quot;string&amp;quot;, &amp;quot;string&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways can be used to create new valu of type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 t = uno.getTypeByName(&amp;quot;string&amp;quot;)&lt;br /&gt;
 t = uno.Type(&amp;quot;string&amp;quot;, uno.Enum(&amp;quot;com.sun.star.uno.TypeClass&amp;quot;, &amp;quot;STRING&amp;quot;))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Byte Sequence ==&lt;br /&gt;
&lt;br /&gt;
The byte sequence is sequence of byte type.&lt;br /&gt;
&lt;br /&gt;
In Basic, array of byte is used to represent it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, it is represented by str wrapped by uno.ByteSequence class. If you takes some byte sequences from UNO, they are the instance of uno.ByteSequence. If you need to get real value of them, refer its &amp;#039;&amp;#039;value&amp;#039;&amp;#039; instance variable.&lt;br /&gt;
&lt;br /&gt;
== Exception ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you get thrown exception as some error. And On Error statement is used to catch it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub ErrorExample&lt;br /&gt;
&lt;br /&gt;
   On Error GoTo Handler&lt;br /&gt;
&lt;br /&gt;
   &amp;#039; ... error&lt;br /&gt;
&lt;br /&gt;
   Exit Sub&lt;br /&gt;
&lt;br /&gt;
   Handler: &lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
And you can not throw any exceptions from StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, the exception thrown in UNO world can be treated as normal Python&amp;#039;s exception. Here is an example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.container import IndexOutOfBoundsException&lt;br /&gt;
&lt;br /&gt;
 try:&lt;br /&gt;
     obj.getByIndex(100) # raises IndexOutOfBoundsException&lt;br /&gt;
 except IndexOutOfBoundsException as e:&lt;br /&gt;
     print(e)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If getByIndex method raises IndexOutOfBoundsException, it can be caught in except statement because all exceptions inherit Python&amp;#039;s Exception class.&lt;br /&gt;
&lt;br /&gt;
And also you can throw UNO&amp;#039;s exception from your Python code as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.uno import RuntimeException&lt;br /&gt;
 raise RuntimeException(&amp;quot;Some message&amp;quot;, None)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Empty Value ==&lt;br /&gt;
&lt;br /&gt;
In Basic, there are some situations to meet variables that they do not contain any value (this is not correct). Null, empty, missing, nothing and so on.&lt;br /&gt;
&lt;br /&gt;
In Python, None is used. If a method defined as void return value in its IDL, it results None if you call it. If you need to pass invalid interface as an argument for the method that takes some interface, pass None for it. The result of this behavior is fully dependent to the implementation of the method.&lt;br /&gt;
&lt;br /&gt;
== Listener and Interface ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can create new listener using CreateUnoListener runtime function with some subroutines or functions.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub Add&lt;br /&gt;
&lt;br /&gt;
   d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
   listener = CreateUnoListener(&amp;quot;ActionListener&amp;quot;, &amp;quot;com.sun.star.awt.XActionListener&amp;quot;)&lt;br /&gt;
   d.getControl(&amp;quot;CommandButton1&amp;quot;).addActionListener(listener)&lt;br /&gt;
   d.execute()&lt;br /&gt;
   d.dispose()&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 Sub ActionListener_actionPerformed(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 Sub ActionListener_disposing(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you have to define your own class with desired interfaces. With helper class, you can define easily as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import unohelper&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt import XActionListener&lt;br /&gt;
&lt;br /&gt;
 class ActionListener(unohelper.Base, XActionListener):&lt;br /&gt;
     def __init__(self):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def disposing(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def actionPerformed(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
unohelper.Base class provides required interface for UNO components.&lt;br /&gt;
&lt;br /&gt;
== Containers ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, container object provides the way to access to its contents in sequentially.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, there is no shortcut provided. &lt;br /&gt;
&lt;br /&gt;
If you need to access to elements of indexed container, use range function to generate sequential indexes.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 for i in range(container.getCount()):&lt;br /&gt;
     obj = container.getByIndex(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== URL and System Path ==&lt;br /&gt;
&lt;br /&gt;
If you work with a file stored in your local file system, you have to get its corresponding URL.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ConvertToURL runtime function is prepared for this task. And there is ConvertFromURL runtime function for reverse conversion.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following functions are defined in uno module for such task.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 path = &amp;quot;/home/foo/Documents/file.odt&amp;quot;&lt;br /&gt;
 url = uno.sytemPathToFileUrl(path)&lt;br /&gt;
 path = uno.fileUrlToSystemPath(url)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments and Return Value ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, mode of the first argument of parseStrict method is &amp;quot;inout&amp;quot; in the following code: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 aURL = CreateUnoStruct(&amp;quot;com.sun.star.util.URL&amp;quot;)&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 CreateUnoService(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;).parseStrict(aURL)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The content of aURL variable is updated after calling the method.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, out mode parameter is returned as part of return value.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.util import URL&lt;br /&gt;
&lt;br /&gt;
 aURL = URL()&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 dummy, aURL = smgr.createInstanceWithContext(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;, ctx).parseStrict(aURL)&lt;br /&gt;
 # Definition of com.sun.star.util.XURLTransformer::parseStrict method: &lt;br /&gt;
 # void parseStrict([inout] com.sun.star.util.URL aURL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If a method has out mode in its parameters, its return is always tuple that contains original return value and values for out parameters.&lt;br /&gt;
&lt;br /&gt;
Here is a potential example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # boolean getSomeValue([in] string aName, [out] short aNum, [inout] long aNum2);&lt;br /&gt;
 result, num, num2 = obj.getSomeValue(&amp;quot;foo&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above example, &amp;#039;&amp;#039;result&amp;#039;&amp;#039; variable takes original return value, &amp;#039;&amp;#039;num&amp;#039;&amp;#039; takes output value for second parameter and &amp;#039;&amp;#039;num2&amp;#039;&amp;#039; takes output value for third parameter. The method takes 100 as the second parameter but it is not used as input of value. No entry in returned tuple for in mode parameter.&lt;br /&gt;
&lt;br /&gt;
== Functions to be Executed ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can not choose routines to be executed by users.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, define &amp;#039;&amp;#039;&amp;#039;g_exportedScripts&amp;#039;&amp;#039;&amp;#039; variable that contains tuple of callable in your macro file.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def func_a(): pass&lt;br /&gt;
 def func_b(): pass&lt;br /&gt;
 def func_hidden(): pass # not shown in the UI&lt;br /&gt;
 &lt;br /&gt;
 g_exportedScripts = func_a, func_b&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above code, func_hidden is not shown in execution dialog of macros.&lt;br /&gt;
&lt;br /&gt;
== Importing Modules ==&lt;br /&gt;
In Basic, you can call subroutines defined in other modules or other libraries that has been loaded.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
BasicLibraries.loadLibrary(&amp;quot;Library1&amp;quot;)&lt;br /&gt;
Library1.Foo()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you can import some modules that can be found in sys.path list. If you want to import your own module placed inside Scripts/python directory, put your module in pythonpath directory nearby your script file.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 - Scripts/&lt;br /&gt;
   - python/&lt;br /&gt;
     - macro.py&lt;br /&gt;
     - pythonpath/  # this directory is added automatically before your macro executed&lt;br /&gt;
       - your_module.py  # this module can be found&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When you execute the macro from your script file, the internal executor adds the pythonpath/ directory to sys.path list to be used as one of lookup location.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, the name of module conflict each other if you have the same named module in the some location, this is the standard python mechanism of importing modules, put your each modules in differently named library to avoid the name conflict.&lt;br /&gt;
&lt;br /&gt;
== Dialog ==&lt;br /&gt;
In Basic, there is CreateUnoDialog runtime function to instantiate the dialog.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 DialogLibraries.loadLibrary(&amp;quot;Standard&amp;quot;)&lt;br /&gt;
 dialog = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
 dialog.execute()&lt;br /&gt;
 dialog.dispose()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, such shortcut function is not provided but you can easily instantiate your dialog using &amp;lt;idl&amp;gt;com.sun.star.awt.DialogProvider&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def dialog_example():&lt;br /&gt;
     ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
     smgr = ctx.getServiceManager()&lt;br /&gt;
     dp = smgr.createInstanceWithContext(&amp;quot;com.sun.star.awt.DialogProvider&amp;quot;, ctx)&lt;br /&gt;
     dialog = dp.createDialog(&amp;quot;vnd.sun.star.script:Standard.Dialog1?location=user&amp;quot;)&lt;br /&gt;
     dialog.execute()&lt;br /&gt;
     dialog.dispose()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Message Box ==&lt;br /&gt;
In Basic, you can use MsgBox runtime function to show some message to the users.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
  Msgbox &amp;quot;Hello.&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, no shortcut function is provided but you can use &amp;lt;idl&amp;gt;com.sun.star.awt.XMessageBoxFactory&amp;lt;/idl&amp;gt; interface through the toolkit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
def messagebox(ctx, parent, message, title, message_type, buttons):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Show message in message box. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    toolkit = parent.getToolkit()&lt;br /&gt;
    older_imple = check_method_parameter(&lt;br /&gt;
        ctx, &amp;quot;com.sun.star.awt.XMessageBoxFactory&amp;quot;, &amp;quot;createMessageBox&amp;quot;, &lt;br /&gt;
        1, &amp;quot;com.sun.star.awt.Rectangle&amp;quot;)&lt;br /&gt;
    if older_imple:&lt;br /&gt;
        msgbox = toolkit.createMessageBox(&lt;br /&gt;
            parent, Rectangle(), message_type, buttons, title, message)&lt;br /&gt;
    else:&lt;br /&gt;
        message_type = uno.getConstantByName(&amp;quot;com.sun.star.awt.MessageBoxType.&amp;quot; + {&lt;br /&gt;
            &amp;quot;messbox&amp;quot;: &amp;quot;MESSAGEBOX&amp;quot;, &amp;quot;infobox&amp;quot;: &amp;quot;INFOBOX&amp;quot;, &lt;br /&gt;
            &amp;quot;warningbox&amp;quot;: &amp;quot;WARNINGBOX&amp;quot;, &amp;quot;errorbox&amp;quot;: &amp;quot;ERRORBOX&amp;quot;, &lt;br /&gt;
            &amp;quot;querybox&amp;quot;: &amp;quot;QUERYBOX&amp;quot;}[message_type])&lt;br /&gt;
        msgbox = toolkit.createMessageBox(&lt;br /&gt;
            parent, message_type, buttons, title, message)&lt;br /&gt;
    n = msgbox.execute()&lt;br /&gt;
    msgbox.dispose()&lt;br /&gt;
    return n&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def check_method_parameter(ctx, interface_name, method_name, param_index, param_type):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Check the method has specific type parameter at the specific position. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    cr = create_service(ctx, &amp;quot;com.sun.star.reflection.CoreReflection&amp;quot;)&lt;br /&gt;
    try:&lt;br /&gt;
        idl = cr.forName(interface_name)&lt;br /&gt;
        m = idl.getMethod(method_name)&lt;br /&gt;
        if m:&lt;br /&gt;
            info = m.getParameterInfos()[param_index]&lt;br /&gt;
            return info.aType.getName() == param_type&lt;br /&gt;
    except:&lt;br /&gt;
        pass&lt;br /&gt;
    return False&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Input Box ==&lt;br /&gt;
&lt;br /&gt;
No function provided for Python, you have to make your own one.&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231617</id>
		<title>Python/Transfer from Basic to Python</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231617"/>
		<updated>2013-10-03T09:20:18Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add code to message box section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Transfer from Basic to Python}}&lt;br /&gt;
&lt;br /&gt;
Translation [[ES/Manuales/GuiaAOO/TemasAvanzados/Macros/Python/BasicAPython| Español]]&lt;br /&gt;
&lt;br /&gt;
If you feel some displeasure at StarBasic/OpenOffice Basic or you meet requirement of custom UNO component, now it is the time to transfer coding environment from Basic to Python.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, there are some runtime function provides shortcut to do something. But using Python-UNO bridge, you have to do such task by API ways.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s start with Python&amp;#039;s tutorial and return back to here when you have learned a bit about Python language.&lt;br /&gt;
&lt;br /&gt;
== Macro Location ==&lt;br /&gt;
On the current version, script organizer for Python do not provide the way to manage script files. So you have to manage yourself. Macros written in Python should be placed in the specific directory under your user&amp;#039;s profile, shared profile or script directory of your document.&lt;br /&gt;
&lt;br /&gt;
The python directory (in all lowercase) should be created in Scripts directory and you can put your python scripts that contain python code.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
path_to_directory/Scripts/python/your_file.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can make subdirectories to put macro files in them under Scripts/python directory.&lt;br /&gt;
&lt;br /&gt;
You have to add &amp;quot;py&amp;quot; file extension to your file name.&lt;br /&gt;
&lt;br /&gt;
== Macro Editor ==&lt;br /&gt;
&lt;br /&gt;
There is no built-in editor dedicated to code in Python. But you can choose your favorite text editor application to edit your Python script.&lt;br /&gt;
&lt;br /&gt;
This is discussed in another page.&lt;br /&gt;
&lt;br /&gt;
== Short Example ==&lt;br /&gt;
&lt;br /&gt;
Here is a small example written in Python.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello():&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Each callable function is the executable unit of Python macro (you can choose which function should be listed in the GUI, see other document).&lt;br /&gt;
&lt;br /&gt;
You can access the current document through getDocument method of XSCRIPTCONTEXT variable of the module. And it changes the document content to &amp;quot;Hello!&amp;quot; of the Writer document.&lt;br /&gt;
&lt;br /&gt;
== Usable Modules ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 import unohelper&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Script Context ==&lt;br /&gt;
&lt;br /&gt;
StarBasic is embedded runtime and it always works with living instance of the office. So the context is always the match with the office&amp;#039;s one. But Python-UNO bridge provides the way to work as RPC client. At that time, remote Python instance does have different context from the office instance. Therefore you have to use correct component context to tell to the multi component factory to instantiate a service.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you have no matching object provided.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039; macro, you have to use &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; module variable that provides &amp;lt;idl&amp;gt;com.sun.star.script.provider.XScriptContext&amp;lt;/idl&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XModel&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDocument()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current document object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.document.XScriptInvocationContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getInvocationContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns invocation dependent object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XDesktop&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDesktop()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns instance of &amp;lt;idl&amp;gt;com.sun.star.frame.Desktop&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.uno.XComponentContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getComponentContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current component context that is used to tell the which context is.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; variable is defined in module level and it is not provided to imported modules from your script.&lt;br /&gt;
&lt;br /&gt;
== Component Context ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get component context as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = GetDefaultContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But you do not need to access to it until you need to get singletons.&lt;br /&gt;
&lt;br /&gt;
In Python, you can get access to the component context through the script context.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need this value to instantiate services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service Manager ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get service manager as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 smgr = GetProcessServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But not so many people having to access to it.&lt;br /&gt;
&lt;br /&gt;
In Python, this instance is most important value to instantiate services to work with the office APIs.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need both the component context and the service manager to instantiate services.&lt;br /&gt;
&lt;br /&gt;
== Service Instance ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can instantiate services by built-in function as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 sfa = CreateUnoService(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or with initialize arguments: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 arg = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = CreateUnoServiceWithArguments(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, Array(arg))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Python, you have to work with com.sun.star.lang.XMultiComponentFactory interface as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
 sfa = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;, ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to initialize the instance, use createInstanceWithArgumentsAndContext method: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = smgr.createInstanceWithArgumentsAndContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, (FILESAVE_SIMPLE,) ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or initialize after the instantiation: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 file_picker = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, ctx)&lt;br /&gt;
 file_picker.initialize((FILESAVE_SIMPLE,))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service with Constructor ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can call service construct from its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 shell_execute = com.sun.star.system.SystemShellExecute.create()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you have to instantiate it with XMultiComponentFactory::createInstanceWithArgumentsAndContext method with initial arguments or instantiate after the instantiation.&lt;br /&gt;
&lt;br /&gt;
The constructor calling does type checking before to pass arguments to createInstanceWithArgumentsAndContext method.&lt;br /&gt;
&lt;br /&gt;
== Current Document ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ThisComponent runtime function provides access to the current document: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = ThisComponent&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Its return value is bound to the macro location. If the macro stored in a document, the result of ThisComponent is the document that the storage of the macro belongs to. And if your macro is stored in application wide, the returned value is the document model of currently active frame, this is the same result taken from StarDesktop.&amp;#039;&amp;#039;&amp;#039;getCurrentComponent()&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can access to the current document through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If your macro is &amp;#039;&amp;#039;&amp;#039;embedded in the document&amp;#039;&amp;#039;&amp;#039;, the document model is match with the document that the macro stored in. If your macro is stored in user or shared location, the document object is from active frame.&lt;br /&gt;
&lt;br /&gt;
== Desktop ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, StarDesktop runtime function is provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = StarDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can get access to the desktop through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = XSCRIPTCONTEXT.getDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Struct Instance ==&lt;br /&gt;
&lt;br /&gt;
In Basic, instance of struct can be instantiated in two ways: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Dim a As New com.sun.star.awt.Point&lt;br /&gt;
 a = CreateUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
With Dim statement and New keyword, you can instantiate a struct or array of structs. Or CreateUnoStruct method provides the way to instantiate a struct at runtime. You can not initialize the instance at the creation, you have to set its value of members.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can use the following ways to instantiate a struct. Import struct class and call it.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.awt import Point&lt;br /&gt;
&lt;br /&gt;
 a = Point()         # instantiate with default values, X=0, Y=0&lt;br /&gt;
 b = Point(100, 200) # initialize with initial values, X=100, Y=200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Calling the class to create new instance of the struct, you can empty its arguments or you have to pass values for all fields. In other words, you can not pass insufficient number of arguments to initialize. And its order should be match with definition of the struct in its IDL. For example, instance of struct b having X=100 and Y=200 in the above piece of code.&lt;br /&gt;
&lt;br /&gt;
You can initialize without to import the class of your target struct with uno.createUnoStruct function as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 a = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
 b = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This makes the same result with the above example. The first parameter of the createUnoStruct method is the name of the struct to initialize. The following arguments are initial values for new instance.&lt;br /&gt;
&lt;br /&gt;
== Enum ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can access to the module of the enum as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ITALIC = com.sun.star.awt.FontSlant.ITALIC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following ways can be used: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontSlant import ITALIC&lt;br /&gt;
 ITALIC = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontSlant.ITALIC&amp;quot;)&lt;br /&gt;
 ITALIC = uno.Enum(&amp;quot;com.sun.star.awt.FontSlant&amp;quot;, &amp;quot;ITALIC&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
All of the way results the instance of uno.Enum class.&lt;br /&gt;
&lt;br /&gt;
== Constants ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get access to constants through its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 BOLD = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways are provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontWeight import BOLD&lt;br /&gt;
 BOLD = uno.getConstantsByName(&amp;quot;com.sun.star.awt.FontWeight.BOLD&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sequence ==&lt;br /&gt;
&lt;br /&gt;
The sequence is sequential value of the same type.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, array is used.&lt;br /&gt;
&lt;br /&gt;
In Python, tuple is chosen to represent UNO&amp;#039;s sequence. Note, list is not allowed to pass as sequence value.&lt;br /&gt;
&lt;br /&gt;
== Boolean ==&lt;br /&gt;
&lt;br /&gt;
In Python, True or False.&lt;br /&gt;
&lt;br /&gt;
== String ==&lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;s string can contain over 64K bytes.&lt;br /&gt;
&lt;br /&gt;
If you have to write non Ascii 7 bit characters in your script, write magic comment at the head of your file. This is standard Python instructions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # -*- coding: utf_8 -*-&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please read Python&amp;#039;s documentation for more detail.&lt;br /&gt;
&lt;br /&gt;
You have to use unicode string to write some unicode characters in Python 2.X. And strings coming from UNO is decoded in unicode in Python 2.X.&lt;br /&gt;
&lt;br /&gt;
== Char ==&lt;br /&gt;
&lt;br /&gt;
There is no dedicated value for char type in StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, uno.Char class is defined for char type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 c = uno.Char(&amp;quot;a&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Type ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Type&amp;quot; type is meta type of UNO that represents type of UNO.&lt;br /&gt;
Since 3.4, if you pass string value to method as an argument that should be type, the bridge of Basic read it as type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
oMap = com.sun.star.container.EnumerableMap.create(&amp;quot;string&amp;quot;, &amp;quot;string&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways can be used to create new valu of type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 t = uno.getTypeByName(&amp;quot;string&amp;quot;)&lt;br /&gt;
 t = uno.Type(&amp;quot;string&amp;quot;, uno.Enum(&amp;quot;com.sun.star.uno.TypeClass&amp;quot;, &amp;quot;STRING&amp;quot;))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Byte Sequence ==&lt;br /&gt;
&lt;br /&gt;
The byte sequence is sequence of byte type.&lt;br /&gt;
&lt;br /&gt;
In Basic, array of byte is used to represent it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, it is represented by str wrapped by uno.ByteSequence class. If you takes some byte sequences from UNO, they are the instance of uno.ByteSequence. If you need to get real value of them, refer its &amp;#039;&amp;#039;value&amp;#039;&amp;#039; instance variable.&lt;br /&gt;
&lt;br /&gt;
== Exception ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you get thrown exception as some error. And On Error statement is used to catch it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub ErrorExample&lt;br /&gt;
&lt;br /&gt;
   On Error GoTo Handler&lt;br /&gt;
&lt;br /&gt;
   &amp;#039; ... error&lt;br /&gt;
&lt;br /&gt;
   Exit Sub&lt;br /&gt;
&lt;br /&gt;
   Handler: &lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
And you can not throw any exceptions from StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, the exception thrown in UNO world can be treated as normal Python&amp;#039;s exception. Here is an example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.container import IndexOutOfBoundsException&lt;br /&gt;
&lt;br /&gt;
 try:&lt;br /&gt;
     obj.getByIndex(100) # raises IndexOutOfBoundsException&lt;br /&gt;
 except IndexOutOfBoundsException as e:&lt;br /&gt;
     print(e)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If getByIndex method raises IndexOutOfBoundsException, it can be caught in except statement because all exceptions inherit Python&amp;#039;s Exception class.&lt;br /&gt;
&lt;br /&gt;
And also you can throw UNO&amp;#039;s exception from your Python code as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.uno import RuntimeException&lt;br /&gt;
 raise RuntimeException(&amp;quot;Some message&amp;quot;, None)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Empty Value ==&lt;br /&gt;
&lt;br /&gt;
In Basic, there are some situations to meet variables that they do not contain any value (this is not correct). Null, empty, missing, nothing and so on.&lt;br /&gt;
&lt;br /&gt;
In Python, None is used. If a method defined as void return value in its IDL, it results None if you call it. If you need to pass invalid interface as an argument for the method that takes some interface, pass None for it. The result of this behavior is fully dependent to the implementation of the method.&lt;br /&gt;
&lt;br /&gt;
== Listener and Interface ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can create new listener using CreateUnoListener runtime function with some subroutines or functions.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub Add&lt;br /&gt;
&lt;br /&gt;
   d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
   listener = CreateUnoListener(&amp;quot;ActionListener&amp;quot;, &amp;quot;com.sun.star.awt.XActionListener&amp;quot;)&lt;br /&gt;
   d.getControl(&amp;quot;CommandButton1&amp;quot;).addActionListener(listener)&lt;br /&gt;
   d.execute()&lt;br /&gt;
   d.dispose()&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 Sub ActionListener_actionPerformed(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 Sub ActionListener_disposing(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you have to define your own class with desired interfaces. With helper class, you can define easily as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import unohelper&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt import XActionListener&lt;br /&gt;
&lt;br /&gt;
 class ActionListener(unohelper.Base, XActionListener):&lt;br /&gt;
     def __init__(self):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def disposing(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def actionPerformed(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
unohelper.Base class provides required interface for UNO components.&lt;br /&gt;
&lt;br /&gt;
== Containers ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, container object provides the way to access to its contents in sequentially.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, there is no shortcut provided. &lt;br /&gt;
&lt;br /&gt;
If you need to access to elements of indexed container, use range function to generate sequential indexes.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 for i in range(container.getCount()):&lt;br /&gt;
     obj = container.getByIndex(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== URL and System Path ==&lt;br /&gt;
&lt;br /&gt;
If you work with a file stored in your local file system, you have to get its corresponding URL.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ConvertToURL runtime function is prepared for this task. And there is ConvertFromURL runtime function for reverse conversion.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following functions are defined in uno module for such task.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 path = &amp;quot;/home/foo/Documents/file.odt&amp;quot;&lt;br /&gt;
 url = uno.sytemPathToFileUrl(path)&lt;br /&gt;
 path = uno.fileUrlToSystemPath(url)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments and Return Value ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, mode of the first argument of parseStrict method is &amp;quot;inout&amp;quot; in the following code: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 aURL = CreateUnoStruct(&amp;quot;com.sun.star.util.URL&amp;quot;)&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 CreateUnoService(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;).parseStrict(aURL)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The content of aURL variable is updated after calling the method.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, out mode parameter is returned as part of return value.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.util import URL&lt;br /&gt;
&lt;br /&gt;
 aURL = URL()&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 dummy, aURL = smgr.createInstanceWithContext(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;, ctx).parseStrict(aURL)&lt;br /&gt;
 # Definition of com.sun.star.util.XURLTransformer::parseStrict method: &lt;br /&gt;
 # void parseStrict([inout] com.sun.star.util.URL aURL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If a method has out mode in its parameters, its return is always tuple that contains original return value and values for out parameters.&lt;br /&gt;
&lt;br /&gt;
Here is a potential example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # boolean getSomeValue([in] string aName, [out] short aNum, [inout] long aNum2);&lt;br /&gt;
 result, num, num2 = obj.getSomeValue(&amp;quot;foo&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above example, &amp;#039;&amp;#039;result&amp;#039;&amp;#039; variable takes original return value, &amp;#039;&amp;#039;num&amp;#039;&amp;#039; takes output value for second parameter and &amp;#039;&amp;#039;num2&amp;#039;&amp;#039; takes output value for third parameter. The method takes 100 as the second parameter but it is not used as input of value. No entry in returned tuple for in mode parameter.&lt;br /&gt;
&lt;br /&gt;
== Functions to be Executed ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can not choose routines to be executed by users.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, define &amp;#039;&amp;#039;&amp;#039;g_exportedScripts&amp;#039;&amp;#039;&amp;#039; variable that contains tuple of callable in your macro file.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def func_a(): pass&lt;br /&gt;
 def func_b(): pass&lt;br /&gt;
 def func_hidden(): pass # not shown in the UI&lt;br /&gt;
 &lt;br /&gt;
 g_exportedScripts = func_a, func_b&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above code, func_hidden is not shown in execution dialog of macros.&lt;br /&gt;
&lt;br /&gt;
== Importing Modules ==&lt;br /&gt;
In Basic, you can call subroutines defined in other modules or other libraries that has been loaded.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
BasicLibraries.loadLibrary(&amp;quot;Library1&amp;quot;)&lt;br /&gt;
Library1.Foo()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you can import some modules that can be found in sys.path list. If you want to import your own module placed inside Scripts/python directory, put your module in pythonpath directory nearby your script file.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 - Scripts/&lt;br /&gt;
   - python/&lt;br /&gt;
     - macro.py&lt;br /&gt;
     - pythonpath/  # this directory is added automatically before your macro executed&lt;br /&gt;
       - your_module.py  # this module can be found&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When you execute the macro from your script file, the internal executor adds the pythonpath/ directory to sys.path list to be used as one of lookup location.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, the name of module conflict each other if you have the same named module in the some location, this is the standard python mechanism of importing modules, put your each modules in differently named library to avoid the name conflict.&lt;br /&gt;
&lt;br /&gt;
== Dialog ==&lt;br /&gt;
In Basic, there is CreateUnoDialog runtime function to instantiate the dialog.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 DialogLibraries.loadLibrary(&amp;quot;Standard&amp;quot;)&lt;br /&gt;
 dialog = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
 dialog.execute()&lt;br /&gt;
 dialog.dispose()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, such shortcut function is not provided but you can easily instantiate your dialog using &amp;lt;idl&amp;gt;com.sun.star.awt.DialogProvider&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def dialog_example():&lt;br /&gt;
     ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
     smgr = ctx.getServiceManager()&lt;br /&gt;
     dp = smgr.createInstanceWithContext(&amp;quot;com.sun.star.awt.DialogProvider&amp;quot;, ctx)&lt;br /&gt;
     dialog = dp.createDialog(&amp;quot;vnd.sun.star.script:Standard.Dialog1?location=user&amp;quot;)&lt;br /&gt;
     dialog.execute()&lt;br /&gt;
     dialog.dispose()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Message Box ==&lt;br /&gt;
In Basic, you can use MsgBox runtime function to show some message to the users.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
  Msgbox &amp;quot;Hello.&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, no shortcut function is provided but you can use &amp;lt;idl&amp;gt;com.sun.star.awt.XMessageBoxFactory&amp;lt;/idl&amp;gt; interface through the toolkit.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
def messagebox(ctx, parent, message, title, message_type, buttons):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Show message in message box. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    toolkit = parent.getToolkit()&lt;br /&gt;
    older_imple = check_method_parameter(&lt;br /&gt;
        ctx, &amp;quot;com.sun.star.awt.XMessageBoxFactory&amp;quot;, &amp;quot;createMessageBox&amp;quot;, &lt;br /&gt;
        1, &amp;quot;com.sun.star.awt.Rectangle&amp;quot;)&lt;br /&gt;
    if older_imple:&lt;br /&gt;
        msgbox = toolkit.createMessageBox(&lt;br /&gt;
            parent, Rectangle(), message_type, buttons, title, message)&lt;br /&gt;
    else:&lt;br /&gt;
        message_type = uno.getConstantByName(&amp;quot;com.sun.star.awt.MessageBoxType.&amp;quot; + {&lt;br /&gt;
            &amp;quot;messbox&amp;quot;: &amp;quot;MESSAGEBOX&amp;quot;, &amp;quot;infobox&amp;quot;: &amp;quot;INFOBOX&amp;quot;, &lt;br /&gt;
            &amp;quot;warningbox&amp;quot;: &amp;quot;WARNINGBOX&amp;quot;, &amp;quot;errorbox&amp;quot;: &amp;quot;ERRORBOX&amp;quot;, &lt;br /&gt;
            &amp;quot;querybox&amp;quot;: &amp;quot;QUERYBOX&amp;quot;}[message_type])&lt;br /&gt;
        msgbox = toolkit.createMessageBox(&lt;br /&gt;
            parent, message_type, buttons, title, message)&lt;br /&gt;
    n = msgbox.execute()&lt;br /&gt;
    msgbox.dispose()&lt;br /&gt;
    return n&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def check_method_parameter(ctx, interface_name, method_name, param_index, param_type):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Check the method has specific type parameter at the specific position. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    cr = create_service(ctx, &amp;quot;com.sun.star.reflection.CoreReflection&amp;quot;)&lt;br /&gt;
    try:&lt;br /&gt;
        idl = cr.forName(interface_name)&lt;br /&gt;
        m = idl.getMethod(method_name)&lt;br /&gt;
        if m:&lt;br /&gt;
            info = m.getParameterInfos()[param_index]&lt;br /&gt;
            return info.aType.getName() == param_type&lt;br /&gt;
    except:&lt;br /&gt;
        pass&lt;br /&gt;
    return False&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Input Box ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231616</id>
		<title>Python/Transfer from Basic to Python</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231616"/>
		<updated>2013-10-03T09:14:42Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add short description about message box&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Transfer from Basic to Python}}&lt;br /&gt;
&lt;br /&gt;
Translation [[ES/Manuales/GuiaAOO/TemasAvanzados/Macros/Python/BasicAPython| Español]]&lt;br /&gt;
&lt;br /&gt;
If you feel some displeasure at StarBasic/OpenOffice Basic or you meet requirement of custom UNO component, now it is the time to transfer coding environment from Basic to Python.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, there are some runtime function provides shortcut to do something. But using Python-UNO bridge, you have to do such task by API ways.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s start with Python&amp;#039;s tutorial and return back to here when you have learned a bit about Python language.&lt;br /&gt;
&lt;br /&gt;
== Macro Location ==&lt;br /&gt;
On the current version, script organizer for Python do not provide the way to manage script files. So you have to manage yourself. Macros written in Python should be placed in the specific directory under your user&amp;#039;s profile, shared profile or script directory of your document.&lt;br /&gt;
&lt;br /&gt;
The python directory (in all lowercase) should be created in Scripts directory and you can put your python scripts that contain python code.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
path_to_directory/Scripts/python/your_file.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can make subdirectories to put macro files in them under Scripts/python directory.&lt;br /&gt;
&lt;br /&gt;
You have to add &amp;quot;py&amp;quot; file extension to your file name.&lt;br /&gt;
&lt;br /&gt;
== Macro Editor ==&lt;br /&gt;
&lt;br /&gt;
There is no built-in editor dedicated to code in Python. But you can choose your favorite text editor application to edit your Python script.&lt;br /&gt;
&lt;br /&gt;
This is discussed in another page.&lt;br /&gt;
&lt;br /&gt;
== Short Example ==&lt;br /&gt;
&lt;br /&gt;
Here is a small example written in Python.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello():&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Each callable function is the executable unit of Python macro (you can choose which function should be listed in the GUI, see other document).&lt;br /&gt;
&lt;br /&gt;
You can access the current document through getDocument method of XSCRIPTCONTEXT variable of the module. And it changes the document content to &amp;quot;Hello!&amp;quot; of the Writer document.&lt;br /&gt;
&lt;br /&gt;
== Usable Modules ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 import unohelper&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Script Context ==&lt;br /&gt;
&lt;br /&gt;
StarBasic is embedded runtime and it always works with living instance of the office. So the context is always the match with the office&amp;#039;s one. But Python-UNO bridge provides the way to work as RPC client. At that time, remote Python instance does have different context from the office instance. Therefore you have to use correct component context to tell to the multi component factory to instantiate a service.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you have no matching object provided.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039; macro, you have to use &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; module variable that provides &amp;lt;idl&amp;gt;com.sun.star.script.provider.XScriptContext&amp;lt;/idl&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XModel&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDocument()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current document object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.document.XScriptInvocationContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getInvocationContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns invocation dependent object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XDesktop&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDesktop()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns instance of &amp;lt;idl&amp;gt;com.sun.star.frame.Desktop&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.uno.XComponentContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getComponentContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current component context that is used to tell the which context is.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; variable is defined in module level and it is not provided to imported modules from your script.&lt;br /&gt;
&lt;br /&gt;
== Component Context ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get component context as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = GetDefaultContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But you do not need to access to it until you need to get singletons.&lt;br /&gt;
&lt;br /&gt;
In Python, you can get access to the component context through the script context.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need this value to instantiate services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service Manager ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get service manager as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 smgr = GetProcessServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But not so many people having to access to it.&lt;br /&gt;
&lt;br /&gt;
In Python, this instance is most important value to instantiate services to work with the office APIs.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need both the component context and the service manager to instantiate services.&lt;br /&gt;
&lt;br /&gt;
== Service Instance ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can instantiate services by built-in function as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 sfa = CreateUnoService(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or with initialize arguments: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 arg = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = CreateUnoServiceWithArguments(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, Array(arg))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Python, you have to work with com.sun.star.lang.XMultiComponentFactory interface as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
 sfa = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;, ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to initialize the instance, use createInstanceWithArgumentsAndContext method: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = smgr.createInstanceWithArgumentsAndContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, (FILESAVE_SIMPLE,) ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or initialize after the instantiation: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 file_picker = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, ctx)&lt;br /&gt;
 file_picker.initialize((FILESAVE_SIMPLE,))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service with Constructor ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can call service construct from its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 shell_execute = com.sun.star.system.SystemShellExecute.create()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you have to instantiate it with XMultiComponentFactory::createInstanceWithArgumentsAndContext method with initial arguments or instantiate after the instantiation.&lt;br /&gt;
&lt;br /&gt;
The constructor calling does type checking before to pass arguments to createInstanceWithArgumentsAndContext method.&lt;br /&gt;
&lt;br /&gt;
== Current Document ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ThisComponent runtime function provides access to the current document: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = ThisComponent&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Its return value is bound to the macro location. If the macro stored in a document, the result of ThisComponent is the document that the storage of the macro belongs to. And if your macro is stored in application wide, the returned value is the document model of currently active frame, this is the same result taken from StarDesktop.&amp;#039;&amp;#039;&amp;#039;getCurrentComponent()&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can access to the current document through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If your macro is &amp;#039;&amp;#039;&amp;#039;embedded in the document&amp;#039;&amp;#039;&amp;#039;, the document model is match with the document that the macro stored in. If your macro is stored in user or shared location, the document object is from active frame.&lt;br /&gt;
&lt;br /&gt;
== Desktop ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, StarDesktop runtime function is provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = StarDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can get access to the desktop through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = XSCRIPTCONTEXT.getDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Struct Instance ==&lt;br /&gt;
&lt;br /&gt;
In Basic, instance of struct can be instantiated in two ways: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Dim a As New com.sun.star.awt.Point&lt;br /&gt;
 a = CreateUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
With Dim statement and New keyword, you can instantiate a struct or array of structs. Or CreateUnoStruct method provides the way to instantiate a struct at runtime. You can not initialize the instance at the creation, you have to set its value of members.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can use the following ways to instantiate a struct. Import struct class and call it.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.awt import Point&lt;br /&gt;
&lt;br /&gt;
 a = Point()         # instantiate with default values, X=0, Y=0&lt;br /&gt;
 b = Point(100, 200) # initialize with initial values, X=100, Y=200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Calling the class to create new instance of the struct, you can empty its arguments or you have to pass values for all fields. In other words, you can not pass insufficient number of arguments to initialize. And its order should be match with definition of the struct in its IDL. For example, instance of struct b having X=100 and Y=200 in the above piece of code.&lt;br /&gt;
&lt;br /&gt;
You can initialize without to import the class of your target struct with uno.createUnoStruct function as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 a = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
 b = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This makes the same result with the above example. The first parameter of the createUnoStruct method is the name of the struct to initialize. The following arguments are initial values for new instance.&lt;br /&gt;
&lt;br /&gt;
== Enum ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can access to the module of the enum as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ITALIC = com.sun.star.awt.FontSlant.ITALIC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following ways can be used: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontSlant import ITALIC&lt;br /&gt;
 ITALIC = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontSlant.ITALIC&amp;quot;)&lt;br /&gt;
 ITALIC = uno.Enum(&amp;quot;com.sun.star.awt.FontSlant&amp;quot;, &amp;quot;ITALIC&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
All of the way results the instance of uno.Enum class.&lt;br /&gt;
&lt;br /&gt;
== Constants ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get access to constants through its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 BOLD = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways are provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontWeight import BOLD&lt;br /&gt;
 BOLD = uno.getConstantsByName(&amp;quot;com.sun.star.awt.FontWeight.BOLD&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sequence ==&lt;br /&gt;
&lt;br /&gt;
The sequence is sequential value of the same type.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, array is used.&lt;br /&gt;
&lt;br /&gt;
In Python, tuple is chosen to represent UNO&amp;#039;s sequence. Note, list is not allowed to pass as sequence value.&lt;br /&gt;
&lt;br /&gt;
== Boolean ==&lt;br /&gt;
&lt;br /&gt;
In Python, True or False.&lt;br /&gt;
&lt;br /&gt;
== String ==&lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;s string can contain over 64K bytes.&lt;br /&gt;
&lt;br /&gt;
If you have to write non Ascii 7 bit characters in your script, write magic comment at the head of your file. This is standard Python instructions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # -*- coding: utf_8 -*-&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please read Python&amp;#039;s documentation for more detail.&lt;br /&gt;
&lt;br /&gt;
You have to use unicode string to write some unicode characters in Python 2.X. And strings coming from UNO is decoded in unicode in Python 2.X.&lt;br /&gt;
&lt;br /&gt;
== Char ==&lt;br /&gt;
&lt;br /&gt;
There is no dedicated value for char type in StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, uno.Char class is defined for char type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 c = uno.Char(&amp;quot;a&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Type ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Type&amp;quot; type is meta type of UNO that represents type of UNO.&lt;br /&gt;
Since 3.4, if you pass string value to method as an argument that should be type, the bridge of Basic read it as type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
oMap = com.sun.star.container.EnumerableMap.create(&amp;quot;string&amp;quot;, &amp;quot;string&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways can be used to create new valu of type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 t = uno.getTypeByName(&amp;quot;string&amp;quot;)&lt;br /&gt;
 t = uno.Type(&amp;quot;string&amp;quot;, uno.Enum(&amp;quot;com.sun.star.uno.TypeClass&amp;quot;, &amp;quot;STRING&amp;quot;))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Byte Sequence ==&lt;br /&gt;
&lt;br /&gt;
The byte sequence is sequence of byte type.&lt;br /&gt;
&lt;br /&gt;
In Basic, array of byte is used to represent it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, it is represented by str wrapped by uno.ByteSequence class. If you takes some byte sequences from UNO, they are the instance of uno.ByteSequence. If you need to get real value of them, refer its &amp;#039;&amp;#039;value&amp;#039;&amp;#039; instance variable.&lt;br /&gt;
&lt;br /&gt;
== Exception ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you get thrown exception as some error. And On Error statement is used to catch it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub ErrorExample&lt;br /&gt;
&lt;br /&gt;
   On Error GoTo Handler&lt;br /&gt;
&lt;br /&gt;
   &amp;#039; ... error&lt;br /&gt;
&lt;br /&gt;
   Exit Sub&lt;br /&gt;
&lt;br /&gt;
   Handler: &lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
And you can not throw any exceptions from StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, the exception thrown in UNO world can be treated as normal Python&amp;#039;s exception. Here is an example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.container import IndexOutOfBoundsException&lt;br /&gt;
&lt;br /&gt;
 try:&lt;br /&gt;
     obj.getByIndex(100) # raises IndexOutOfBoundsException&lt;br /&gt;
 except IndexOutOfBoundsException as e:&lt;br /&gt;
     print(e)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If getByIndex method raises IndexOutOfBoundsException, it can be caught in except statement because all exceptions inherit Python&amp;#039;s Exception class.&lt;br /&gt;
&lt;br /&gt;
And also you can throw UNO&amp;#039;s exception from your Python code as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.uno import RuntimeException&lt;br /&gt;
 raise RuntimeException(&amp;quot;Some message&amp;quot;, None)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Empty Value ==&lt;br /&gt;
&lt;br /&gt;
In Basic, there are some situations to meet variables that they do not contain any value (this is not correct). Null, empty, missing, nothing and so on.&lt;br /&gt;
&lt;br /&gt;
In Python, None is used. If a method defined as void return value in its IDL, it results None if you call it. If you need to pass invalid interface as an argument for the method that takes some interface, pass None for it. The result of this behavior is fully dependent to the implementation of the method.&lt;br /&gt;
&lt;br /&gt;
== Listener and Interface ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can create new listener using CreateUnoListener runtime function with some subroutines or functions.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub Add&lt;br /&gt;
&lt;br /&gt;
   d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
   listener = CreateUnoListener(&amp;quot;ActionListener&amp;quot;, &amp;quot;com.sun.star.awt.XActionListener&amp;quot;)&lt;br /&gt;
   d.getControl(&amp;quot;CommandButton1&amp;quot;).addActionListener(listener)&lt;br /&gt;
   d.execute()&lt;br /&gt;
   d.dispose()&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 Sub ActionListener_actionPerformed(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 Sub ActionListener_disposing(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you have to define your own class with desired interfaces. With helper class, you can define easily as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import unohelper&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt import XActionListener&lt;br /&gt;
&lt;br /&gt;
 class ActionListener(unohelper.Base, XActionListener):&lt;br /&gt;
     def __init__(self):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def disposing(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def actionPerformed(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
unohelper.Base class provides required interface for UNO components.&lt;br /&gt;
&lt;br /&gt;
== Containers ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, container object provides the way to access to its contents in sequentially.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, there is no shortcut provided. &lt;br /&gt;
&lt;br /&gt;
If you need to access to elements of indexed container, use range function to generate sequential indexes.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 for i in range(container.getCount()):&lt;br /&gt;
     obj = container.getByIndex(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== URL and System Path ==&lt;br /&gt;
&lt;br /&gt;
If you work with a file stored in your local file system, you have to get its corresponding URL.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ConvertToURL runtime function is prepared for this task. And there is ConvertFromURL runtime function for reverse conversion.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following functions are defined in uno module for such task.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 path = &amp;quot;/home/foo/Documents/file.odt&amp;quot;&lt;br /&gt;
 url = uno.sytemPathToFileUrl(path)&lt;br /&gt;
 path = uno.fileUrlToSystemPath(url)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments and Return Value ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, mode of the first argument of parseStrict method is &amp;quot;inout&amp;quot; in the following code: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 aURL = CreateUnoStruct(&amp;quot;com.sun.star.util.URL&amp;quot;)&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 CreateUnoService(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;).parseStrict(aURL)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The content of aURL variable is updated after calling the method.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, out mode parameter is returned as part of return value.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.util import URL&lt;br /&gt;
&lt;br /&gt;
 aURL = URL()&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 dummy, aURL = smgr.createInstanceWithContext(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;, ctx).parseStrict(aURL)&lt;br /&gt;
 # Definition of com.sun.star.util.XURLTransformer::parseStrict method: &lt;br /&gt;
 # void parseStrict([inout] com.sun.star.util.URL aURL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If a method has out mode in its parameters, its return is always tuple that contains original return value and values for out parameters.&lt;br /&gt;
&lt;br /&gt;
Here is a potential example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # boolean getSomeValue([in] string aName, [out] short aNum, [inout] long aNum2);&lt;br /&gt;
 result, num, num2 = obj.getSomeValue(&amp;quot;foo&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above example, &amp;#039;&amp;#039;result&amp;#039;&amp;#039; variable takes original return value, &amp;#039;&amp;#039;num&amp;#039;&amp;#039; takes output value for second parameter and &amp;#039;&amp;#039;num2&amp;#039;&amp;#039; takes output value for third parameter. The method takes 100 as the second parameter but it is not used as input of value. No entry in returned tuple for in mode parameter.&lt;br /&gt;
&lt;br /&gt;
== Functions to be Executed ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can not choose routines to be executed by users.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, define &amp;#039;&amp;#039;&amp;#039;g_exportedScripts&amp;#039;&amp;#039;&amp;#039; variable that contains tuple of callable in your macro file.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def func_a(): pass&lt;br /&gt;
 def func_b(): pass&lt;br /&gt;
 def func_hidden(): pass # not shown in the UI&lt;br /&gt;
 &lt;br /&gt;
 g_exportedScripts = func_a, func_b&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above code, func_hidden is not shown in execution dialog of macros.&lt;br /&gt;
&lt;br /&gt;
== Importing Modules ==&lt;br /&gt;
In Basic, you can call subroutines defined in other modules or other libraries that has been loaded.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
BasicLibraries.loadLibrary(&amp;quot;Library1&amp;quot;)&lt;br /&gt;
Library1.Foo()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you can import some modules that can be found in sys.path list. If you want to import your own module placed inside Scripts/python directory, put your module in pythonpath directory nearby your script file.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 - Scripts/&lt;br /&gt;
   - python/&lt;br /&gt;
     - macro.py&lt;br /&gt;
     - pythonpath/  # this directory is added automatically before your macro executed&lt;br /&gt;
       - your_module.py  # this module can be found&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When you execute the macro from your script file, the internal executor adds the pythonpath/ directory to sys.path list to be used as one of lookup location.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, the name of module conflict each other if you have the same named module in the some location, this is the standard python mechanism of importing modules, put your each modules in differently named library to avoid the name conflict.&lt;br /&gt;
&lt;br /&gt;
== Dialog ==&lt;br /&gt;
In Basic, there is CreateUnoDialog runtime function to instantiate the dialog.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 DialogLibraries.loadLibrary(&amp;quot;Standard&amp;quot;)&lt;br /&gt;
 dialog = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
 dialog.execute()&lt;br /&gt;
 dialog.dispose()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, such shortcut function is not provided but you can easily instantiate your dialog using &amp;lt;idl&amp;gt;com.sun.star.awt.DialogProvider&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def dialog_example():&lt;br /&gt;
     ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
     smgr = ctx.getServiceManager()&lt;br /&gt;
     dp = smgr.createInstanceWithContext(&amp;quot;com.sun.star.awt.DialogProvider&amp;quot;, ctx)&lt;br /&gt;
     dialog = dp.createDialog(&amp;quot;vnd.sun.star.script:Standard.Dialog1?location=user&amp;quot;)&lt;br /&gt;
     dialog.execute()&lt;br /&gt;
     dialog.dispose()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Message Box ==&lt;br /&gt;
In Basic, you can use MsgBox runtime function to show some message to the users.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
  Msgbox &amp;quot;Hello.&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, no shortcut function is provided but you can use &amp;lt;idl&amp;gt;com.sun.star.awt.XMessageBoxFactory&amp;lt;/idl&amp;gt; interface through the toolkit.&lt;br /&gt;
&lt;br /&gt;
== Input Box ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231614</id>
		<title>Python/Transfer from Basic to Python</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231614"/>
		<updated>2013-10-03T09:08:30Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add description about Dialog creation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Transfer from Basic to Python}}&lt;br /&gt;
&lt;br /&gt;
Translation [[ES/Manuales/GuiaAOO/TemasAvanzados/Macros/Python/BasicAPython| Español]]&lt;br /&gt;
&lt;br /&gt;
If you feel some displeasure at StarBasic/OpenOffice Basic or you meet requirement of custom UNO component, now it is the time to transfer coding environment from Basic to Python.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, there are some runtime function provides shortcut to do something. But using Python-UNO bridge, you have to do such task by API ways.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s start with Python&amp;#039;s tutorial and return back to here when you have learned a bit about Python language.&lt;br /&gt;
&lt;br /&gt;
== Macro Location ==&lt;br /&gt;
On the current version, script organizer for Python do not provide the way to manage script files. So you have to manage yourself. Macros written in Python should be placed in the specific directory under your user&amp;#039;s profile, shared profile or script directory of your document.&lt;br /&gt;
&lt;br /&gt;
The python directory (in all lowercase) should be created in Scripts directory and you can put your python scripts that contain python code.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
path_to_directory/Scripts/python/your_file.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can make subdirectories to put macro files in them under Scripts/python directory.&lt;br /&gt;
&lt;br /&gt;
You have to add &amp;quot;py&amp;quot; file extension to your file name.&lt;br /&gt;
&lt;br /&gt;
== Macro Editor ==&lt;br /&gt;
&lt;br /&gt;
There is no built-in editor dedicated to code in Python. But you can choose your favorite text editor application to edit your Python script.&lt;br /&gt;
&lt;br /&gt;
This is discussed in another page.&lt;br /&gt;
&lt;br /&gt;
== Short Example ==&lt;br /&gt;
&lt;br /&gt;
Here is a small example written in Python.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello():&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Each callable function is the executable unit of Python macro (you can choose which function should be listed in the GUI, see other document).&lt;br /&gt;
&lt;br /&gt;
You can access the current document through getDocument method of XSCRIPTCONTEXT variable of the module. And it changes the document content to &amp;quot;Hello!&amp;quot; of the Writer document.&lt;br /&gt;
&lt;br /&gt;
== Usable Modules ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 import unohelper&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Script Context ==&lt;br /&gt;
&lt;br /&gt;
StarBasic is embedded runtime and it always works with living instance of the office. So the context is always the match with the office&amp;#039;s one. But Python-UNO bridge provides the way to work as RPC client. At that time, remote Python instance does have different context from the office instance. Therefore you have to use correct component context to tell to the multi component factory to instantiate a service.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you have no matching object provided.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039; macro, you have to use &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; module variable that provides &amp;lt;idl&amp;gt;com.sun.star.script.provider.XScriptContext&amp;lt;/idl&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XModel&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDocument()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current document object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.document.XScriptInvocationContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getInvocationContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns invocation dependent object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XDesktop&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDesktop()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns instance of &amp;lt;idl&amp;gt;com.sun.star.frame.Desktop&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.uno.XComponentContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getComponentContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current component context that is used to tell the which context is.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; variable is defined in module level and it is not provided to imported modules from your script.&lt;br /&gt;
&lt;br /&gt;
== Component Context ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get component context as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = GetDefaultContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But you do not need to access to it until you need to get singletons.&lt;br /&gt;
&lt;br /&gt;
In Python, you can get access to the component context through the script context.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need this value to instantiate services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service Manager ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get service manager as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 smgr = GetProcessServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But not so many people having to access to it.&lt;br /&gt;
&lt;br /&gt;
In Python, this instance is most important value to instantiate services to work with the office APIs.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need both the component context and the service manager to instantiate services.&lt;br /&gt;
&lt;br /&gt;
== Service Instance ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can instantiate services by built-in function as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 sfa = CreateUnoService(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or with initialize arguments: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 arg = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = CreateUnoServiceWithArguments(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, Array(arg))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Python, you have to work with com.sun.star.lang.XMultiComponentFactory interface as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
 sfa = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;, ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to initialize the instance, use createInstanceWithArgumentsAndContext method: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = smgr.createInstanceWithArgumentsAndContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, (FILESAVE_SIMPLE,) ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or initialize after the instantiation: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 file_picker = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, ctx)&lt;br /&gt;
 file_picker.initialize((FILESAVE_SIMPLE,))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service with Constructor ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can call service construct from its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 shell_execute = com.sun.star.system.SystemShellExecute.create()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you have to instantiate it with XMultiComponentFactory::createInstanceWithArgumentsAndContext method with initial arguments or instantiate after the instantiation.&lt;br /&gt;
&lt;br /&gt;
The constructor calling does type checking before to pass arguments to createInstanceWithArgumentsAndContext method.&lt;br /&gt;
&lt;br /&gt;
== Current Document ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ThisComponent runtime function provides access to the current document: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = ThisComponent&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Its return value is bound to the macro location. If the macro stored in a document, the result of ThisComponent is the document that the storage of the macro belongs to. And if your macro is stored in application wide, the returned value is the document model of currently active frame, this is the same result taken from StarDesktop.&amp;#039;&amp;#039;&amp;#039;getCurrentComponent()&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can access to the current document through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If your macro is &amp;#039;&amp;#039;&amp;#039;embedded in the document&amp;#039;&amp;#039;&amp;#039;, the document model is match with the document that the macro stored in. If your macro is stored in user or shared location, the document object is from active frame.&lt;br /&gt;
&lt;br /&gt;
== Desktop ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, StarDesktop runtime function is provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = StarDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can get access to the desktop through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = XSCRIPTCONTEXT.getDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Struct Instance ==&lt;br /&gt;
&lt;br /&gt;
In Basic, instance of struct can be instantiated in two ways: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Dim a As New com.sun.star.awt.Point&lt;br /&gt;
 a = CreateUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
With Dim statement and New keyword, you can instantiate a struct or array of structs. Or CreateUnoStruct method provides the way to instantiate a struct at runtime. You can not initialize the instance at the creation, you have to set its value of members.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can use the following ways to instantiate a struct. Import struct class and call it.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.awt import Point&lt;br /&gt;
&lt;br /&gt;
 a = Point()         # instantiate with default values, X=0, Y=0&lt;br /&gt;
 b = Point(100, 200) # initialize with initial values, X=100, Y=200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Calling the class to create new instance of the struct, you can empty its arguments or you have to pass values for all fields. In other words, you can not pass insufficient number of arguments to initialize. And its order should be match with definition of the struct in its IDL. For example, instance of struct b having X=100 and Y=200 in the above piece of code.&lt;br /&gt;
&lt;br /&gt;
You can initialize without to import the class of your target struct with uno.createUnoStruct function as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 a = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
 b = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This makes the same result with the above example. The first parameter of the createUnoStruct method is the name of the struct to initialize. The following arguments are initial values for new instance.&lt;br /&gt;
&lt;br /&gt;
== Enum ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can access to the module of the enum as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ITALIC = com.sun.star.awt.FontSlant.ITALIC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following ways can be used: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontSlant import ITALIC&lt;br /&gt;
 ITALIC = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontSlant.ITALIC&amp;quot;)&lt;br /&gt;
 ITALIC = uno.Enum(&amp;quot;com.sun.star.awt.FontSlant&amp;quot;, &amp;quot;ITALIC&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
All of the way results the instance of uno.Enum class.&lt;br /&gt;
&lt;br /&gt;
== Constants ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get access to constants through its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 BOLD = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways are provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontWeight import BOLD&lt;br /&gt;
 BOLD = uno.getConstantsByName(&amp;quot;com.sun.star.awt.FontWeight.BOLD&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sequence ==&lt;br /&gt;
&lt;br /&gt;
The sequence is sequential value of the same type.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, array is used.&lt;br /&gt;
&lt;br /&gt;
In Python, tuple is chosen to represent UNO&amp;#039;s sequence. Note, list is not allowed to pass as sequence value.&lt;br /&gt;
&lt;br /&gt;
== Boolean ==&lt;br /&gt;
&lt;br /&gt;
In Python, True or False.&lt;br /&gt;
&lt;br /&gt;
== String ==&lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;s string can contain over 64K bytes.&lt;br /&gt;
&lt;br /&gt;
If you have to write non Ascii 7 bit characters in your script, write magic comment at the head of your file. This is standard Python instructions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # -*- coding: utf_8 -*-&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please read Python&amp;#039;s documentation for more detail.&lt;br /&gt;
&lt;br /&gt;
You have to use unicode string to write some unicode characters in Python 2.X. And strings coming from UNO is decoded in unicode in Python 2.X.&lt;br /&gt;
&lt;br /&gt;
== Char ==&lt;br /&gt;
&lt;br /&gt;
There is no dedicated value for char type in StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, uno.Char class is defined for char type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 c = uno.Char(&amp;quot;a&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Type ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Type&amp;quot; type is meta type of UNO that represents type of UNO.&lt;br /&gt;
Since 3.4, if you pass string value to method as an argument that should be type, the bridge of Basic read it as type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
oMap = com.sun.star.container.EnumerableMap.create(&amp;quot;string&amp;quot;, &amp;quot;string&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways can be used to create new valu of type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 t = uno.getTypeByName(&amp;quot;string&amp;quot;)&lt;br /&gt;
 t = uno.Type(&amp;quot;string&amp;quot;, uno.Enum(&amp;quot;com.sun.star.uno.TypeClass&amp;quot;, &amp;quot;STRING&amp;quot;))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Byte Sequence ==&lt;br /&gt;
&lt;br /&gt;
The byte sequence is sequence of byte type.&lt;br /&gt;
&lt;br /&gt;
In Basic, array of byte is used to represent it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, it is represented by str wrapped by uno.ByteSequence class. If you takes some byte sequences from UNO, they are the instance of uno.ByteSequence. If you need to get real value of them, refer its &amp;#039;&amp;#039;value&amp;#039;&amp;#039; instance variable.&lt;br /&gt;
&lt;br /&gt;
== Exception ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you get thrown exception as some error. And On Error statement is used to catch it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub ErrorExample&lt;br /&gt;
&lt;br /&gt;
   On Error GoTo Handler&lt;br /&gt;
&lt;br /&gt;
   &amp;#039; ... error&lt;br /&gt;
&lt;br /&gt;
   Exit Sub&lt;br /&gt;
&lt;br /&gt;
   Handler: &lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
And you can not throw any exceptions from StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, the exception thrown in UNO world can be treated as normal Python&amp;#039;s exception. Here is an example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.container import IndexOutOfBoundsException&lt;br /&gt;
&lt;br /&gt;
 try:&lt;br /&gt;
     obj.getByIndex(100) # raises IndexOutOfBoundsException&lt;br /&gt;
 except IndexOutOfBoundsException as e:&lt;br /&gt;
     print(e)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If getByIndex method raises IndexOutOfBoundsException, it can be caught in except statement because all exceptions inherit Python&amp;#039;s Exception class.&lt;br /&gt;
&lt;br /&gt;
And also you can throw UNO&amp;#039;s exception from your Python code as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.uno import RuntimeException&lt;br /&gt;
 raise RuntimeException(&amp;quot;Some message&amp;quot;, None)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Empty Value ==&lt;br /&gt;
&lt;br /&gt;
In Basic, there are some situations to meet variables that they do not contain any value (this is not correct). Null, empty, missing, nothing and so on.&lt;br /&gt;
&lt;br /&gt;
In Python, None is used. If a method defined as void return value in its IDL, it results None if you call it. If you need to pass invalid interface as an argument for the method that takes some interface, pass None for it. The result of this behavior is fully dependent to the implementation of the method.&lt;br /&gt;
&lt;br /&gt;
== Listener and Interface ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can create new listener using CreateUnoListener runtime function with some subroutines or functions.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub Add&lt;br /&gt;
&lt;br /&gt;
   d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
   listener = CreateUnoListener(&amp;quot;ActionListener&amp;quot;, &amp;quot;com.sun.star.awt.XActionListener&amp;quot;)&lt;br /&gt;
   d.getControl(&amp;quot;CommandButton1&amp;quot;).addActionListener(listener)&lt;br /&gt;
   d.execute()&lt;br /&gt;
   d.dispose()&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 Sub ActionListener_actionPerformed(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 Sub ActionListener_disposing(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you have to define your own class with desired interfaces. With helper class, you can define easily as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import unohelper&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt import XActionListener&lt;br /&gt;
&lt;br /&gt;
 class ActionListener(unohelper.Base, XActionListener):&lt;br /&gt;
     def __init__(self):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def disposing(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def actionPerformed(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
unohelper.Base class provides required interface for UNO components.&lt;br /&gt;
&lt;br /&gt;
== Containers ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, container object provides the way to access to its contents in sequentially.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, there is no shortcut provided. &lt;br /&gt;
&lt;br /&gt;
If you need to access to elements of indexed container, use range function to generate sequential indexes.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 for i in range(container.getCount()):&lt;br /&gt;
     obj = container.getByIndex(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== URL and System Path ==&lt;br /&gt;
&lt;br /&gt;
If you work with a file stored in your local file system, you have to get its corresponding URL.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ConvertToURL runtime function is prepared for this task. And there is ConvertFromURL runtime function for reverse conversion.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following functions are defined in uno module for such task.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 path = &amp;quot;/home/foo/Documents/file.odt&amp;quot;&lt;br /&gt;
 url = uno.sytemPathToFileUrl(path)&lt;br /&gt;
 path = uno.fileUrlToSystemPath(url)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments and Return Value ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, mode of the first argument of parseStrict method is &amp;quot;inout&amp;quot; in the following code: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 aURL = CreateUnoStruct(&amp;quot;com.sun.star.util.URL&amp;quot;)&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 CreateUnoService(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;).parseStrict(aURL)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The content of aURL variable is updated after calling the method.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, out mode parameter is returned as part of return value.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.util import URL&lt;br /&gt;
&lt;br /&gt;
 aURL = URL()&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 dummy, aURL = smgr.createInstanceWithContext(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;, ctx).parseStrict(aURL)&lt;br /&gt;
 # Definition of com.sun.star.util.XURLTransformer::parseStrict method: &lt;br /&gt;
 # void parseStrict([inout] com.sun.star.util.URL aURL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If a method has out mode in its parameters, its return is always tuple that contains original return value and values for out parameters.&lt;br /&gt;
&lt;br /&gt;
Here is a potential example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # boolean getSomeValue([in] string aName, [out] short aNum, [inout] long aNum2);&lt;br /&gt;
 result, num, num2 = obj.getSomeValue(&amp;quot;foo&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above example, &amp;#039;&amp;#039;result&amp;#039;&amp;#039; variable takes original return value, &amp;#039;&amp;#039;num&amp;#039;&amp;#039; takes output value for second parameter and &amp;#039;&amp;#039;num2&amp;#039;&amp;#039; takes output value for third parameter. The method takes 100 as the second parameter but it is not used as input of value. No entry in returned tuple for in mode parameter.&lt;br /&gt;
&lt;br /&gt;
== Functions to be Executed ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can not choose routines to be executed by users.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, define &amp;#039;&amp;#039;&amp;#039;g_exportedScripts&amp;#039;&amp;#039;&amp;#039; variable that contains tuple of callable in your macro file.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def func_a(): pass&lt;br /&gt;
 def func_b(): pass&lt;br /&gt;
 def func_hidden(): pass # not shown in the UI&lt;br /&gt;
 &lt;br /&gt;
 g_exportedScripts = func_a, func_b&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above code, func_hidden is not shown in execution dialog of macros.&lt;br /&gt;
&lt;br /&gt;
== Importing Modules ==&lt;br /&gt;
In Basic, you can call subroutines defined in other modules or other libraries that has been loaded.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
BasicLibraries.loadLibrary(&amp;quot;Library1&amp;quot;)&lt;br /&gt;
Library1.Foo()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you can import some modules that can be found in sys.path list. If you want to import your own module placed inside Scripts/python directory, put your module in pythonpath directory nearby your script file.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 - Scripts/&lt;br /&gt;
   - python/&lt;br /&gt;
     - macro.py&lt;br /&gt;
     - pythonpath/  # this directory is added automatically before your macro executed&lt;br /&gt;
       - your_module.py  # this module can be found&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When you execute the macro from your script file, the internal executor adds the pythonpath/ directory to sys.path list to be used as one of lookup location.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, the name of module conflict each other if you have the same named module in the some location, this is the standard python mechanism of importing modules, put your each modules in differently named library to avoid the name conflict.&lt;br /&gt;
&lt;br /&gt;
== Dialog ==&lt;br /&gt;
In Basic, there is CreateUnoDialog runtime function to instantiate the dialog.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 DialogLibraries.loadLibrary(&amp;quot;Standard&amp;quot;)&lt;br /&gt;
 dialog = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
 dialog.execute()&lt;br /&gt;
 dialog.dispose()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, such shortcut function is not provided but you can easily instantiate your dialog using &amp;lt;idl&amp;gt;com.sun.star.awt.DialogProvider&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def dialog_example():&lt;br /&gt;
     ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
     smgr = ctx.getServiceManager()&lt;br /&gt;
     dp = smgr.createInstanceWithContext(&amp;quot;com.sun.star.awt.DialogProvider&amp;quot;, ctx)&lt;br /&gt;
     dialog = dp.createDialog(&amp;quot;vnd.sun.star.script:Standard.Dialog1?location=user&amp;quot;)&lt;br /&gt;
     dialog.execute()&lt;br /&gt;
     dialog.dispose()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Message Box ==&lt;br /&gt;
&lt;br /&gt;
== Input Box ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231613</id>
		<title>Python/Transfer from Basic to Python</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231613"/>
		<updated>2013-10-03T08:53:37Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add description about Importing Modules&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Transfer from Basic to Python}}&lt;br /&gt;
&lt;br /&gt;
Translation [[ES/Manuales/GuiaAOO/TemasAvanzados/Macros/Python/BasicAPython| Español]]&lt;br /&gt;
&lt;br /&gt;
If you feel some displeasure at StarBasic/OpenOffice Basic or you meet requirement of custom UNO component, now it is the time to transfer coding environment from Basic to Python.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, there are some runtime function provides shortcut to do something. But using Python-UNO bridge, you have to do such task by API ways.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s start with Python&amp;#039;s tutorial and return back to here when you have learned a bit about Python language.&lt;br /&gt;
&lt;br /&gt;
== Macro Location ==&lt;br /&gt;
On the current version, script organizer for Python do not provide the way to manage script files. So you have to manage yourself. Macros written in Python should be placed in the specific directory under your user&amp;#039;s profile, shared profile or script directory of your document.&lt;br /&gt;
&lt;br /&gt;
The python directory (in all lowercase) should be created in Scripts directory and you can put your python scripts that contain python code.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
path_to_directory/Scripts/python/your_file.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can make subdirectories to put macro files in them under Scripts/python directory.&lt;br /&gt;
&lt;br /&gt;
You have to add &amp;quot;py&amp;quot; file extension to your file name.&lt;br /&gt;
&lt;br /&gt;
== Macro Editor ==&lt;br /&gt;
&lt;br /&gt;
There is no built-in editor dedicated to code in Python. But you can choose your favorite text editor application to edit your Python script.&lt;br /&gt;
&lt;br /&gt;
This is discussed in another page.&lt;br /&gt;
&lt;br /&gt;
== Short Example ==&lt;br /&gt;
&lt;br /&gt;
Here is a small example written in Python.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello():&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Each callable function is the executable unit of Python macro (you can choose which function should be listed in the GUI, see other document).&lt;br /&gt;
&lt;br /&gt;
You can access the current document through getDocument method of XSCRIPTCONTEXT variable of the module. And it changes the document content to &amp;quot;Hello!&amp;quot; of the Writer document.&lt;br /&gt;
&lt;br /&gt;
== Usable Modules ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 import unohelper&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Script Context ==&lt;br /&gt;
&lt;br /&gt;
StarBasic is embedded runtime and it always works with living instance of the office. So the context is always the match with the office&amp;#039;s one. But Python-UNO bridge provides the way to work as RPC client. At that time, remote Python instance does have different context from the office instance. Therefore you have to use correct component context to tell to the multi component factory to instantiate a service.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you have no matching object provided.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039; macro, you have to use &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; module variable that provides &amp;lt;idl&amp;gt;com.sun.star.script.provider.XScriptContext&amp;lt;/idl&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XModel&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDocument()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current document object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.document.XScriptInvocationContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getInvocationContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns invocation dependent object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XDesktop&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDesktop()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns instance of &amp;lt;idl&amp;gt;com.sun.star.frame.Desktop&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.uno.XComponentContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getComponentContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current component context that is used to tell the which context is.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; variable is defined in module level and it is not provided to imported modules from your script.&lt;br /&gt;
&lt;br /&gt;
== Component Context ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get component context as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = GetDefaultContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But you do not need to access to it until you need to get singletons.&lt;br /&gt;
&lt;br /&gt;
In Python, you can get access to the component context through the script context.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need this value to instantiate services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service Manager ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get service manager as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 smgr = GetProcessServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But not so many people having to access to it.&lt;br /&gt;
&lt;br /&gt;
In Python, this instance is most important value to instantiate services to work with the office APIs.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need both the component context and the service manager to instantiate services.&lt;br /&gt;
&lt;br /&gt;
== Service Instance ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can instantiate services by built-in function as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 sfa = CreateUnoService(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or with initialize arguments: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 arg = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = CreateUnoServiceWithArguments(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, Array(arg))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Python, you have to work with com.sun.star.lang.XMultiComponentFactory interface as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
 sfa = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;, ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to initialize the instance, use createInstanceWithArgumentsAndContext method: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = smgr.createInstanceWithArgumentsAndContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, (FILESAVE_SIMPLE,) ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or initialize after the instantiation: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 file_picker = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, ctx)&lt;br /&gt;
 file_picker.initialize((FILESAVE_SIMPLE,))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service with Constructor ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can call service construct from its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 shell_execute = com.sun.star.system.SystemShellExecute.create()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you have to instantiate it with XMultiComponentFactory::createInstanceWithArgumentsAndContext method with initial arguments or instantiate after the instantiation.&lt;br /&gt;
&lt;br /&gt;
The constructor calling does type checking before to pass arguments to createInstanceWithArgumentsAndContext method.&lt;br /&gt;
&lt;br /&gt;
== Current Document ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ThisComponent runtime function provides access to the current document: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = ThisComponent&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Its return value is bound to the macro location. If the macro stored in a document, the result of ThisComponent is the document that the storage of the macro belongs to. And if your macro is stored in application wide, the returned value is the document model of currently active frame, this is the same result taken from StarDesktop.&amp;#039;&amp;#039;&amp;#039;getCurrentComponent()&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can access to the current document through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If your macro is &amp;#039;&amp;#039;&amp;#039;embedded in the document&amp;#039;&amp;#039;&amp;#039;, the document model is match with the document that the macro stored in. If your macro is stored in user or shared location, the document object is from active frame.&lt;br /&gt;
&lt;br /&gt;
== Desktop ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, StarDesktop runtime function is provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = StarDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can get access to the desktop through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = XSCRIPTCONTEXT.getDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Struct Instance ==&lt;br /&gt;
&lt;br /&gt;
In Basic, instance of struct can be instantiated in two ways: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Dim a As New com.sun.star.awt.Point&lt;br /&gt;
 a = CreateUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
With Dim statement and New keyword, you can instantiate a struct or array of structs. Or CreateUnoStruct method provides the way to instantiate a struct at runtime. You can not initialize the instance at the creation, you have to set its value of members.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can use the following ways to instantiate a struct. Import struct class and call it.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.awt import Point&lt;br /&gt;
&lt;br /&gt;
 a = Point()         # instantiate with default values, X=0, Y=0&lt;br /&gt;
 b = Point(100, 200) # initialize with initial values, X=100, Y=200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Calling the class to create new instance of the struct, you can empty its arguments or you have to pass values for all fields. In other words, you can not pass insufficient number of arguments to initialize. And its order should be match with definition of the struct in its IDL. For example, instance of struct b having X=100 and Y=200 in the above piece of code.&lt;br /&gt;
&lt;br /&gt;
You can initialize without to import the class of your target struct with uno.createUnoStruct function as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 a = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
 b = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This makes the same result with the above example. The first parameter of the createUnoStruct method is the name of the struct to initialize. The following arguments are initial values for new instance.&lt;br /&gt;
&lt;br /&gt;
== Enum ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can access to the module of the enum as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ITALIC = com.sun.star.awt.FontSlant.ITALIC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following ways can be used: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontSlant import ITALIC&lt;br /&gt;
 ITALIC = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontSlant.ITALIC&amp;quot;)&lt;br /&gt;
 ITALIC = uno.Enum(&amp;quot;com.sun.star.awt.FontSlant&amp;quot;, &amp;quot;ITALIC&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
All of the way results the instance of uno.Enum class.&lt;br /&gt;
&lt;br /&gt;
== Constants ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get access to constants through its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 BOLD = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways are provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontWeight import BOLD&lt;br /&gt;
 BOLD = uno.getConstantsByName(&amp;quot;com.sun.star.awt.FontWeight.BOLD&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sequence ==&lt;br /&gt;
&lt;br /&gt;
The sequence is sequential value of the same type.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, array is used.&lt;br /&gt;
&lt;br /&gt;
In Python, tuple is chosen to represent UNO&amp;#039;s sequence. Note, list is not allowed to pass as sequence value.&lt;br /&gt;
&lt;br /&gt;
== Boolean ==&lt;br /&gt;
&lt;br /&gt;
In Python, True or False.&lt;br /&gt;
&lt;br /&gt;
== String ==&lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;s string can contain over 64K bytes.&lt;br /&gt;
&lt;br /&gt;
If you have to write non Ascii 7 bit characters in your script, write magic comment at the head of your file. This is standard Python instructions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # -*- coding: utf_8 -*-&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please read Python&amp;#039;s documentation for more detail.&lt;br /&gt;
&lt;br /&gt;
You have to use unicode string to write some unicode characters in Python 2.X. And strings coming from UNO is decoded in unicode in Python 2.X.&lt;br /&gt;
&lt;br /&gt;
== Char ==&lt;br /&gt;
&lt;br /&gt;
There is no dedicated value for char type in StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, uno.Char class is defined for char type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 c = uno.Char(&amp;quot;a&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Type ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Type&amp;quot; type is meta type of UNO that represents type of UNO.&lt;br /&gt;
Since 3.4, if you pass string value to method as an argument that should be type, the bridge of Basic read it as type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
oMap = com.sun.star.container.EnumerableMap.create(&amp;quot;string&amp;quot;, &amp;quot;string&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways can be used to create new valu of type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 t = uno.getTypeByName(&amp;quot;string&amp;quot;)&lt;br /&gt;
 t = uno.Type(&amp;quot;string&amp;quot;, uno.Enum(&amp;quot;com.sun.star.uno.TypeClass&amp;quot;, &amp;quot;STRING&amp;quot;))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Byte Sequence ==&lt;br /&gt;
&lt;br /&gt;
The byte sequence is sequence of byte type.&lt;br /&gt;
&lt;br /&gt;
In Basic, array of byte is used to represent it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, it is represented by str wrapped by uno.ByteSequence class. If you takes some byte sequences from UNO, they are the instance of uno.ByteSequence. If you need to get real value of them, refer its &amp;#039;&amp;#039;value&amp;#039;&amp;#039; instance variable.&lt;br /&gt;
&lt;br /&gt;
== Exception ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you get thrown exception as some error. And On Error statement is used to catch it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub ErrorExample&lt;br /&gt;
&lt;br /&gt;
   On Error GoTo Handler&lt;br /&gt;
&lt;br /&gt;
   &amp;#039; ... error&lt;br /&gt;
&lt;br /&gt;
   Exit Sub&lt;br /&gt;
&lt;br /&gt;
   Handler: &lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
And you can not throw any exceptions from StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, the exception thrown in UNO world can be treated as normal Python&amp;#039;s exception. Here is an example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.container import IndexOutOfBoundsException&lt;br /&gt;
&lt;br /&gt;
 try:&lt;br /&gt;
     obj.getByIndex(100) # raises IndexOutOfBoundsException&lt;br /&gt;
 except IndexOutOfBoundsException as e:&lt;br /&gt;
     print(e)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If getByIndex method raises IndexOutOfBoundsException, it can be caught in except statement because all exceptions inherit Python&amp;#039;s Exception class.&lt;br /&gt;
&lt;br /&gt;
And also you can throw UNO&amp;#039;s exception from your Python code as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.uno import RuntimeException&lt;br /&gt;
 raise RuntimeException(&amp;quot;Some message&amp;quot;, None)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Empty Value ==&lt;br /&gt;
&lt;br /&gt;
In Basic, there are some situations to meet variables that they do not contain any value (this is not correct). Null, empty, missing, nothing and so on.&lt;br /&gt;
&lt;br /&gt;
In Python, None is used. If a method defined as void return value in its IDL, it results None if you call it. If you need to pass invalid interface as an argument for the method that takes some interface, pass None for it. The result of this behavior is fully dependent to the implementation of the method.&lt;br /&gt;
&lt;br /&gt;
== Listener and Interface ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can create new listener using CreateUnoListener runtime function with some subroutines or functions.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub Add&lt;br /&gt;
&lt;br /&gt;
   d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
   listener = CreateUnoListener(&amp;quot;ActionListener&amp;quot;, &amp;quot;com.sun.star.awt.XActionListener&amp;quot;)&lt;br /&gt;
   d.getControl(&amp;quot;CommandButton1&amp;quot;).addActionListener(listener)&lt;br /&gt;
   d.execute()&lt;br /&gt;
   d.dispose()&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 Sub ActionListener_actionPerformed(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 Sub ActionListener_disposing(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you have to define your own class with desired interfaces. With helper class, you can define easily as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import unohelper&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt import XActionListener&lt;br /&gt;
&lt;br /&gt;
 class ActionListener(unohelper.Base, XActionListener):&lt;br /&gt;
     def __init__(self):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def disposing(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def actionPerformed(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
unohelper.Base class provides required interface for UNO components.&lt;br /&gt;
&lt;br /&gt;
== Containers ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, container object provides the way to access to its contents in sequentially.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, there is no shortcut provided. &lt;br /&gt;
&lt;br /&gt;
If you need to access to elements of indexed container, use range function to generate sequential indexes.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 for i in range(container.getCount()):&lt;br /&gt;
     obj = container.getByIndex(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== URL and System Path ==&lt;br /&gt;
&lt;br /&gt;
If you work with a file stored in your local file system, you have to get its corresponding URL.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ConvertToURL runtime function is prepared for this task. And there is ConvertFromURL runtime function for reverse conversion.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following functions are defined in uno module for such task.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 path = &amp;quot;/home/foo/Documents/file.odt&amp;quot;&lt;br /&gt;
 url = uno.sytemPathToFileUrl(path)&lt;br /&gt;
 path = uno.fileUrlToSystemPath(url)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments and Return Value ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, mode of the first argument of parseStrict method is &amp;quot;inout&amp;quot; in the following code: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 aURL = CreateUnoStruct(&amp;quot;com.sun.star.util.URL&amp;quot;)&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 CreateUnoService(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;).parseStrict(aURL)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The content of aURL variable is updated after calling the method.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, out mode parameter is returned as part of return value.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.util import URL&lt;br /&gt;
&lt;br /&gt;
 aURL = URL()&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 dummy, aURL = smgr.createInstanceWithContext(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;, ctx).parseStrict(aURL)&lt;br /&gt;
 # Definition of com.sun.star.util.XURLTransformer::parseStrict method: &lt;br /&gt;
 # void parseStrict([inout] com.sun.star.util.URL aURL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If a method has out mode in its parameters, its return is always tuple that contains original return value and values for out parameters.&lt;br /&gt;
&lt;br /&gt;
Here is a potential example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # boolean getSomeValue([in] string aName, [out] short aNum, [inout] long aNum2);&lt;br /&gt;
 result, num, num2 = obj.getSomeValue(&amp;quot;foo&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above example, &amp;#039;&amp;#039;result&amp;#039;&amp;#039; variable takes original return value, &amp;#039;&amp;#039;num&amp;#039;&amp;#039; takes output value for second parameter and &amp;#039;&amp;#039;num2&amp;#039;&amp;#039; takes output value for third parameter. The method takes 100 as the second parameter but it is not used as input of value. No entry in returned tuple for in mode parameter.&lt;br /&gt;
&lt;br /&gt;
== Functions to be Executed ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can not choose routines to be executed by users.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, define &amp;#039;&amp;#039;&amp;#039;g_exportedScripts&amp;#039;&amp;#039;&amp;#039; variable that contains tuple of callable in your macro file.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def func_a(): pass&lt;br /&gt;
 def func_b(): pass&lt;br /&gt;
 def func_hidden(): pass # not shown in the UI&lt;br /&gt;
 &lt;br /&gt;
 g_exportedScripts = func_a, func_b&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above code, func_hidden is not shown in execution dialog of macros.&lt;br /&gt;
&lt;br /&gt;
== Importing Modules ==&lt;br /&gt;
In Basic, you can call subroutines defined in other modules or other libraries that has been loaded.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
BasicLibraries.loadLibrary(&amp;quot;Library1&amp;quot;)&lt;br /&gt;
Library1.Foo()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you can import some modules that can be found in sys.path list. If you want to import your own module placed inside Scripts/python directory, put your module in pythonpath directory nearby your script file.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 - Scripts/&lt;br /&gt;
   - python/&lt;br /&gt;
     - macro.py&lt;br /&gt;
     - pythonpath/  # this directory is added automatically before your macro executed&lt;br /&gt;
       - your_module.py  # this module can be found&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
When you execute the macro from your script file, the internal executor adds the pythonpath/ directory to sys.path list to be used as one of lookup location.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, the name of module conflict each other if you have the same named module in the some location, this is the standard python mechanism of importing modules, put your each modules in differently named library to avoid the name conflict.&lt;br /&gt;
&lt;br /&gt;
== Dialog ==&lt;br /&gt;
&lt;br /&gt;
== Message Box ==&lt;br /&gt;
&lt;br /&gt;
== Input Box ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231609</id>
		<title>Python/Transfer from Basic to Python</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231609"/>
		<updated>2013-10-03T08:01:58Z</updated>

		<summary type="html">&lt;p&gt;Hanya: /* Listener and Interface */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Transfer from Basic to Python}}&lt;br /&gt;
&lt;br /&gt;
Translation [[ES/Manuales/GuiaAOO/TemasAvanzados/Macros/Python/BasicAPython| Español]]&lt;br /&gt;
&lt;br /&gt;
If you feel some displeasure at StarBasic/OpenOffice Basic or you meet requirement of custom UNO component, now it is the time to transfer coding environment from Basic to Python.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, there are some runtime function provides shortcut to do something. But using Python-UNO bridge, you have to do such task by API ways.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s start with Python&amp;#039;s tutorial and return back to here when you have learned a bit about Python language.&lt;br /&gt;
&lt;br /&gt;
== Macro Location ==&lt;br /&gt;
On the current version, script organizer for Python do not provide the way to manage script files. So you have to manage yourself. Macros written in Python should be placed in the specific directory under your user&amp;#039;s profile, shared profile or script directory of your document.&lt;br /&gt;
&lt;br /&gt;
The python directory (in all lowercase) should be created in Scripts directory and you can put your python scripts that contain python code.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
path_to_directory/Scripts/python/your_file.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can make subdirectories to put macro files in them under Scripts/python directory.&lt;br /&gt;
&lt;br /&gt;
You have to add &amp;quot;py&amp;quot; file extension to your file name.&lt;br /&gt;
&lt;br /&gt;
== Macro Editor ==&lt;br /&gt;
&lt;br /&gt;
There is no built-in editor dedicated to code in Python. But you can choose your favorite text editor application to edit your Python script.&lt;br /&gt;
&lt;br /&gt;
This is discussed in another page.&lt;br /&gt;
&lt;br /&gt;
== Short Example ==&lt;br /&gt;
&lt;br /&gt;
Here is a small example written in Python.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello():&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Each callable function is the executable unit of Python macro (you can choose which function should be listed in the GUI, see other document).&lt;br /&gt;
&lt;br /&gt;
You can access the current document through getDocument method of XSCRIPTCONTEXT variable of the module. And it changes the document content to &amp;quot;Hello!&amp;quot; of the Writer document.&lt;br /&gt;
&lt;br /&gt;
== Usable Modules ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 import unohelper&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Script Context ==&lt;br /&gt;
&lt;br /&gt;
StarBasic is embedded runtime and it always works with living instance of the office. So the context is always the match with the office&amp;#039;s one. But Python-UNO bridge provides the way to work as RPC client. At that time, remote Python instance does have different context from the office instance. Therefore you have to use correct component context to tell to the multi component factory to instantiate a service.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you have no matching object provided.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039; macro, you have to use &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; module variable that provides &amp;lt;idl&amp;gt;com.sun.star.script.provider.XScriptContext&amp;lt;/idl&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XModel&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDocument()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current document object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.document.XScriptInvocationContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getInvocationContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns invocation dependent object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XDesktop&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDesktop()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns instance of &amp;lt;idl&amp;gt;com.sun.star.frame.Desktop&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.uno.XComponentContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getComponentContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current component context that is used to tell the which context is.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; variable is defined in module level and it is not provided to imported modules from your script.&lt;br /&gt;
&lt;br /&gt;
== Component Context ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get component context as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = GetDefaultContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But you do not need to access to it until you need to get singletons.&lt;br /&gt;
&lt;br /&gt;
In Python, you can get access to the component context through the script context.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need this value to instantiate services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service Manager ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get service manager as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 smgr = GetProcessServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But not so many people having to access to it.&lt;br /&gt;
&lt;br /&gt;
In Python, this instance is most important value to instantiate services to work with the office APIs.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need both the component context and the service manager to instantiate services.&lt;br /&gt;
&lt;br /&gt;
== Service Instance ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can instantiate services by built-in function as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 sfa = CreateUnoService(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or with initialize arguments: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 arg = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = CreateUnoServiceWithArguments(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, Array(arg))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Python, you have to work with com.sun.star.lang.XMultiComponentFactory interface as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
 sfa = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;, ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to initialize the instance, use createInstanceWithArgumentsAndContext method: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = smgr.createInstanceWithArgumentsAndContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, (FILESAVE_SIMPLE,) ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or initialize after the instantiation: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 file_picker = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, ctx)&lt;br /&gt;
 file_picker.initialize((FILESAVE_SIMPLE,))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service with Constructor ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can call service construct from its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 shell_execute = com.sun.star.system.SystemShellExecute.create()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you have to instantiate it with XMultiComponentFactory::createInstanceWithArgumentsAndContext method with initial arguments or instantiate after the instantiation.&lt;br /&gt;
&lt;br /&gt;
The constructor calling does type checking before to pass arguments to createInstanceWithArgumentsAndContext method.&lt;br /&gt;
&lt;br /&gt;
== Current Document ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ThisComponent runtime function provides access to the current document: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = ThisComponent&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Its return value is bound to the macro location. If the macro stored in a document, the result of ThisComponent is the document that the storage of the macro belongs to. And if your macro is stored in application wide, the returned value is the document model of currently active frame, this is the same result taken from StarDesktop.&amp;#039;&amp;#039;&amp;#039;getCurrentComponent()&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can access to the current document through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If your macro is &amp;#039;&amp;#039;&amp;#039;embedded in the document&amp;#039;&amp;#039;&amp;#039;, the document model is match with the document that the macro stored in. If your macro is stored in user or shared location, the document object is from active frame.&lt;br /&gt;
&lt;br /&gt;
== Desktop ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, StarDesktop runtime function is provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = StarDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can get access to the desktop through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = XSCRIPTCONTEXT.getDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Struct Instance ==&lt;br /&gt;
&lt;br /&gt;
In Basic, instance of struct can be instantiated in two ways: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Dim a As New com.sun.star.awt.Point&lt;br /&gt;
 a = CreateUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
With Dim statement and New keyword, you can instantiate a struct or array of structs. Or CreateUnoStruct method provides the way to instantiate a struct at runtime. You can not initialize the instance at the creation, you have to set its value of members.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can use the following ways to instantiate a struct. Import struct class and call it.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.awt import Point&lt;br /&gt;
&lt;br /&gt;
 a = Point()         # instantiate with default values, X=0, Y=0&lt;br /&gt;
 b = Point(100, 200) # initialize with initial values, X=100, Y=200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Calling the class to create new instance of the struct, you can empty its arguments or you have to pass values for all fields. In other words, you can not pass insufficient number of arguments to initialize. And its order should be match with definition of the struct in its IDL. For example, instance of struct b having X=100 and Y=200 in the above piece of code.&lt;br /&gt;
&lt;br /&gt;
You can initialize without to import the class of your target struct with uno.createUnoStruct function as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 a = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
 b = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This makes the same result with the above example. The first parameter of the createUnoStruct method is the name of the struct to initialize. The following arguments are initial values for new instance.&lt;br /&gt;
&lt;br /&gt;
== Enum ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can access to the module of the enum as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ITALIC = com.sun.star.awt.FontSlant.ITALIC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following ways can be used: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontSlant import ITALIC&lt;br /&gt;
 ITALIC = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontSlant.ITALIC&amp;quot;)&lt;br /&gt;
 ITALIC = uno.Enum(&amp;quot;com.sun.star.awt.FontSlant&amp;quot;, &amp;quot;ITALIC&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
All of the way results the instance of uno.Enum class.&lt;br /&gt;
&lt;br /&gt;
== Constants ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get access to constants through its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 BOLD = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways are provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontWeight import BOLD&lt;br /&gt;
 BOLD = uno.getConstantsByName(&amp;quot;com.sun.star.awt.FontWeight.BOLD&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sequence ==&lt;br /&gt;
&lt;br /&gt;
The sequence is sequential value of the same type.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, array is used.&lt;br /&gt;
&lt;br /&gt;
In Python, tuple is chosen to represent UNO&amp;#039;s sequence. Note, list is not allowed to pass as sequence value.&lt;br /&gt;
&lt;br /&gt;
== Boolean ==&lt;br /&gt;
&lt;br /&gt;
In Python, True or False.&lt;br /&gt;
&lt;br /&gt;
== String ==&lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;s string can contain over 64K bytes.&lt;br /&gt;
&lt;br /&gt;
If you have to write non Ascii 7 bit characters in your script, write magic comment at the head of your file. This is standard Python instructions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # -*- coding: utf_8 -*-&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please read Python&amp;#039;s documentation for more detail.&lt;br /&gt;
&lt;br /&gt;
You have to use unicode string to write some unicode characters in Python 2.X. And strings coming from UNO is decoded in unicode in Python 2.X.&lt;br /&gt;
&lt;br /&gt;
== Char ==&lt;br /&gt;
&lt;br /&gt;
There is no dedicated value for char type in StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, uno.Char class is defined for char type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 c = uno.Char(&amp;quot;a&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Type ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Type&amp;quot; type is meta type of UNO that represents type of UNO.&lt;br /&gt;
Since 3.4, if you pass string value to method as an argument that should be type, the bridge of Basic read it as type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
oMap = com.sun.star.container.EnumerableMap.create(&amp;quot;string&amp;quot;, &amp;quot;string&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways can be used to create new valu of type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 t = uno.getTypeByName(&amp;quot;string&amp;quot;)&lt;br /&gt;
 t = uno.Type(&amp;quot;string&amp;quot;, uno.Enum(&amp;quot;com.sun.star.uno.TypeClass&amp;quot;, &amp;quot;STRING&amp;quot;))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Byte Sequence ==&lt;br /&gt;
&lt;br /&gt;
The byte sequence is sequence of byte type.&lt;br /&gt;
&lt;br /&gt;
In Basic, array of byte is used to represent it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, it is represented by str wrapped by uno.ByteSequence class. If you takes some byte sequences from UNO, they are the instance of uno.ByteSequence. If you need to get real value of them, refer its &amp;#039;&amp;#039;value&amp;#039;&amp;#039; instance variable.&lt;br /&gt;
&lt;br /&gt;
== Exception ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you get thrown exception as some error. And On Error statement is used to catch it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub ErrorExample&lt;br /&gt;
&lt;br /&gt;
   On Error GoTo Handler&lt;br /&gt;
&lt;br /&gt;
   &amp;#039; ... error&lt;br /&gt;
&lt;br /&gt;
   Exit Sub&lt;br /&gt;
&lt;br /&gt;
   Handler: &lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
And you can not throw any exceptions from StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, the exception thrown in UNO world can be treated as normal Python&amp;#039;s exception. Here is an example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.container import IndexOutOfBoundsException&lt;br /&gt;
&lt;br /&gt;
 try:&lt;br /&gt;
     obj.getByIndex(100) # raises IndexOutOfBoundsException&lt;br /&gt;
 except IndexOutOfBoundsException as e:&lt;br /&gt;
     print(e)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If getByIndex method raises IndexOutOfBoundsException, it can be caught in except statement because all exceptions inherit Python&amp;#039;s Exception class.&lt;br /&gt;
&lt;br /&gt;
And also you can throw UNO&amp;#039;s exception from your Python code as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.uno import RuntimeException&lt;br /&gt;
 raise RuntimeException(&amp;quot;Some message&amp;quot;, None)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Empty Value ==&lt;br /&gt;
&lt;br /&gt;
In Basic, there are some situations to meet variables that they do not contain any value (this is not correct). Null, empty, missing, nothing and so on.&lt;br /&gt;
&lt;br /&gt;
In Python, None is used. If a method defined as void return value in its IDL, it results None if you call it. If you need to pass invalid interface as an argument for the method that takes some interface, pass None for it. The result of this behavior is fully dependent to the implementation of the method.&lt;br /&gt;
&lt;br /&gt;
== Listener and Interface ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can create new listener using CreateUnoListener runtime function with some subroutines or functions.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub Add&lt;br /&gt;
&lt;br /&gt;
   d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
   listener = CreateUnoListener(&amp;quot;ActionListener&amp;quot;, &amp;quot;com.sun.star.awt.XActionListener&amp;quot;)&lt;br /&gt;
   d.getControl(&amp;quot;CommandButton1&amp;quot;).addActionListener(listener)&lt;br /&gt;
   d.execute()&lt;br /&gt;
   d.dispose()&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 Sub ActionListener_actionPerformed(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 Sub ActionListener_disposing(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you have to define your own class with desired interfaces. With helper class, you can define easily as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import unohelper&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt import XActionListener&lt;br /&gt;
&lt;br /&gt;
 class ActionListener(unohelper.Base, XActionListener):&lt;br /&gt;
     def __init__(self):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def disposing(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def actionPerformed(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
unohelper.Base class provides required interface for UNO components.&lt;br /&gt;
&lt;br /&gt;
== Containers ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, container object provides the way to access to its contents in sequentially.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, there is no shortcut provided. &lt;br /&gt;
&lt;br /&gt;
If you need to access to elements of indexed container, use range function to generate sequential indexes.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 for i in range(container.getCount()):&lt;br /&gt;
     obj = container.getByIndex(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== URL and System Path ==&lt;br /&gt;
&lt;br /&gt;
If you work with a file stored in your local file system, you have to get its corresponding URL.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ConvertToURL runtime function is prepared for this task. And there is ConvertFromURL runtime function for reverse conversion.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following functions are defined in uno module for such task.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 path = &amp;quot;/home/foo/Documents/file.odt&amp;quot;&lt;br /&gt;
 url = uno.sytemPathToFileUrl(path)&lt;br /&gt;
 path = uno.fileUrlToSystemPath(url)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments and Return Value ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, mode of the first argument of parseStrict method is &amp;quot;inout&amp;quot; in the following code: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 aURL = CreateUnoStruct(&amp;quot;com.sun.star.util.URL&amp;quot;)&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 CreateUnoService(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;).parseStrict(aURL)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The content of aURL variable is updated after calling the method.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, out mode parameter is returned as part of return value.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.util import URL&lt;br /&gt;
&lt;br /&gt;
 aURL = URL()&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 dummy, aURL = smgr.createInstanceWithContext(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;, ctx).parseStrict(aURL)&lt;br /&gt;
 # Definition of com.sun.star.util.XURLTransformer::parseStrict method: &lt;br /&gt;
 # void parseStrict([inout] com.sun.star.util.URL aURL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If a method has out mode in its parameters, its return is always tuple that contains original return value and values for out parameters.&lt;br /&gt;
&lt;br /&gt;
Here is a potential example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # boolean getSomeValue([in] string aName, [out] short aNum, [inout] long aNum2);&lt;br /&gt;
 result, num, num2 = obj.getSomeValue(&amp;quot;foo&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above example, &amp;#039;&amp;#039;result&amp;#039;&amp;#039; variable takes original return value, &amp;#039;&amp;#039;num&amp;#039;&amp;#039; takes output value for second parameter and &amp;#039;&amp;#039;num2&amp;#039;&amp;#039; takes output value for third parameter. The method takes 100 as the second parameter but it is not used as input of value. No entry in returned tuple for in mode parameter.&lt;br /&gt;
&lt;br /&gt;
== Functions to be Executed ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can not choose routines to be executed by users.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, define &amp;#039;&amp;#039;&amp;#039;g_exportedScripts&amp;#039;&amp;#039;&amp;#039; variable that contains tuple of callable in your macro file.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def func_a(): pass&lt;br /&gt;
 def func_b(): pass&lt;br /&gt;
 def func_hidden(): pass # not shown in the UI&lt;br /&gt;
 &lt;br /&gt;
 g_exportedScripts = func_a, func_b&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above code, func_hidden is not shown in execution dialog of macros.&lt;br /&gt;
&lt;br /&gt;
== Importing Modules ==&lt;br /&gt;
&lt;br /&gt;
== Dialog ==&lt;br /&gt;
&lt;br /&gt;
== Message Box ==&lt;br /&gt;
&lt;br /&gt;
== Input Box ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231607</id>
		<title>Python/Transfer from Basic to Python</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231607"/>
		<updated>2013-10-03T07:36:47Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add Type section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Transfer from Basic to Python}}&lt;br /&gt;
&lt;br /&gt;
Translation [[ES/Manuales/GuiaAOO/TemasAvanzados/Macros/Python/BasicAPython| Español]]&lt;br /&gt;
&lt;br /&gt;
If you feel some displeasure at StarBasic/OpenOffice Basic or you meet requirement of custom UNO component, now it is the time to transfer coding environment from Basic to Python.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, there are some runtime function provides shortcut to do something. But using Python-UNO bridge, you have to do such task by API ways.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s start with Python&amp;#039;s tutorial and return back to here when you have learned a bit about Python language.&lt;br /&gt;
&lt;br /&gt;
== Macro Location ==&lt;br /&gt;
On the current version, script organizer for Python do not provide the way to manage script files. So you have to manage yourself. Macros written in Python should be placed in the specific directory under your user&amp;#039;s profile, shared profile or script directory of your document.&lt;br /&gt;
&lt;br /&gt;
The python directory (in all lowercase) should be created in Scripts directory and you can put your python scripts that contain python code.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
path_to_directory/Scripts/python/your_file.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can make subdirectories to put macro files in them under Scripts/python directory.&lt;br /&gt;
&lt;br /&gt;
You have to add &amp;quot;py&amp;quot; file extension to your file name.&lt;br /&gt;
&lt;br /&gt;
== Macro Editor ==&lt;br /&gt;
&lt;br /&gt;
There is no built-in editor dedicated to code in Python. But you can choose your favorite text editor application to edit your Python script.&lt;br /&gt;
&lt;br /&gt;
This is discussed in another page.&lt;br /&gt;
&lt;br /&gt;
== Short Example ==&lt;br /&gt;
&lt;br /&gt;
Here is a small example written in Python.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello():&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Each callable function is the executable unit of Python macro (you can choose which function should be listed in the GUI, see other document).&lt;br /&gt;
&lt;br /&gt;
You can access the current document through getDocument method of XSCRIPTCONTEXT variable of the module. And it changes the document content to &amp;quot;Hello!&amp;quot; of the Writer document.&lt;br /&gt;
&lt;br /&gt;
== Usable Modules ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 import unohelper&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Script Context ==&lt;br /&gt;
&lt;br /&gt;
StarBasic is embedded runtime and it always works with living instance of the office. So the context is always the match with the office&amp;#039;s one. But Python-UNO bridge provides the way to work as RPC client. At that time, remote Python instance does have different context from the office instance. Therefore you have to use correct component context to tell to the multi component factory to instantiate a service.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you have no matching object provided.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039; macro, you have to use &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; module variable that provides &amp;lt;idl&amp;gt;com.sun.star.script.provider.XScriptContext&amp;lt;/idl&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XModel&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDocument()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current document object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.document.XScriptInvocationContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getInvocationContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns invocation dependent object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XDesktop&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDesktop()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns instance of &amp;lt;idl&amp;gt;com.sun.star.frame.Desktop&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.uno.XComponentContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getComponentContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current component context that is used to tell the which context is.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; variable is defined in module level and it is not provided to imported modules from your script.&lt;br /&gt;
&lt;br /&gt;
== Component Context ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get component context as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = GetDefaultContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But you do not need to access to it until you need to get singletons.&lt;br /&gt;
&lt;br /&gt;
In Python, you can get access to the component context through the script context.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need this value to instantiate services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service Manager ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get service manager as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 smgr = GetProcessServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But not so many people having to access to it.&lt;br /&gt;
&lt;br /&gt;
In Python, this instance is most important value to instantiate services to work with the office APIs.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need both the component context and the service manager to instantiate services.&lt;br /&gt;
&lt;br /&gt;
== Service Instance ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can instantiate services by built-in function as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 sfa = CreateUnoService(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or with initialize arguments: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 arg = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = CreateUnoServiceWithArguments(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, Array(arg))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Python, you have to work with com.sun.star.lang.XMultiComponentFactory interface as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
 sfa = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;, ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to initialize the instance, use createInstanceWithArgumentsAndContext method: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = smgr.createInstanceWithArgumentsAndContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, (FILESAVE_SIMPLE,) ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or initialize after the instantiation: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 file_picker = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, ctx)&lt;br /&gt;
 file_picker.initialize((FILESAVE_SIMPLE,))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service with Constructor ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can call service construct from its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 shell_execute = com.sun.star.system.SystemShellExecute.create()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you have to instantiate it with XMultiComponentFactory::createInstanceWithArgumentsAndContext method with initial arguments or instantiate after the instantiation.&lt;br /&gt;
&lt;br /&gt;
The constructor calling does type checking before to pass arguments to createInstanceWithArgumentsAndContext method.&lt;br /&gt;
&lt;br /&gt;
== Current Document ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ThisComponent runtime function provides access to the current document: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = ThisComponent&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Its return value is bound to the macro location. If the macro stored in a document, the result of ThisComponent is the document that the storage of the macro belongs to. And if your macro is stored in application wide, the returned value is the document model of currently active frame, this is the same result taken from StarDesktop.&amp;#039;&amp;#039;&amp;#039;getCurrentComponent()&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can access to the current document through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If your macro is &amp;#039;&amp;#039;&amp;#039;embedded in the document&amp;#039;&amp;#039;&amp;#039;, the document model is match with the document that the macro stored in. If your macro is stored in user or shared location, the document object is from active frame.&lt;br /&gt;
&lt;br /&gt;
== Desktop ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, StarDesktop runtime function is provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = StarDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can get access to the desktop through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = XSCRIPTCONTEXT.getDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Struct Instance ==&lt;br /&gt;
&lt;br /&gt;
In Basic, instance of struct can be instantiated in two ways: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Dim a As New com.sun.star.awt.Point&lt;br /&gt;
 a = CreateUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
With Dim statement and New keyword, you can instantiate a struct or array of structs. Or CreateUnoStruct method provides the way to instantiate a struct at runtime. You can not initialize the instance at the creation, you have to set its value of members.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can use the following ways to instantiate a struct. Import struct class and call it.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.awt import Point&lt;br /&gt;
&lt;br /&gt;
 a = Point()         # instantiate with default values, X=0, Y=0&lt;br /&gt;
 b = Point(100, 200) # initialize with initial values, X=100, Y=200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Calling the class to create new instance of the struct, you can empty its arguments or you have to pass values for all fields. In other words, you can not pass insufficient number of arguments to initialize. And its order should be match with definition of the struct in its IDL. For example, instance of struct b having X=100 and Y=200 in the above piece of code.&lt;br /&gt;
&lt;br /&gt;
You can initialize without to import the class of your target struct with uno.createUnoStruct function as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 a = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
 b = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This makes the same result with the above example. The first parameter of the createUnoStruct method is the name of the struct to initialize. The following arguments are initial values for new instance.&lt;br /&gt;
&lt;br /&gt;
== Enum ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can access to the module of the enum as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ITALIC = com.sun.star.awt.FontSlant.ITALIC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following ways can be used: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontSlant import ITALIC&lt;br /&gt;
 ITALIC = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontSlant.ITALIC&amp;quot;)&lt;br /&gt;
 ITALIC = uno.Enum(&amp;quot;com.sun.star.awt.FontSlant&amp;quot;, &amp;quot;ITALIC&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
All of the way results the instance of uno.Enum class.&lt;br /&gt;
&lt;br /&gt;
== Constants ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get access to constants through its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 BOLD = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways are provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontWeight import BOLD&lt;br /&gt;
 BOLD = uno.getConstantsByName(&amp;quot;com.sun.star.awt.FontWeight.BOLD&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sequence ==&lt;br /&gt;
&lt;br /&gt;
The sequence is sequential value of the same type.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, array is used.&lt;br /&gt;
&lt;br /&gt;
In Python, tuple is chosen to represent UNO&amp;#039;s sequence. Note, list is not allowed to pass as sequence value.&lt;br /&gt;
&lt;br /&gt;
== Boolean ==&lt;br /&gt;
&lt;br /&gt;
In Python, True or False.&lt;br /&gt;
&lt;br /&gt;
== String ==&lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;s string can contain over 64K bytes.&lt;br /&gt;
&lt;br /&gt;
If you have to write non Ascii 7 bit characters in your script, write magic comment at the head of your file. This is standard Python instructions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # -*- coding: utf_8 -*-&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please read Python&amp;#039;s documentation for more detail.&lt;br /&gt;
&lt;br /&gt;
You have to use unicode string to write some unicode characters in Python 2.X. And strings coming from UNO is decoded in unicode in Python 2.X.&lt;br /&gt;
&lt;br /&gt;
== Char ==&lt;br /&gt;
&lt;br /&gt;
There is no dedicated value for char type in StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, uno.Char class is defined for char type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 c = uno.Char(&amp;quot;a&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Type ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Type&amp;quot; type is meta type of UNO that represents type of UNO.&lt;br /&gt;
Since 3.4, if you pass string value to method as an argument that should be type, the bridge of Basic read it as type.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
oMap = com.sun.star.container.EnumerableMap.create(&amp;quot;string&amp;quot;, &amp;quot;string&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways can be used to create new valu of type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 t = uno.getTypeByName(&amp;quot;string&amp;quot;)&lt;br /&gt;
 t = uno.Type(&amp;quot;string&amp;quot;, uno.Enum(&amp;quot;com.sun.star.uno.TypeClass&amp;quot;, &amp;quot;STRING&amp;quot;))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Byte Sequence ==&lt;br /&gt;
&lt;br /&gt;
The byte sequence is sequence of byte type.&lt;br /&gt;
&lt;br /&gt;
In Basic, array of byte is used to represent it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, it is represented by str wrapped by uno.ByteSequence class. If you takes some byte sequences from UNO, they are the instance of uno.ByteSequence. If you need to get real value of them, refer its &amp;#039;&amp;#039;value&amp;#039;&amp;#039; instance variable.&lt;br /&gt;
&lt;br /&gt;
== Exception ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you get thrown exception as some error. And On Error statement is used to catch it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub ErrorExample&lt;br /&gt;
&lt;br /&gt;
   On Error GoTo Handler&lt;br /&gt;
&lt;br /&gt;
   &amp;#039; ... error&lt;br /&gt;
&lt;br /&gt;
   Exit Sub&lt;br /&gt;
&lt;br /&gt;
   Handler: &lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
And you can not throw any exceptions from StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, the exception thrown in UNO world can be treated as normal Python&amp;#039;s exception. Here is an example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.container import IndexOutOfBoundsException&lt;br /&gt;
&lt;br /&gt;
 try:&lt;br /&gt;
     obj.getByIndex(100) # raises IndexOutOfBoundsException&lt;br /&gt;
 except IndexOutOfBoundsException as e:&lt;br /&gt;
     print(e)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If getByIndex method raises IndexOutOfBoundsException, it can be caught in except statement because all exceptions inherit Python&amp;#039;s Exception class.&lt;br /&gt;
&lt;br /&gt;
And also you can throw UNO&amp;#039;s exception from your Python code as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.uno import RuntimeException&lt;br /&gt;
 raise RuntimeException(&amp;quot;Some message&amp;quot;, None)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Empty Value ==&lt;br /&gt;
&lt;br /&gt;
In Basic, there are some situations to meet variables that they do not contain any value (this is not correct). Null, empty, missing, nothing and so on.&lt;br /&gt;
&lt;br /&gt;
In Python, None is used. If a method defined as void return value in its IDL, it results None if you call it. If you need to pass invalid interface as an argument for the method that takes some interface, pass None for it. The result of this behavior is fully dependent to the implementation of the method.&lt;br /&gt;
&lt;br /&gt;
== Listener and Interface ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can create new listener using CreateUnoListener runtime function with some subroutines or functions.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub Add&lt;br /&gt;
&lt;br /&gt;
   d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
   listener = CreateUnoListener(&amp;quot;ActionListener&amp;quot;, &amp;quot;com.sun.star.awt.XActionListener&amp;quot;)&lt;br /&gt;
   d.getControl(&amp;quot;CommandButton1&amp;quot;).addActionListener(listener)&lt;br /&gt;
   d.execute()&lt;br /&gt;
   d.dispose()&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 Sub ActionListener_actionPerformed(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 Sub ActionListener_disposing(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you have define your own class with desired interfaces. With helper class, you can define easily as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import unohelper&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt import XActionListener&lt;br /&gt;
&lt;br /&gt;
 class ActionListener(unohelper.Base, XActionListener):&lt;br /&gt;
     def __init__(self):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def disposing(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def actionPerformed(self, ev):&lt;br /&gt;
&lt;br /&gt;
         pass&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
unohelper.Base class provides required interface for UNO components.&lt;br /&gt;
&lt;br /&gt;
== Containers ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, container object provides the way to access to its contents in sequentially.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, there is no shortcut provided. &lt;br /&gt;
&lt;br /&gt;
If you need to access to elements of indexed container, use range function to generate sequential indexes.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 for i in range(container.getCount()):&lt;br /&gt;
     obj = container.getByIndex(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== URL and System Path ==&lt;br /&gt;
&lt;br /&gt;
If you work with a file stored in your local file system, you have to get its corresponding URL.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ConvertToURL runtime function is prepared for this task. And there is ConvertFromURL runtime function for reverse conversion.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following functions are defined in uno module for such task.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 path = &amp;quot;/home/foo/Documents/file.odt&amp;quot;&lt;br /&gt;
 url = uno.sytemPathToFileUrl(path)&lt;br /&gt;
 path = uno.fileUrlToSystemPath(url)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments and Return Value ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, mode of the first argument of parseStrict method is &amp;quot;inout&amp;quot; in the following code: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 aURL = CreateUnoStruct(&amp;quot;com.sun.star.util.URL&amp;quot;)&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 CreateUnoService(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;).parseStrict(aURL)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The content of aURL variable is updated after calling the method.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, out mode parameter is returned as part of return value.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.util import URL&lt;br /&gt;
&lt;br /&gt;
 aURL = URL()&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 dummy, aURL = smgr.createInstanceWithContext(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;, ctx).parseStrict(aURL)&lt;br /&gt;
 # Definition of com.sun.star.util.XURLTransformer::parseStrict method: &lt;br /&gt;
 # void parseStrict([inout] com.sun.star.util.URL aURL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If a method has out mode in its parameters, its return is always tuple that contains original return value and values for out parameters.&lt;br /&gt;
&lt;br /&gt;
Here is a potential example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # boolean getSomeValue([in] string aName, [out] short aNum, [inout] long aNum2);&lt;br /&gt;
 result, num, num2 = obj.getSomeValue(&amp;quot;foo&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above example, &amp;#039;&amp;#039;result&amp;#039;&amp;#039; variable takes original return value, &amp;#039;&amp;#039;num&amp;#039;&amp;#039; takes output value for second parameter and &amp;#039;&amp;#039;num2&amp;#039;&amp;#039; takes output value for third parameter. The method takes 100 as the second parameter but it is not used as input of value. No entry in returned tuple for in mode parameter.&lt;br /&gt;
&lt;br /&gt;
== Functions to be Executed ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can not choose routines to be executed by users.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, define &amp;#039;&amp;#039;&amp;#039;g_exportedScripts&amp;#039;&amp;#039;&amp;#039; variable that contains tuple of callable in your macro file.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def func_a(): pass&lt;br /&gt;
 def func_b(): pass&lt;br /&gt;
 def func_hidden(): pass # not shown in the UI&lt;br /&gt;
 &lt;br /&gt;
 g_exportedScripts = func_a, func_b&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above code, func_hidden is not shown in execution dialog of macros.&lt;br /&gt;
&lt;br /&gt;
== Importing Modules ==&lt;br /&gt;
&lt;br /&gt;
== Dialog ==&lt;br /&gt;
&lt;br /&gt;
== Message Box ==&lt;br /&gt;
&lt;br /&gt;
== Input Box ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231604</id>
		<title>Python/Transfer from Basic to Python</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231604"/>
		<updated>2013-10-03T07:07:43Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add description about unicode in String&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Transfer from Basic to Python}}&lt;br /&gt;
&lt;br /&gt;
Translation [[ES/Manuales/GuiaAOO/TemasAvanzados/Macros/Python/BasicAPython| Español]]&lt;br /&gt;
&lt;br /&gt;
If you feel some displeasure at StarBasic/OpenOffice Basic or you meet requirement of custom UNO component, now it is the time to transfer coding environment from Basic to Python.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, there are some runtime function provides shortcut to do something. But using Python-UNO bridge, you have to do such task by API ways.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s start with Python&amp;#039;s tutorial and return back to here when you have learned a bit about Python language.&lt;br /&gt;
&lt;br /&gt;
== Macro Location ==&lt;br /&gt;
On the current version, script organizer for Python do not provide the way to manage script files. So you have to manage yourself. Macros written in Python should be placed in the specific directory under your user&amp;#039;s profile, shared profile or script directory of your document.&lt;br /&gt;
&lt;br /&gt;
The python directory (in all lowercase) should be created in Scripts directory and you can put your python scripts that contain python code.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
path_to_directory/Scripts/python/your_file.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can make subdirectories to put macro files in them under Scripts/python directory.&lt;br /&gt;
&lt;br /&gt;
You have to add &amp;quot;py&amp;quot; file extension to your file name.&lt;br /&gt;
&lt;br /&gt;
== Macro Editor ==&lt;br /&gt;
&lt;br /&gt;
There is no built-in editor dedicated to code in Python. But you can choose your favorite text editor application to edit your Python script.&lt;br /&gt;
&lt;br /&gt;
This is discussed in another page.&lt;br /&gt;
&lt;br /&gt;
== Short Example ==&lt;br /&gt;
&lt;br /&gt;
Here is a small example written in Python.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello():&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Each callable function is the executable unit of Python macro (you can choose which function should be listed in the GUI, see other document).&lt;br /&gt;
&lt;br /&gt;
You can access the current document through getDocument method of XSCRIPTCONTEXT variable of the module. And it changes the document content to &amp;quot;Hello!&amp;quot; of the Writer document.&lt;br /&gt;
&lt;br /&gt;
== Usable Modules ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 import unohelper&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Script Context ==&lt;br /&gt;
&lt;br /&gt;
StarBasic is embedded runtime and it always works with living instance of the office. So the context is always the match with the office&amp;#039;s one. But Python-UNO bridge provides the way to work as RPC client. At that time, remote Python instance does have different context from the office instance. Therefore you have to use correct component context to tell to the multi component factory to instantiate a service.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you have no matching object provided.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039; macro, you have to use &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; module variable that provides &amp;lt;idl&amp;gt;com.sun.star.script.provider.XScriptContext&amp;lt;/idl&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XModel&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDocument()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current document object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.document.XScriptInvocationContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getInvocationContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns invocation dependent object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XDesktop&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDesktop()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns instance of &amp;lt;idl&amp;gt;com.sun.star.frame.Desktop&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.uno.XComponentContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getComponentContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current component context that is used to tell the which context is.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; variable is defined in module level and it is not provided to imported modules from your script.&lt;br /&gt;
&lt;br /&gt;
== Component Context ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get component context as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = GetDefaultContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But you do not need to access to it until you need to get singletons.&lt;br /&gt;
&lt;br /&gt;
In Python, you can get access to the component context through the script context.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need this value to instantiate services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service Manager ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get service manager as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 smgr = GetProcessServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But not so many people having to access to it.&lt;br /&gt;
&lt;br /&gt;
In Python, this instance is most important value to instantiate services to work with the office APIs.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need both the component context and the service manager to instantiate services.&lt;br /&gt;
&lt;br /&gt;
== Service Instance ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can instantiate services by built-in function as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 sfa = CreateUnoService(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or with initialize arguments: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 arg = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = CreateUnoServiceWithArguments(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, Array(arg))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Python, you have to work with com.sun.star.lang.XMultiComponentFactory interface as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
 sfa = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;, ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to initialize the instance, use createInstanceWithArgumentsAndContext method: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = smgr.createInstanceWithArgumentsAndContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, (FILESAVE_SIMPLE,) ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or initialize after the instantiation: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 file_picker = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, ctx)&lt;br /&gt;
 file_picker.initialize((FILESAVE_SIMPLE,))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service with Constructor ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can call service construct from its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 shell_execute = com.sun.star.system.SystemShellExecute.create()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you have to instantiate it with XMultiComponentFactory::createInstanceWithArgumentsAndContext method with initial arguments or instantiate after the instantiation.&lt;br /&gt;
&lt;br /&gt;
The constructor calling does type checking before to pass arguments to createInstanceWithArgumentsAndContext method.&lt;br /&gt;
&lt;br /&gt;
== Current Document ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ThisComponent runtime function provides access to the current document: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = ThisComponent&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Its return value is bound to the macro location. If the macro stored in a document, the result of ThisComponent is the document that the storage of the macro belongs to. And if your macro is stored in application wide, the returned value is the document model of currently active frame, this is the same result taken from StarDesktop.&amp;#039;&amp;#039;&amp;#039;getCurrentComponent()&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can access to the current document through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If your macro is &amp;#039;&amp;#039;&amp;#039;embedded in the document&amp;#039;&amp;#039;&amp;#039;, the document model is match with the document that the macro stored in. If your macro is stored in user or shared location, the document object is from active frame.&lt;br /&gt;
&lt;br /&gt;
== Desktop ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, StarDesktop runtime function is provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = StarDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can get access to the desktop through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = XSCRIPTCONTEXT.getDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Struct Instance ==&lt;br /&gt;
&lt;br /&gt;
In Basic, instance of struct can be instantiated in two ways: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Dim a As New com.sun.star.awt.Point&lt;br /&gt;
 a = CreateUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
With Dim statement and New keyword, you can instantiate a struct or array of structs. Or CreateUnoStruct method provides the way to instantiate a struct at runtime. You can not initialize the instance at the creation, you have to set its value of members.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can use the following ways to instantiate a struct. Import struct class and call it.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.awt import Point&lt;br /&gt;
&lt;br /&gt;
 a = Point()         # instantiate with default values, X=0, Y=0&lt;br /&gt;
 b = Point(100, 200) # initialize with initial values, X=100, Y=200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Calling the class to create new instance of the struct, you can empty its arguments or you have to pass values for all fields. In other words, you can not pass insufficient number of arguments to initialize. And its order should be match with definition of the struct in its IDL. For example, instance of struct b having X=100 and Y=200 in the above piece of code.&lt;br /&gt;
&lt;br /&gt;
You can initialize without to import the class of your target struct with uno.createUnoStruct function as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 a = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
 b = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This makes the same result with the above example. The first parameter of the createUnoStruct method is the name of the struct to initialize. The following arguments are initial values for new instance.&lt;br /&gt;
&lt;br /&gt;
== Enum ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can access to the module of the enum as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ITALIC = com.sun.star.awt.FontSlant.ITALIC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following ways can be used: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontSlant import ITALIC&lt;br /&gt;
 ITALIC = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontSlant.ITALIC&amp;quot;)&lt;br /&gt;
 ITALIC = uno.Enum(&amp;quot;com.sun.star.awt.FontSlant&amp;quot;, &amp;quot;ITALIC&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
All of the way results the instance of uno.Enum class.&lt;br /&gt;
&lt;br /&gt;
== Constants ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get access to constants through its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 BOLD = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways are provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontWeight import BOLD&lt;br /&gt;
 BOLD = uno.getConstantsByName(&amp;quot;com.sun.star.awt.FontWeight.BOLD&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sequence ==&lt;br /&gt;
&lt;br /&gt;
The sequence is sequential value of the same type.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, array is used.&lt;br /&gt;
&lt;br /&gt;
In Python, tuple is chosen to represent UNO&amp;#039;s sequence. Note, list is not allowed to pass as sequence value.&lt;br /&gt;
&lt;br /&gt;
== Boolean ==&lt;br /&gt;
&lt;br /&gt;
In Python, True or False.&lt;br /&gt;
&lt;br /&gt;
== String ==&lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;s string can contain over 64K bytes.&lt;br /&gt;
&lt;br /&gt;
If you have to write non Ascii 7 bit characters in your script, write magic comment at the head of your file. This is standard Python instructions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # -*- coding: utf_8 -*-&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please read Python&amp;#039;s documentation for more detail.&lt;br /&gt;
&lt;br /&gt;
You have to use unicode string to write some unicode characters in Python 2.X. And strings coming from UNO is decoded in unicode in Python 2.X.&lt;br /&gt;
&lt;br /&gt;
== Char ==&lt;br /&gt;
&lt;br /&gt;
There is no dedicated value for char type in StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, uno.Char class is defined for char type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 c = uno.Char(&amp;quot;a&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Byte Sequence ==&lt;br /&gt;
&lt;br /&gt;
The byte sequence is sequence of byte type.&lt;br /&gt;
&lt;br /&gt;
In Basic, array of byte is used to represent it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, it is represented by str wrapped by uno.ByteSequence class. If you takes some byte sequences from UNO, they are the instance of uno.ByteSequence. If you need to get real value of them, refer its &amp;#039;&amp;#039;value&amp;#039;&amp;#039; instance variable.&lt;br /&gt;
&lt;br /&gt;
== Exception ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you get thrown exception as some error. And On Error statement is used to catch it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub ErrorExample&lt;br /&gt;
&lt;br /&gt;
   On Error GoTo Handler&lt;br /&gt;
&lt;br /&gt;
   &amp;#039; ... error&lt;br /&gt;
&lt;br /&gt;
   Exit Sub&lt;br /&gt;
&lt;br /&gt;
   Handler: &lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
And you can not throw any exceptions from StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, the exception thrown in UNO world can be treated as normal Python&amp;#039;s exception. Here is an example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.container import IndexOutOfBoundsException&lt;br /&gt;
&lt;br /&gt;
 try:&lt;br /&gt;
     obj.getByIndex(100) # raises IndexOutOfBoundsException&lt;br /&gt;
 except IndexOutOfBoundsException as e:&lt;br /&gt;
     print(e)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If getByIndex method raises IndexOutOfBoundsException, it can be caught in except statement because all exceptions inherit Python&amp;#039;s Exception class.&lt;br /&gt;
&lt;br /&gt;
And also you can throw UNO&amp;#039;s exception from your Python code as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.uno import RuntimeException&lt;br /&gt;
 raise RuntimeException(&amp;quot;Some message&amp;quot;, None)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Empty Value ==&lt;br /&gt;
&lt;br /&gt;
In Basic, there are some situations to meet variables that they do not contain any value (this is not correct). Null, empty, missing, nothing and so on.&lt;br /&gt;
&lt;br /&gt;
In Python, None is used. If a method defined as void return value in its IDL, it results None if you call it. If you need to pass invalid interface as an argument for the method that takes some interface, pass None for it. The result of this behavior is fully dependent to the implementation of the method.&lt;br /&gt;
&lt;br /&gt;
== Listener and Interface ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can create new listener using CreateUnoListener runtime function with some subroutines or functions.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub Add&lt;br /&gt;
&lt;br /&gt;
   d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
   listener = CreateUnoListener(&amp;quot;ActionListener&amp;quot;, &amp;quot;com.sun.star.awt.XActionListener&amp;quot;)&lt;br /&gt;
   d.getControl(&amp;quot;CommandButton1&amp;quot;).addActionListener(listener)&lt;br /&gt;
   d.execute()&lt;br /&gt;
   d.dispose()&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 Sub ActionListener_actionPerformed(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 Sub ActionListener_disposing(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you have define your own class with desired interfaces. With helper class, you can define easily as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import unohelper&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt import XActionListener&lt;br /&gt;
&lt;br /&gt;
 class ActionListener(unohelper.Base, XActionListener):&lt;br /&gt;
     def __init__(self):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def disposing(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def actionPerformed(self, ev):&lt;br /&gt;
&lt;br /&gt;
         pass&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
unohelper.Base class provides required interface for UNO components.&lt;br /&gt;
&lt;br /&gt;
== Containers ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, container object provides the way to access to its contents in sequentially.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, there is no shortcut provided. &lt;br /&gt;
&lt;br /&gt;
If you need to access to elements of indexed container, use range function to generate sequential indexes.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 for i in range(container.getCount()):&lt;br /&gt;
     obj = container.getByIndex(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== URL and System Path ==&lt;br /&gt;
&lt;br /&gt;
If you work with a file stored in your local file system, you have to get its corresponding URL.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ConvertToURL runtime function is prepared for this task. And there is ConvertFromURL runtime function for reverse conversion.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following functions are defined in uno module for such task.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 path = &amp;quot;/home/foo/Documents/file.odt&amp;quot;&lt;br /&gt;
 url = uno.sytemPathToFileUrl(path)&lt;br /&gt;
 path = uno.fileUrlToSystemPath(url)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments and Return Value ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, mode of the first argument of parseStrict method is &amp;quot;inout&amp;quot; in the following code: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 aURL = CreateUnoStruct(&amp;quot;com.sun.star.util.URL&amp;quot;)&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 CreateUnoService(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;).parseStrict(aURL)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The content of aURL variable is updated after calling the method.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, out mode parameter is returned as part of return value.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.util import URL&lt;br /&gt;
&lt;br /&gt;
 aURL = URL()&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 dummy, aURL = smgr.createInstanceWithContext(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;, ctx).parseStrict(aURL)&lt;br /&gt;
 # Definition of com.sun.star.util.XURLTransformer::parseStrict method: &lt;br /&gt;
 # void parseStrict([inout] com.sun.star.util.URL aURL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If a method has out mode in its parameters, its return is always tuple that contains original return value and values for out parameters.&lt;br /&gt;
&lt;br /&gt;
Here is a potential example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # boolean getSomeValue([in] string aName, [out] short aNum, [inout] long aNum2);&lt;br /&gt;
 result, num, num2 = obj.getSomeValue(&amp;quot;foo&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above example, &amp;#039;&amp;#039;result&amp;#039;&amp;#039; variable takes original return value, &amp;#039;&amp;#039;num&amp;#039;&amp;#039; takes output value for second parameter and &amp;#039;&amp;#039;num2&amp;#039;&amp;#039; takes output value for third parameter. The method takes 100 as the second parameter but it is not used as input of value. No entry in returned tuple for in mode parameter.&lt;br /&gt;
&lt;br /&gt;
== Functions to be Executed ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can not choose routines to be executed by users.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, define &amp;#039;&amp;#039;&amp;#039;g_exportedScripts&amp;#039;&amp;#039;&amp;#039; variable that contains tuple of callable in your macro file.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def func_a(): pass&lt;br /&gt;
 def func_b(): pass&lt;br /&gt;
 def func_hidden(): pass # not shown in the UI&lt;br /&gt;
 &lt;br /&gt;
 g_exportedScripts = func_a, func_b&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above code, func_hidden is not shown in execution dialog of macros.&lt;br /&gt;
&lt;br /&gt;
== Importing Modules ==&lt;br /&gt;
&lt;br /&gt;
== Dialog ==&lt;br /&gt;
&lt;br /&gt;
== Message Box ==&lt;br /&gt;
&lt;br /&gt;
== Input Box ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231603</id>
		<title>Python/Transfer from Basic to Python</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231603"/>
		<updated>2013-10-03T06:59:56Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Fix source tag in Constants&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Transfer from Basic to Python}}&lt;br /&gt;
&lt;br /&gt;
Translation [[ES/Manuales/GuiaAOO/TemasAvanzados/Macros/Python/BasicAPython| Español]]&lt;br /&gt;
&lt;br /&gt;
If you feel some displeasure at StarBasic/OpenOffice Basic or you meet requirement of custom UNO component, now it is the time to transfer coding environment from Basic to Python.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, there are some runtime function provides shortcut to do something. But using Python-UNO bridge, you have to do such task by API ways.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s start with Python&amp;#039;s tutorial and return back to here when you have learned a bit about Python language.&lt;br /&gt;
&lt;br /&gt;
== Macro Location ==&lt;br /&gt;
On the current version, script organizer for Python do not provide the way to manage script files. So you have to manage yourself. Macros written in Python should be placed in the specific directory under your user&amp;#039;s profile, shared profile or script directory of your document.&lt;br /&gt;
&lt;br /&gt;
The python directory (in all lowercase) should be created in Scripts directory and you can put your python scripts that contain python code.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
path_to_directory/Scripts/python/your_file.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can make subdirectories to put macro files in them under Scripts/python directory.&lt;br /&gt;
&lt;br /&gt;
You have to add &amp;quot;py&amp;quot; file extension to your file name.&lt;br /&gt;
&lt;br /&gt;
== Macro Editor ==&lt;br /&gt;
&lt;br /&gt;
There is no built-in editor dedicated to code in Python. But you can choose your favorite text editor application to edit your Python script.&lt;br /&gt;
&lt;br /&gt;
This is discussed in another page.&lt;br /&gt;
&lt;br /&gt;
== Short Example ==&lt;br /&gt;
&lt;br /&gt;
Here is a small example written in Python.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello():&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Each callable function is the executable unit of Python macro (you can choose which function should be listed in the GUI, see other document).&lt;br /&gt;
&lt;br /&gt;
You can access the current document through getDocument method of XSCRIPTCONTEXT variable of the module. And it changes the document content to &amp;quot;Hello!&amp;quot; of the Writer document.&lt;br /&gt;
&lt;br /&gt;
== Usable Modules ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 import unohelper&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Script Context ==&lt;br /&gt;
&lt;br /&gt;
StarBasic is embedded runtime and it always works with living instance of the office. So the context is always the match with the office&amp;#039;s one. But Python-UNO bridge provides the way to work as RPC client. At that time, remote Python instance does have different context from the office instance. Therefore you have to use correct component context to tell to the multi component factory to instantiate a service.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you have no matching object provided.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039; macro, you have to use &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; module variable that provides &amp;lt;idl&amp;gt;com.sun.star.script.provider.XScriptContext&amp;lt;/idl&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XModel&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDocument()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current document object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.document.XScriptInvocationContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getInvocationContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns invocation dependent object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XDesktop&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDesktop()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns instance of &amp;lt;idl&amp;gt;com.sun.star.frame.Desktop&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.uno.XComponentContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getComponentContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current component context that is used to tell the which context is.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; variable is defined in module level and it is not provided to imported modules from your script.&lt;br /&gt;
&lt;br /&gt;
== Component Context ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get component context as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = GetDefaultContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But you do not need to access to it until you need to get singletons.&lt;br /&gt;
&lt;br /&gt;
In Python, you can get access to the component context through the script context.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need this value to instantiate services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service Manager ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get service manager as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 smgr = GetProcessServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But not so many people having to access to it.&lt;br /&gt;
&lt;br /&gt;
In Python, this instance is most important value to instantiate services to work with the office APIs.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need both the component context and the service manager to instantiate services.&lt;br /&gt;
&lt;br /&gt;
== Service Instance ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can instantiate services by built-in function as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 sfa = CreateUnoService(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or with initialize arguments: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 arg = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = CreateUnoServiceWithArguments(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, Array(arg))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Python, you have to work with com.sun.star.lang.XMultiComponentFactory interface as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
 sfa = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;, ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to initialize the instance, use createInstanceWithArgumentsAndContext method: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = smgr.createInstanceWithArgumentsAndContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, (FILESAVE_SIMPLE,) ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or initialize after the instantiation: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 file_picker = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, ctx)&lt;br /&gt;
 file_picker.initialize((FILESAVE_SIMPLE,))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service with Constructor ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can call service construct from its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 shell_execute = com.sun.star.system.SystemShellExecute.create()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you have to instantiate it with XMultiComponentFactory::createInstanceWithArgumentsAndContext method with initial arguments or instantiate after the instantiation.&lt;br /&gt;
&lt;br /&gt;
The constructor calling does type checking before to pass arguments to createInstanceWithArgumentsAndContext method.&lt;br /&gt;
&lt;br /&gt;
== Current Document ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ThisComponent runtime function provides access to the current document: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = ThisComponent&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Its return value is bound to the macro location. If the macro stored in a document, the result of ThisComponent is the document that the storage of the macro belongs to. And if your macro is stored in application wide, the returned value is the document model of currently active frame, this is the same result taken from StarDesktop.&amp;#039;&amp;#039;&amp;#039;getCurrentComponent()&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can access to the current document through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If your macro is &amp;#039;&amp;#039;&amp;#039;embedded in the document&amp;#039;&amp;#039;&amp;#039;, the document model is match with the document that the macro stored in. If your macro is stored in user or shared location, the document object is from active frame.&lt;br /&gt;
&lt;br /&gt;
== Desktop ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, StarDesktop runtime function is provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = StarDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can get access to the desktop through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = XSCRIPTCONTEXT.getDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Struct Instance ==&lt;br /&gt;
&lt;br /&gt;
In Basic, instance of struct can be instantiated in two ways: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Dim a As New com.sun.star.awt.Point&lt;br /&gt;
 a = CreateUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
With Dim statement and New keyword, you can instantiate a struct or array of structs. Or CreateUnoStruct method provides the way to instantiate a struct at runtime. You can not initialize the instance at the creation, you have to set its value of members.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can use the following ways to instantiate a struct. Import struct class and call it.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.awt import Point&lt;br /&gt;
&lt;br /&gt;
 a = Point()         # instantiate with default values, X=0, Y=0&lt;br /&gt;
 b = Point(100, 200) # initialize with initial values, X=100, Y=200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Calling the class to create new instance of the struct, you can empty its arguments or you have to pass values for all fields. In other words, you can not pass insufficient number of arguments to initialize. And its order should be match with definition of the struct in its IDL. For example, instance of struct b having X=100 and Y=200 in the above piece of code.&lt;br /&gt;
&lt;br /&gt;
You can initialize without to import the class of your target struct with uno.createUnoStruct function as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 a = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
 b = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This makes the same result with the above example. The first parameter of the createUnoStruct method is the name of the struct to initialize. The following arguments are initial values for new instance.&lt;br /&gt;
&lt;br /&gt;
== Enum ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can access to the module of the enum as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ITALIC = com.sun.star.awt.FontSlant.ITALIC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following ways can be used: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontSlant import ITALIC&lt;br /&gt;
 ITALIC = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontSlant.ITALIC&amp;quot;)&lt;br /&gt;
 ITALIC = uno.Enum(&amp;quot;com.sun.star.awt.FontSlant&amp;quot;, &amp;quot;ITALIC&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
All of the way results the instance of uno.Enum class.&lt;br /&gt;
&lt;br /&gt;
== Constants ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get access to constants through its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 BOLD = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways are provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontWeight import BOLD&lt;br /&gt;
 BOLD = uno.getConstantsByName(&amp;quot;com.sun.star.awt.FontWeight.BOLD&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sequence ==&lt;br /&gt;
&lt;br /&gt;
The sequence is sequential value of the same type.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, array is used.&lt;br /&gt;
&lt;br /&gt;
In Python, tuple is chosen to represent UNO&amp;#039;s sequence. Note, list is not allowed to pass as sequence value.&lt;br /&gt;
&lt;br /&gt;
== Boolean ==&lt;br /&gt;
&lt;br /&gt;
In Python, True or False.&lt;br /&gt;
&lt;br /&gt;
== String ==&lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;s string can contain over 64K bytes.&lt;br /&gt;
&lt;br /&gt;
If you have to write non Ascii 7 bit characters in your script, write magic comment at the head of your file. This is standard Python instructions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # -*- coding: utf_8 -*-&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please read Python&amp;#039;s documentation for more detail.&lt;br /&gt;
&lt;br /&gt;
== Char ==&lt;br /&gt;
&lt;br /&gt;
There is no dedicated value for char type in StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, uno.Char class is defined for char type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 c = uno.Char(&amp;quot;a&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Byte Sequence ==&lt;br /&gt;
&lt;br /&gt;
The byte sequence is sequence of byte type.&lt;br /&gt;
&lt;br /&gt;
In Basic, array of byte is used to represent it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, it is represented by str wrapped by uno.ByteSequence class. If you takes some byte sequences from UNO, they are the instance of uno.ByteSequence. If you need to get real value of them, refer its &amp;#039;&amp;#039;value&amp;#039;&amp;#039; instance variable.&lt;br /&gt;
&lt;br /&gt;
== Exception ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you get thrown exception as some error. And On Error statement is used to catch it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub ErrorExample&lt;br /&gt;
&lt;br /&gt;
   On Error GoTo Handler&lt;br /&gt;
&lt;br /&gt;
   &amp;#039; ... error&lt;br /&gt;
&lt;br /&gt;
   Exit Sub&lt;br /&gt;
&lt;br /&gt;
   Handler: &lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
And you can not throw any exceptions from StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, the exception thrown in UNO world can be treated as normal Python&amp;#039;s exception. Here is an example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.container import IndexOutOfBoundsException&lt;br /&gt;
&lt;br /&gt;
 try:&lt;br /&gt;
     obj.getByIndex(100) # raises IndexOutOfBoundsException&lt;br /&gt;
 except IndexOutOfBoundsException as e:&lt;br /&gt;
     print(e)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If getByIndex method raises IndexOutOfBoundsException, it can be caught in except statement because all exceptions inherit Python&amp;#039;s Exception class.&lt;br /&gt;
&lt;br /&gt;
And also you can throw UNO&amp;#039;s exception from your Python code as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.uno import RuntimeException&lt;br /&gt;
 raise RuntimeException(&amp;quot;Some message&amp;quot;, None)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Empty Value ==&lt;br /&gt;
&lt;br /&gt;
In Basic, there are some situations to meet variables that they do not contain any value (this is not correct). Null, empty, missing, nothing and so on.&lt;br /&gt;
&lt;br /&gt;
In Python, None is used. If a method defined as void return value in its IDL, it results None if you call it. If you need to pass invalid interface as an argument for the method that takes some interface, pass None for it. The result of this behavior is fully dependent to the implementation of the method.&lt;br /&gt;
&lt;br /&gt;
== Listener and Interface ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can create new listener using CreateUnoListener runtime function with some subroutines or functions.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub Add&lt;br /&gt;
&lt;br /&gt;
   d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
   listener = CreateUnoListener(&amp;quot;ActionListener&amp;quot;, &amp;quot;com.sun.star.awt.XActionListener&amp;quot;)&lt;br /&gt;
   d.getControl(&amp;quot;CommandButton1&amp;quot;).addActionListener(listener)&lt;br /&gt;
   d.execute()&lt;br /&gt;
   d.dispose()&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 Sub ActionListener_actionPerformed(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 Sub ActionListener_disposing(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you have define your own class with desired interfaces. With helper class, you can define easily as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import unohelper&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt import XActionListener&lt;br /&gt;
&lt;br /&gt;
 class ActionListener(unohelper.Base, XActionListener):&lt;br /&gt;
     def __init__(self):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def disposing(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def actionPerformed(self, ev):&lt;br /&gt;
&lt;br /&gt;
         pass&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
unohelper.Base class provides required interface for UNO components.&lt;br /&gt;
&lt;br /&gt;
== Containers ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, container object provides the way to access to its contents in sequentially.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, there is no shortcut provided. &lt;br /&gt;
&lt;br /&gt;
If you need to access to elements of indexed container, use range function to generate sequential indexes.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 for i in range(container.getCount()):&lt;br /&gt;
     obj = container.getByIndex(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== URL and System Path ==&lt;br /&gt;
&lt;br /&gt;
If you work with a file stored in your local file system, you have to get its corresponding URL.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ConvertToURL runtime function is prepared for this task. And there is ConvertFromURL runtime function for reverse conversion.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following functions are defined in uno module for such task.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 path = &amp;quot;/home/foo/Documents/file.odt&amp;quot;&lt;br /&gt;
 url = uno.sytemPathToFileUrl(path)&lt;br /&gt;
 path = uno.fileUrlToSystemPath(url)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments and Return Value ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, mode of the first argument of parseStrict method is &amp;quot;inout&amp;quot; in the following code: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 aURL = CreateUnoStruct(&amp;quot;com.sun.star.util.URL&amp;quot;)&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 CreateUnoService(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;).parseStrict(aURL)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The content of aURL variable is updated after calling the method.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, out mode parameter is returned as part of return value.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.util import URL&lt;br /&gt;
&lt;br /&gt;
 aURL = URL()&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 dummy, aURL = smgr.createInstanceWithContext(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;, ctx).parseStrict(aURL)&lt;br /&gt;
 # Definition of com.sun.star.util.XURLTransformer::parseStrict method: &lt;br /&gt;
 # void parseStrict([inout] com.sun.star.util.URL aURL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If a method has out mode in its parameters, its return is always tuple that contains original return value and values for out parameters.&lt;br /&gt;
&lt;br /&gt;
Here is a potential example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # boolean getSomeValue([in] string aName, [out] short aNum, [inout] long aNum2);&lt;br /&gt;
 result, num, num2 = obj.getSomeValue(&amp;quot;foo&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above example, &amp;#039;&amp;#039;result&amp;#039;&amp;#039; variable takes original return value, &amp;#039;&amp;#039;num&amp;#039;&amp;#039; takes output value for second parameter and &amp;#039;&amp;#039;num2&amp;#039;&amp;#039; takes output value for third parameter. The method takes 100 as the second parameter but it is not used as input of value. No entry in returned tuple for in mode parameter.&lt;br /&gt;
&lt;br /&gt;
== Functions to be Executed ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can not choose routines to be executed by users.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, define &amp;#039;&amp;#039;&amp;#039;g_exportedScripts&amp;#039;&amp;#039;&amp;#039; variable that contains tuple of callable in your macro file.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def func_a(): pass&lt;br /&gt;
 def func_b(): pass&lt;br /&gt;
 def func_hidden(): pass # not shown in the UI&lt;br /&gt;
 &lt;br /&gt;
 g_exportedScripts = func_a, func_b&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above code, func_hidden is not shown in execution dialog of macros.&lt;br /&gt;
&lt;br /&gt;
== Importing Modules ==&lt;br /&gt;
&lt;br /&gt;
== Dialog ==&lt;br /&gt;
&lt;br /&gt;
== Message Box ==&lt;br /&gt;
&lt;br /&gt;
== Input Box ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231600</id>
		<title>Python/Transfer from Basic to Python</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231600"/>
		<updated>2013-10-03T06:43:34Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add spaces between return value and method in Script Context&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Transfer from Basic to Python}}&lt;br /&gt;
&lt;br /&gt;
Translation [[ES/Manuales/GuiaAOO/TemasAvanzados/Macros/Python/BasicAPython| Español]]&lt;br /&gt;
&lt;br /&gt;
If you feel some displeasure at StarBasic/OpenOffice Basic or you meet requirement of custom UNO component, now it is the time to transfer coding environment from Basic to Python.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, there are some runtime function provides shortcut to do something. But using Python-UNO bridge, you have to do such task by API ways.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s start with Python&amp;#039;s tutorial and return back to here when you have learned a bit about Python language.&lt;br /&gt;
&lt;br /&gt;
== Macro Location ==&lt;br /&gt;
On the current version, script organizer for Python do not provide the way to manage script files. So you have to manage yourself. Macros written in Python should be placed in the specific directory under your user&amp;#039;s profile, shared profile or script directory of your document.&lt;br /&gt;
&lt;br /&gt;
The python directory (in all lowercase) should be created in Scripts directory and you can put your python scripts that contain python code.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
path_to_directory/Scripts/python/your_file.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can make subdirectories to put macro files in them under Scripts/python directory.&lt;br /&gt;
&lt;br /&gt;
You have to add &amp;quot;py&amp;quot; file extension to your file name.&lt;br /&gt;
&lt;br /&gt;
== Macro Editor ==&lt;br /&gt;
&lt;br /&gt;
There is no built-in editor dedicated to code in Python. But you can choose your favorite text editor application to edit your Python script.&lt;br /&gt;
&lt;br /&gt;
This is discussed in another page.&lt;br /&gt;
&lt;br /&gt;
== Short Example ==&lt;br /&gt;
&lt;br /&gt;
Here is a small example written in Python.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello():&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Each callable function is the executable unit of Python macro (you can choose which function should be listed in the GUI, see other document).&lt;br /&gt;
&lt;br /&gt;
You can access the current document through getDocument method of XSCRIPTCONTEXT variable of the module. And it changes the document content to &amp;quot;Hello!&amp;quot; of the Writer document.&lt;br /&gt;
&lt;br /&gt;
== Usable Modules ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 import unohelper&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Script Context ==&lt;br /&gt;
&lt;br /&gt;
StarBasic is embedded runtime and it always works with living instance of the office. So the context is always the match with the office&amp;#039;s one. But Python-UNO bridge provides the way to work as RPC client. At that time, remote Python instance does have different context from the office instance. Therefore you have to use correct component context to tell to the multi component factory to instantiate a service.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you have no matching object provided.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039; macro, you have to use &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; module variable that provides &amp;lt;idl&amp;gt;com.sun.star.script.provider.XScriptContext&amp;lt;/idl&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XModel&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDocument()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current document object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.document.XScriptInvocationContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getInvocationContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns invocation dependent object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XDesktop&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getDesktop()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns instance of &amp;lt;idl&amp;gt;com.sun.star.frame.Desktop&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.uno.XComponentContext&amp;lt;/idl&amp;gt; &amp;#039;&amp;#039;&amp;#039;getComponentContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current component context that is used to tell the which context is.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; variable is defined in module level and it is not provided to imported modules from your script.&lt;br /&gt;
&lt;br /&gt;
== Component Context ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get component context as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = GetDefaultContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But you do not need to access to it until you need to get singletons.&lt;br /&gt;
&lt;br /&gt;
In Python, you can get access to the component context through the script context.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need this value to instantiate services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service Manager ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get service manager as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 smgr = GetProcessServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But not so many people having to access to it.&lt;br /&gt;
&lt;br /&gt;
In Python, this instance is most important value to instantiate services to work with the office APIs.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need both the component context and the service manager to instantiate services.&lt;br /&gt;
&lt;br /&gt;
== Service Instance ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can instantiate services by built-in function as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 sfa = CreateUnoService(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or with initialize arguments: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 arg = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = CreateUnoServiceWithArguments(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, Array(arg))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Python, you have to work with com.sun.star.lang.XMultiComponentFactory interface as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
 sfa = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;, ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to initialize the instance, use createInstanceWithArgumentsAndContext method: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = smgr.createInstanceWithArgumentsAndContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, (FILESAVE_SIMPLE,) ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or initialize after the instantiation: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 file_picker = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, ctx)&lt;br /&gt;
 file_picker.initialize((FILESAVE_SIMPLE,))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service with Constructor ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can call service construct from its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 shell_execute = com.sun.star.system.SystemShellExecute.create()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you have to instantiate it with XMultiComponentFactory::createInstanceWithArgumentsAndContext method with initial arguments or instantiate after the instantiation.&lt;br /&gt;
&lt;br /&gt;
The constructor calling does type checking before to pass arguments to createInstanceWithArgumentsAndContext method.&lt;br /&gt;
&lt;br /&gt;
== Current Document ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ThisComponent runtime function provides access to the current document: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = ThisComponent&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Its return value is bound to the macro location. If the macro stored in a document, the result of ThisComponent is the document that the storage of the macro belongs to. And if your macro is stored in application wide, the returned value is the document model of currently active frame, this is the same result taken from StarDesktop.&amp;#039;&amp;#039;&amp;#039;getCurrentComponent()&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can access to the current document through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If your macro is &amp;#039;&amp;#039;&amp;#039;embedded in the document&amp;#039;&amp;#039;&amp;#039;, the document model is match with the document that the macro stored in. If your macro is stored in user or shared location, the document object is from active frame.&lt;br /&gt;
&lt;br /&gt;
== Desktop ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, StarDesktop runtime function is provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = StarDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can get access to the desktop through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = XSCRIPTCONTEXT.getDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Struct Instance ==&lt;br /&gt;
&lt;br /&gt;
In Basic, instance of struct can be instantiated in two ways: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Dim a As New com.sun.star.awt.Point&lt;br /&gt;
 a = CreateUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
With Dim statement and New keyword, you can instantiate a struct or array of structs. Or CreateUnoStruct method provides the way to instantiate a struct at runtime. You can not initialize the instance at the creation, you have to set its value of members.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can use the following ways to instantiate a struct. Import struct class and call it.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.awt import Point&lt;br /&gt;
&lt;br /&gt;
 a = Point()         # instantiate with default values, X=0, Y=0&lt;br /&gt;
 b = Point(100, 200) # initialize with initial values, X=100, Y=200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Calling the class to create new instance of the struct, you can empty its arguments or you have to pass values for all fields. In other words, you can not pass insufficient number of arguments to initialize. And its order should be match with definition of the struct in its IDL. For example, instance of struct b having X=100 and Y=200 in the above piece of code.&lt;br /&gt;
&lt;br /&gt;
You can initialize without to import the class of your target struct with uno.createUnoStruct function as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 a = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
 b = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This makes the same result with the above example. The first parameter of the createUnoStruct method is the name of the struct to initialize. The following arguments are initial values for new instance.&lt;br /&gt;
&lt;br /&gt;
== Enum ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can access to the module of the enum as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ITALIC = com.sun.star.awt.FontSlant.ITALIC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following ways can be used: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontSlant import ITALIC&lt;br /&gt;
 ITALIC = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontSlant.ITALIC&amp;quot;)&lt;br /&gt;
 ITALIC = uno.Enum(&amp;quot;com.sun.star.awt.FontSlant&amp;quot;, &amp;quot;ITALIC&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
All of the way results the instance of uno.Enum class.&lt;br /&gt;
&lt;br /&gt;
== Constants ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get access to constants through its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 BOLD = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways are provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontWeight import BOLD&lt;br /&gt;
 BOLD = uno.getConstantsByName(&amp;quot;com.sun.star.awt.FontWeight.BOLD&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sequence ==&lt;br /&gt;
&lt;br /&gt;
The sequence is sequential value of the same type.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, array is used.&lt;br /&gt;
&lt;br /&gt;
In Python, tuple is chosen to represent UNO&amp;#039;s sequence. Note, list is not allowed to pass as sequence value.&lt;br /&gt;
&lt;br /&gt;
== Boolean ==&lt;br /&gt;
&lt;br /&gt;
In Python, True or False.&lt;br /&gt;
&lt;br /&gt;
== String ==&lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;s string can contain over 64K bytes.&lt;br /&gt;
&lt;br /&gt;
If you have to write non Ascii 7 bit characters in your script, write magic comment at the head of your file. This is standard Python instructions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # -*- coding: utf_8 -*-&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please read Python&amp;#039;s documentation for more detail.&lt;br /&gt;
&lt;br /&gt;
== Char ==&lt;br /&gt;
&lt;br /&gt;
There is no dedicated value for char type in StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, uno.Char class is defined for char type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 c = uno.Char(&amp;quot;a&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Byte Sequence ==&lt;br /&gt;
&lt;br /&gt;
The byte sequence is sequence of byte type.&lt;br /&gt;
&lt;br /&gt;
In Basic, array of byte is used to represent it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, it is represented by str wrapped by uno.ByteSequence class. If you takes some byte sequences from UNO, they are the instance of uno.ByteSequence. If you need to get real value of them, refer its &amp;#039;&amp;#039;value&amp;#039;&amp;#039; instance variable.&lt;br /&gt;
&lt;br /&gt;
== Exception ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you get thrown exception as some error. And On Error statement is used to catch it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub ErrorExample&lt;br /&gt;
&lt;br /&gt;
   On Error GoTo Handler&lt;br /&gt;
&lt;br /&gt;
   &amp;#039; ... error&lt;br /&gt;
&lt;br /&gt;
   Exit Sub&lt;br /&gt;
&lt;br /&gt;
   Handler: &lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
And you can not throw any exceptions from StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, the exception thrown in UNO world can be treated as normal Python&amp;#039;s exception. Here is an example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.container import IndexOutOfBoundsException&lt;br /&gt;
&lt;br /&gt;
 try:&lt;br /&gt;
     obj.getByIndex(100) # raises IndexOutOfBoundsException&lt;br /&gt;
 except IndexOutOfBoundsException as e:&lt;br /&gt;
     print(e)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If getByIndex method raises IndexOutOfBoundsException, it can be caught in except statement because all exceptions inherit Python&amp;#039;s Exception class.&lt;br /&gt;
&lt;br /&gt;
And also you can throw UNO&amp;#039;s exception from your Python code as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.uno import RuntimeException&lt;br /&gt;
 raise RuntimeException(&amp;quot;Some message&amp;quot;, None)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Empty Value ==&lt;br /&gt;
&lt;br /&gt;
In Basic, there are some situations to meet variables that they do not contain any value (this is not correct). Null, empty, missing, nothing and so on.&lt;br /&gt;
&lt;br /&gt;
In Python, None is used. If a method defined as void return value in its IDL, it results None if you call it. If you need to pass invalid interface as an argument for the method that takes some interface, pass None for it. The result of this behavior is fully dependent to the implementation of the method.&lt;br /&gt;
&lt;br /&gt;
== Listener and Interface ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can create new listener using CreateUnoListener runtime function with some subroutines or functions.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub Add&lt;br /&gt;
&lt;br /&gt;
   d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
   listener = CreateUnoListener(&amp;quot;ActionListener&amp;quot;, &amp;quot;com.sun.star.awt.XActionListener&amp;quot;)&lt;br /&gt;
   d.getControl(&amp;quot;CommandButton1&amp;quot;).addActionListener(listener)&lt;br /&gt;
   d.execute()&lt;br /&gt;
   d.dispose()&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 Sub ActionListener_actionPerformed(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 Sub ActionListener_disposing(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you have define your own class with desired interfaces. With helper class, you can define easily as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import unohelper&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt import XActionListener&lt;br /&gt;
&lt;br /&gt;
 class ActionListener(unohelper.Base, XActionListener):&lt;br /&gt;
     def __init__(self):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def disposing(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def actionPerformed(self, ev):&lt;br /&gt;
&lt;br /&gt;
         pass&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
unohelper.Base class provides required interface for UNO components.&lt;br /&gt;
&lt;br /&gt;
== Containers ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, container object provides the way to access to its contents in sequentially.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, there is no shortcut provided. &lt;br /&gt;
&lt;br /&gt;
If you need to access to elements of indexed container, use range function to generate sequential indexes.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 for i in range(container.getCount()):&lt;br /&gt;
     obj = container.getByIndex(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== URL and System Path ==&lt;br /&gt;
&lt;br /&gt;
If you work with a file stored in your local file system, you have to get its corresponding URL.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ConvertToURL runtime function is prepared for this task. And there is ConvertFromURL runtime function for reverse conversion.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following functions are defined in uno module for such task.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 path = &amp;quot;/home/foo/Documents/file.odt&amp;quot;&lt;br /&gt;
 url = uno.sytemPathToFileUrl(path)&lt;br /&gt;
 path = uno.fileUrlToSystemPath(url)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments and Return Value ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, mode of the first argument of parseStrict method is &amp;quot;inout&amp;quot; in the following code: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 aURL = CreateUnoStruct(&amp;quot;com.sun.star.util.URL&amp;quot;)&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 CreateUnoService(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;).parseStrict(aURL)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The content of aURL variable is updated after calling the method.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, out mode parameter is returned as part of return value.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.util import URL&lt;br /&gt;
&lt;br /&gt;
 aURL = URL()&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 dummy, aURL = smgr.createInstanceWithContext(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;, ctx).parseStrict(aURL)&lt;br /&gt;
 # Definition of com.sun.star.util.XURLTransformer::parseStrict method: &lt;br /&gt;
 # void parseStrict([inout] com.sun.star.util.URL aURL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If a method has out mode in its parameters, its return is always tuple that contains original return value and values for out parameters.&lt;br /&gt;
&lt;br /&gt;
Here is a potential example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # boolean getSomeValue([in] string aName, [out] short aNum, [inout] long aNum2);&lt;br /&gt;
 result, num, num2 = obj.getSomeValue(&amp;quot;foo&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above example, &amp;#039;&amp;#039;result&amp;#039;&amp;#039; variable takes original return value, &amp;#039;&amp;#039;num&amp;#039;&amp;#039; takes output value for second parameter and &amp;#039;&amp;#039;num2&amp;#039;&amp;#039; takes output value for third parameter. The method takes 100 as the second parameter but it is not used as input of value. No entry in returned tuple for in mode parameter.&lt;br /&gt;
&lt;br /&gt;
== Functions to be Executed ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can not choose routines to be executed by users.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, define &amp;#039;&amp;#039;&amp;#039;g_exportedScripts&amp;#039;&amp;#039;&amp;#039; variable that contains tuple of callable in your macro file.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def func_a(): pass&lt;br /&gt;
 def func_b(): pass&lt;br /&gt;
 def func_hidden(): pass # not shown in the UI&lt;br /&gt;
 &lt;br /&gt;
 g_exportedScripts = func_a, func_b&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above code, func_hidden is not shown in execution dialog of macros.&lt;br /&gt;
&lt;br /&gt;
== Importing Modules ==&lt;br /&gt;
&lt;br /&gt;
== Dialog ==&lt;br /&gt;
&lt;br /&gt;
== Message Box ==&lt;br /&gt;
&lt;br /&gt;
== Input Box ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231598</id>
		<title>Python/Transfer from Basic to Python</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231598"/>
		<updated>2013-10-03T06:10:27Z</updated>

		<summary type="html">&lt;p&gt;Hanya: /* Short Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Transfer from Basic to Python}}&lt;br /&gt;
&lt;br /&gt;
Translation [[ES/Manuales/GuiaAOO/TemasAvanzados/Macros/Python/BasicAPython| Español]]&lt;br /&gt;
&lt;br /&gt;
If you feel some displeasure at StarBasic/OpenOffice Basic or you meet requirement of custom UNO component, now it is the time to transfer coding environment from Basic to Python.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, there are some runtime function provides shortcut to do something. But using Python-UNO bridge, you have to do such task by API ways.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s start with Python&amp;#039;s tutorial and return back to here when you have learned a bit about Python language.&lt;br /&gt;
&lt;br /&gt;
== Macro Location ==&lt;br /&gt;
On the current version, script organizer for Python do not provide the way to manage script files. So you have to manage yourself. Macros written in Python should be placed in the specific directory under your user&amp;#039;s profile, shared profile or script directory of your document.&lt;br /&gt;
&lt;br /&gt;
The python directory (in all lowercase) should be created in Scripts directory and you can put your python scripts that contain python code.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
path_to_directory/Scripts/python/your_file.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can make subdirectories to put macro files in them under Scripts/python directory.&lt;br /&gt;
&lt;br /&gt;
You have to add &amp;quot;py&amp;quot; file extension to your file name.&lt;br /&gt;
&lt;br /&gt;
== Macro Editor ==&lt;br /&gt;
&lt;br /&gt;
There is no built-in editor dedicated to code in Python. But you can choose your favorite text editor application to edit your Python script.&lt;br /&gt;
&lt;br /&gt;
This is discussed in another page.&lt;br /&gt;
&lt;br /&gt;
== Short Example ==&lt;br /&gt;
&lt;br /&gt;
Here is a small example written in Python.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello():&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Each callable function is the executable unit of Python macro (you can choose which function should be listed in the GUI, see other document).&lt;br /&gt;
&lt;br /&gt;
You can access the current document through getDocument method of XSCRIPTCONTEXT variable of the module. And it changes the document content to &amp;quot;Hello!&amp;quot; of the Writer document.&lt;br /&gt;
&lt;br /&gt;
== Usable Modules ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 import unohelper&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Script Context ==&lt;br /&gt;
&lt;br /&gt;
StarBasic is embedded runtime and it always works with living instance of the office. So the context is always the match with the office&amp;#039;s one. But Python-UNO bridge provides the way to work as RPC client. At that time, remote Python instance does have different context from the office instance. Therefore you have to use correct component context to tell to the multi component factory to instantiate a service.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you have no matching object provided.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039; macro, you have to use &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; module variable that provides &amp;lt;idl&amp;gt;com.sun.star.script.provider.XScriptContext&amp;lt;/idl&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XModel&amp;lt;/idl&amp;gt;&amp;#039;&amp;#039;&amp;#039;getDocument()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current document object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.document.XScriptInvocationContext&amp;lt;/idl&amp;gt;&amp;#039;&amp;#039;&amp;#039;getInvocationContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns invocation dependent object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XDesktop&amp;lt;/idl&amp;gt;&amp;#039;&amp;#039;&amp;#039;getDesktop()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns instance of &amp;lt;idl&amp;gt;com.sun.star.frame.Desktop&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.uno.XComponentContext&amp;lt;/idl&amp;gt;&amp;#039;&amp;#039;&amp;#039;getComponentContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current component context that is used to tell the which context is.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; variable is defined in module level and it is not provided to imported modules from your script.&lt;br /&gt;
&lt;br /&gt;
== Component Context ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get component context as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = GetDefaultContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But you do not need to access to it until you need to get singletons.&lt;br /&gt;
&lt;br /&gt;
In Python, you can get access to the component context through the script context.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need this value to instantiate services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service Manager ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get service manager as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 smgr = GetProcessServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But not so many people having to access to it.&lt;br /&gt;
&lt;br /&gt;
In Python, this instance is most important value to instantiate services to work with the office APIs.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need both the component context and the service manager to instantiate services.&lt;br /&gt;
&lt;br /&gt;
== Service Instance ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can instantiate services by built-in function as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 sfa = CreateUnoService(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or with initialize arguments: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 arg = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = CreateUnoServiceWithArguments(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, Array(arg))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Python, you have to work with com.sun.star.lang.XMultiComponentFactory interface as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
 sfa = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;, ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to initialize the instance, use createInstanceWithArgumentsAndContext method: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = smgr.createInstanceWithArgumentsAndContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, (FILESAVE_SIMPLE,) ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or initialize after the instantiation: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 file_picker = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, ctx)&lt;br /&gt;
 file_picker.initialize((FILESAVE_SIMPLE,))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service with Constructor ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can call service construct from its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 shell_execute = com.sun.star.system.SystemShellExecute.create()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you have to instantiate it with XMultiComponentFactory::createInstanceWithArgumentsAndContext method with initial arguments or instantiate after the instantiation.&lt;br /&gt;
&lt;br /&gt;
The constructor calling does type checking before to pass arguments to createInstanceWithArgumentsAndContext method.&lt;br /&gt;
&lt;br /&gt;
== Current Document ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ThisComponent runtime function provides access to the current document: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = ThisComponent&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Its return value is bound to the macro location. If the macro stored in a document, the result of ThisComponent is the document that the storage of the macro belongs to. And if your macro is stored in application wide, the returned value is the document model of currently active frame, this is the same result taken from StarDesktop.&amp;#039;&amp;#039;&amp;#039;getCurrentComponent()&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can access to the current document through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If your macro is &amp;#039;&amp;#039;&amp;#039;embedded in the document&amp;#039;&amp;#039;&amp;#039;, the document model is match with the document that the macro stored in. If your macro is stored in user or shared location, the document object is from active frame.&lt;br /&gt;
&lt;br /&gt;
== Desktop ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, StarDesktop runtime function is provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = StarDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can get access to the desktop through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = XSCRIPTCONTEXT.getDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Struct Instance ==&lt;br /&gt;
&lt;br /&gt;
In Basic, instance of struct can be instantiated in two ways: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Dim a As New com.sun.star.awt.Point&lt;br /&gt;
 a = CreateUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
With Dim statement and New keyword, you can instantiate a struct or array of structs. Or CreateUnoStruct method provides the way to instantiate a struct at runtime. You can not initialize the instance at the creation, you have to set its value of members.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can use the following ways to instantiate a struct. Import struct class and call it.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.awt import Point&lt;br /&gt;
&lt;br /&gt;
 a = Point()         # instantiate with default values, X=0, Y=0&lt;br /&gt;
 b = Point(100, 200) # initialize with initial values, X=100, Y=200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Calling the class to create new instance of the struct, you can empty its arguments or you have to pass values for all fields. In other words, you can not pass insufficient number of arguments to initialize. And its order should be match with definition of the struct in its IDL. For example, instance of struct b having X=100 and Y=200 in the above piece of code.&lt;br /&gt;
&lt;br /&gt;
You can initialize without to import the class of your target struct with uno.createUnoStruct function as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 a = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
 b = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This makes the same result with the above example. The first parameter of the createUnoStruct method is the name of the struct to initialize. The following arguments are initial values for new instance.&lt;br /&gt;
&lt;br /&gt;
== Enum ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can access to the module of the enum as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ITALIC = com.sun.star.awt.FontSlant.ITALIC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following ways can be used: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontSlant import ITALIC&lt;br /&gt;
 ITALIC = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontSlant.ITALIC&amp;quot;)&lt;br /&gt;
 ITALIC = uno.Enum(&amp;quot;com.sun.star.awt.FontSlant&amp;quot;, &amp;quot;ITALIC&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
All of the way results the instance of uno.Enum class.&lt;br /&gt;
&lt;br /&gt;
== Constants ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get access to constants through its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 BOLD = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways are provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontWeight import BOLD&lt;br /&gt;
 BOLD = uno.getConstantsByName(&amp;quot;com.sun.star.awt.FontWeight.BOLD&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sequence ==&lt;br /&gt;
&lt;br /&gt;
The sequence is sequential value of the same type.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, array is used.&lt;br /&gt;
&lt;br /&gt;
In Python, tuple is chosen to represent UNO&amp;#039;s sequence. Note, list is not allowed to pass as sequence value.&lt;br /&gt;
&lt;br /&gt;
== Boolean ==&lt;br /&gt;
&lt;br /&gt;
In Python, True or False.&lt;br /&gt;
&lt;br /&gt;
== String ==&lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;s string can contain over 64K bytes.&lt;br /&gt;
&lt;br /&gt;
If you have to write non Ascii 7 bit characters in your script, write magic comment at the head of your file. This is standard Python instructions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # -*- coding: utf_8 -*-&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please read Python&amp;#039;s documentation for more detail.&lt;br /&gt;
&lt;br /&gt;
== Char ==&lt;br /&gt;
&lt;br /&gt;
There is no dedicated value for char type in StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, uno.Char class is defined for char type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 c = uno.Char(&amp;quot;a&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Byte Sequence ==&lt;br /&gt;
&lt;br /&gt;
The byte sequence is sequence of byte type.&lt;br /&gt;
&lt;br /&gt;
In Basic, array of byte is used to represent it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, it is represented by str wrapped by uno.ByteSequence class. If you takes some byte sequences from UNO, they are the instance of uno.ByteSequence. If you need to get real value of them, refer its &amp;#039;&amp;#039;value&amp;#039;&amp;#039; instance variable.&lt;br /&gt;
&lt;br /&gt;
== Exception ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you get thrown exception as some error. And On Error statement is used to catch it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub ErrorExample&lt;br /&gt;
&lt;br /&gt;
   On Error GoTo Handler&lt;br /&gt;
&lt;br /&gt;
   &amp;#039; ... error&lt;br /&gt;
&lt;br /&gt;
   Exit Sub&lt;br /&gt;
&lt;br /&gt;
   Handler: &lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
And you can not throw any exceptions from StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, the exception thrown in UNO world can be treated as normal Python&amp;#039;s exception. Here is an example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.container import IndexOutOfBoundsException&lt;br /&gt;
&lt;br /&gt;
 try:&lt;br /&gt;
     obj.getByIndex(100) # raises IndexOutOfBoundsException&lt;br /&gt;
 except IndexOutOfBoundsException as e:&lt;br /&gt;
     print(e)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If getByIndex method raises IndexOutOfBoundsException, it can be caught in except statement because all exceptions inherit Python&amp;#039;s Exception class.&lt;br /&gt;
&lt;br /&gt;
And also you can throw UNO&amp;#039;s exception from your Python code as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.uno import RuntimeException&lt;br /&gt;
 raise RuntimeException(&amp;quot;Some message&amp;quot;, None)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Empty Value ==&lt;br /&gt;
&lt;br /&gt;
In Basic, there are some situations to meet variables that they do not contain any value (this is not correct). Null, empty, missing, nothing and so on.&lt;br /&gt;
&lt;br /&gt;
In Python, None is used. If a method defined as void return value in its IDL, it results None if you call it. If you need to pass invalid interface as an argument for the method that takes some interface, pass None for it. The result of this behavior is fully dependent to the implementation of the method.&lt;br /&gt;
&lt;br /&gt;
== Listener and Interface ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can create new listener using CreateUnoListener runtime function with some subroutines or functions.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub Add&lt;br /&gt;
&lt;br /&gt;
   d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
   listener = CreateUnoListener(&amp;quot;ActionListener&amp;quot;, &amp;quot;com.sun.star.awt.XActionListener&amp;quot;)&lt;br /&gt;
   d.getControl(&amp;quot;CommandButton1&amp;quot;).addActionListener(listener)&lt;br /&gt;
   d.execute()&lt;br /&gt;
   d.dispose()&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 Sub ActionListener_actionPerformed(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 Sub ActionListener_disposing(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you have define your own class with desired interfaces. With helper class, you can define easily as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import unohelper&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt import XActionListener&lt;br /&gt;
&lt;br /&gt;
 class ActionListener(unohelper.Base, XActionListener):&lt;br /&gt;
     def __init__(self):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def disposing(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def actionPerformed(self, ev):&lt;br /&gt;
&lt;br /&gt;
         pass&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
unohelper.Base class provides required interface for UNO components.&lt;br /&gt;
&lt;br /&gt;
== Containers ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, container object provides the way to access to its contents in sequentially.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, there is no shortcut provided. &lt;br /&gt;
&lt;br /&gt;
If you need to access to elements of indexed container, use range function to generate sequential indexes.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 for i in range(container.getCount()):&lt;br /&gt;
     obj = container.getByIndex(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== URL and System Path ==&lt;br /&gt;
&lt;br /&gt;
If you work with a file stored in your local file system, you have to get its corresponding URL.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ConvertToURL runtime function is prepared for this task. And there is ConvertFromURL runtime function for reverse conversion.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following functions are defined in uno module for such task.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 path = &amp;quot;/home/foo/Documents/file.odt&amp;quot;&lt;br /&gt;
 url = uno.sytemPathToFileUrl(path)&lt;br /&gt;
 path = uno.fileUrlToSystemPath(url)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments and Return Value ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, mode of the first argument of parseStrict method is &amp;quot;inout&amp;quot; in the following code: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 aURL = CreateUnoStruct(&amp;quot;com.sun.star.util.URL&amp;quot;)&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 CreateUnoService(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;).parseStrict(aURL)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The content of aURL variable is updated after calling the method.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, out mode parameter is returned as part of return value.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.util import URL&lt;br /&gt;
&lt;br /&gt;
 aURL = URL()&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 dummy, aURL = smgr.createInstanceWithContext(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;, ctx).parseStrict(aURL)&lt;br /&gt;
 # Definition of com.sun.star.util.XURLTransformer::parseStrict method: &lt;br /&gt;
 # void parseStrict([inout] com.sun.star.util.URL aURL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If a method has out mode in its parameters, its return is always tuple that contains original return value and values for out parameters.&lt;br /&gt;
&lt;br /&gt;
Here is a potential example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # boolean getSomeValue([in] string aName, [out] short aNum, [inout] long aNum2);&lt;br /&gt;
 result, num, num2 = obj.getSomeValue(&amp;quot;foo&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above example, &amp;#039;&amp;#039;result&amp;#039;&amp;#039; variable takes original return value, &amp;#039;&amp;#039;num&amp;#039;&amp;#039; takes output value for second parameter and &amp;#039;&amp;#039;num2&amp;#039;&amp;#039; takes output value for third parameter. The method takes 100 as the second parameter but it is not used as input of value. No entry in returned tuple for in mode parameter.&lt;br /&gt;
&lt;br /&gt;
== Functions to be Executed ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can not choose routines to be executed by users.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, define &amp;#039;&amp;#039;&amp;#039;g_exportedScripts&amp;#039;&amp;#039;&amp;#039; variable that contains tuple of callable in your macro file.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def func_a(): pass&lt;br /&gt;
 def func_b(): pass&lt;br /&gt;
 def func_hidden(): pass # not shown in the UI&lt;br /&gt;
 &lt;br /&gt;
 g_exportedScripts = func_a, func_b&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above code, func_hidden is not shown in execution dialog of macros.&lt;br /&gt;
&lt;br /&gt;
== Importing Modules ==&lt;br /&gt;
&lt;br /&gt;
== Dialog ==&lt;br /&gt;
&lt;br /&gt;
== Message Box ==&lt;br /&gt;
&lt;br /&gt;
== Input Box ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231597</id>
		<title>Python/Transfer from Basic to Python</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231597"/>
		<updated>2013-10-03T06:10:02Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add short example&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Transfer from Basic to Python}}&lt;br /&gt;
&lt;br /&gt;
Translation [[ES/Manuales/GuiaAOO/TemasAvanzados/Macros/Python/BasicAPython| Español]]&lt;br /&gt;
&lt;br /&gt;
If you feel some displeasure at StarBasic/OpenOffice Basic or you meet requirement of custom UNO component, now it is the time to transfer coding environment from Basic to Python.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, there are some runtime function provides shortcut to do something. But using Python-UNO bridge, you have to do such task by API ways.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s start with Python&amp;#039;s tutorial and return back to here when you have learned a bit about Python language.&lt;br /&gt;
&lt;br /&gt;
== Macro Location ==&lt;br /&gt;
On the current version, script organizer for Python do not provide the way to manage script files. So you have to manage yourself. Macros written in Python should be placed in the specific directory under your user&amp;#039;s profile, shared profile or script directory of your document.&lt;br /&gt;
&lt;br /&gt;
The python directory (in all lowercase) should be created in Scripts directory and you can put your python scripts that contain python code.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
path_to_directory/Scripts/python/your_file.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can make subdirectories to put macro files in them under Scripts/python directory.&lt;br /&gt;
&lt;br /&gt;
You have to add &amp;quot;py&amp;quot; file extension to your file name.&lt;br /&gt;
&lt;br /&gt;
== Macro Editor ==&lt;br /&gt;
&lt;br /&gt;
There is no built-in editor dedicated to code in Python. But you can choose your favorite text editor application to edit your Python script.&lt;br /&gt;
&lt;br /&gt;
This is discussed in another page.&lt;br /&gt;
&lt;br /&gt;
== Short Example ==&lt;br /&gt;
&lt;br /&gt;
Here is a small example written in Python.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello():&lt;br /&gt;
    XSCRIPTCONTEXT.getDocument().getText().setString(&amp;quot;Hello!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Each callable function is the executable unit of Python macro (you can choose which function should be listed in the GUI, see other document).&lt;br /&gt;
You can access the current document through getDocument method of XSCRIPTCONTEXT variable of the module. And it changes the document content to &amp;quot;Hello!&amp;quot; of the Writer document.&lt;br /&gt;
&lt;br /&gt;
== Usable Modules ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 import unohelper&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Script Context ==&lt;br /&gt;
&lt;br /&gt;
StarBasic is embedded runtime and it always works with living instance of the office. So the context is always the match with the office&amp;#039;s one. But Python-UNO bridge provides the way to work as RPC client. At that time, remote Python instance does have different context from the office instance. Therefore you have to use correct component context to tell to the multi component factory to instantiate a service.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you have no matching object provided.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039; macro, you have to use &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; module variable that provides &amp;lt;idl&amp;gt;com.sun.star.script.provider.XScriptContext&amp;lt;/idl&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XModel&amp;lt;/idl&amp;gt;&amp;#039;&amp;#039;&amp;#039;getDocument()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current document object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.document.XScriptInvocationContext&amp;lt;/idl&amp;gt;&amp;#039;&amp;#039;&amp;#039;getInvocationContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns invocation dependent object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XDesktop&amp;lt;/idl&amp;gt;&amp;#039;&amp;#039;&amp;#039;getDesktop()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns instance of &amp;lt;idl&amp;gt;com.sun.star.frame.Desktop&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.uno.XComponentContext&amp;lt;/idl&amp;gt;&amp;#039;&amp;#039;&amp;#039;getComponentContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current component context that is used to tell the which context is.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; variable is defined in module level and it is not provided to imported modules from your script.&lt;br /&gt;
&lt;br /&gt;
== Component Context ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get component context as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = GetDefaultContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But you do not need to access to it until you need to get singletons.&lt;br /&gt;
&lt;br /&gt;
In Python, you can get access to the component context through the script context.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need this value to instantiate services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service Manager ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get service manager as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 smgr = GetProcessServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But not so many people having to access to it.&lt;br /&gt;
&lt;br /&gt;
In Python, this instance is most important value to instantiate services to work with the office APIs.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need both the component context and the service manager to instantiate services.&lt;br /&gt;
&lt;br /&gt;
== Service Instance ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can instantiate services by built-in function as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 sfa = CreateUnoService(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or with initialize arguments: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 arg = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = CreateUnoServiceWithArguments(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, Array(arg))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Python, you have to work with com.sun.star.lang.XMultiComponentFactory interface as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
 sfa = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;, ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to initialize the instance, use createInstanceWithArgumentsAndContext method: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = smgr.createInstanceWithArgumentsAndContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, (FILESAVE_SIMPLE,) ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or initialize after the instantiation: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 file_picker = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, ctx)&lt;br /&gt;
 file_picker.initialize((FILESAVE_SIMPLE,))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service with Constructor ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can call service construct from its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 shell_execute = com.sun.star.system.SystemShellExecute.create()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you have to instantiate it with XMultiComponentFactory::createInstanceWithArgumentsAndContext method with initial arguments or instantiate after the instantiation.&lt;br /&gt;
&lt;br /&gt;
The constructor calling does type checking before to pass arguments to createInstanceWithArgumentsAndContext method.&lt;br /&gt;
&lt;br /&gt;
== Current Document ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ThisComponent runtime function provides access to the current document: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = ThisComponent&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Its return value is bound to the macro location. If the macro stored in a document, the result of ThisComponent is the document that the storage of the macro belongs to. And if your macro is stored in application wide, the returned value is the document model of currently active frame, this is the same result taken from StarDesktop.&amp;#039;&amp;#039;&amp;#039;getCurrentComponent()&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can access to the current document through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If your macro is &amp;#039;&amp;#039;&amp;#039;embedded in the document&amp;#039;&amp;#039;&amp;#039;, the document model is match with the document that the macro stored in. If your macro is stored in user or shared location, the document object is from active frame.&lt;br /&gt;
&lt;br /&gt;
== Desktop ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, StarDesktop runtime function is provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = StarDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can get access to the desktop through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = XSCRIPTCONTEXT.getDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Struct Instance ==&lt;br /&gt;
&lt;br /&gt;
In Basic, instance of struct can be instantiated in two ways: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Dim a As New com.sun.star.awt.Point&lt;br /&gt;
 a = CreateUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
With Dim statement and New keyword, you can instantiate a struct or array of structs. Or CreateUnoStruct method provides the way to instantiate a struct at runtime. You can not initialize the instance at the creation, you have to set its value of members.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can use the following ways to instantiate a struct. Import struct class and call it.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.awt import Point&lt;br /&gt;
&lt;br /&gt;
 a = Point()         # instantiate with default values, X=0, Y=0&lt;br /&gt;
 b = Point(100, 200) # initialize with initial values, X=100, Y=200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Calling the class to create new instance of the struct, you can empty its arguments or you have to pass values for all fields. In other words, you can not pass insufficient number of arguments to initialize. And its order should be match with definition of the struct in its IDL. For example, instance of struct b having X=100 and Y=200 in the above piece of code.&lt;br /&gt;
&lt;br /&gt;
You can initialize without to import the class of your target struct with uno.createUnoStruct function as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 a = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
 b = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This makes the same result with the above example. The first parameter of the createUnoStruct method is the name of the struct to initialize. The following arguments are initial values for new instance.&lt;br /&gt;
&lt;br /&gt;
== Enum ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can access to the module of the enum as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ITALIC = com.sun.star.awt.FontSlant.ITALIC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following ways can be used: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontSlant import ITALIC&lt;br /&gt;
 ITALIC = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontSlant.ITALIC&amp;quot;)&lt;br /&gt;
 ITALIC = uno.Enum(&amp;quot;com.sun.star.awt.FontSlant&amp;quot;, &amp;quot;ITALIC&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
All of the way results the instance of uno.Enum class.&lt;br /&gt;
&lt;br /&gt;
== Constants ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get access to constants through its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 BOLD = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways are provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontWeight import BOLD&lt;br /&gt;
 BOLD = uno.getConstantsByName(&amp;quot;com.sun.star.awt.FontWeight.BOLD&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sequence ==&lt;br /&gt;
&lt;br /&gt;
The sequence is sequential value of the same type.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, array is used.&lt;br /&gt;
&lt;br /&gt;
In Python, tuple is chosen to represent UNO&amp;#039;s sequence. Note, list is not allowed to pass as sequence value.&lt;br /&gt;
&lt;br /&gt;
== Boolean ==&lt;br /&gt;
&lt;br /&gt;
In Python, True or False.&lt;br /&gt;
&lt;br /&gt;
== String ==&lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;s string can contain over 64K bytes.&lt;br /&gt;
&lt;br /&gt;
If you have to write non Ascii 7 bit characters in your script, write magic comment at the head of your file. This is standard Python instructions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # -*- coding: utf_8 -*-&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please read Python&amp;#039;s documentation for more detail.&lt;br /&gt;
&lt;br /&gt;
== Char ==&lt;br /&gt;
&lt;br /&gt;
There is no dedicated value for char type in StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, uno.Char class is defined for char type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 c = uno.Char(&amp;quot;a&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Byte Sequence ==&lt;br /&gt;
&lt;br /&gt;
The byte sequence is sequence of byte type.&lt;br /&gt;
&lt;br /&gt;
In Basic, array of byte is used to represent it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, it is represented by str wrapped by uno.ByteSequence class. If you takes some byte sequences from UNO, they are the instance of uno.ByteSequence. If you need to get real value of them, refer its &amp;#039;&amp;#039;value&amp;#039;&amp;#039; instance variable.&lt;br /&gt;
&lt;br /&gt;
== Exception ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you get thrown exception as some error. And On Error statement is used to catch it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub ErrorExample&lt;br /&gt;
&lt;br /&gt;
   On Error GoTo Handler&lt;br /&gt;
&lt;br /&gt;
   &amp;#039; ... error&lt;br /&gt;
&lt;br /&gt;
   Exit Sub&lt;br /&gt;
&lt;br /&gt;
   Handler: &lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
And you can not throw any exceptions from StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, the exception thrown in UNO world can be treated as normal Python&amp;#039;s exception. Here is an example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.container import IndexOutOfBoundsException&lt;br /&gt;
&lt;br /&gt;
 try:&lt;br /&gt;
     obj.getByIndex(100) # raises IndexOutOfBoundsException&lt;br /&gt;
 except IndexOutOfBoundsException as e:&lt;br /&gt;
     print(e)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If getByIndex method raises IndexOutOfBoundsException, it can be caught in except statement because all exceptions inherit Python&amp;#039;s Exception class.&lt;br /&gt;
&lt;br /&gt;
And also you can throw UNO&amp;#039;s exception from your Python code as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.uno import RuntimeException&lt;br /&gt;
 raise RuntimeException(&amp;quot;Some message&amp;quot;, None)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Empty Value ==&lt;br /&gt;
&lt;br /&gt;
In Basic, there are some situations to meet variables that they do not contain any value (this is not correct). Null, empty, missing, nothing and so on.&lt;br /&gt;
&lt;br /&gt;
In Python, None is used. If a method defined as void return value in its IDL, it results None if you call it. If you need to pass invalid interface as an argument for the method that takes some interface, pass None for it. The result of this behavior is fully dependent to the implementation of the method.&lt;br /&gt;
&lt;br /&gt;
== Listener and Interface ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can create new listener using CreateUnoListener runtime function with some subroutines or functions.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub Add&lt;br /&gt;
&lt;br /&gt;
   d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
   listener = CreateUnoListener(&amp;quot;ActionListener&amp;quot;, &amp;quot;com.sun.star.awt.XActionListener&amp;quot;)&lt;br /&gt;
   d.getControl(&amp;quot;CommandButton1&amp;quot;).addActionListener(listener)&lt;br /&gt;
   d.execute()&lt;br /&gt;
   d.dispose()&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 Sub ActionListener_actionPerformed(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 Sub ActionListener_disposing(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you have define your own class with desired interfaces. With helper class, you can define easily as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import unohelper&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt import XActionListener&lt;br /&gt;
&lt;br /&gt;
 class ActionListener(unohelper.Base, XActionListener):&lt;br /&gt;
     def __init__(self):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def disposing(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def actionPerformed(self, ev):&lt;br /&gt;
&lt;br /&gt;
         pass&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
unohelper.Base class provides required interface for UNO components.&lt;br /&gt;
&lt;br /&gt;
== Containers ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, container object provides the way to access to its contents in sequentially.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, there is no shortcut provided. &lt;br /&gt;
&lt;br /&gt;
If you need to access to elements of indexed container, use range function to generate sequential indexes.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 for i in range(container.getCount()):&lt;br /&gt;
     obj = container.getByIndex(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== URL and System Path ==&lt;br /&gt;
&lt;br /&gt;
If you work with a file stored in your local file system, you have to get its corresponding URL.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ConvertToURL runtime function is prepared for this task. And there is ConvertFromURL runtime function for reverse conversion.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following functions are defined in uno module for such task.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 path = &amp;quot;/home/foo/Documents/file.odt&amp;quot;&lt;br /&gt;
 url = uno.sytemPathToFileUrl(path)&lt;br /&gt;
 path = uno.fileUrlToSystemPath(url)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments and Return Value ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, mode of the first argument of parseStrict method is &amp;quot;inout&amp;quot; in the following code: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 aURL = CreateUnoStruct(&amp;quot;com.sun.star.util.URL&amp;quot;)&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 CreateUnoService(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;).parseStrict(aURL)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The content of aURL variable is updated after calling the method.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, out mode parameter is returned as part of return value.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.util import URL&lt;br /&gt;
&lt;br /&gt;
 aURL = URL()&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 dummy, aURL = smgr.createInstanceWithContext(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;, ctx).parseStrict(aURL)&lt;br /&gt;
 # Definition of com.sun.star.util.XURLTransformer::parseStrict method: &lt;br /&gt;
 # void parseStrict([inout] com.sun.star.util.URL aURL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If a method has out mode in its parameters, its return is always tuple that contains original return value and values for out parameters.&lt;br /&gt;
&lt;br /&gt;
Here is a potential example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # boolean getSomeValue([in] string aName, [out] short aNum, [inout] long aNum2);&lt;br /&gt;
 result, num, num2 = obj.getSomeValue(&amp;quot;foo&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above example, &amp;#039;&amp;#039;result&amp;#039;&amp;#039; variable takes original return value, &amp;#039;&amp;#039;num&amp;#039;&amp;#039; takes output value for second parameter and &amp;#039;&amp;#039;num2&amp;#039;&amp;#039; takes output value for third parameter. The method takes 100 as the second parameter but it is not used as input of value. No entry in returned tuple for in mode parameter.&lt;br /&gt;
&lt;br /&gt;
== Functions to be Executed ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can not choose routines to be executed by users.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, define &amp;#039;&amp;#039;&amp;#039;g_exportedScripts&amp;#039;&amp;#039;&amp;#039; variable that contains tuple of callable in your macro file.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def func_a(): pass&lt;br /&gt;
 def func_b(): pass&lt;br /&gt;
 def func_hidden(): pass # not shown in the UI&lt;br /&gt;
 &lt;br /&gt;
 g_exportedScripts = func_a, func_b&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above code, func_hidden is not shown in execution dialog of macros.&lt;br /&gt;
&lt;br /&gt;
== Importing Modules ==&lt;br /&gt;
&lt;br /&gt;
== Dialog ==&lt;br /&gt;
&lt;br /&gt;
== Message Box ==&lt;br /&gt;
&lt;br /&gt;
== Input Box ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231596</id>
		<title>Python/Transfer from Basic to Python</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231596"/>
		<updated>2013-10-03T06:01:37Z</updated>

		<summary type="html">&lt;p&gt;Hanya: /* Macro Location */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Transfer from Basic to Python}}&lt;br /&gt;
&lt;br /&gt;
Translation [[ES/Manuales/GuiaAOO/TemasAvanzados/Macros/Python/BasicAPython| Español]]&lt;br /&gt;
&lt;br /&gt;
If you feel some displeasure at StarBasic/OpenOffice Basic or you meet requirement of custom UNO component, now it is the time to transfer coding environment from Basic to Python.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, there are some runtime function provides shortcut to do something. But using Python-UNO bridge, you have to do such task by API ways.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s start with Python&amp;#039;s tutorial and return back to here when you have learned a bit about Python language.&lt;br /&gt;
&lt;br /&gt;
== Macro Location ==&lt;br /&gt;
On the current version, script organizer for Python do not provide the way to manage script files. So you have to manage yourself. Macros written in Python should be placed in the specific directory under your user&amp;#039;s profile, shared profile or script directory of your document.&lt;br /&gt;
&lt;br /&gt;
The python directory (in all lowercase) should be created in Scripts directory and you can put your python scripts that contain python code.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
path_to_directory/Scripts/python/your_file.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can make subdirectories to put macro files in them under Scripts/python directory.&lt;br /&gt;
&lt;br /&gt;
You have to add &amp;quot;py&amp;quot; file extension to your file name.&lt;br /&gt;
&lt;br /&gt;
== Macro Editor ==&lt;br /&gt;
&lt;br /&gt;
There is no built-in editor dedicated to code in Python. But you can choose your favorite text editor application to edit your Python script.&lt;br /&gt;
&lt;br /&gt;
This is discussed in another page.&lt;br /&gt;
&lt;br /&gt;
== Short Example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Usable Modules ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 import unohelper&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Script Context ==&lt;br /&gt;
&lt;br /&gt;
StarBasic is embedded runtime and it always works with living instance of the office. So the context is always the match with the office&amp;#039;s one. But Python-UNO bridge provides the way to work as RPC client. At that time, remote Python instance does have different context from the office instance. Therefore you have to use correct component context to tell to the multi component factory to instantiate a service.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you have no matching object provided.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039; macro, you have to use &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; module variable that provides &amp;lt;idl&amp;gt;com.sun.star.script.provider.XScriptContext&amp;lt;/idl&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XModel&amp;lt;/idl&amp;gt;&amp;#039;&amp;#039;&amp;#039;getDocument()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current document object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.document.XScriptInvocationContext&amp;lt;/idl&amp;gt;&amp;#039;&amp;#039;&amp;#039;getInvocationContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns invocation dependent object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XDesktop&amp;lt;/idl&amp;gt;&amp;#039;&amp;#039;&amp;#039;getDesktop()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns instance of &amp;lt;idl&amp;gt;com.sun.star.frame.Desktop&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.uno.XComponentContext&amp;lt;/idl&amp;gt;&amp;#039;&amp;#039;&amp;#039;getComponentContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current component context that is used to tell the which context is.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; variable is defined in module level and it is not provided to imported modules from your script.&lt;br /&gt;
&lt;br /&gt;
== Component Context ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get component context as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = GetDefaultContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But you do not need to access to it until you need to get singletons.&lt;br /&gt;
&lt;br /&gt;
In Python, you can get access to the component context through the script context.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need this value to instantiate services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service Manager ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get service manager as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 smgr = GetProcessServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But not so many people having to access to it.&lt;br /&gt;
&lt;br /&gt;
In Python, this instance is most important value to instantiate services to work with the office APIs.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need both the component context and the service manager to instantiate services.&lt;br /&gt;
&lt;br /&gt;
== Service Instance ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can instantiate services by built-in function as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 sfa = CreateUnoService(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or with initialize arguments: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 arg = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = CreateUnoServiceWithArguments(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, Array(arg))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Python, you have to work with com.sun.star.lang.XMultiComponentFactory interface as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
 sfa = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;, ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to initialize the instance, use createInstanceWithArgumentsAndContext method: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = smgr.createInstanceWithArgumentsAndContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, (FILESAVE_SIMPLE,) ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or initialize after the instantiation: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 file_picker = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, ctx)&lt;br /&gt;
 file_picker.initialize((FILESAVE_SIMPLE,))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service with Constructor ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can call service construct from its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 shell_execute = com.sun.star.system.SystemShellExecute.create()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you have to instantiate it with XMultiComponentFactory::createInstanceWithArgumentsAndContext method with initial arguments or instantiate after the instantiation.&lt;br /&gt;
&lt;br /&gt;
The constructor calling does type checking before to pass arguments to createInstanceWithArgumentsAndContext method.&lt;br /&gt;
&lt;br /&gt;
== Current Document ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ThisComponent runtime function provides access to the current document: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = ThisComponent&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Its return value is bound to the macro location. If the macro stored in a document, the result of ThisComponent is the document that the storage of the macro belongs to. And if your macro is stored in application wide, the returned value is the document model of currently active frame, this is the same result taken from StarDesktop.&amp;#039;&amp;#039;&amp;#039;getCurrentComponent()&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can access to the current document through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If your macro is &amp;#039;&amp;#039;&amp;#039;embedded in the document&amp;#039;&amp;#039;&amp;#039;, the document model is match with the document that the macro stored in. If your macro is stored in user or shared location, the document object is from active frame.&lt;br /&gt;
&lt;br /&gt;
== Desktop ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, StarDesktop runtime function is provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = StarDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can get access to the desktop through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = XSCRIPTCONTEXT.getDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Struct Instance ==&lt;br /&gt;
&lt;br /&gt;
In Basic, instance of struct can be instantiated in two ways: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Dim a As New com.sun.star.awt.Point&lt;br /&gt;
 a = CreateUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
With Dim statement and New keyword, you can instantiate a struct or array of structs. Or CreateUnoStruct method provides the way to instantiate a struct at runtime. You can not initialize the instance at the creation, you have to set its value of members.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can use the following ways to instantiate a struct. Import struct class and call it.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.awt import Point&lt;br /&gt;
&lt;br /&gt;
 a = Point()         # instantiate with default values, X=0, Y=0&lt;br /&gt;
 b = Point(100, 200) # initialize with initial values, X=100, Y=200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Calling the class to create new instance of the struct, you can empty its arguments or you have to pass values for all fields. In other words, you can not pass insufficient number of arguments to initialize. And its order should be match with definition of the struct in its IDL. For example, instance of struct b having X=100 and Y=200 in the above piece of code.&lt;br /&gt;
&lt;br /&gt;
You can initialize without to import the class of your target struct with uno.createUnoStruct function as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 a = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
 b = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This makes the same result with the above example. The first parameter of the createUnoStruct method is the name of the struct to initialize. The following arguments are initial values for new instance.&lt;br /&gt;
&lt;br /&gt;
== Enum ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can access to the module of the enum as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ITALIC = com.sun.star.awt.FontSlant.ITALIC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following ways can be used: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontSlant import ITALIC&lt;br /&gt;
 ITALIC = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontSlant.ITALIC&amp;quot;)&lt;br /&gt;
 ITALIC = uno.Enum(&amp;quot;com.sun.star.awt.FontSlant&amp;quot;, &amp;quot;ITALIC&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
All of the way results the instance of uno.Enum class.&lt;br /&gt;
&lt;br /&gt;
== Constants ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get access to constants through its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 BOLD = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways are provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontWeight import BOLD&lt;br /&gt;
 BOLD = uno.getConstantsByName(&amp;quot;com.sun.star.awt.FontWeight.BOLD&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sequence ==&lt;br /&gt;
&lt;br /&gt;
The sequence is sequential value of the same type.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, array is used.&lt;br /&gt;
&lt;br /&gt;
In Python, tuple is chosen to represent UNO&amp;#039;s sequence. Note, list is not allowed to pass as sequence value.&lt;br /&gt;
&lt;br /&gt;
== Boolean ==&lt;br /&gt;
&lt;br /&gt;
In Python, True or False.&lt;br /&gt;
&lt;br /&gt;
== String ==&lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;s string can contain over 64K bytes.&lt;br /&gt;
&lt;br /&gt;
If you have to write non Ascii 7 bit characters in your script, write magic comment at the head of your file. This is standard Python instructions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # -*- coding: utf_8 -*-&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please read Python&amp;#039;s documentation for more detail.&lt;br /&gt;
&lt;br /&gt;
== Char ==&lt;br /&gt;
&lt;br /&gt;
There is no dedicated value for char type in StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, uno.Char class is defined for char type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 c = uno.Char(&amp;quot;a&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Byte Sequence ==&lt;br /&gt;
&lt;br /&gt;
The byte sequence is sequence of byte type.&lt;br /&gt;
&lt;br /&gt;
In Basic, array of byte is used to represent it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, it is represented by str wrapped by uno.ByteSequence class. If you takes some byte sequences from UNO, they are the instance of uno.ByteSequence. If you need to get real value of them, refer its &amp;#039;&amp;#039;value&amp;#039;&amp;#039; instance variable.&lt;br /&gt;
&lt;br /&gt;
== Exception ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you get thrown exception as some error. And On Error statement is used to catch it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub ErrorExample&lt;br /&gt;
&lt;br /&gt;
   On Error GoTo Handler&lt;br /&gt;
&lt;br /&gt;
   &amp;#039; ... error&lt;br /&gt;
&lt;br /&gt;
   Exit Sub&lt;br /&gt;
&lt;br /&gt;
   Handler: &lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
And you can not throw any exceptions from StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, the exception thrown in UNO world can be treated as normal Python&amp;#039;s exception. Here is an example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.container import IndexOutOfBoundsException&lt;br /&gt;
&lt;br /&gt;
 try:&lt;br /&gt;
     obj.getByIndex(100) # raises IndexOutOfBoundsException&lt;br /&gt;
 except IndexOutOfBoundsException as e:&lt;br /&gt;
     print(e)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If getByIndex method raises IndexOutOfBoundsException, it can be caught in except statement because all exceptions inherit Python&amp;#039;s Exception class.&lt;br /&gt;
&lt;br /&gt;
And also you can throw UNO&amp;#039;s exception from your Python code as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.uno import RuntimeException&lt;br /&gt;
 raise RuntimeException(&amp;quot;Some message&amp;quot;, None)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Empty Value ==&lt;br /&gt;
&lt;br /&gt;
In Basic, there are some situations to meet variables that they do not contain any value (this is not correct). Null, empty, missing, nothing and so on.&lt;br /&gt;
&lt;br /&gt;
In Python, None is used. If a method defined as void return value in its IDL, it results None if you call it. If you need to pass invalid interface as an argument for the method that takes some interface, pass None for it. The result of this behavior is fully dependent to the implementation of the method.&lt;br /&gt;
&lt;br /&gt;
== Listener and Interface ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can create new listener using CreateUnoListener runtime function with some subroutines or functions.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub Add&lt;br /&gt;
&lt;br /&gt;
   d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
   listener = CreateUnoListener(&amp;quot;ActionListener&amp;quot;, &amp;quot;com.sun.star.awt.XActionListener&amp;quot;)&lt;br /&gt;
   d.getControl(&amp;quot;CommandButton1&amp;quot;).addActionListener(listener)&lt;br /&gt;
   d.execute()&lt;br /&gt;
   d.dispose()&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 Sub ActionListener_actionPerformed(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 Sub ActionListener_disposing(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you have define your own class with desired interfaces. With helper class, you can define easily as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import unohelper&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt import XActionListener&lt;br /&gt;
&lt;br /&gt;
 class ActionListener(unohelper.Base, XActionListener):&lt;br /&gt;
     def __init__(self):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def disposing(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def actionPerformed(self, ev):&lt;br /&gt;
&lt;br /&gt;
         pass&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
unohelper.Base class provides required interface for UNO components.&lt;br /&gt;
&lt;br /&gt;
== Containers ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, container object provides the way to access to its contents in sequentially.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, there is no shortcut provided. &lt;br /&gt;
&lt;br /&gt;
If you need to access to elements of indexed container, use range function to generate sequential indexes.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 for i in range(container.getCount()):&lt;br /&gt;
     obj = container.getByIndex(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== URL and System Path ==&lt;br /&gt;
&lt;br /&gt;
If you work with a file stored in your local file system, you have to get its corresponding URL.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ConvertToURL runtime function is prepared for this task. And there is ConvertFromURL runtime function for reverse conversion.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following functions are defined in uno module for such task.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 path = &amp;quot;/home/foo/Documents/file.odt&amp;quot;&lt;br /&gt;
 url = uno.sytemPathToFileUrl(path)&lt;br /&gt;
 path = uno.fileUrlToSystemPath(url)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments and Return Value ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, mode of the first argument of parseStrict method is &amp;quot;inout&amp;quot; in the following code: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 aURL = CreateUnoStruct(&amp;quot;com.sun.star.util.URL&amp;quot;)&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 CreateUnoService(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;).parseStrict(aURL)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The content of aURL variable is updated after calling the method.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, out mode parameter is returned as part of return value.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.util import URL&lt;br /&gt;
&lt;br /&gt;
 aURL = URL()&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 dummy, aURL = smgr.createInstanceWithContext(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;, ctx).parseStrict(aURL)&lt;br /&gt;
 # Definition of com.sun.star.util.XURLTransformer::parseStrict method: &lt;br /&gt;
 # void parseStrict([inout] com.sun.star.util.URL aURL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If a method has out mode in its parameters, its return is always tuple that contains original return value and values for out parameters.&lt;br /&gt;
&lt;br /&gt;
Here is a potential example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # boolean getSomeValue([in] string aName, [out] short aNum, [inout] long aNum2);&lt;br /&gt;
 result, num, num2 = obj.getSomeValue(&amp;quot;foo&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above example, &amp;#039;&amp;#039;result&amp;#039;&amp;#039; variable takes original return value, &amp;#039;&amp;#039;num&amp;#039;&amp;#039; takes output value for second parameter and &amp;#039;&amp;#039;num2&amp;#039;&amp;#039; takes output value for third parameter. The method takes 100 as the second parameter but it is not used as input of value. No entry in returned tuple for in mode parameter.&lt;br /&gt;
&lt;br /&gt;
== Functions to be Executed ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can not choose routines to be executed by users.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, define &amp;#039;&amp;#039;&amp;#039;g_exportedScripts&amp;#039;&amp;#039;&amp;#039; variable that contains tuple of callable in your macro file.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def func_a(): pass&lt;br /&gt;
 def func_b(): pass&lt;br /&gt;
 def func_hidden(): pass # not shown in the UI&lt;br /&gt;
 &lt;br /&gt;
 g_exportedScripts = func_a, func_b&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above code, func_hidden is not shown in execution dialog of macros.&lt;br /&gt;
&lt;br /&gt;
== Importing Modules ==&lt;br /&gt;
&lt;br /&gt;
== Dialog ==&lt;br /&gt;
&lt;br /&gt;
== Message Box ==&lt;br /&gt;
&lt;br /&gt;
== Input Box ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231595</id>
		<title>Python/Transfer from Basic to Python</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Python/Transfer_from_Basic_to_Python&amp;diff=231595"/>
		<updated>2013-10-03T05:56:21Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add descriptions about macro location&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{DISPLAYTITLE:Transfer from Basic to Python}}&lt;br /&gt;
&lt;br /&gt;
Translation [[ES/Manuales/GuiaAOO/TemasAvanzados/Macros/Python/BasicAPython| Español]]&lt;br /&gt;
&lt;br /&gt;
If you feel some displeasure at StarBasic/OpenOffice Basic or you meet requirement of custom UNO component, now it is the time to transfer coding environment from Basic to Python.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, there are some runtime function provides shortcut to do something. But using Python-UNO bridge, you have to do such task by API ways.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s start with Python&amp;#039;s tutorial and return back to here when you have learned a bit about Python language.&lt;br /&gt;
&lt;br /&gt;
== Macro Location ==&lt;br /&gt;
On the current version, script organizer for Python do not provide the way to manage script files. So you have to manage yourself. Macros written in Python should be placed in the specific directory under your user&amp;#039;s profile, shared profile or script directory of your document.&lt;br /&gt;
&lt;br /&gt;
The python directory (in all lowercase) should be created in Scripts directory and you can put your python scripts that contain python code.&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
path_to_directory/Scripts/python/your_file.py&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can make subdirectories to put macro files in them under Scripts/python directory.&lt;br /&gt;
&lt;br /&gt;
== Macro Editor ==&lt;br /&gt;
&lt;br /&gt;
There is no built-in editor dedicated to code in Python. But you can choose your favorite text editor application to edit your Python script.&lt;br /&gt;
&lt;br /&gt;
This is discussed in another page.&lt;br /&gt;
&lt;br /&gt;
== Short Example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Usable Modules ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 import unohelper&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Script Context ==&lt;br /&gt;
&lt;br /&gt;
StarBasic is embedded runtime and it always works with living instance of the office. So the context is always the match with the office&amp;#039;s one. But Python-UNO bridge provides the way to work as RPC client. At that time, remote Python instance does have different context from the office instance. Therefore you have to use correct component context to tell to the multi component factory to instantiate a service.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you have no matching object provided.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039; macro, you have to use &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; module variable that provides &amp;lt;idl&amp;gt;com.sun.star.script.provider.XScriptContext&amp;lt;/idl&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XModel&amp;lt;/idl&amp;gt;&amp;#039;&amp;#039;&amp;#039;getDocument()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current document object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.document.XScriptInvocationContext&amp;lt;/idl&amp;gt;&amp;#039;&amp;#039;&amp;#039;getInvocationContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns invocation dependent object.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.frame.XDesktop&amp;lt;/idl&amp;gt;&amp;#039;&amp;#039;&amp;#039;getDesktop()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns instance of &amp;lt;idl&amp;gt;com.sun.star.frame.Desktop&amp;lt;/idl&amp;gt; service.&lt;br /&gt;
* &amp;lt;idl&amp;gt;com.sun.star.uno.XComponentContext&amp;lt;/idl&amp;gt;&amp;#039;&amp;#039;&amp;#039;getComponentContext()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:Returns current component context that is used to tell the which context is.&lt;br /&gt;
&lt;br /&gt;
Please keep in mind, &amp;#039;&amp;#039;&amp;#039;XSCRIPTCONTEXT&amp;#039;&amp;#039;&amp;#039; variable is defined in module level and it is not provided to imported modules from your script.&lt;br /&gt;
&lt;br /&gt;
== Component Context ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get component context as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = GetDefaultContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But you do not need to access to it until you need to get singletons.&lt;br /&gt;
&lt;br /&gt;
In Python, you can get access to the component context through the script context.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need this value to instantiate services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service Manager ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get service manager as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 smgr = GetProcessServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
But not so many people having to access to it.&lt;br /&gt;
&lt;br /&gt;
In Python, this instance is most important value to instantiate services to work with the office APIs.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need both the component context and the service manager to instantiate services.&lt;br /&gt;
&lt;br /&gt;
== Service Instance ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can instantiate services by built-in function as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 sfa = CreateUnoService(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or with initialize arguments: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 arg = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = CreateUnoServiceWithArguments(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, Array(arg))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Python, you have to work with com.sun.star.lang.XMultiComponentFactory interface as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ctx = XSCRIPTCONTEXT.getComponentContext()&lt;br /&gt;
 smgr = ctx.getServiceManager()&lt;br /&gt;
 sfa = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ucb.SimpleFileAccess&amp;quot;, ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you need to initialize the instance, use createInstanceWithArgumentsAndContext method: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE&lt;br /&gt;
 file_picker = smgr.createInstanceWithArgumentsAndContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, (FILESAVE_SIMPLE,) ctx)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
or initialize after the instantiation: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 file_picker = smgr.createInstanceWithContext(&amp;quot;com.sun.star.ui.dialogs.FilePicker&amp;quot;, ctx)&lt;br /&gt;
 file_picker.initialize((FILESAVE_SIMPLE,))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Service with Constructor ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can call service construct from its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 shell_execute = com.sun.star.system.SystemShellExecute.create()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In Python, you have to instantiate it with XMultiComponentFactory::createInstanceWithArgumentsAndContext method with initial arguments or instantiate after the instantiation.&lt;br /&gt;
&lt;br /&gt;
The constructor calling does type checking before to pass arguments to createInstanceWithArgumentsAndContext method.&lt;br /&gt;
&lt;br /&gt;
== Current Document ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ThisComponent runtime function provides access to the current document: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = ThisComponent&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Its return value is bound to the macro location. If the macro stored in a document, the result of ThisComponent is the document that the storage of the macro belongs to. And if your macro is stored in application wide, the returned value is the document model of currently active frame, this is the same result taken from StarDesktop.&amp;#039;&amp;#039;&amp;#039;getCurrentComponent()&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can access to the current document through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 doc = XSCRIPTCONTEXT.getDocument()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If your macro is &amp;#039;&amp;#039;&amp;#039;embedded in the document&amp;#039;&amp;#039;&amp;#039;, the document model is match with the document that the macro stored in. If your macro is stored in user or shared location, the document object is from active frame.&lt;br /&gt;
&lt;br /&gt;
== Desktop ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, StarDesktop runtime function is provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = StarDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can get access to the desktop through the script context: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 desktop = XSCRIPTCONTEXT.getDesktop()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Struct Instance ==&lt;br /&gt;
&lt;br /&gt;
In Basic, instance of struct can be instantiated in two ways: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Dim a As New com.sun.star.awt.Point&lt;br /&gt;
 a = CreateUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
With Dim statement and New keyword, you can instantiate a struct or array of structs. Or CreateUnoStruct method provides the way to instantiate a struct at runtime. You can not initialize the instance at the creation, you have to set its value of members.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you can use the following ways to instantiate a struct. Import struct class and call it.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.awt import Point&lt;br /&gt;
&lt;br /&gt;
 a = Point()         # instantiate with default values, X=0, Y=0&lt;br /&gt;
 b = Point(100, 200) # initialize with initial values, X=100, Y=200&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Calling the class to create new instance of the struct, you can empty its arguments or you have to pass values for all fields. In other words, you can not pass insufficient number of arguments to initialize. And its order should be match with definition of the struct in its IDL. For example, instance of struct b having X=100 and Y=200 in the above piece of code.&lt;br /&gt;
&lt;br /&gt;
You can initialize without to import the class of your target struct with uno.createUnoStruct function as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 a = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;)&lt;br /&gt;
 b = uno.createUnoStruct(&amp;quot;com.sun.star.awt.Point&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This makes the same result with the above example. The first parameter of the createUnoStruct method is the name of the struct to initialize. The following arguments are initial values for new instance.&lt;br /&gt;
&lt;br /&gt;
== Enum ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can access to the module of the enum as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 ITALIC = com.sun.star.awt.FontSlant.ITALIC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following ways can be used: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontSlant import ITALIC&lt;br /&gt;
 ITALIC = uno.getConstantByName(&amp;quot;com.sun.star.awt.FontSlant.ITALIC&amp;quot;)&lt;br /&gt;
 ITALIC = uno.Enum(&amp;quot;com.sun.star.awt.FontSlant&amp;quot;, &amp;quot;ITALIC&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
All of the way results the instance of uno.Enum class.&lt;br /&gt;
&lt;br /&gt;
== Constants ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can get access to constants through its module: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 BOLD = com.sun.star.awt.FontWeight.BOLD&lt;br /&gt;
&lt;br /&gt;
In Python, the following ways are provided: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt.FontWeight import BOLD&lt;br /&gt;
 BOLD = uno.getConstantsByName(&amp;quot;com.sun.star.awt.FontWeight.BOLD&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sequence ==&lt;br /&gt;
&lt;br /&gt;
The sequence is sequential value of the same type.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, array is used.&lt;br /&gt;
&lt;br /&gt;
In Python, tuple is chosen to represent UNO&amp;#039;s sequence. Note, list is not allowed to pass as sequence value.&lt;br /&gt;
&lt;br /&gt;
== Boolean ==&lt;br /&gt;
&lt;br /&gt;
In Python, True or False.&lt;br /&gt;
&lt;br /&gt;
== String ==&lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;s string can contain over 64K bytes.&lt;br /&gt;
&lt;br /&gt;
If you have to write non Ascii 7 bit characters in your script, write magic comment at the head of your file. This is standard Python instructions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # -*- coding: utf_8 -*-&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please read Python&amp;#039;s documentation for more detail.&lt;br /&gt;
&lt;br /&gt;
== Char ==&lt;br /&gt;
&lt;br /&gt;
There is no dedicated value for char type in StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, uno.Char class is defined for char type.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
 c = uno.Char(&amp;quot;a&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Byte Sequence ==&lt;br /&gt;
&lt;br /&gt;
The byte sequence is sequence of byte type.&lt;br /&gt;
&lt;br /&gt;
In Basic, array of byte is used to represent it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, it is represented by str wrapped by uno.ByteSequence class. If you takes some byte sequences from UNO, they are the instance of uno.ByteSequence. If you need to get real value of them, refer its &amp;#039;&amp;#039;value&amp;#039;&amp;#039; instance variable.&lt;br /&gt;
&lt;br /&gt;
== Exception ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you get thrown exception as some error. And On Error statement is used to catch it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub ErrorExample&lt;br /&gt;
&lt;br /&gt;
   On Error GoTo Handler&lt;br /&gt;
&lt;br /&gt;
   &amp;#039; ... error&lt;br /&gt;
&lt;br /&gt;
   Exit Sub&lt;br /&gt;
&lt;br /&gt;
   Handler: &lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
And you can not throw any exceptions from StarBasic.&lt;br /&gt;
&lt;br /&gt;
In Python, the exception thrown in UNO world can be treated as normal Python&amp;#039;s exception. Here is an example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.container import IndexOutOfBoundsException&lt;br /&gt;
&lt;br /&gt;
 try:&lt;br /&gt;
     obj.getByIndex(100) # raises IndexOutOfBoundsException&lt;br /&gt;
 except IndexOutOfBoundsException as e:&lt;br /&gt;
     print(e)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If getByIndex method raises IndexOutOfBoundsException, it can be caught in except statement because all exceptions inherit Python&amp;#039;s Exception class.&lt;br /&gt;
&lt;br /&gt;
And also you can throw UNO&amp;#039;s exception from your Python code as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.uno import RuntimeException&lt;br /&gt;
 raise RuntimeException(&amp;quot;Some message&amp;quot;, None)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Empty Value ==&lt;br /&gt;
&lt;br /&gt;
In Basic, there are some situations to meet variables that they do not contain any value (this is not correct). Null, empty, missing, nothing and so on.&lt;br /&gt;
&lt;br /&gt;
In Python, None is used. If a method defined as void return value in its IDL, it results None if you call it. If you need to pass invalid interface as an argument for the method that takes some interface, pass None for it. The result of this behavior is fully dependent to the implementation of the method.&lt;br /&gt;
&lt;br /&gt;
== Listener and Interface ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, you can create new listener using CreateUnoListener runtime function with some subroutines or functions.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 Sub Add&lt;br /&gt;
&lt;br /&gt;
   d = CreateUnoDialog(DialogLibraries.Standard.Dialog1)&lt;br /&gt;
   listener = CreateUnoListener(&amp;quot;ActionListener&amp;quot;, &amp;quot;com.sun.star.awt.XActionListener&amp;quot;)&lt;br /&gt;
   d.getControl(&amp;quot;CommandButton1&amp;quot;).addActionListener(listener)&lt;br /&gt;
   d.execute()&lt;br /&gt;
   d.dispose()&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 Sub ActionListener_actionPerformed(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 Sub ActionListener_disposing(ev)&lt;br /&gt;
&lt;br /&gt;
 End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, you have define your own class with desired interfaces. With helper class, you can define easily as follows: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import unohelper&lt;br /&gt;
&lt;br /&gt;
 from com.sun.star.awt import XActionListener&lt;br /&gt;
&lt;br /&gt;
 class ActionListener(unohelper.Base, XActionListener):&lt;br /&gt;
     def __init__(self):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def disposing(self, ev):&lt;br /&gt;
         pass&lt;br /&gt;
&lt;br /&gt;
     def actionPerformed(self, ev):&lt;br /&gt;
&lt;br /&gt;
         pass&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
unohelper.Base class provides required interface for UNO components.&lt;br /&gt;
&lt;br /&gt;
== Containers ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, container object provides the way to access to its contents in sequentially.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, there is no shortcut provided. &lt;br /&gt;
&lt;br /&gt;
If you need to access to elements of indexed container, use range function to generate sequential indexes.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 for i in range(container.getCount()):&lt;br /&gt;
     obj = container.getByIndex(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== URL and System Path ==&lt;br /&gt;
&lt;br /&gt;
If you work with a file stored in your local file system, you have to get its corresponding URL.&lt;br /&gt;
&lt;br /&gt;
In StarBasic, ConvertToURL runtime function is prepared for this task. And there is ConvertFromURL runtime function for reverse conversion.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, the following functions are defined in uno module for such task.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 import uno&lt;br /&gt;
&lt;br /&gt;
 path = &amp;quot;/home/foo/Documents/file.odt&amp;quot;&lt;br /&gt;
 url = uno.sytemPathToFileUrl(path)&lt;br /&gt;
 path = uno.fileUrlToSystemPath(url)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments and Return Value ==&lt;br /&gt;
&lt;br /&gt;
In StarBasic, mode of the first argument of parseStrict method is &amp;quot;inout&amp;quot; in the following code: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 aURL = CreateUnoStruct(&amp;quot;com.sun.star.util.URL&amp;quot;)&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 CreateUnoService(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;).parseStrict(aURL)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The content of aURL variable is updated after calling the method.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, out mode parameter is returned as part of return value.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 from com.sun.star.util import URL&lt;br /&gt;
&lt;br /&gt;
 aURL = URL()&lt;br /&gt;
 aURL.Complete = &amp;quot;.uno:Paste&amp;quot;&lt;br /&gt;
 dummy, aURL = smgr.createInstanceWithContext(&amp;quot;com.sun.star.util.URLTransformer&amp;quot;, ctx).parseStrict(aURL)&lt;br /&gt;
 # Definition of com.sun.star.util.XURLTransformer::parseStrict method: &lt;br /&gt;
 # void parseStrict([inout] com.sun.star.util.URL aURL);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If a method has out mode in its parameters, its return is always tuple that contains original return value and values for out parameters.&lt;br /&gt;
&lt;br /&gt;
Here is a potential example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 # boolean getSomeValue([in] string aName, [out] short aNum, [inout] long aNum2);&lt;br /&gt;
 result, num, num2 = obj.getSomeValue(&amp;quot;foo&amp;quot;, 100, 200)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above example, &amp;#039;&amp;#039;result&amp;#039;&amp;#039; variable takes original return value, &amp;#039;&amp;#039;num&amp;#039;&amp;#039; takes output value for second parameter and &amp;#039;&amp;#039;num2&amp;#039;&amp;#039; takes output value for third parameter. The method takes 100 as the second parameter but it is not used as input of value. No entry in returned tuple for in mode parameter.&lt;br /&gt;
&lt;br /&gt;
== Functions to be Executed ==&lt;br /&gt;
&lt;br /&gt;
In Basic, you can not choose routines to be executed by users.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;In Python&amp;#039;&amp;#039;&amp;#039;, define &amp;#039;&amp;#039;&amp;#039;g_exportedScripts&amp;#039;&amp;#039;&amp;#039; variable that contains tuple of callable in your macro file.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
 def func_a(): pass&lt;br /&gt;
 def func_b(): pass&lt;br /&gt;
 def func_hidden(): pass # not shown in the UI&lt;br /&gt;
 &lt;br /&gt;
 g_exportedScripts = func_a, func_b&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In the above code, func_hidden is not shown in execution dialog of macros.&lt;br /&gt;
&lt;br /&gt;
== Importing Modules ==&lt;br /&gt;
&lt;br /&gt;
== Dialog ==&lt;br /&gt;
&lt;br /&gt;
== Message Box ==&lt;br /&gt;
&lt;br /&gt;
== Input Box ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/API_Changes_on_4.0_since_3.4&amp;diff=229453</id>
		<title>User:Hanya/API Changes on 4.0 since 3.4</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/API_Changes_on_4.0_since_3.4&amp;diff=229453"/>
		<updated>2013-07-30T07:45:58Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add description about css.awt.ImageScaleMode&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There are some API changes applied to Apache OpenOffice 4.0 since version 3.4.&lt;br /&gt;
&lt;br /&gt;
== Impact ==&lt;br /&gt;
The impact of these changes are influence differently over your code.&lt;br /&gt;
* C++: recompilation required because of stlport removal. &lt;br /&gt;
* Java: should be migrated and recompiled.&lt;br /&gt;
* Basic or Python: should be migrated.&lt;br /&gt;
&lt;br /&gt;
== Message box ==&lt;br /&gt;
Message box APIs were cleaned up. See issue 121544.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMessageBoxFactory&lt;br /&gt;
** createMessageBox method&lt;br /&gt;
*** second argument that specifiy size of the box was removed, it was not used. &lt;br /&gt;
*** third argument that specify the type of the icon shown in the box is changed from string to com.sun.star.awt.MessageBoxType, see below.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMessageBox&lt;br /&gt;
** setCaptionText, getCaptionText, setMessageText, getMessageText methods were changed to corresponding attributes.&lt;br /&gt;
** return value of execute method was defined in com.sun.star.awt.MessageBoxResults, see below.&lt;br /&gt;
** No longer deprecated.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxType&lt;br /&gt;
** Member of this enumerated value can be used to specify type of the message box.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxResults&lt;br /&gt;
** Member of this constants group can be used to check the result of the execution of the message box. Renamed from MessageBoxCommand. And IGNORE member was added.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxCommand&lt;br /&gt;
** Renamed to MessageBoxResults.&lt;br /&gt;
&lt;br /&gt;
== Menu ==&lt;br /&gt;
Menu APIs were integrated. See issue 121542.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMenuBarExtended&lt;br /&gt;
** Integrated into other interfaces, this interface is used to integrate some menu interfaces without any methods.&lt;br /&gt;
* com.sun.star.awt.XMenuExtended&lt;br /&gt;
** getCommand, getCommand, setHelpCommand and getHelpCommmand methods are moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
* com.sun.star.awt.XMenuExtended2&lt;br /&gt;
** isPopupMenu, clear, getItemType, hideDisableEntries methods are moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
* com.sun.star.awt.XPopupMenuExtended&lt;br /&gt;
** isInExecute, endExecute, setAcceleratorKeyEvent, getAcceleratorKeyEvent, setItemImage and getItemImage methods were moved into com.sun.star.awt.XPopupMenu interface.&lt;br /&gt;
** setHelpText, getHelpText, setTipHelpText and getTipHelpText methods were moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
** setItemImageAngle, getItemImageAngle, setItemImageMirrorMode and isItemImageInMirrorMode methods were removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XPopupMenu&lt;br /&gt;
** Some methods were moved from each interfaces described above to this interface.&lt;br /&gt;
* com.sun.star.awt.XMenu&lt;br /&gt;
** Some methods were moved from each interfaces to this interface.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMenuListener&lt;br /&gt;
** The following method names were changed.&lt;br /&gt;
*** highlight -&amp;gt; itemHighlighted&lt;br /&gt;
*** select -&amp;gt; itemSelected&lt;br /&gt;
*** activate -&amp;gt; itemActivated&lt;br /&gt;
*** deactivate -&amp;gt; itemDeactivated&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MenuItemStyle&lt;br /&gt;
** Unpublished, no changes in the members.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.PopupMenuDirection&lt;br /&gt;
** deprecated members were removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MenuLogo&lt;br /&gt;
** Removed. See issue 121542.&lt;br /&gt;
&lt;br /&gt;
== Controls ==&lt;br /&gt;
com.sun.star.awt.UnoControlThrobberModel was replaced with com.sun.star.awt.SpinningProgressControlModel. See issue 121513.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.UnoControlThrobber&lt;br /&gt;
* com.sun.star.awt.UnoControlThrobberModel&lt;br /&gt;
* com.sun.star.awt.XThrobber&lt;br /&gt;
** Please use com.sun.star.awt.AnimatedImagesControl control with com.sun.star.awt.SpinningProgressControlModel.&lt;br /&gt;
&lt;br /&gt;
com.sun.star.awt.UnoControlSimpleAnimation control was replaced with com.sun.star.awt.AnimatedImagesControl.&lt;br /&gt;
* com.sun.star.awt.UnoControlSimpleAnimation&lt;br /&gt;
* com.sun.star.awt.UnoControlSimpleAnimationModel&lt;br /&gt;
* com.sun.star.awt.XSimpleAnimation&lt;br /&gt;
** Please use com.sun.star.awt.AnimatedImagesControl. issue 121514.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.awt Module ==&lt;br /&gt;
Graphics APIs were cleaned up. See issue 121442.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XGraphics&lt;br /&gt;
** getDevice, getFontMetric, setFont, setTextColor, setTextFillColor, setLineColor, setFillColor, setRasterOp methods were changed to corresponding attributes.&lt;br /&gt;
** clear and drawImage methods were added.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.ImageDrawMode&lt;br /&gt;
** Added. Constants are used to specify the mode in com.sun.star.awt.XGraphics::drawImage method.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.ImageScaleMode&lt;br /&gt;
** Member names were corrected to be uppercase.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.PrinterServer&lt;br /&gt;
** This service was converted into new style service with constructor.&lt;br /&gt;
&lt;br /&gt;
== System ==&lt;br /&gt;
&lt;br /&gt;
Clean-up system mail API. See issue 121579.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.SimpleCommandMail&lt;br /&gt;
* com.sun.star.system.SimpleMailClientFlags&lt;br /&gt;
* com.sun.star.system.SimpleSystemMail&lt;br /&gt;
* com.sun.star.system.XMailClient&lt;br /&gt;
* com.sun.star.system.XMailMessage&lt;br /&gt;
* com.sun.star.system.XSimpleMailClient&lt;br /&gt;
* com.sun.star.system.XSimpleMailClientSupplier&lt;br /&gt;
* com.sun.star.system.XSimpleMailMessage&lt;br /&gt;
* com.sun.star.system.XSystemMailProvider&lt;br /&gt;
* com.sun.star.system.SimpleMailClientFlags&lt;br /&gt;
** Removed. See below.&lt;br /&gt;
* com.sun.star.system.SystemMailProvider&lt;br /&gt;
** System dependent mail services were integrated into com.sun.star.system.SystemMailProvider.&lt;br /&gt;
Remove deprecated system proxy API. See issue 121548.&lt;br /&gt;
* com.sun.star.system.MailClientFlags&lt;br /&gt;
** Renamed from SimpleMailClientFlags.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.ProxySettings&lt;br /&gt;
* com.sun.star.system.XProxySettings&lt;br /&gt;
* com.sun.star.system.SystemProxySettings&lt;br /&gt;
* com.sun.star.system.SOffice52ProxySettings&lt;br /&gt;
** No longer used, removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.SystemShellExecute&lt;br /&gt;
** This service was converted to new style service with a constructor.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.text Module ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.text.AutoTextGroup&lt;br /&gt;
** FilePath and Title properties were added for documenting. See issue 87780.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.text.ViewSettings&lt;br /&gt;
** ShowContentTips and ShowScrollBarTips properties were added. See issue 25945.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.frame Module ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.PopupMenuControllerFactory&lt;br /&gt;
* com.sun.star.frame.StatusbarControllerFactory&lt;br /&gt;
** These services were converted to new style service with constructors.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.ToolbarControllerFactory&lt;br /&gt;
* com.sun.star.frame.XUIControllerFactory&lt;br /&gt;
** Added.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.XStatusbarController&lt;br /&gt;
** click and doubleClick methods takes an argument.&lt;br /&gt;
&lt;br /&gt;
== Sidebar ==&lt;br /&gt;
See issue 121420.&lt;br /&gt;
* com.sun.star.ui.ContextChangeEventMultiplexer&lt;br /&gt;
* com.sun.star.ui.ContextChangeEventObject&lt;br /&gt;
* com.sun.star.ui.XContextChangeEventMultiplexer&lt;br /&gt;
* com.sun.star.ui.XContextChangeEventListener&lt;br /&gt;
* com.sun.star.ui.XSidebar&lt;br /&gt;
* com.sun.star.ui.XSidebarPanel&lt;br /&gt;
* com.sun.star.ui.LayoutSize&lt;br /&gt;
* com.sun.star.util.EventMultiplexer&lt;br /&gt;
** Added. They are used in the sidebar.&lt;br /&gt;
&lt;br /&gt;
== UCB ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ucb.Content&lt;br /&gt;
** addProperty and removeProperty commands were added. See issue 121935.&lt;br /&gt;
* com.sun.star.ucb.PropertyCommandArgument&lt;br /&gt;
** Added. Argument for the new commands.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ucb.XWebDAVCommandEnvironment&lt;br /&gt;
** Request method is specified by WebDAVHTTPMethod, see below.&lt;br /&gt;
* com.sun.star.ucb.WebDAVHTTPMethod&lt;br /&gt;
** Added. Request methods were defined in WebDAVHTTPMethod.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== SmartTag ==&lt;br /&gt;
&lt;br /&gt;
Make smarttag function more powrful.&lt;br /&gt;
&lt;br /&gt;
See issue 121391, 121730, 121731, 121732, 121733, 121734 and http://mail-archives.apache.org/mod_mbox/openoffice-dev/201302.mbox/browser .&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.smarttags.XRangeBasedSmartTagRecognizer&lt;br /&gt;
** Added.&lt;br /&gt;
* com.sun.star.smarttags.XSmartTagAction&lt;br /&gt;
** getActionCount method takes additional parameter.&lt;br /&gt;
* com.sun.star.text.XMarkingAccess&lt;br /&gt;
* com.sun.star.container.XNamedEx&lt;br /&gt;
** Added.&lt;br /&gt;
* com.sun.star.text.XTextMarkup&lt;br /&gt;
** commitTextMarkup method was renamed to commitStringMarkup&lt;br /&gt;
** commitTextRangeMarkup method was added.&lt;br /&gt;
&lt;br /&gt;
== Calc ==&lt;br /&gt;
See issue 120478.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.sheet.XNamedRange2&lt;br /&gt;
* com.sun.star.sheet.XNamedRanges2&lt;br /&gt;
* com.sun.star.sheet.RangeScopeName&lt;br /&gt;
** Added.&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.configuration.BootstrapContext&lt;br /&gt;
** Deprecated. See issue 118815.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ui.XStatusbarItem&lt;br /&gt;
** Added. See issue 121442.&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/API_Changes_on_4.0_since_3.4&amp;diff=229452</id>
		<title>User:Hanya/API Changes on 4.0 since 3.4</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/API_Changes_on_4.0_since_3.4&amp;diff=229452"/>
		<updated>2013-07-30T07:44:14Z</updated>

		<summary type="html">&lt;p&gt;Hanya: /* Other com.sun.star.awt Module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There are some API changes applied to Apache OpenOffice 4.0 since version 3.4.&lt;br /&gt;
&lt;br /&gt;
== Impact ==&lt;br /&gt;
The impact of these changes are influence differently over your code.&lt;br /&gt;
* C++: recompilation required because of stlport removal. &lt;br /&gt;
* Java: should be migrated and recompiled.&lt;br /&gt;
* Basic or Python: should be migrated.&lt;br /&gt;
&lt;br /&gt;
== Message box ==&lt;br /&gt;
Message box APIs were cleaned up. See issue 121544.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMessageBoxFactory&lt;br /&gt;
** createMessageBox method&lt;br /&gt;
*** second argument that specifiy size of the box was removed, it was not used. &lt;br /&gt;
*** third argument that specify the type of the icon shown in the box is changed from string to com.sun.star.awt.MessageBoxType, see below.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMessageBox&lt;br /&gt;
** setCaptionText, getCaptionText, setMessageText, getMessageText methods were changed to corresponding attributes.&lt;br /&gt;
** return value of execute method was defined in com.sun.star.awt.MessageBoxResults, see below.&lt;br /&gt;
** No longer deprecated.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxType&lt;br /&gt;
** Member of this enumerated value can be used to specify type of the message box.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxResults&lt;br /&gt;
** Member of this constants group can be used to check the result of the execution of the message box. Renamed from MessageBoxCommand. And IGNORE member was added.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxCommand&lt;br /&gt;
** Renamed to MessageBoxResults.&lt;br /&gt;
&lt;br /&gt;
== Menu ==&lt;br /&gt;
Menu APIs were integrated. See issue 121542.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMenuBarExtended&lt;br /&gt;
** Integrated into other interfaces, this interface is used to integrate some menu interfaces without any methods.&lt;br /&gt;
* com.sun.star.awt.XMenuExtended&lt;br /&gt;
** getCommand, getCommand, setHelpCommand and getHelpCommmand methods are moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
* com.sun.star.awt.XMenuExtended2&lt;br /&gt;
** isPopupMenu, clear, getItemType, hideDisableEntries methods are moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
* com.sun.star.awt.XPopupMenuExtended&lt;br /&gt;
** isInExecute, endExecute, setAcceleratorKeyEvent, getAcceleratorKeyEvent, setItemImage and getItemImage methods were moved into com.sun.star.awt.XPopupMenu interface.&lt;br /&gt;
** setHelpText, getHelpText, setTipHelpText and getTipHelpText methods were moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
** setItemImageAngle, getItemImageAngle, setItemImageMirrorMode and isItemImageInMirrorMode methods were removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XPopupMenu&lt;br /&gt;
** Some methods were moved from each interfaces described above to this interface.&lt;br /&gt;
* com.sun.star.awt.XMenu&lt;br /&gt;
** Some methods were moved from each interfaces to this interface.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMenuListener&lt;br /&gt;
** The following method names were changed.&lt;br /&gt;
*** highlight -&amp;gt; itemHighlighted&lt;br /&gt;
*** select -&amp;gt; itemSelected&lt;br /&gt;
*** activate -&amp;gt; itemActivated&lt;br /&gt;
*** deactivate -&amp;gt; itemDeactivated&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MenuItemStyle&lt;br /&gt;
** Unpublished, no changes in the members.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.PopupMenuDirection&lt;br /&gt;
** deprecated members were removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MenuLogo&lt;br /&gt;
** Removed. See issue 121542.&lt;br /&gt;
&lt;br /&gt;
== Controls ==&lt;br /&gt;
com.sun.star.awt.UnoControlThrobberModel was replaced with com.sun.star.awt.SpinningProgressControlModel. See issue 121513.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.UnoControlThrobber&lt;br /&gt;
* com.sun.star.awt.UnoControlThrobberModel&lt;br /&gt;
* com.sun.star.awt.XThrobber&lt;br /&gt;
** Please use com.sun.star.awt.AnimatedImagesControl control with com.sun.star.awt.SpinningProgressControlModel.&lt;br /&gt;
&lt;br /&gt;
com.sun.star.awt.UnoControlSimpleAnimation control was replaced with com.sun.star.awt.AnimatedImagesControl.&lt;br /&gt;
* com.sun.star.awt.UnoControlSimpleAnimation&lt;br /&gt;
* com.sun.star.awt.UnoControlSimpleAnimationModel&lt;br /&gt;
* com.sun.star.awt.XSimpleAnimation&lt;br /&gt;
** Please use com.sun.star.awt.AnimatedImagesControl. issue 121514.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.awt Module ==&lt;br /&gt;
Graphics APIs were cleaned up. See issue 121442.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XGraphics&lt;br /&gt;
** getDevice, getFontMetric, setFont, setTextColor, setTextFillColor, setLineColor, setFillColor, setRasterOp methods were changed to corresponding attributes.&lt;br /&gt;
** clear and drawImage methods were added.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.ImageDrawMode&lt;br /&gt;
** Added. Constants are used to specify the mode in com.sun.star.awt.XGraphics::drawImage method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.PrinterServer&lt;br /&gt;
** This service was converted into new style service with constructor.&lt;br /&gt;
&lt;br /&gt;
== System ==&lt;br /&gt;
&lt;br /&gt;
Clean-up system mail API. See issue 121579.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.SimpleCommandMail&lt;br /&gt;
* com.sun.star.system.SimpleMailClientFlags&lt;br /&gt;
* com.sun.star.system.SimpleSystemMail&lt;br /&gt;
* com.sun.star.system.XMailClient&lt;br /&gt;
* com.sun.star.system.XMailMessage&lt;br /&gt;
* com.sun.star.system.XSimpleMailClient&lt;br /&gt;
* com.sun.star.system.XSimpleMailClientSupplier&lt;br /&gt;
* com.sun.star.system.XSimpleMailMessage&lt;br /&gt;
* com.sun.star.system.XSystemMailProvider&lt;br /&gt;
* com.sun.star.system.SimpleMailClientFlags&lt;br /&gt;
** Removed. See below.&lt;br /&gt;
* com.sun.star.system.SystemMailProvider&lt;br /&gt;
** System dependent mail services were integrated into com.sun.star.system.SystemMailProvider.&lt;br /&gt;
Remove deprecated system proxy API. See issue 121548.&lt;br /&gt;
* com.sun.star.system.MailClientFlags&lt;br /&gt;
** Renamed from SimpleMailClientFlags.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.ProxySettings&lt;br /&gt;
* com.sun.star.system.XProxySettings&lt;br /&gt;
* com.sun.star.system.SystemProxySettings&lt;br /&gt;
* com.sun.star.system.SOffice52ProxySettings&lt;br /&gt;
** No longer used, removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.SystemShellExecute&lt;br /&gt;
** This service was converted to new style service with a constructor.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.text Module ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.text.AutoTextGroup&lt;br /&gt;
** FilePath and Title properties were added for documenting. See issue 87780.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.text.ViewSettings&lt;br /&gt;
** ShowContentTips and ShowScrollBarTips properties were added. See issue 25945.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.frame Module ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.PopupMenuControllerFactory&lt;br /&gt;
* com.sun.star.frame.StatusbarControllerFactory&lt;br /&gt;
** These services were converted to new style service with constructors.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.ToolbarControllerFactory&lt;br /&gt;
* com.sun.star.frame.XUIControllerFactory&lt;br /&gt;
** Added.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.XStatusbarController&lt;br /&gt;
** click and doubleClick methods takes an argument.&lt;br /&gt;
&lt;br /&gt;
== Sidebar ==&lt;br /&gt;
See issue 121420.&lt;br /&gt;
* com.sun.star.ui.ContextChangeEventMultiplexer&lt;br /&gt;
* com.sun.star.ui.ContextChangeEventObject&lt;br /&gt;
* com.sun.star.ui.XContextChangeEventMultiplexer&lt;br /&gt;
* com.sun.star.ui.XContextChangeEventListener&lt;br /&gt;
* com.sun.star.ui.XSidebar&lt;br /&gt;
* com.sun.star.ui.XSidebarPanel&lt;br /&gt;
* com.sun.star.ui.LayoutSize&lt;br /&gt;
* com.sun.star.util.EventMultiplexer&lt;br /&gt;
** Added. They are used in the sidebar.&lt;br /&gt;
&lt;br /&gt;
== UCB ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ucb.Content&lt;br /&gt;
** addProperty and removeProperty commands were added. See issue 121935.&lt;br /&gt;
* com.sun.star.ucb.PropertyCommandArgument&lt;br /&gt;
** Added. Argument for the new commands.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ucb.XWebDAVCommandEnvironment&lt;br /&gt;
** Request method is specified by WebDAVHTTPMethod, see below.&lt;br /&gt;
* com.sun.star.ucb.WebDAVHTTPMethod&lt;br /&gt;
** Added. Request methods were defined in WebDAVHTTPMethod.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== SmartTag ==&lt;br /&gt;
&lt;br /&gt;
Make smarttag function more powrful.&lt;br /&gt;
&lt;br /&gt;
See issue 121391, 121730, 121731, 121732, 121733, 121734 and http://mail-archives.apache.org/mod_mbox/openoffice-dev/201302.mbox/browser .&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.smarttags.XRangeBasedSmartTagRecognizer&lt;br /&gt;
** Added.&lt;br /&gt;
* com.sun.star.smarttags.XSmartTagAction&lt;br /&gt;
** getActionCount method takes additional parameter.&lt;br /&gt;
* com.sun.star.text.XMarkingAccess&lt;br /&gt;
* com.sun.star.container.XNamedEx&lt;br /&gt;
** Added.&lt;br /&gt;
* com.sun.star.text.XTextMarkup&lt;br /&gt;
** commitTextMarkup method was renamed to commitStringMarkup&lt;br /&gt;
** commitTextRangeMarkup method was added.&lt;br /&gt;
&lt;br /&gt;
== Calc ==&lt;br /&gt;
See issue 120478.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.sheet.XNamedRange2&lt;br /&gt;
* com.sun.star.sheet.XNamedRanges2&lt;br /&gt;
* com.sun.star.sheet.RangeScopeName&lt;br /&gt;
** Added.&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.configuration.BootstrapContext&lt;br /&gt;
** Deprecated. See issue 118815.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ui.XStatusbarItem&lt;br /&gt;
** Added. See issue 121442.&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/API_Changes_on_4.0_since_3.4&amp;diff=229451</id>
		<title>User:Hanya/API Changes on 4.0 since 3.4</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/API_Changes_on_4.0_since_3.4&amp;diff=229451"/>
		<updated>2013-07-30T07:43:03Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add description about css.frame.XStatusbarController&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There are some API changes applied to Apache OpenOffice 4.0 since version 3.4.&lt;br /&gt;
&lt;br /&gt;
== Impact ==&lt;br /&gt;
The impact of these changes are influence differently over your code.&lt;br /&gt;
* C++: recompilation required because of stlport removal. &lt;br /&gt;
* Java: should be migrated and recompiled.&lt;br /&gt;
* Basic or Python: should be migrated.&lt;br /&gt;
&lt;br /&gt;
== Message box ==&lt;br /&gt;
Message box APIs were cleaned up. See issue 121544.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMessageBoxFactory&lt;br /&gt;
** createMessageBox method&lt;br /&gt;
*** second argument that specifiy size of the box was removed, it was not used. &lt;br /&gt;
*** third argument that specify the type of the icon shown in the box is changed from string to com.sun.star.awt.MessageBoxType, see below.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMessageBox&lt;br /&gt;
** setCaptionText, getCaptionText, setMessageText, getMessageText methods were changed to corresponding attributes.&lt;br /&gt;
** return value of execute method was defined in com.sun.star.awt.MessageBoxResults, see below.&lt;br /&gt;
** No longer deprecated.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxType&lt;br /&gt;
** Member of this enumerated value can be used to specify type of the message box.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxResults&lt;br /&gt;
** Member of this constants group can be used to check the result of the execution of the message box. Renamed from MessageBoxCommand. And IGNORE member was added.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxCommand&lt;br /&gt;
** Renamed to MessageBoxResults.&lt;br /&gt;
&lt;br /&gt;
== Menu ==&lt;br /&gt;
Menu APIs were integrated. See issue 121542.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMenuBarExtended&lt;br /&gt;
** Integrated into other interfaces, this interface is used to integrate some menu interfaces without any methods.&lt;br /&gt;
* com.sun.star.awt.XMenuExtended&lt;br /&gt;
** getCommand, getCommand, setHelpCommand and getHelpCommmand methods are moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
* com.sun.star.awt.XMenuExtended2&lt;br /&gt;
** isPopupMenu, clear, getItemType, hideDisableEntries methods are moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
* com.sun.star.awt.XPopupMenuExtended&lt;br /&gt;
** isInExecute, endExecute, setAcceleratorKeyEvent, getAcceleratorKeyEvent, setItemImage and getItemImage methods were moved into com.sun.star.awt.XPopupMenu interface.&lt;br /&gt;
** setHelpText, getHelpText, setTipHelpText and getTipHelpText methods were moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
** setItemImageAngle, getItemImageAngle, setItemImageMirrorMode and isItemImageInMirrorMode methods were removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XPopupMenu&lt;br /&gt;
** Some methods were moved from each interfaces described above to this interface.&lt;br /&gt;
* com.sun.star.awt.XMenu&lt;br /&gt;
** Some methods were moved from each interfaces to this interface.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMenuListener&lt;br /&gt;
** The following method names were changed.&lt;br /&gt;
*** highlight -&amp;gt; itemHighlighted&lt;br /&gt;
*** select -&amp;gt; itemSelected&lt;br /&gt;
*** activate -&amp;gt; itemActivated&lt;br /&gt;
*** deactivate -&amp;gt; itemDeactivated&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MenuItemStyle&lt;br /&gt;
** Unpublished, no changes in the members.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.PopupMenuDirection&lt;br /&gt;
** deprecated members were removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MenuLogo&lt;br /&gt;
** Removed. See issue 121542.&lt;br /&gt;
&lt;br /&gt;
== Controls ==&lt;br /&gt;
com.sun.star.awt.UnoControlThrobberModel was replaced with com.sun.star.awt.SpinningProgressControlModel. See issue 121513.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.UnoControlThrobber&lt;br /&gt;
* com.sun.star.awt.UnoControlThrobberModel&lt;br /&gt;
* com.sun.star.awt.XThrobber&lt;br /&gt;
** Please use com.sun.star.awt.AnimatedImagesControl control with com.sun.star.awt.SpinningProgressControlModel.&lt;br /&gt;
&lt;br /&gt;
com.sun.star.awt.UnoControlSimpleAnimation control was replaced with com.sun.star.awt.AnimatedImagesControl.&lt;br /&gt;
* com.sun.star.awt.UnoControlSimpleAnimation&lt;br /&gt;
* com.sun.star.awt.UnoControlSimpleAnimationModel&lt;br /&gt;
* com.sun.star.awt.XSimpleAnimation&lt;br /&gt;
** Please use com.sun.star.awt.AnimatedImagesControl. issue 121514.&lt;br /&gt;
&lt;br /&gt;
== Other com.sun.star.awt Module ==&lt;br /&gt;
Graphics APIs were cleaned up. See issue 121442.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XGraphics&lt;br /&gt;
** getDevice, getFontMetric, setFont, setTextColor, setTextFillColor, setLineColor, setFillColor, setRasterOp methods were changed to corresponding attributes.&lt;br /&gt;
** clear and drawImage methods were added.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.ImageDrawMode&lt;br /&gt;
** Added. Constants are used to specify the mode in com.sun.star.awt.XGraphics::drawImage method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.PrinterServer&lt;br /&gt;
** This service was converted into new style service with constructor.&lt;br /&gt;
&lt;br /&gt;
== System ==&lt;br /&gt;
&lt;br /&gt;
Clean-up system mail API. See issue 121579.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.SimpleCommandMail&lt;br /&gt;
* com.sun.star.system.SimpleMailClientFlags&lt;br /&gt;
* com.sun.star.system.SimpleSystemMail&lt;br /&gt;
* com.sun.star.system.XMailClient&lt;br /&gt;
* com.sun.star.system.XMailMessage&lt;br /&gt;
* com.sun.star.system.XSimpleMailClient&lt;br /&gt;
* com.sun.star.system.XSimpleMailClientSupplier&lt;br /&gt;
* com.sun.star.system.XSimpleMailMessage&lt;br /&gt;
* com.sun.star.system.XSystemMailProvider&lt;br /&gt;
* com.sun.star.system.SimpleMailClientFlags&lt;br /&gt;
** Removed. See below.&lt;br /&gt;
* com.sun.star.system.SystemMailProvider&lt;br /&gt;
** System dependent mail services were integrated into com.sun.star.system.SystemMailProvider.&lt;br /&gt;
Remove deprecated system proxy API. See issue 121548.&lt;br /&gt;
* com.sun.star.system.MailClientFlags&lt;br /&gt;
** Renamed from SimpleMailClientFlags.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.ProxySettings&lt;br /&gt;
* com.sun.star.system.XProxySettings&lt;br /&gt;
* com.sun.star.system.SystemProxySettings&lt;br /&gt;
* com.sun.star.system.SOffice52ProxySettings&lt;br /&gt;
** No longer used, removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.SystemShellExecute&lt;br /&gt;
** This service was converted to new style service with a constructor.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.text Module ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.text.AutoTextGroup&lt;br /&gt;
** FilePath and Title properties were added for documenting. See issue 87780.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.text.ViewSettings&lt;br /&gt;
** ShowContentTips and ShowScrollBarTips properties were added. See issue 25945.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.frame Module ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.PopupMenuControllerFactory&lt;br /&gt;
* com.sun.star.frame.StatusbarControllerFactory&lt;br /&gt;
** These services were converted to new style service with constructors.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.ToolbarControllerFactory&lt;br /&gt;
* com.sun.star.frame.XUIControllerFactory&lt;br /&gt;
** Added.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.XStatusbarController&lt;br /&gt;
** click and doubleClick methods takes an argument.&lt;br /&gt;
&lt;br /&gt;
== Sidebar ==&lt;br /&gt;
See issue 121420.&lt;br /&gt;
* com.sun.star.ui.ContextChangeEventMultiplexer&lt;br /&gt;
* com.sun.star.ui.ContextChangeEventObject&lt;br /&gt;
* com.sun.star.ui.XContextChangeEventMultiplexer&lt;br /&gt;
* com.sun.star.ui.XContextChangeEventListener&lt;br /&gt;
* com.sun.star.ui.XSidebar&lt;br /&gt;
* com.sun.star.ui.XSidebarPanel&lt;br /&gt;
* com.sun.star.ui.LayoutSize&lt;br /&gt;
* com.sun.star.util.EventMultiplexer&lt;br /&gt;
** Added. They are used in the sidebar.&lt;br /&gt;
&lt;br /&gt;
== UCB ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ucb.Content&lt;br /&gt;
** addProperty and removeProperty commands were added. See issue 121935.&lt;br /&gt;
* com.sun.star.ucb.PropertyCommandArgument&lt;br /&gt;
** Added. Argument for the new commands.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ucb.XWebDAVCommandEnvironment&lt;br /&gt;
** Request method is specified by WebDAVHTTPMethod, see below.&lt;br /&gt;
* com.sun.star.ucb.WebDAVHTTPMethod&lt;br /&gt;
** Added. Request methods were defined in WebDAVHTTPMethod.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== SmartTag ==&lt;br /&gt;
&lt;br /&gt;
Make smarttag function more powrful.&lt;br /&gt;
&lt;br /&gt;
See issue 121391, 121730, 121731, 121732, 121733, 121734 and http://mail-archives.apache.org/mod_mbox/openoffice-dev/201302.mbox/browser .&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.smarttags.XRangeBasedSmartTagRecognizer&lt;br /&gt;
** Added.&lt;br /&gt;
* com.sun.star.smarttags.XSmartTagAction&lt;br /&gt;
** getActionCount method takes additional parameter.&lt;br /&gt;
* com.sun.star.text.XMarkingAccess&lt;br /&gt;
* com.sun.star.container.XNamedEx&lt;br /&gt;
** Added.&lt;br /&gt;
* com.sun.star.text.XTextMarkup&lt;br /&gt;
** commitTextMarkup method was renamed to commitStringMarkup&lt;br /&gt;
** commitTextRangeMarkup method was added.&lt;br /&gt;
&lt;br /&gt;
== Calc ==&lt;br /&gt;
See issue 120478.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.sheet.XNamedRange2&lt;br /&gt;
* com.sun.star.sheet.XNamedRanges2&lt;br /&gt;
* com.sun.star.sheet.RangeScopeName&lt;br /&gt;
** Added.&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.configuration.BootstrapContext&lt;br /&gt;
** Deprecated. See issue 118815.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ui.XStatusbarItem&lt;br /&gt;
** Added. See issue 121442.&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/API_Changes_on_4.0_since_3.4&amp;diff=229450</id>
		<title>User:Hanya/API Changes on 4.0 since 3.4</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/API_Changes_on_4.0_since_3.4&amp;diff=229450"/>
		<updated>2013-07-30T07:20:57Z</updated>

		<summary type="html">&lt;p&gt;Hanya: /* Menu */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There are some API changes applied to Apache OpenOffice 4.0 since version 3.4.&lt;br /&gt;
&lt;br /&gt;
== Impact ==&lt;br /&gt;
The impact of these changes are influence differently over your code.&lt;br /&gt;
* C++: recompilation required because of stlport removal. &lt;br /&gt;
* Java: should be migrated and recompiled.&lt;br /&gt;
* Basic or Python: should be migrated.&lt;br /&gt;
&lt;br /&gt;
== Message box ==&lt;br /&gt;
Message box APIs were cleaned up. See issue 121544.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMessageBoxFactory&lt;br /&gt;
** createMessageBox method&lt;br /&gt;
*** second argument that specifiy size of the box was removed, it was not used. &lt;br /&gt;
*** third argument that specify the type of the icon shown in the box is changed from string to com.sun.star.awt.MessageBoxType, see below.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMessageBox&lt;br /&gt;
** setCaptionText, getCaptionText, setMessageText, getMessageText methods were changed to corresponding attributes.&lt;br /&gt;
** return value of execute method was defined in com.sun.star.awt.MessageBoxResults, see below.&lt;br /&gt;
** No longer deprecated.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxType&lt;br /&gt;
** Member of this enumerated value can be used to specify type of the message box.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxResults&lt;br /&gt;
** Member of this constants group can be used to check the result of the execution of the message box. Renamed from MessageBoxCommand. And IGNORE member was added.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxCommand&lt;br /&gt;
** Renamed to MessageBoxResults.&lt;br /&gt;
&lt;br /&gt;
== Menu ==&lt;br /&gt;
Menu APIs were integrated. See issue 121542.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMenuBarExtended&lt;br /&gt;
** Integrated into other interfaces, this interface is used to integrate some menu interfaces without any methods.&lt;br /&gt;
* com.sun.star.awt.XMenuExtended&lt;br /&gt;
** getCommand, getCommand, setHelpCommand and getHelpCommmand methods are moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
* com.sun.star.awt.XMenuExtended2&lt;br /&gt;
** isPopupMenu, clear, getItemType, hideDisableEntries methods are moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
* com.sun.star.awt.XPopupMenuExtended&lt;br /&gt;
** isInExecute, endExecute, setAcceleratorKeyEvent, getAcceleratorKeyEvent, setItemImage and getItemImage methods were moved into com.sun.star.awt.XPopupMenu interface.&lt;br /&gt;
** setHelpText, getHelpText, setTipHelpText and getTipHelpText methods were moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
** setItemImageAngle, getItemImageAngle, setItemImageMirrorMode and isItemImageInMirrorMode methods were removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XPopupMenu&lt;br /&gt;
** Some methods were moved from each interfaces described above to this interface.&lt;br /&gt;
* com.sun.star.awt.XMenu&lt;br /&gt;
** Some methods were moved from each interfaces to this interface.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMenuListener&lt;br /&gt;
** The following method names were changed.&lt;br /&gt;
*** highlight -&amp;gt; itemHighlighted&lt;br /&gt;
*** select -&amp;gt; itemSelected&lt;br /&gt;
*** activate -&amp;gt; itemActivated&lt;br /&gt;
*** deactivate -&amp;gt; itemDeactivated&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MenuItemStyle&lt;br /&gt;
** Unpublished, no changes in the members.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.PopupMenuDirection&lt;br /&gt;
** deprecated members were removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MenuLogo&lt;br /&gt;
** Removed. See issue 121542.&lt;br /&gt;
&lt;br /&gt;
== Controls ==&lt;br /&gt;
com.sun.star.awt.UnoControlThrobberModel was replaced with com.sun.star.awt.SpinningProgressControlModel. See issue 121513.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.UnoControlThrobber&lt;br /&gt;
* com.sun.star.awt.UnoControlThrobberModel&lt;br /&gt;
* com.sun.star.awt.XThrobber&lt;br /&gt;
** Please use com.sun.star.awt.AnimatedImagesControl control with com.sun.star.awt.SpinningProgressControlModel.&lt;br /&gt;
&lt;br /&gt;
com.sun.star.awt.UnoControlSimpleAnimation control was replaced with com.sun.star.awt.AnimatedImagesControl.&lt;br /&gt;
* com.sun.star.awt.UnoControlSimpleAnimation&lt;br /&gt;
* com.sun.star.awt.UnoControlSimpleAnimationModel&lt;br /&gt;
* com.sun.star.awt.XSimpleAnimation&lt;br /&gt;
** Please use com.sun.star.awt.AnimatedImagesControl. issue 121514.&lt;br /&gt;
&lt;br /&gt;
== Other com.sun.star.awt Module ==&lt;br /&gt;
Graphics APIs were cleaned up. See issue 121442.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XGraphics&lt;br /&gt;
** getDevice, getFontMetric, setFont, setTextColor, setTextFillColor, setLineColor, setFillColor, setRasterOp methods were changed to corresponding attributes.&lt;br /&gt;
** clear and drawImage methods were added.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.ImageDrawMode&lt;br /&gt;
** Added. Constants are used to specify the mode in com.sun.star.awt.XGraphics::drawImage method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.PrinterServer&lt;br /&gt;
** This service was converted into new style service with constructor.&lt;br /&gt;
&lt;br /&gt;
== System ==&lt;br /&gt;
&lt;br /&gt;
Clean-up system mail API. See issue 121579.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.SimpleCommandMail&lt;br /&gt;
* com.sun.star.system.SimpleMailClientFlags&lt;br /&gt;
* com.sun.star.system.SimpleSystemMail&lt;br /&gt;
* com.sun.star.system.XMailClient&lt;br /&gt;
* com.sun.star.system.XMailMessage&lt;br /&gt;
* com.sun.star.system.XSimpleMailClient&lt;br /&gt;
* com.sun.star.system.XSimpleMailClientSupplier&lt;br /&gt;
* com.sun.star.system.XSimpleMailMessage&lt;br /&gt;
* com.sun.star.system.XSystemMailProvider&lt;br /&gt;
* com.sun.star.system.SimpleMailClientFlags&lt;br /&gt;
** Removed. See below.&lt;br /&gt;
* com.sun.star.system.SystemMailProvider&lt;br /&gt;
** System dependent mail services were integrated into com.sun.star.system.SystemMailProvider.&lt;br /&gt;
Remove deprecated system proxy API. See issue 121548.&lt;br /&gt;
* com.sun.star.system.MailClientFlags&lt;br /&gt;
** Renamed from SimpleMailClientFlags.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.ProxySettings&lt;br /&gt;
* com.sun.star.system.XProxySettings&lt;br /&gt;
* com.sun.star.system.SystemProxySettings&lt;br /&gt;
* com.sun.star.system.SOffice52ProxySettings&lt;br /&gt;
** No longer used, removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.SystemShellExecute&lt;br /&gt;
** This service was converted to new style service with a constructor.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.text Module ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.text.AutoTextGroup&lt;br /&gt;
** FilePath and Title properties were added for documenting. See issue 87780.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.text.ViewSettings&lt;br /&gt;
** ShowContentTips and ShowScrollBarTips properties were added. See issue 25945.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.frame Module ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.PopupMenuControllerFactory&lt;br /&gt;
* com.sun.star.frame.StatusbarControllerFactory&lt;br /&gt;
** These services were converted to new style service with constructors.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.ToolbarControllerFactory&lt;br /&gt;
* com.sun.star.frame.XUIControllerFactory&lt;br /&gt;
** Added.&lt;br /&gt;
&lt;br /&gt;
== Sidebar ==&lt;br /&gt;
See issue 121420.&lt;br /&gt;
* com.sun.star.ui.ContextChangeEventMultiplexer&lt;br /&gt;
* com.sun.star.ui.ContextChangeEventObject&lt;br /&gt;
* com.sun.star.ui.XContextChangeEventMultiplexer&lt;br /&gt;
* com.sun.star.ui.XContextChangeEventListener&lt;br /&gt;
* com.sun.star.ui.XSidebar&lt;br /&gt;
* com.sun.star.ui.XSidebarPanel&lt;br /&gt;
* com.sun.star.ui.LayoutSize&lt;br /&gt;
* com.sun.star.util.EventMultiplexer&lt;br /&gt;
** Added. They are used in the sidebar.&lt;br /&gt;
&lt;br /&gt;
== UCB ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ucb.Content&lt;br /&gt;
** addProperty and removeProperty commands were added. See issue 121935.&lt;br /&gt;
* com.sun.star.ucb.PropertyCommandArgument&lt;br /&gt;
** Added. Argument for the new commands.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ucb.XWebDAVCommandEnvironment&lt;br /&gt;
** Request method is specified by WebDAVHTTPMethod, see below.&lt;br /&gt;
* com.sun.star.ucb.WebDAVHTTPMethod&lt;br /&gt;
** Added. Request methods were defined in WebDAVHTTPMethod.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== SmartTag ==&lt;br /&gt;
&lt;br /&gt;
Make smarttag function more powrful.&lt;br /&gt;
&lt;br /&gt;
See issue 121391, 121730, 121731, 121732, 121733, 121734 and http://mail-archives.apache.org/mod_mbox/openoffice-dev/201302.mbox/browser .&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.smarttags.XRangeBasedSmartTagRecognizer&lt;br /&gt;
** Added.&lt;br /&gt;
* com.sun.star.smarttags.XSmartTagAction&lt;br /&gt;
** getActionCount method takes additional parameter.&lt;br /&gt;
* com.sun.star.text.XMarkingAccess&lt;br /&gt;
* com.sun.star.container.XNamedEx&lt;br /&gt;
** Added.&lt;br /&gt;
* com.sun.star.text.XTextMarkup&lt;br /&gt;
** commitTextMarkup method was renamed to commitStringMarkup&lt;br /&gt;
** commitTextRangeMarkup method was added.&lt;br /&gt;
&lt;br /&gt;
== Calc ==&lt;br /&gt;
See issue 120478.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.sheet.XNamedRange2&lt;br /&gt;
* com.sun.star.sheet.XNamedRanges2&lt;br /&gt;
* com.sun.star.sheet.RangeScopeName&lt;br /&gt;
** Added.&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.configuration.BootstrapContext&lt;br /&gt;
** Deprecated. See issue 118815.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ui.XStatusbarItem&lt;br /&gt;
** Added. See issue 121442.&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/API_Changes_on_4.0_since_3.4&amp;diff=229449</id>
		<title>User:Hanya/API Changes on 4.0 since 3.4</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/API_Changes_on_4.0_since_3.4&amp;diff=229449"/>
		<updated>2013-07-30T07:18:44Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Remove regcompare description, it does not list all differences&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There are some API changes applied to Apache OpenOffice 4.0 since version 3.4.&lt;br /&gt;
&lt;br /&gt;
== Impact ==&lt;br /&gt;
The impact of these changes are influence differently over your code.&lt;br /&gt;
* C++: recompilation required because of stlport removal. &lt;br /&gt;
* Java: should be migrated and recompiled.&lt;br /&gt;
* Basic or Python: should be migrated.&lt;br /&gt;
&lt;br /&gt;
== Message box ==&lt;br /&gt;
Message box APIs were cleaned up. See issue 121544.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMessageBoxFactory&lt;br /&gt;
** createMessageBox method&lt;br /&gt;
*** second argument that specifiy size of the box was removed, it was not used. &lt;br /&gt;
*** third argument that specify the type of the icon shown in the box is changed from string to com.sun.star.awt.MessageBoxType, see below.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMessageBox&lt;br /&gt;
** setCaptionText, getCaptionText, setMessageText, getMessageText methods were changed to corresponding attributes.&lt;br /&gt;
** return value of execute method was defined in com.sun.star.awt.MessageBoxResults, see below.&lt;br /&gt;
** No longer deprecated.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxType&lt;br /&gt;
** Member of this enumerated value can be used to specify type of the message box.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxResults&lt;br /&gt;
** Member of this constants group can be used to check the result of the execution of the message box. Renamed from MessageBoxCommand. And IGNORE member was added.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxCommand&lt;br /&gt;
** Renamed to MessageBoxResults.&lt;br /&gt;
&lt;br /&gt;
== Menu ==&lt;br /&gt;
Menu APIs were integrated. See issue 121542.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMenuBarExtended&lt;br /&gt;
** Integrated into other interfaces, this interface is used to integrate some menu interfaces without any methods.&lt;br /&gt;
* com.sun.star.awt.XMenuExtended&lt;br /&gt;
** getCommand, getCommand, setHelpCommand and getHelpCommmand methods are moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
* com.sun.star.awt.XMenuExtended2&lt;br /&gt;
** isPopupMenu, clear, getItemType, hideDisableEntries methods are moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
* com.sun.star.awt.XPopupMenuExtended&lt;br /&gt;
** isInExecute, endExecute, setAcceleratorKeyEvent, getAcceleratorKeyEvent, setItemImage and getItemImage methods were moved into com.sun.star.awt.XPopupMenu interface.&lt;br /&gt;
** setHelpText, getHelpText, setTipHelpText and getTipHelpText methods were moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
** setItemImageAngle, getItemImageAngle, setItemImageMirrorMode and isItemImageInMirrorMode methods were removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XPopupMenu&lt;br /&gt;
** Some methods were moved from each interfaces described above to this interface.&lt;br /&gt;
* com.sun.star.awt.XMenu&lt;br /&gt;
** Some methods were moved from each interfaces to this interface.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMenuListener&lt;br /&gt;
** The following method names were changed.&lt;br /&gt;
*** highlight -&amp;gt; itemHighlighted&lt;br /&gt;
*** select -&amp;gt; itemSelected&lt;br /&gt;
*** activate -&amp;gt; itemActivated&lt;br /&gt;
*** deactivate -&amp;gt; itemDeactivated&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MenuItemStyle&lt;br /&gt;
** Unpublished, no changes in there members.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.PopupMenuDirection&lt;br /&gt;
** deprecated members were removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MenuLogo&lt;br /&gt;
** Removed. See issue 121542.&lt;br /&gt;
&lt;br /&gt;
== Controls ==&lt;br /&gt;
com.sun.star.awt.UnoControlThrobberModel was replaced with com.sun.star.awt.SpinningProgressControlModel. See issue 121513.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.UnoControlThrobber&lt;br /&gt;
* com.sun.star.awt.UnoControlThrobberModel&lt;br /&gt;
* com.sun.star.awt.XThrobber&lt;br /&gt;
** Please use com.sun.star.awt.AnimatedImagesControl control with com.sun.star.awt.SpinningProgressControlModel.&lt;br /&gt;
&lt;br /&gt;
com.sun.star.awt.UnoControlSimpleAnimation control was replaced with com.sun.star.awt.AnimatedImagesControl.&lt;br /&gt;
* com.sun.star.awt.UnoControlSimpleAnimation&lt;br /&gt;
* com.sun.star.awt.UnoControlSimpleAnimationModel&lt;br /&gt;
* com.sun.star.awt.XSimpleAnimation&lt;br /&gt;
** Please use com.sun.star.awt.AnimatedImagesControl. issue 121514.&lt;br /&gt;
&lt;br /&gt;
== Other com.sun.star.awt Module ==&lt;br /&gt;
Graphics APIs were cleaned up. See issue 121442.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XGraphics&lt;br /&gt;
** getDevice, getFontMetric, setFont, setTextColor, setTextFillColor, setLineColor, setFillColor, setRasterOp methods were changed to corresponding attributes.&lt;br /&gt;
** clear and drawImage methods were added.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.ImageDrawMode&lt;br /&gt;
** Added. Constants are used to specify the mode in com.sun.star.awt.XGraphics::drawImage method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.PrinterServer&lt;br /&gt;
** This service was converted into new style service with constructor.&lt;br /&gt;
&lt;br /&gt;
== System ==&lt;br /&gt;
&lt;br /&gt;
Clean-up system mail API. See issue 121579.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.SimpleCommandMail&lt;br /&gt;
* com.sun.star.system.SimpleMailClientFlags&lt;br /&gt;
* com.sun.star.system.SimpleSystemMail&lt;br /&gt;
* com.sun.star.system.XMailClient&lt;br /&gt;
* com.sun.star.system.XMailMessage&lt;br /&gt;
* com.sun.star.system.XSimpleMailClient&lt;br /&gt;
* com.sun.star.system.XSimpleMailClientSupplier&lt;br /&gt;
* com.sun.star.system.XSimpleMailMessage&lt;br /&gt;
* com.sun.star.system.XSystemMailProvider&lt;br /&gt;
* com.sun.star.system.SimpleMailClientFlags&lt;br /&gt;
** Removed. See below.&lt;br /&gt;
* com.sun.star.system.SystemMailProvider&lt;br /&gt;
** System dependent mail services were integrated into com.sun.star.system.SystemMailProvider.&lt;br /&gt;
Remove deprecated system proxy API. See issue 121548.&lt;br /&gt;
* com.sun.star.system.MailClientFlags&lt;br /&gt;
** Renamed from SimpleMailClientFlags.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.ProxySettings&lt;br /&gt;
* com.sun.star.system.XProxySettings&lt;br /&gt;
* com.sun.star.system.SystemProxySettings&lt;br /&gt;
* com.sun.star.system.SOffice52ProxySettings&lt;br /&gt;
** No longer used, removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.SystemShellExecute&lt;br /&gt;
** This service was converted to new style service with a constructor.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.text Module ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.text.AutoTextGroup&lt;br /&gt;
** FilePath and Title properties were added for documenting. See issue 87780.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.text.ViewSettings&lt;br /&gt;
** ShowContentTips and ShowScrollBarTips properties were added. See issue 25945.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.frame Module ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.PopupMenuControllerFactory&lt;br /&gt;
* com.sun.star.frame.StatusbarControllerFactory&lt;br /&gt;
** These services were converted to new style service with constructors.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.ToolbarControllerFactory&lt;br /&gt;
* com.sun.star.frame.XUIControllerFactory&lt;br /&gt;
** Added.&lt;br /&gt;
&lt;br /&gt;
== Sidebar ==&lt;br /&gt;
See issue 121420.&lt;br /&gt;
* com.sun.star.ui.ContextChangeEventMultiplexer&lt;br /&gt;
* com.sun.star.ui.ContextChangeEventObject&lt;br /&gt;
* com.sun.star.ui.XContextChangeEventMultiplexer&lt;br /&gt;
* com.sun.star.ui.XContextChangeEventListener&lt;br /&gt;
* com.sun.star.ui.XSidebar&lt;br /&gt;
* com.sun.star.ui.XSidebarPanel&lt;br /&gt;
* com.sun.star.ui.LayoutSize&lt;br /&gt;
* com.sun.star.util.EventMultiplexer&lt;br /&gt;
** Added. They are used in the sidebar.&lt;br /&gt;
&lt;br /&gt;
== UCB ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ucb.Content&lt;br /&gt;
** addProperty and removeProperty commands were added. See issue 121935.&lt;br /&gt;
* com.sun.star.ucb.PropertyCommandArgument&lt;br /&gt;
** Added. Argument for the new commands.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ucb.XWebDAVCommandEnvironment&lt;br /&gt;
** Request method is specified by WebDAVHTTPMethod, see below.&lt;br /&gt;
* com.sun.star.ucb.WebDAVHTTPMethod&lt;br /&gt;
** Added. Request methods were defined in WebDAVHTTPMethod.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== SmartTag ==&lt;br /&gt;
&lt;br /&gt;
Make smarttag function more powrful.&lt;br /&gt;
&lt;br /&gt;
See issue 121391, 121730, 121731, 121732, 121733, 121734 and http://mail-archives.apache.org/mod_mbox/openoffice-dev/201302.mbox/browser .&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.smarttags.XRangeBasedSmartTagRecognizer&lt;br /&gt;
** Added.&lt;br /&gt;
* com.sun.star.smarttags.XSmartTagAction&lt;br /&gt;
** getActionCount method takes additional parameter.&lt;br /&gt;
* com.sun.star.text.XMarkingAccess&lt;br /&gt;
* com.sun.star.container.XNamedEx&lt;br /&gt;
** Added.&lt;br /&gt;
* com.sun.star.text.XTextMarkup&lt;br /&gt;
** commitTextMarkup method was renamed to commitStringMarkup&lt;br /&gt;
** commitTextRangeMarkup method was added.&lt;br /&gt;
&lt;br /&gt;
== Calc ==&lt;br /&gt;
See issue 120478.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.sheet.XNamedRange2&lt;br /&gt;
* com.sun.star.sheet.XNamedRanges2&lt;br /&gt;
* com.sun.star.sheet.RangeScopeName&lt;br /&gt;
** Added.&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.configuration.BootstrapContext&lt;br /&gt;
** Deprecated. See issue 118815.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ui.XStatusbarItem&lt;br /&gt;
** Added. See issue 121442.&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/API_Changes_on_4.0_since_3.4&amp;diff=229448</id>
		<title>User:Hanya/API Changes on 4.0 since 3.4</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/API_Changes_on_4.0_since_3.4&amp;diff=229448"/>
		<updated>2013-07-30T07:15:10Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add description about MessageBoxResults.IGNORE member&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There are some API changes applied to Apache OpenOffice 4.0 since version 3.4.&lt;br /&gt;
&lt;br /&gt;
The following differences were detected by regcompare program bound to SDK with f and c options between rdb files of 3.4 and 4.0.&lt;br /&gt;
&lt;br /&gt;
== Impact ==&lt;br /&gt;
The impact of these changes are influence differently over your code.&lt;br /&gt;
* C++: recompilation required because of stlport removal. &lt;br /&gt;
* Java: should be migrated and recompiled.&lt;br /&gt;
* Basic or Python: should be migrated.&lt;br /&gt;
&lt;br /&gt;
== Message box ==&lt;br /&gt;
Message box APIs were cleaned up. See issue 121544.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMessageBoxFactory&lt;br /&gt;
** createMessageBox method&lt;br /&gt;
*** second argument that specifiy size of the box was removed, it was not used. &lt;br /&gt;
*** third argument that specify the type of the icon shown in the box is changed from string to com.sun.star.awt.MessageBoxType, see below.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMessageBox&lt;br /&gt;
** setCaptionText, getCaptionText, setMessageText, getMessageText methods were changed to corresponding attributes.&lt;br /&gt;
** return value of execute method was defined in com.sun.star.awt.MessageBoxResults, see below.&lt;br /&gt;
** No longer deprecated.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxType&lt;br /&gt;
** Member of this enumerated value can be used to specify type of the message box.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxResults&lt;br /&gt;
** Member of this constants group can be used to check the result of the execution of the message box. Renamed from MessageBoxCommand. And IGNORE member was added.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxCommand&lt;br /&gt;
** Renamed to MessageBoxResults.&lt;br /&gt;
&lt;br /&gt;
== Menu ==&lt;br /&gt;
Menu APIs were integrated. See issue 121542.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMenuBarExtended&lt;br /&gt;
** Integrated into other interfaces, this interface is used to integrate some menu interfaces without any methods.&lt;br /&gt;
* com.sun.star.awt.XMenuExtended&lt;br /&gt;
** getCommand, getCommand, setHelpCommand and getHelpCommmand methods are moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
* com.sun.star.awt.XMenuExtended2&lt;br /&gt;
** isPopupMenu, clear, getItemType, hideDisableEntries methods are moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
* com.sun.star.awt.XPopupMenuExtended&lt;br /&gt;
** isInExecute, endExecute, setAcceleratorKeyEvent, getAcceleratorKeyEvent, setItemImage and getItemImage methods were moved into com.sun.star.awt.XPopupMenu interface.&lt;br /&gt;
** setHelpText, getHelpText, setTipHelpText and getTipHelpText methods were moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
** setItemImageAngle, getItemImageAngle, setItemImageMirrorMode and isItemImageInMirrorMode methods were removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XPopupMenu&lt;br /&gt;
** Some methods were moved from each interfaces described above to this interface.&lt;br /&gt;
* com.sun.star.awt.XMenu&lt;br /&gt;
** Some methods were moved from each interfaces to this interface.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMenuListener&lt;br /&gt;
** The following method names were changed.&lt;br /&gt;
*** highlight -&amp;gt; itemHighlighted&lt;br /&gt;
*** select -&amp;gt; itemSelected&lt;br /&gt;
*** activate -&amp;gt; itemActivated&lt;br /&gt;
*** deactivate -&amp;gt; itemDeactivated&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MenuItemStyle&lt;br /&gt;
** Unpublished, no changes in there members.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.PopupMenuDirection&lt;br /&gt;
** deprecated members were removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MenuLogo&lt;br /&gt;
** Removed. See issue 121542.&lt;br /&gt;
&lt;br /&gt;
== Controls ==&lt;br /&gt;
com.sun.star.awt.UnoControlThrobberModel was replaced with com.sun.star.awt.SpinningProgressControlModel. See issue 121513.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.UnoControlThrobber&lt;br /&gt;
* com.sun.star.awt.UnoControlThrobberModel&lt;br /&gt;
* com.sun.star.awt.XThrobber&lt;br /&gt;
** Please use com.sun.star.awt.AnimatedImagesControl control with com.sun.star.awt.SpinningProgressControlModel.&lt;br /&gt;
&lt;br /&gt;
com.sun.star.awt.UnoControlSimpleAnimation control was replaced with com.sun.star.awt.AnimatedImagesControl.&lt;br /&gt;
* com.sun.star.awt.UnoControlSimpleAnimation&lt;br /&gt;
* com.sun.star.awt.UnoControlSimpleAnimationModel&lt;br /&gt;
* com.sun.star.awt.XSimpleAnimation&lt;br /&gt;
** Please use com.sun.star.awt.AnimatedImagesControl. issue 121514.&lt;br /&gt;
&lt;br /&gt;
== Other com.sun.star.awt Module ==&lt;br /&gt;
Graphics APIs were cleaned up. See issue 121442.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XGraphics&lt;br /&gt;
** getDevice, getFontMetric, setFont, setTextColor, setTextFillColor, setLineColor, setFillColor, setRasterOp methods were changed to corresponding attributes.&lt;br /&gt;
** clear and drawImage methods were added.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.ImageDrawMode&lt;br /&gt;
** Added. Constants are used to specify the mode in com.sun.star.awt.XGraphics::drawImage method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.PrinterServer&lt;br /&gt;
** This service was converted into new style service with constructor.&lt;br /&gt;
&lt;br /&gt;
== System ==&lt;br /&gt;
&lt;br /&gt;
Clean-up system mail API. See issue 121579.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.SimpleCommandMail&lt;br /&gt;
* com.sun.star.system.SimpleMailClientFlags&lt;br /&gt;
* com.sun.star.system.SimpleSystemMail&lt;br /&gt;
* com.sun.star.system.XMailClient&lt;br /&gt;
* com.sun.star.system.XMailMessage&lt;br /&gt;
* com.sun.star.system.XSimpleMailClient&lt;br /&gt;
* com.sun.star.system.XSimpleMailClientSupplier&lt;br /&gt;
* com.sun.star.system.XSimpleMailMessage&lt;br /&gt;
* com.sun.star.system.XSystemMailProvider&lt;br /&gt;
* com.sun.star.system.SimpleMailClientFlags&lt;br /&gt;
** Removed. See below.&lt;br /&gt;
* com.sun.star.system.SystemMailProvider&lt;br /&gt;
** System dependent mail services were integrated into com.sun.star.system.SystemMailProvider.&lt;br /&gt;
Remove deprecated system proxy API. See issue 121548.&lt;br /&gt;
* com.sun.star.system.MailClientFlags&lt;br /&gt;
** Renamed from SimpleMailClientFlags.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.ProxySettings&lt;br /&gt;
* com.sun.star.system.XProxySettings&lt;br /&gt;
* com.sun.star.system.SystemProxySettings&lt;br /&gt;
* com.sun.star.system.SOffice52ProxySettings&lt;br /&gt;
** No longer used, removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.SystemShellExecute&lt;br /&gt;
** This service was converted to new style service with a constructor.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.text Module ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.text.AutoTextGroup&lt;br /&gt;
** FilePath and Title properties were added for documenting. See issue 87780.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.text.ViewSettings&lt;br /&gt;
** ShowContentTips and ShowScrollBarTips properties were added. See issue 25945.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.frame Module ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.PopupMenuControllerFactory&lt;br /&gt;
* com.sun.star.frame.StatusbarControllerFactory&lt;br /&gt;
** These services were converted to new style service with constructors.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.ToolbarControllerFactory&lt;br /&gt;
* com.sun.star.frame.XUIControllerFactory&lt;br /&gt;
** Added.&lt;br /&gt;
&lt;br /&gt;
== Sidebar ==&lt;br /&gt;
See issue 121420.&lt;br /&gt;
* com.sun.star.ui.ContextChangeEventMultiplexer&lt;br /&gt;
* com.sun.star.ui.ContextChangeEventObject&lt;br /&gt;
* com.sun.star.ui.XContextChangeEventMultiplexer&lt;br /&gt;
* com.sun.star.ui.XContextChangeEventListener&lt;br /&gt;
* com.sun.star.ui.XSidebar&lt;br /&gt;
* com.sun.star.ui.XSidebarPanel&lt;br /&gt;
* com.sun.star.ui.LayoutSize&lt;br /&gt;
* com.sun.star.util.EventMultiplexer&lt;br /&gt;
** Added. They are used in the sidebar.&lt;br /&gt;
&lt;br /&gt;
== UCB ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ucb.Content&lt;br /&gt;
** addProperty and removeProperty commands were added. See issue 121935.&lt;br /&gt;
* com.sun.star.ucb.PropertyCommandArgument&lt;br /&gt;
** Added. Argument for the new commands.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ucb.XWebDAVCommandEnvironment&lt;br /&gt;
** Request method is specified by WebDAVHTTPMethod, see below.&lt;br /&gt;
* com.sun.star.ucb.WebDAVHTTPMethod&lt;br /&gt;
** Added. Request methods were defined in WebDAVHTTPMethod.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== SmartTag ==&lt;br /&gt;
&lt;br /&gt;
Make smarttag function more powrful.&lt;br /&gt;
&lt;br /&gt;
See issue 121391, 121730, 121731, 121732, 121733, 121734 and http://mail-archives.apache.org/mod_mbox/openoffice-dev/201302.mbox/browser .&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.smarttags.XRangeBasedSmartTagRecognizer&lt;br /&gt;
** Added.&lt;br /&gt;
* com.sun.star.smarttags.XSmartTagAction&lt;br /&gt;
** getActionCount method takes additional parameter.&lt;br /&gt;
* com.sun.star.text.XMarkingAccess&lt;br /&gt;
* com.sun.star.container.XNamedEx&lt;br /&gt;
** Added.&lt;br /&gt;
* com.sun.star.text.XTextMarkup&lt;br /&gt;
** commitTextMarkup method was renamed to commitStringMarkup&lt;br /&gt;
** commitTextRangeMarkup method was added.&lt;br /&gt;
&lt;br /&gt;
== Calc ==&lt;br /&gt;
See issue 120478.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.sheet.XNamedRange2&lt;br /&gt;
* com.sun.star.sheet.XNamedRanges2&lt;br /&gt;
* com.sun.star.sheet.RangeScopeName&lt;br /&gt;
** Added.&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.configuration.BootstrapContext&lt;br /&gt;
** Deprecated. See issue 118815.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ui.XStatusbarItem&lt;br /&gt;
** Added. See issue 121442.&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/API_Changes_on_4.0_since_3.4&amp;diff=229447</id>
		<title>User:Hanya/API Changes on 4.0 since 3.4</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/API_Changes_on_4.0_since_3.4&amp;diff=229447"/>
		<updated>2013-07-30T07:01:01Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Fix MailClientFlags was renamed from SimpleMailClientFlags&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There are some API changes applied to Apache OpenOffice 4.0 since version 3.4.&lt;br /&gt;
&lt;br /&gt;
The following differences were detected by regcompare program bound to SDK with f and c options between rdb files of 3.4 and 4.0.&lt;br /&gt;
&lt;br /&gt;
== Impact ==&lt;br /&gt;
The impact of these changes are influence differently over your code.&lt;br /&gt;
* C++: recompilation required because of stlport removal. &lt;br /&gt;
* Java: should be migrated and recompiled.&lt;br /&gt;
* Basic or Python: should be migrated.&lt;br /&gt;
&lt;br /&gt;
== Message box ==&lt;br /&gt;
Message box APIs were cleaned up. See issue 121544.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMessageBoxFactory&lt;br /&gt;
** createMessageBox method&lt;br /&gt;
*** second argument that specifiy size of the box was removed, it was not used. &lt;br /&gt;
*** third argument that specify the type of the icon shown in the box is changed from string to com.sun.star.awt.MessageBoxType, see below.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMessageBox&lt;br /&gt;
** setCaptionText, getCaptionText, setMessageText, getMessageText methods were changed to corresponding attributes.&lt;br /&gt;
** return value of execute method was defined in com.sun.star.awt.MessageBoxResults, see below.&lt;br /&gt;
** No longer deprecated.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxType&lt;br /&gt;
** Member of this enumerated value can be used to specify type of the message box.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxResults&lt;br /&gt;
** Member of this constants group can be used to check the result of the execution of the message box.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxCommand&lt;br /&gt;
** Removed, deprecated module.&lt;br /&gt;
&lt;br /&gt;
== Menu ==&lt;br /&gt;
Menu APIs were integrated. See issue 121542.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMenuBarExtended&lt;br /&gt;
** Integrated into other interfaces, this interface is used to integrate some menu interfaces without any methods.&lt;br /&gt;
* com.sun.star.awt.XMenuExtended&lt;br /&gt;
** getCommand, getCommand, setHelpCommand and getHelpCommmand methods are moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
* com.sun.star.awt.XMenuExtended2&lt;br /&gt;
** isPopupMenu, clear, getItemType, hideDisableEntries methods are moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
* com.sun.star.awt.XPopupMenuExtended&lt;br /&gt;
** isInExecute, endExecute, setAcceleratorKeyEvent, getAcceleratorKeyEvent, setItemImage and getItemImage methods were moved into com.sun.star.awt.XPopupMenu interface.&lt;br /&gt;
** setHelpText, getHelpText, setTipHelpText and getTipHelpText methods were moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
** setItemImageAngle, getItemImageAngle, setItemImageMirrorMode and isItemImageInMirrorMode methods were removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XPopupMenu&lt;br /&gt;
** Some methods were moved from each interfaces described above to this interface.&lt;br /&gt;
* com.sun.star.awt.XMenu&lt;br /&gt;
** Some methods were moved from each interfaces to this interface.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMenuListener&lt;br /&gt;
** The following method names were changed.&lt;br /&gt;
*** highlight -&amp;gt; itemHighlighted&lt;br /&gt;
*** select -&amp;gt; itemSelected&lt;br /&gt;
*** activate -&amp;gt; itemActivated&lt;br /&gt;
*** deactivate -&amp;gt; itemDeactivated&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MenuItemStyle&lt;br /&gt;
** Unpublished, no changes in there members.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.PopupMenuDirection&lt;br /&gt;
** deprecated members were removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MenuLogo&lt;br /&gt;
** Removed. See issue 121542.&lt;br /&gt;
&lt;br /&gt;
== Controls ==&lt;br /&gt;
com.sun.star.awt.UnoControlThrobberModel was replaced with com.sun.star.awt.SpinningProgressControlModel. See issue 121513.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.UnoControlThrobber&lt;br /&gt;
* com.sun.star.awt.UnoControlThrobberModel&lt;br /&gt;
* com.sun.star.awt.XThrobber&lt;br /&gt;
** Please use com.sun.star.awt.AnimatedImagesControl control with com.sun.star.awt.SpinningProgressControlModel.&lt;br /&gt;
&lt;br /&gt;
com.sun.star.awt.UnoControlSimpleAnimation control was replaced with com.sun.star.awt.AnimatedImagesControl.&lt;br /&gt;
* com.sun.star.awt.UnoControlSimpleAnimation&lt;br /&gt;
* com.sun.star.awt.UnoControlSimpleAnimationModel&lt;br /&gt;
* com.sun.star.awt.XSimpleAnimation&lt;br /&gt;
** Please use com.sun.star.awt.AnimatedImagesControl. issue 121514.&lt;br /&gt;
&lt;br /&gt;
== Other com.sun.star.awt Module ==&lt;br /&gt;
Graphics APIs were cleaned up. See issue 121442.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XGraphics&lt;br /&gt;
** getDevice, getFontMetric, setFont, setTextColor, setTextFillColor, setLineColor, setFillColor, setRasterOp methods were changed to corresponding attributes.&lt;br /&gt;
** clear and drawImage methods were added.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.ImageDrawMode&lt;br /&gt;
** Added. Constants are used to specify the mode in com.sun.star.awt.XGraphics::drawImage method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.PrinterServer&lt;br /&gt;
** This service was converted into new style service with constructor.&lt;br /&gt;
&lt;br /&gt;
== System ==&lt;br /&gt;
&lt;br /&gt;
Clean-up system mail API. See issue 121579.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.SimpleCommandMail&lt;br /&gt;
* com.sun.star.system.SimpleMailClientFlags&lt;br /&gt;
* com.sun.star.system.SimpleSystemMail&lt;br /&gt;
* com.sun.star.system.XMailClient&lt;br /&gt;
* com.sun.star.system.XMailMessage&lt;br /&gt;
* com.sun.star.system.XSimpleMailClient&lt;br /&gt;
* com.sun.star.system.XSimpleMailClientSupplier&lt;br /&gt;
* com.sun.star.system.XSimpleMailMessage&lt;br /&gt;
* com.sun.star.system.XSystemMailProvider&lt;br /&gt;
* com.sun.star.system.SimpleMailClientFlags&lt;br /&gt;
** Removed. See below.&lt;br /&gt;
* com.sun.star.system.SystemMailProvider&lt;br /&gt;
** System dependent mail services were integrated into com.sun.star.system.SystemMailProvider.&lt;br /&gt;
Remove deprecated system proxy API. See issue 121548.&lt;br /&gt;
* com.sun.star.system.MailClientFlags&lt;br /&gt;
** Renamed from SimpleMailClientFlags.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.ProxySettings&lt;br /&gt;
* com.sun.star.system.XProxySettings&lt;br /&gt;
* com.sun.star.system.SystemProxySettings&lt;br /&gt;
* com.sun.star.system.SOffice52ProxySettings&lt;br /&gt;
** No longer used, removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.SystemShellExecute&lt;br /&gt;
** This service was converted to new style service with a constructor.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.text Module ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.text.AutoTextGroup&lt;br /&gt;
** FilePath and Title properties were added for documenting. See issue 87780.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.text.ViewSettings&lt;br /&gt;
** ShowContentTips and ShowScrollBarTips properties were added. See issue 25945.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.frame Module ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.PopupMenuControllerFactory&lt;br /&gt;
* com.sun.star.frame.StatusbarControllerFactory&lt;br /&gt;
** These services were converted to new style service with constructors.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.ToolbarControllerFactory&lt;br /&gt;
* com.sun.star.frame.XUIControllerFactory&lt;br /&gt;
** Added.&lt;br /&gt;
&lt;br /&gt;
== Sidebar ==&lt;br /&gt;
See issue 121420.&lt;br /&gt;
* com.sun.star.ui.ContextChangeEventMultiplexer&lt;br /&gt;
* com.sun.star.ui.ContextChangeEventObject&lt;br /&gt;
* com.sun.star.ui.XContextChangeEventMultiplexer&lt;br /&gt;
* com.sun.star.ui.XContextChangeEventListener&lt;br /&gt;
* com.sun.star.ui.XSidebar&lt;br /&gt;
* com.sun.star.ui.XSidebarPanel&lt;br /&gt;
* com.sun.star.ui.LayoutSize&lt;br /&gt;
* com.sun.star.util.EventMultiplexer&lt;br /&gt;
** Added. They are used in the sidebar.&lt;br /&gt;
&lt;br /&gt;
== UCB ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ucb.Content&lt;br /&gt;
** addProperty and removeProperty commands were added. See issue 121935.&lt;br /&gt;
* com.sun.star.ucb.PropertyCommandArgument&lt;br /&gt;
** Added. Argument for the new commands.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ucb.XWebDAVCommandEnvironment&lt;br /&gt;
** Request method is specified by WebDAVHTTPMethod, see below.&lt;br /&gt;
* com.sun.star.ucb.WebDAVHTTPMethod&lt;br /&gt;
** Added. Request methods were defined in WebDAVHTTPMethod.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== SmartTag ==&lt;br /&gt;
&lt;br /&gt;
Make smarttag function more powrful.&lt;br /&gt;
&lt;br /&gt;
See issue 121391, 121730, 121731, 121732, 121733, 121734 and http://mail-archives.apache.org/mod_mbox/openoffice-dev/201302.mbox/browser .&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.smarttags.XRangeBasedSmartTagRecognizer&lt;br /&gt;
** Added.&lt;br /&gt;
* com.sun.star.smarttags.XSmartTagAction&lt;br /&gt;
** getActionCount method takes additional parameter.&lt;br /&gt;
* com.sun.star.text.XMarkingAccess&lt;br /&gt;
* com.sun.star.container.XNamedEx&lt;br /&gt;
** Added.&lt;br /&gt;
* com.sun.star.text.XTextMarkup&lt;br /&gt;
** commitTextMarkup method was renamed to commitStringMarkup&lt;br /&gt;
** commitTextRangeMarkup method was added.&lt;br /&gt;
&lt;br /&gt;
== Calc ==&lt;br /&gt;
See issue 120478.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.sheet.XNamedRange2&lt;br /&gt;
* com.sun.star.sheet.XNamedRanges2&lt;br /&gt;
* com.sun.star.sheet.RangeScopeName&lt;br /&gt;
** Added.&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.configuration.BootstrapContext&lt;br /&gt;
** Deprecated. See issue 118815.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ui.XStatusbarItem&lt;br /&gt;
** Added. See issue 121442.&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/API_Changes_on_4.0_since_3.4&amp;diff=229446</id>
		<title>User:Hanya/API Changes on 4.0 since 3.4</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/API_Changes_on_4.0_since_3.4&amp;diff=229446"/>
		<updated>2013-07-30T06:54:32Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add about stlport removal&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There are some API changes applied to Apache OpenOffice 4.0 since version 3.4.&lt;br /&gt;
&lt;br /&gt;
The following differences were detected by regcompare program bound to SDK with f and c options between rdb files of 3.4 and 4.0.&lt;br /&gt;
&lt;br /&gt;
== Impact ==&lt;br /&gt;
The impact of these changes are influence differently over your code.&lt;br /&gt;
* C++: recompilation required because of stlport removal. &lt;br /&gt;
* Java: should be migrated and recompiled.&lt;br /&gt;
* Basic or Python: should be migrated.&lt;br /&gt;
&lt;br /&gt;
== Message box ==&lt;br /&gt;
Message box APIs were cleaned up. See issue 121544.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMessageBoxFactory&lt;br /&gt;
** createMessageBox method&lt;br /&gt;
*** second argument that specifiy size of the box was removed, it was not used. &lt;br /&gt;
*** third argument that specify the type of the icon shown in the box is changed from string to com.sun.star.awt.MessageBoxType, see below.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMessageBox&lt;br /&gt;
** setCaptionText, getCaptionText, setMessageText, getMessageText methods were changed to corresponding attributes.&lt;br /&gt;
** return value of execute method was defined in com.sun.star.awt.MessageBoxResults, see below.&lt;br /&gt;
** No longer deprecated.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxType&lt;br /&gt;
** Member of this enumerated value can be used to specify type of the message box.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxResults&lt;br /&gt;
** Member of this constants group can be used to check the result of the execution of the message box.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxCommand&lt;br /&gt;
** Removed, deprecated module.&lt;br /&gt;
&lt;br /&gt;
== Menu ==&lt;br /&gt;
Menu APIs were integrated. See issue 121542.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMenuBarExtended&lt;br /&gt;
** Integrated into other interfaces, this interface is used to integrate some menu interfaces without any methods.&lt;br /&gt;
* com.sun.star.awt.XMenuExtended&lt;br /&gt;
** getCommand, getCommand, setHelpCommand and getHelpCommmand methods are moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
* com.sun.star.awt.XMenuExtended2&lt;br /&gt;
** isPopupMenu, clear, getItemType, hideDisableEntries methods are moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
* com.sun.star.awt.XPopupMenuExtended&lt;br /&gt;
** isInExecute, endExecute, setAcceleratorKeyEvent, getAcceleratorKeyEvent, setItemImage and getItemImage methods were moved into com.sun.star.awt.XPopupMenu interface.&lt;br /&gt;
** setHelpText, getHelpText, setTipHelpText and getTipHelpText methods were moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
** setItemImageAngle, getItemImageAngle, setItemImageMirrorMode and isItemImageInMirrorMode methods were removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XPopupMenu&lt;br /&gt;
** Some methods were moved from each interfaces described above to this interface.&lt;br /&gt;
* com.sun.star.awt.XMenu&lt;br /&gt;
** Some methods were moved from each interfaces to this interface.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMenuListener&lt;br /&gt;
** The following method names were changed.&lt;br /&gt;
*** highlight -&amp;gt; itemHighlighted&lt;br /&gt;
*** select -&amp;gt; itemSelected&lt;br /&gt;
*** activate -&amp;gt; itemActivated&lt;br /&gt;
*** deactivate -&amp;gt; itemDeactivated&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MenuItemStyle&lt;br /&gt;
** Unpublished, no changes in there members.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.PopupMenuDirection&lt;br /&gt;
** deprecated members were removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MenuLogo&lt;br /&gt;
** Removed. See issue 121542.&lt;br /&gt;
&lt;br /&gt;
== Controls ==&lt;br /&gt;
com.sun.star.awt.UnoControlThrobberModel was replaced with com.sun.star.awt.SpinningProgressControlModel. See issue 121513.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.UnoControlThrobber&lt;br /&gt;
* com.sun.star.awt.UnoControlThrobberModel&lt;br /&gt;
* com.sun.star.awt.XThrobber&lt;br /&gt;
** Please use com.sun.star.awt.AnimatedImagesControl control with com.sun.star.awt.SpinningProgressControlModel.&lt;br /&gt;
&lt;br /&gt;
com.sun.star.awt.UnoControlSimpleAnimation control was replaced with com.sun.star.awt.AnimatedImagesControl.&lt;br /&gt;
* com.sun.star.awt.UnoControlSimpleAnimation&lt;br /&gt;
* com.sun.star.awt.UnoControlSimpleAnimationModel&lt;br /&gt;
* com.sun.star.awt.XSimpleAnimation&lt;br /&gt;
** Please use com.sun.star.awt.AnimatedImagesControl. issue 121514.&lt;br /&gt;
&lt;br /&gt;
== Other com.sun.star.awt Module ==&lt;br /&gt;
Graphics APIs were cleaned up. See issue 121442.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XGraphics&lt;br /&gt;
** getDevice, getFontMetric, setFont, setTextColor, setTextFillColor, setLineColor, setFillColor, setRasterOp methods were changed to corresponding attributes.&lt;br /&gt;
** clear and drawImage methods were added.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.ImageDrawMode&lt;br /&gt;
** Added. Constants are used to specify the mode in com.sun.star.awt.XGraphics::drawImage method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.PrinterServer&lt;br /&gt;
** This service was converted into new style service with constructor.&lt;br /&gt;
&lt;br /&gt;
== System ==&lt;br /&gt;
&lt;br /&gt;
Clean-up system mail API. See issue 121579.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.MailClientFlags&lt;br /&gt;
* com.sun.star.system.SimpleCommandMail&lt;br /&gt;
* com.sun.star.system.SimpleMailClientFlags&lt;br /&gt;
* com.sun.star.system.SimpleSystemMai&lt;br /&gt;
* com.sun.star.system.XMailClient&lt;br /&gt;
* com.sun.star.system.XMailMessage&lt;br /&gt;
* com.sun.star.system.XSimpleMailClient&lt;br /&gt;
* com.sun.star.system.XSimpleMailClientSupplier&lt;br /&gt;
* com.sun.star.system.XSimpleMailMessage&lt;br /&gt;
* com.sun.star.system.XSystemMailProvider&lt;br /&gt;
** Removed. See below.&lt;br /&gt;
* com.sun.star.system.SystemMailProvider&lt;br /&gt;
** System dependent mail services were integrated into com.sun.star.system.SystemMailProvider.&lt;br /&gt;
Remove deprecated system proxy API. See issue 121548.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.ProxySettings&lt;br /&gt;
* com.sun.star.system.XProxySettings&lt;br /&gt;
* com.sun.star.system.SystemProxySettings&lt;br /&gt;
* com.sun.star.system.SOffice52ProxySettings&lt;br /&gt;
** No longer used, removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.SystemShellExecute&lt;br /&gt;
** This service was converted to new style service with a constructor.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.text Module ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.text.AutoTextGroup&lt;br /&gt;
** FilePath and Title properties were added for documenting. See issue 87780.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.text.ViewSettings&lt;br /&gt;
** ShowContentTips and ShowScrollBarTips properties were added. See issue 25945.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.frame Module ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.PopupMenuControllerFactory&lt;br /&gt;
* com.sun.star.frame.StatusbarControllerFactory&lt;br /&gt;
** These services were converted to new style service with constructors.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.ToolbarControllerFactory&lt;br /&gt;
* com.sun.star.frame.XUIControllerFactory&lt;br /&gt;
** Added.&lt;br /&gt;
&lt;br /&gt;
== Sidebar ==&lt;br /&gt;
See issue 121420.&lt;br /&gt;
* com.sun.star.ui.ContextChangeEventMultiplexer&lt;br /&gt;
* com.sun.star.ui.ContextChangeEventObject&lt;br /&gt;
* com.sun.star.ui.XContextChangeEventMultiplexer&lt;br /&gt;
* com.sun.star.ui.XContextChangeEventListener&lt;br /&gt;
* com.sun.star.ui.XSidebar&lt;br /&gt;
* com.sun.star.ui.XSidebarPanel&lt;br /&gt;
* com.sun.star.ui.LayoutSize&lt;br /&gt;
* com.sun.star.util.EventMultiplexer&lt;br /&gt;
** Added. They are used in the sidebar.&lt;br /&gt;
&lt;br /&gt;
== UCB ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ucb.Content&lt;br /&gt;
** addProperty and removeProperty commands were added. See issue 121935.&lt;br /&gt;
* com.sun.star.ucb.PropertyCommandArgument&lt;br /&gt;
** Added. Argument for the new commands.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ucb.XWebDAVCommandEnvironment&lt;br /&gt;
** Request method is specified by WebDAVHTTPMethod, see below.&lt;br /&gt;
* com.sun.star.ucb.WebDAVHTTPMethod&lt;br /&gt;
** Added. Request methods were defined in WebDAVHTTPMethod.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== SmartTag ==&lt;br /&gt;
&lt;br /&gt;
Make smarttag function more powrful.&lt;br /&gt;
&lt;br /&gt;
See issue 121391, 121730, 121731, 121732, 121733, 121734 and http://mail-archives.apache.org/mod_mbox/openoffice-dev/201302.mbox/browser .&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.smarttags.XRangeBasedSmartTagRecognizer&lt;br /&gt;
** Added.&lt;br /&gt;
* com.sun.star.smarttags.XSmartTagAction&lt;br /&gt;
** getActionCount method takes additional parameter.&lt;br /&gt;
* com.sun.star.text.XMarkingAccess&lt;br /&gt;
* com.sun.star.container.XNamedEx&lt;br /&gt;
** Added.&lt;br /&gt;
* com.sun.star.text.XTextMarkup&lt;br /&gt;
** commitTextMarkup method was renamed to commitStringMarkup&lt;br /&gt;
** commitTextRangeMarkup method was added.&lt;br /&gt;
&lt;br /&gt;
== Calc ==&lt;br /&gt;
See issue 120478.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.sheet.XNamedRange2&lt;br /&gt;
* com.sun.star.sheet.XNamedRanges2&lt;br /&gt;
* com.sun.star.sheet.RangeScopeName&lt;br /&gt;
** Added.&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.configuration.BootstrapContext&lt;br /&gt;
** Deprecated. See issue 118815.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ui.XStatusbarItem&lt;br /&gt;
** Added. See issue 121442.&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/API_Changes_on_4.0_since_3.4&amp;diff=229445</id>
		<title>User:Hanya/API Changes on 4.0 since 3.4</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/API_Changes_on_4.0_since_3.4&amp;diff=229445"/>
		<updated>2013-07-30T06:52:22Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add css.ui.XStatusbarItem&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There are some API changes applied to Apache OpenOffice 4.0 since version 3.4.&lt;br /&gt;
&lt;br /&gt;
The following differences were detected by regcompare program bound to SDK with f and c options between rdb files of 3.4 and 4.0.&lt;br /&gt;
&lt;br /&gt;
== Impact ==&lt;br /&gt;
The impact of these changes are influence differently over your code.&lt;br /&gt;
* C++ or Java: should be migrated and recompiled.&lt;br /&gt;
* Basic or Python: should be migrated. &lt;br /&gt;
&lt;br /&gt;
== Message box ==&lt;br /&gt;
Message box APIs were cleaned up. See issue 121544.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMessageBoxFactory&lt;br /&gt;
** createMessageBox method&lt;br /&gt;
*** second argument that specifiy size of the box was removed, it was not used. &lt;br /&gt;
*** third argument that specify the type of the icon shown in the box is changed from string to com.sun.star.awt.MessageBoxType, see below.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMessageBox&lt;br /&gt;
** setCaptionText, getCaptionText, setMessageText, getMessageText methods were changed to corresponding attributes.&lt;br /&gt;
** return value of execute method was defined in com.sun.star.awt.MessageBoxResults, see below.&lt;br /&gt;
** No longer deprecated.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxType&lt;br /&gt;
** Member of this enumerated value can be used to specify type of the message box.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxResults&lt;br /&gt;
** Member of this constants group can be used to check the result of the execution of the message box.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MessageBoxCommand&lt;br /&gt;
** Removed, deprecated module.&lt;br /&gt;
&lt;br /&gt;
== Menu ==&lt;br /&gt;
Menu APIs were integrated. See issue 121542.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMenuBarExtended&lt;br /&gt;
** Integrated into other interfaces, this interface is used to integrate some menu interfaces without any methods.&lt;br /&gt;
* com.sun.star.awt.XMenuExtended&lt;br /&gt;
** getCommand, getCommand, setHelpCommand and getHelpCommmand methods are moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
* com.sun.star.awt.XMenuExtended2&lt;br /&gt;
** isPopupMenu, clear, getItemType, hideDisableEntries methods are moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
* com.sun.star.awt.XPopupMenuExtended&lt;br /&gt;
** isInExecute, endExecute, setAcceleratorKeyEvent, getAcceleratorKeyEvent, setItemImage and getItemImage methods were moved into com.sun.star.awt.XPopupMenu interface.&lt;br /&gt;
** setHelpText, getHelpText, setTipHelpText and getTipHelpText methods were moved into com.sun.star.awt.XMenu interface.&lt;br /&gt;
** setItemImageAngle, getItemImageAngle, setItemImageMirrorMode and isItemImageInMirrorMode methods were removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XPopupMenu&lt;br /&gt;
** Some methods were moved from each interfaces described above to this interface.&lt;br /&gt;
* com.sun.star.awt.XMenu&lt;br /&gt;
** Some methods were moved from each interfaces to this interface.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XMenuListener&lt;br /&gt;
** The following method names were changed.&lt;br /&gt;
*** highlight -&amp;gt; itemHighlighted&lt;br /&gt;
*** select -&amp;gt; itemSelected&lt;br /&gt;
*** activate -&amp;gt; itemActivated&lt;br /&gt;
*** deactivate -&amp;gt; itemDeactivated&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MenuItemStyle&lt;br /&gt;
** Unpublished, no changes in there members.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.PopupMenuDirection&lt;br /&gt;
** deprecated members were removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.MenuLogo&lt;br /&gt;
** Removed. See issue 121542.&lt;br /&gt;
&lt;br /&gt;
== Controls ==&lt;br /&gt;
com.sun.star.awt.UnoControlThrobberModel was replaced with com.sun.star.awt.SpinningProgressControlModel. See issue 121513.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.UnoControlThrobber&lt;br /&gt;
* com.sun.star.awt.UnoControlThrobberModel&lt;br /&gt;
* com.sun.star.awt.XThrobber&lt;br /&gt;
** Please use com.sun.star.awt.AnimatedImagesControl control with com.sun.star.awt.SpinningProgressControlModel.&lt;br /&gt;
&lt;br /&gt;
com.sun.star.awt.UnoControlSimpleAnimation control was replaced with com.sun.star.awt.AnimatedImagesControl.&lt;br /&gt;
* com.sun.star.awt.UnoControlSimpleAnimation&lt;br /&gt;
* com.sun.star.awt.UnoControlSimpleAnimationModel&lt;br /&gt;
* com.sun.star.awt.XSimpleAnimation&lt;br /&gt;
** Please use com.sun.star.awt.AnimatedImagesControl. issue 121514.&lt;br /&gt;
&lt;br /&gt;
== Other com.sun.star.awt Module ==&lt;br /&gt;
Graphics APIs were cleaned up. See issue 121442.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.XGraphics&lt;br /&gt;
** getDevice, getFontMetric, setFont, setTextColor, setTextFillColor, setLineColor, setFillColor, setRasterOp methods were changed to corresponding attributes.&lt;br /&gt;
** clear and drawImage methods were added.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.ImageDrawMode&lt;br /&gt;
** Added. Constants are used to specify the mode in com.sun.star.awt.XGraphics::drawImage method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.awt.PrinterServer&lt;br /&gt;
** This service was converted into new style service with constructor.&lt;br /&gt;
&lt;br /&gt;
== System ==&lt;br /&gt;
&lt;br /&gt;
Clean-up system mail API. See issue 121579.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.MailClientFlags&lt;br /&gt;
* com.sun.star.system.SimpleCommandMail&lt;br /&gt;
* com.sun.star.system.SimpleMailClientFlags&lt;br /&gt;
* com.sun.star.system.SimpleSystemMai&lt;br /&gt;
* com.sun.star.system.XMailClient&lt;br /&gt;
* com.sun.star.system.XMailMessage&lt;br /&gt;
* com.sun.star.system.XSimpleMailClient&lt;br /&gt;
* com.sun.star.system.XSimpleMailClientSupplier&lt;br /&gt;
* com.sun.star.system.XSimpleMailMessage&lt;br /&gt;
* com.sun.star.system.XSystemMailProvider&lt;br /&gt;
** Removed. See below.&lt;br /&gt;
* com.sun.star.system.SystemMailProvider&lt;br /&gt;
** System dependent mail services were integrated into com.sun.star.system.SystemMailProvider.&lt;br /&gt;
Remove deprecated system proxy API. See issue 121548.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.ProxySettings&lt;br /&gt;
* com.sun.star.system.XProxySettings&lt;br /&gt;
* com.sun.star.system.SystemProxySettings&lt;br /&gt;
* com.sun.star.system.SOffice52ProxySettings&lt;br /&gt;
** No longer used, removed.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.system.SystemShellExecute&lt;br /&gt;
** This service was converted to new style service with a constructor.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.text Module ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.text.AutoTextGroup&lt;br /&gt;
** FilePath and Title properties were added for documenting. See issue 87780.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.text.ViewSettings&lt;br /&gt;
** ShowContentTips and ShowScrollBarTips properties were added. See issue 25945.&lt;br /&gt;
&lt;br /&gt;
== com.sun.star.frame Module ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.PopupMenuControllerFactory&lt;br /&gt;
* com.sun.star.frame.StatusbarControllerFactory&lt;br /&gt;
** These services were converted to new style service with constructors.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.frame.ToolbarControllerFactory&lt;br /&gt;
* com.sun.star.frame.XUIControllerFactory&lt;br /&gt;
** Added.&lt;br /&gt;
&lt;br /&gt;
== Sidebar ==&lt;br /&gt;
See issue 121420.&lt;br /&gt;
* com.sun.star.ui.ContextChangeEventMultiplexer&lt;br /&gt;
* com.sun.star.ui.ContextChangeEventObject&lt;br /&gt;
* com.sun.star.ui.XContextChangeEventMultiplexer&lt;br /&gt;
* com.sun.star.ui.XContextChangeEventListener&lt;br /&gt;
* com.sun.star.ui.XSidebar&lt;br /&gt;
* com.sun.star.ui.XSidebarPanel&lt;br /&gt;
* com.sun.star.ui.LayoutSize&lt;br /&gt;
* com.sun.star.util.EventMultiplexer&lt;br /&gt;
** Added. They are used in the sidebar.&lt;br /&gt;
&lt;br /&gt;
== UCB ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ucb.Content&lt;br /&gt;
** addProperty and removeProperty commands were added. See issue 121935.&lt;br /&gt;
* com.sun.star.ucb.PropertyCommandArgument&lt;br /&gt;
** Added. Argument for the new commands.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ucb.XWebDAVCommandEnvironment&lt;br /&gt;
** Request method is specified by WebDAVHTTPMethod, see below.&lt;br /&gt;
* com.sun.star.ucb.WebDAVHTTPMethod&lt;br /&gt;
** Added. Request methods were defined in WebDAVHTTPMethod.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== SmartTag ==&lt;br /&gt;
&lt;br /&gt;
Make smarttag function more powrful.&lt;br /&gt;
&lt;br /&gt;
See issue 121391, 121730, 121731, 121732, 121733, 121734 and http://mail-archives.apache.org/mod_mbox/openoffice-dev/201302.mbox/browser .&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.smarttags.XRangeBasedSmartTagRecognizer&lt;br /&gt;
** Added.&lt;br /&gt;
* com.sun.star.smarttags.XSmartTagAction&lt;br /&gt;
** getActionCount method takes additional parameter.&lt;br /&gt;
* com.sun.star.text.XMarkingAccess&lt;br /&gt;
* com.sun.star.container.XNamedEx&lt;br /&gt;
** Added.&lt;br /&gt;
* com.sun.star.text.XTextMarkup&lt;br /&gt;
** commitTextMarkup method was renamed to commitStringMarkup&lt;br /&gt;
** commitTextRangeMarkup method was added.&lt;br /&gt;
&lt;br /&gt;
== Calc ==&lt;br /&gt;
See issue 120478.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.sheet.XNamedRange2&lt;br /&gt;
* com.sun.star.sheet.XNamedRanges2&lt;br /&gt;
* com.sun.star.sheet.RangeScopeName&lt;br /&gt;
** Added.&lt;br /&gt;
&lt;br /&gt;
== Other ==&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.configuration.BootstrapContext&lt;br /&gt;
** Deprecated. See issue 118815.&lt;br /&gt;
&lt;br /&gt;
* com.sun.star.ui.XStatusbarItem&lt;br /&gt;
** Added. See issue 121442.&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Talk:Extensions/Extensions_and_Apache_OpenOffice_4.0&amp;diff=229404</id>
		<title>Talk:Extensions/Extensions and Apache OpenOffice 4.0</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Talk:Extensions/Extensions_and_Apache_OpenOffice_4.0&amp;diff=229404"/>
		<updated>2013-07-27T13:30:10Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Possibility to make the package compatible about add-ons toolbar&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Here is an example add-on toolbar in old structure: &lt;br /&gt;
 &amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;#039;1.0&amp;#039; encoding=&amp;#039;UTF-8&amp;#039;?&amp;gt;&lt;br /&gt;
&amp;lt;oor:component-data xmlns:oor=&amp;quot;http://openoffice.org/2001/registry&amp;quot; &lt;br /&gt;
xmlns:xs=&amp;quot;http://www.w3.org/2001/XMLSchema&amp;quot; &lt;br /&gt;
oor:name=&amp;quot;Addons&amp;quot; oor:package=&amp;quot;org.openoffice.Office&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;node oor:name=&amp;quot;AddonUI&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;node oor:name=&amp;quot;OfficeToolBar&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;node oor:name=&amp;quot;foo.bar.hoge.addons.ToolbarTest.old&amp;quot; oor:op=&amp;quot;replace&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;node oor:name=&amp;quot;button_1&amp;quot; oor:op=&amp;quot;replace&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;prop oor:name=&amp;quot;Title&amp;quot; oor:type=&amp;quot;xs:string&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;value xml:lang=&amp;quot;en-US&amp;quot;&amp;gt;Show All&amp;lt;/value&amp;gt;&lt;br /&gt;
          &amp;lt;/prop&amp;gt;&lt;br /&gt;
          &amp;lt;prop oor:name=&amp;quot;URL&amp;quot; oor:type=&amp;quot;xs:string&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;value&amp;gt;vnd.sun.star.script:myts?language=Basic&amp;amp;amp;location=application&amp;lt;/value&amp;gt;&lt;br /&gt;
          &amp;lt;/prop&amp;gt;&lt;br /&gt;
          &amp;lt;prop oor:name=&amp;quot;Target&amp;quot; oor:type=&amp;quot;xs:string&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;value&amp;gt;_self&amp;lt;/value&amp;gt;&lt;br /&gt;
          &amp;lt;/prop&amp;gt;&lt;br /&gt;
          &amp;lt;prop oor:name=&amp;quot;Context&amp;quot; oor:type=&amp;quot;xs:string&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;value&amp;gt;com.sun.star.sheet.SpreadsheetDocument&amp;lt;/value&amp;gt;&lt;br /&gt;
          &amp;lt;/prop&amp;gt;&lt;br /&gt;
        &amp;lt;/node&amp;gt;&lt;br /&gt;
      &amp;lt;/node&amp;gt;&lt;br /&gt;
    &amp;lt;/node&amp;gt;&lt;br /&gt;
  &amp;lt;/node&amp;gt;&lt;br /&gt;
&amp;lt;/oor:component-data&amp;gt;&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
with its name: &lt;br /&gt;
 &amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;oor:component-data xmlns:oor=&amp;quot;http://openoffice.org/2001/registry&amp;quot; &lt;br /&gt;
xmlns:xs=&amp;quot;http://www.w3.org/2001/XMLSchema&amp;quot; &lt;br /&gt;
oor:name=&amp;quot;CalcWindowState&amp;quot; oor:package=&amp;quot;org.openoffice.Office.UI&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;node oor:name=&amp;quot;UIElements&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;node oor:name=&amp;quot;States&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;node oor:name=&amp;quot;private:resource/toolbar/addon_foo.bar.hoge.addons.ToolbarTest.old&amp;quot; oor:op=&amp;quot;replace&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;prop oor:name=&amp;quot;UIName&amp;quot; oor:type=&amp;quot;xs:string&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;value xml:lang=&amp;quot;en&amp;quot;&amp;gt;Toolbar Title&amp;lt;/value&amp;gt;&lt;br /&gt;
        &amp;lt;/prop&amp;gt;&lt;br /&gt;
      &amp;lt;/node&amp;gt;&lt;br /&gt;
    &amp;lt;/node&amp;gt;&lt;br /&gt;
  &amp;lt;/node&amp;gt;&lt;br /&gt;
&amp;lt;/oor:component-data&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It should be converted into the following structure: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;#039;1.0&amp;#039; encoding=&amp;#039;UTF-8&amp;#039;?&amp;gt;&lt;br /&gt;
&amp;lt;oor:component-data xmlns:oor=&amp;quot;http://openoffice.org/2001/registry&amp;quot; &lt;br /&gt;
xmlns:xs=&amp;quot;http://www.w3.org/2001/XMLSchema&amp;quot; &lt;br /&gt;
oor:name=&amp;quot;Addons&amp;quot; oor:package=&amp;quot;org.openoffice.Office&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;node oor:name=&amp;quot;AddonUI&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;node oor:name=&amp;quot;OfficeToolBar&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;node oor:name=&amp;quot;foo.bar.hoge.addons.ToolbarTest.new&amp;quot; oor:op=&amp;quot;replace&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;prop oor:name=&amp;quot;Title&amp;quot; oor:type=&amp;quot;xs:string&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;value xml:lang=&amp;quot;en-US&amp;quot;&amp;gt;Toolbar Title&amp;lt;/value&amp;gt;&lt;br /&gt;
        &amp;lt;/prop&amp;gt;&lt;br /&gt;
        &amp;lt;node oor:name=&amp;quot;ToolBarItems&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;node oor:name=&amp;quot;button_1&amp;quot; oor:op=&amp;quot;replace&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;prop oor:name=&amp;quot;Title&amp;quot; oor:type=&amp;quot;xs:string&amp;quot;&amp;gt;&lt;br /&gt;
              &amp;lt;value xml:lang=&amp;quot;en-US&amp;quot;&amp;gt;Show All&amp;lt;/value&amp;gt;&lt;br /&gt;
            &amp;lt;/prop&amp;gt;&lt;br /&gt;
            &amp;lt;prop oor:name=&amp;quot;URL&amp;quot; oor:type=&amp;quot;xs:string&amp;quot;&amp;gt;&lt;br /&gt;
              &amp;lt;value&amp;gt;vnd.sun.star.script:myts?language=Basic&amp;amp;amp;location=application&amp;lt;/value&amp;gt;&lt;br /&gt;
            &amp;lt;/prop&amp;gt;&lt;br /&gt;
            &amp;lt;prop oor:name=&amp;quot;Target&amp;quot; oor:type=&amp;quot;xs:string&amp;quot;&amp;gt;&lt;br /&gt;
              &amp;lt;value&amp;gt;_self&amp;lt;/value&amp;gt;&lt;br /&gt;
            &amp;lt;/prop&amp;gt;&lt;br /&gt;
            &amp;lt;prop oor:name=&amp;quot;Context&amp;quot; oor:type=&amp;quot;xs:string&amp;quot;&amp;gt;&lt;br /&gt;
              &amp;lt;value&amp;gt;com.sun.star.sheet.SpreadsheetDocument&amp;lt;/value&amp;gt;&lt;br /&gt;
            &amp;lt;/prop&amp;gt;&lt;br /&gt;
          &amp;lt;/node&amp;gt;&lt;br /&gt;
        &amp;lt;/node&amp;gt;&lt;br /&gt;
      &amp;lt;/node&amp;gt;&lt;br /&gt;
    &amp;lt;/node&amp;gt;&lt;br /&gt;
  &amp;lt;/node&amp;gt;&lt;br /&gt;
&amp;lt;/oor:component-data&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add Title property in your child node of OfficeToolBar node to specify its title. And create ToolBarItems node in your toolbar node, and move your toolbar entries into it.&lt;br /&gt;
&lt;br /&gt;
In the above example, new one has different toolbar name from the older one. When I put both older one and new one into the same package as the following list of contents, the toolbar of the package is shown on both Apache OpenOffice 3.4 and 4.0 (I testes only OpenOffice.org 3.2 and 3.3, Apache OpenOffice 3.4 and 4.0 on Linux environment. I thought configuration data has been checked to match with installed schema during the installation of the package in the past but I forgot version that has been changed.).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;manifest:manifest&amp;gt;&lt;br /&gt;
    &amp;lt;manifest:file-entry manifest:full-path=&amp;quot;Addons_old.xcu&amp;quot; &lt;br /&gt;
     manifest:media-type=&amp;quot;application/vnd.sun.star.configuration-data&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;manifest:file-entry manifest:full-path=&amp;quot;CalcWindowState.xcu&amp;quot; &lt;br /&gt;
     manifest:media-type=&amp;quot;application/vnd.sun.star.configuration-data&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;manifest:file-entry manifest:full-path=&amp;quot;Addons_new.xcu&amp;quot; &lt;br /&gt;
     manifest:media-type=&amp;quot;application/vnd.sun.star.configuration-data&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/manifest:manifest&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=Extensions/Extensions_and_Apache_OpenOffice_4.0&amp;diff=229403</id>
		<title>Extensions/Extensions and Apache OpenOffice 4.0</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=Extensions/Extensions_and_Apache_OpenOffice_4.0&amp;diff=229403"/>
		<updated>2013-07-27T12:03:20Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Fix link URL to Magenta Lorem Ipsum generator&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Apache OpenOffice 4.0 introduces new handling mechanisms and new APIs for Extensions.&lt;br /&gt;
&lt;br /&gt;
Extensions compatible with OpenOffice 3.x may or may not work in version 4.0.&lt;br /&gt;
&lt;br /&gt;
This pages collects useful information for end users and developers.&lt;br /&gt;
&lt;br /&gt;
== Information For End Users ==&lt;br /&gt;
&lt;br /&gt;
=== General upgrade information ===&lt;br /&gt;
&lt;br /&gt;
Extensions that you installed in OpenOffice 3.x won&amp;#039;t be automatically available in OpenOffice 4.0 when you upgrade from OpenOffice 3.x to OpenOffice 4.0.&lt;br /&gt;
&lt;br /&gt;
It is recommended that, &amp;#039;&amp;#039;&amp;#039;before installing OpenOffice 4.0&amp;#039;&amp;#039;&amp;#039;, you take note of the installed Extensions with: &amp;#039;&amp;#039;Tools&amp;#039;&amp;#039; → &amp;#039;&amp;#039;Manage Extensions&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
You can then check the site you downloaded the Extensions from (usually http://extensions.openoffice.org) and search for your Extensions, to see if there is a version compatible with OpenOffice 4.0.&lt;br /&gt;
&lt;br /&gt;
In doubt, you can download the latest version and install it in OpenOffice 4.0 (save the file from the Extensions site, then open it with &amp;#039;&amp;#039;File&amp;#039;&amp;#039; → &amp;#039;&amp;#039;Open&amp;#039;&amp;#039; in OpenOffice) and check if it works correctly.&lt;br /&gt;
&lt;br /&gt;
For commercial extensions, please contact the publisher for support. In case an extension is not publicly available, but only used privately or in your company/institution, please ask either the author of your extension or a person responsible in your company/institution for help.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Please note: If a certain extension is crucial for your personal or professional workflow, you should not install OpenOffice 4.0 before having made sure that this extension will work on version 4.0 or that an update of the extension is available.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
=== Extensions known to be working ===&lt;br /&gt;
&lt;br /&gt;
Popular Extensions that are &amp;#039;&amp;#039;&amp;#039;reported to work correctly&amp;#039;&amp;#039;&amp;#039; with OpenOffice 4.0 are:&lt;br /&gt;
* All dictionaries&lt;br /&gt;
* [http://extensions.openoffice.org/en/node/17351 PDF Import - NEW VERSION] (use this one by Ariel, not the old &amp;quot;Oracle&amp;quot; one)&lt;br /&gt;
* [http://extensions.openoffice.org/en/node/5644 MySQL Driver for Apache OpenOffice - NEW VERSION] (use this one by Ariel, not the old &amp;quot;Sun MySQL Connector&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
=== Extensions known not to be working ===&lt;br /&gt;
 &lt;br /&gt;
The following Extensions do not have a release compatible with OpenOffice 4.0:&lt;br /&gt;
* [http://extensions.openoffice.org/en/project/pdfimport Oracle PDF Import] - needs to be updated for OpenOffice 4.0 on Windows, Mac, 32-bit Linux and the &amp;#039;&amp;#039;&amp;#039;4.0-compatible update&amp;#039;&amp;#039;&amp;#039; is available at http://extensions.openoffice.org/en/node/17351&lt;br /&gt;
* [http://extensions.openoffice.org/en/project/mysql_connector MySQL Connector] and [http://code.google.com/a/apache-extras.org/p/aoo-my-sdbc/ Ariel&amp;#039;s old version of it] - both need to be updated for OpenOffice 4.0 on Windows, Mac, 32-bit Linux and the &amp;#039;&amp;#039;&amp;#039;4.0-compatible update&amp;#039;&amp;#039;&amp;#039; is available at http://extensions.openoffice.org/en/node/5644&lt;br /&gt;
* [http://extensions.openoffice.org/en/project/magenta-lorem-ipsum-generator Magenta Lorem Ipsum generator] - reported to be incompatible.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Please check the http://extensions.openoffice.org site (or your provider) for the latest information about upgrades.&lt;br /&gt;
&lt;br /&gt;
== Information for Developers ==&lt;br /&gt;
&lt;br /&gt;
OpenOffice 4.0 brings some significant changes to the API used in Extensions.&lt;br /&gt;
&lt;br /&gt;
=== Good practices ===&lt;br /&gt;
&lt;br /&gt;
==== Specify both a minimal and maximal version of OpenOffice for compatibility ====&lt;br /&gt;
&lt;br /&gt;
This is to be done when you create a new Extension release, within the &amp;lt;tt&amp;gt;description.xml&amp;lt;/tt&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
Typical (minimal version only) configuration:&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;dependencies&amp;gt;&lt;br /&gt;
        &amp;lt;OpenOffice.org-minimal-version value=&amp;quot;3.0&amp;quot; d:name=&amp;quot;OpenOffice.org 3.0&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/dependencies&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Recommended (both minimal and maximal version) configuration:&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;dependencies&amp;gt;&lt;br /&gt;
        &amp;lt;OpenOffice.org-minimal-version value=&amp;quot;3.0&amp;quot; d:name=&amp;quot;OpenOffice.org 3.0&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;OpenOffice.org-maximal-version value=&amp;quot;4.0&amp;quot; d:name=&amp;quot;OpenOffice.org 4.0&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;/dependencies&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Test your Extension with a recent OpenOffice 4.0 snapshot ====&lt;br /&gt;
&lt;br /&gt;
Download a recent OpenOffice 4.0 snapshot from [https://cwiki.apache.org/confluence/display/OOOUSERS/Development+Snapshot+Builds#DevelopmentSnapshotBuilds-AOOSnapshotfullsets here] (remember: snapshots are not official releases and they are meant for testing only) and try installing your Extension.&lt;br /&gt;
&lt;br /&gt;
Check that everything works, especially toolbar integration.&lt;br /&gt;
&lt;br /&gt;
If the Extension works, you may want to create a new micro release with updated minimal and maximal version compatibility and  upload it to http://extensions.openoffice.org&lt;br /&gt;
&lt;br /&gt;
=== Technical details ===&lt;br /&gt;
&lt;br /&gt;
* All dictionaries will work with no modifications in version 4.0.&lt;br /&gt;
* If your Extension does not contain an &amp;lt;tt&amp;gt;addons.xcu&amp;lt;/tt&amp;gt; file, it will work with no modifications too.&lt;br /&gt;
* If your Extension contains an &amp;lt;tt&amp;gt;addons.xcu&amp;lt;/tt&amp;gt; file, you will usually have to make some small changes for it to run in OpenOffice 4.0, see below.&lt;br /&gt;
&lt;br /&gt;
[TODO: Example: how to adapt &amp;lt;tt&amp;gt;addons.xcu&amp;lt;/tt&amp;gt; from version 3.x to version 4.0]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya/Translation_Review&amp;diff=229284</id>
		<title>User:Hanya/Translation Review</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya/Translation_Review&amp;diff=229284"/>
		<updated>2013-07-18T03:26:42Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add about creation of search plug-in in Pootle server&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Some tools to help reviewing existing translations in UI and help contents. &lt;br /&gt;
&lt;br /&gt;
== Create Pootle Search Plug-in ==&lt;br /&gt;
Recent web browser supports embedded search plug-in to search. It can be make one for your locale using Ready2Search[1] easily.&lt;br /&gt;
&lt;br /&gt;
Here is an example to make one for ja locale:&lt;br /&gt;
&lt;br /&gt;
# Open Ready2Search page.&lt;br /&gt;
# the search name: Pootle UI-ja target&lt;br /&gt;
# the front of search term: https://translate.apache.org/ja/aoo40/translate.html#sfields=target&amp;amp;search=&lt;br /&gt;
# description of the search: Pootle Search in UI-ja target&lt;br /&gt;
# input encoding: UTF-8&lt;br /&gt;
# output encoding: not specified&lt;br /&gt;
# Push Make search plug-in button&lt;br /&gt;
# Push Download the setting of OpenSearch to store the result&lt;br /&gt;
# Deploy it according to your web browser instructions&lt;br /&gt;
&lt;br /&gt;
The front of search term should be: &lt;br /&gt;
https://translate.apache.org/{LOCALE}/{CATEGORY}/translate.html#sfields=target&amp;amp;search=&lt;br /&gt;
&lt;br /&gt;
* LOCALE: ISO language and country code for your target locale.&lt;br /&gt;
* CATEGORY: aoo40 or aoo40help&lt;br /&gt;
&lt;br /&gt;
sfields specifies the context to search in. It should be one of source: source text,target: translated text, notes: comments and locations: position. If you want to search in the two or more context at a time, separate multiple items with &amp;quot;,&amp;quot;, c.g. sfields=source,target.&lt;br /&gt;
&lt;br /&gt;
If you want to share it with your coworker, sent the setting URL shown after the creation.&lt;br /&gt;
&lt;br /&gt;
[1] http://ready.to/search/en/&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
	<entry>
		<id>https://wiki.openoffice.org/w/index.php?title=User:Hanya&amp;diff=229283</id>
		<title>User:Hanya</title>
		<link rel="alternate" type="text/html" href="https://wiki.openoffice.org/w/index.php?title=User:Hanya&amp;diff=229283"/>
		<updated>2013-07-18T03:20:52Z</updated>

		<summary type="html">&lt;p&gt;Hanya: Add link to new page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ICLA submitted.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
* [[/Tracked_API_Changes]]&lt;br /&gt;
* [[/Hyperlink_Control_on_Dialog_Editor]]&lt;br /&gt;
* [[/Distribute_SymbolStyles_by_Extension]]&lt;br /&gt;
* [[/External_Libraries]]&lt;br /&gt;
* [[/API Changes on 4.0 since 3.4]]&lt;br /&gt;
* [[/Translation_Review]]&lt;/div&gt;</summary>
		<author><name>Hanya</name></author>
	</entry>
</feed>