[PATCH] SDK examples : add Python section and ToolPanel python example

Laurent Godard lgodard.libre at laposte.net
Wed Dec 7 08:24:12 PST 2011


correct minor css rendering too
---
 odk/docs/sdk_styles.css                            |   16 ++-
 odk/examples/examples.html                         |   63 ++++++++-
 odk/examples/python/toolpanel/CalcWindowState.xcu  |   21 +++
 odk/examples/python/toolpanel/Factory.xcu          |   26 ++++
 .../python/toolpanel/META-INF/manifest.xml         |   15 ++
 odk/examples/python/toolpanel/description.xml      |    5 +
 .../python/toolpanel/toolPanelPocBasic/Module1.xba |   29 ++++
 .../python/toolpanel/toolPanelPocBasic/dialog.xlb  |    3 +
 .../python/toolpanel/toolPanelPocBasic/script.xlb  |    5 +
 odk/examples/python/toolpanel/toolpanel.component  |   35 +++++
 odk/examples/python/toolpanel/toolpanel.py         |  148 ++++++++++++++++++++
 odk/examples/python/toolpanel/toolpanels/poc.xdl   |   11 ++
 12 files changed, 369 insertions(+), 8 deletions(-)
 create mode 100644 odk/examples/python/toolpanel/CalcWindowState.xcu
 create mode 100644 odk/examples/python/toolpanel/Factory.xcu
 create mode 100644 odk/examples/python/toolpanel/META-INF/manifest.xml
 create mode 100755 odk/examples/python/toolpanel/description.xml
 create mode 100644 odk/examples/python/toolpanel/toolPanelPocBasic/Module1.xba
 create mode 100644 odk/examples/python/toolpanel/toolPanelPocBasic/dialog.xlb
 create mode 100644 odk/examples/python/toolpanel/toolPanelPocBasic/script.xlb
 create mode 100644 odk/examples/python/toolpanel/toolpanel.component
 create mode 100644 odk/examples/python/toolpanel/toolpanel.py
 create mode 100755 odk/examples/python/toolpanel/toolpanels/poc.xdl

diff --git a/odk/docs/sdk_styles.css b/odk/docs/sdk_styles.css
index d1cd940..5be9eb7 100644
--- a/odk/docs/sdk_styles.css
+++ b/odk/docs/sdk_styles.css
@@ -876,7 +876,8 @@ hr {
 	  border-color: #CCCCCC;
 	  border-spacing: 0;
 	  border-collapse: collapse; 
-	  padding: 4; }
+	  padding: 4;
+	  color: #000000; }
 
 .cell20 { width: 20%; 
 	  border-width: 2px; 
@@ -884,7 +885,8 @@ hr {
 	  border-color: #CCCCCC;
 	  border-spacing: 0;
 	  border-collapse: collapse; 
-	  padding: 4; }
+	  padding: 4;
+	  color: #000000; }
 
 .cell80 { width: 80%;
 	  border-width: 2px; 
@@ -892,7 +894,8 @@ hr {
 	  border-color: #CCCCCC;
 	  border-spacing: 0;
 	  border-collapse: collapse;
-	  padding: 4; }
+	  padding: 4;
+	  color: #000000; }
 
 .cell85 { width: 85%; 
 	  border-width: 2px; 
@@ -900,7 +903,8 @@ hr {
 	  border-color: #CCCCCC;
 	  border-spacing: 0;
 	  border-collapse: collapse; 
-	  padding: 4; }
+	  padding: 4; 
+	  color: #000000;}
 
 .nothing1 { width: 20;
 	   height: 1; }
@@ -941,8 +945,8 @@ hr {
          font-weight: bold; }
 
 .thead { font-weight: bold;
-         background-image:url(../docs/images/bg_table.png);
-	 backgorund-position: middle; }
+         background-color:#18a303;
+         background-position: middle; }
 
 .navigate { border: 0; }
 
diff --git a/odk/examples/examples.html b/odk/examples/examples.html
index ed66695..0c9c6b1 100644
--- a/odk/examples/examples.html
+++ b/odk/examples/examples.html
@@ -1,6 +1,6 @@
 <html>
 <head>
-  <title>OpenOffice.org %PRODUCT_RELEASE% SDK - Examples</title>
+  <title>LibreOffice %PRODUCT_RELEASE% SDK - Examples</title>
   <link rel="stylesheet" type="text/css" href="../docs/sdk_styles.css">
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <meta name="author" content="J&uuml;rgen Schmidt">
@@ -10,7 +10,7 @@
 <body class="sdkbody"><a name="examples"/>
 <table class="table1" cellpadding=0>
   <tr style="background-image:url(../docs/images/sdk_head-2.png); backgorund-position: bottom; "> 
-    <td class="background" colspan="3" align="left"><img src="../docs/images/sdk_head-1.png" width="800" height="120" usemap="#Map" border="0"></td>
+    <td class="background" colspan="3" align="left"><img src="../docs/images/sdk_head-1.png" height="120" usemap="#Map" border="0"></td>
   </tr>
   <tr> 
     <td colspan="3"><img  class="nothing10" src="../docs/images/nada.gif"></td>
@@ -77,6 +77,11 @@
             </tr>
             <tr valign="top">
               <td class="content3"><img src="../docs/images/arrow-1.gif"></td>
+              <td><a href="#python_examples" title="link to the Python examples section">Python examples</a></td>
+              <td class="content75">Small set of examples which shows the use of the API from Python.</td>
+            </tr>
+            <tr valign="top">
+              <td class="content3"><img src="../docs/images/arrow-1.gif"></td>
               <td><a href="#Cpp_examples" title="link to the C++ examples section">C++ examples</a></td>
               <td class="content75">Small set of examples which shows the use of 
 			  the API from C++.</td>
@@ -372,6 +377,60 @@
           <td> 
           <table class="table3">
 		  <tr> 
+			<td colspan="2" class="head1"><a name="python_examples">Python examples</td>
+			<td align="right">
+		      <a href="#examples" title="link to the examples overview"><img class="navigate" src="../docs/images/nav_up.png"></a>
+		      <a href="../index.html" title="link to the SDK start page"><img class="navigate" src="../docs/images/nav_home.png"></a>
+		  </td>
+		  </tr> 
+		  <tr> 
+		  <td  colspan="3"></td> 
+		  </tr> 
+		  </table>
+          </td>
+        </tr> 
+		<tr>
+		  <td>
+		  <table class="table4">
+		  <tbody>
+		  <tr class="thead">
+		  <td class="cell20">Example</td>
+		  <td class="cell80">Description</td>
+		  </tr>
+		  <tr>
+		  <td class="cell20"><a href="python/toolpanel/"title="link to the source directory of the ToolPanel python axample">ToolPanelPoc</a></td>
+		  <td class="cell80">This extension illustrates how to create a ToolPanel in Calc.</td>
+		  </tr>		  
+		  <tbody>
+		  </table>
+		  </td>
+		</tr>
+        <tr> 
+          <td> 
+          <table class="table3">
+		  <tr> 
+		  <td  colspan="3">
+		  <p>No Additional information</p>
+		  </td> 
+		  </tr> 
+		  </table>
+          </td>
+        </tr> 
+      </table>
+    </td>
+    <td class="content1"><img class="nothing8" src="../docs/images/nada.gif"></td>
+  </tr>
+  <tr> 
+    <td colspan="3"><img class="line" src="../docs/images/sdk_line-1.gif"></td>
+  </tr>
+  <tr>
+    <td class="content1"><img class="nothing8" src="../docs/images/nada.gif"></td>
+    <td>
+      <table class="table2">
+        <tr> 
+          <td> 
+          <table class="table3">
+		  <tr> 
 			<td colspan="2" class="head1"><a name="Cpp_examples">C++ examples</td>
 			<td align="right">
 		      <a href="#examples" title="link to the examples overview"><img class="navigate" src="../docs/images/nav_up.png"></a>
diff --git a/odk/examples/python/toolpanel/CalcWindowState.xcu b/odk/examples/python/toolpanel/CalcWindowState.xcu
new file mode 100644
index 0000000..cb1706b
--- /dev/null
+++ b/odk/examples/python/toolpanel/CalcWindowState.xcu
@@ -0,0 +1,21 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<oor:component-data
+    oor:name="CalcWindowState"
+    oor:package="org.openoffice.Office.UI"
+    xmlns:install="http://openoffice.org/2004/installation"
+    xmlns:oor="http://openoffice.org/2001/registry"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <node oor:name="UIElements">
+    <node oor:name="States">
+      <node oor:name="private:resource/toolpanel/myToolPanelPoc" oor:op="replace">
+        <prop oor:name="UIName" oor:type="xs:string">
+          <value> ToolPanel Proof of Concept</value>
+        </prop>
+        <prop oor:name="Visible" oor:type="xs:boolean">
+          <value>true</value>
+        </prop>
+      </node>
+    </node>
+  </node>
+</oor:component-data>
diff --git a/odk/examples/python/toolpanel/Factory.xcu b/odk/examples/python/toolpanel/Factory.xcu
new file mode 100644
index 0000000..b25a3d2
--- /dev/null
+++ b/odk/examples/python/toolpanel/Factory.xcu
@@ -0,0 +1,26 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<oor:component-data
+    oor:name="Factories"
+    oor:package="org.openoffice.Office.UI"
+    xmlns:oor="http://openoffice.org/2001/registry"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <node oor:name="Registered">
+    <node oor:name="UIElementFactories">
+      <node oor:name="org.libreoffice.example.CustomToolPanel.lgodard" oor:op="replace">
+        <prop oor:name="Type">
+          <value>toolpanel</value>
+        </prop>
+        <prop oor:name="Name">
+          <value>myToolPanelPoc</value>
+        </prop>
+        <prop oor:name="Module">
+          <value/>
+        </prop>
+        <prop oor:name="FactoryImplementation">
+          <value>org.libreoffice.example.toolpanel.pocFactory</value>
+        </prop>
+      </node>
+    </node>
+  </node>
+</oor:component-data>
diff --git a/odk/examples/python/toolpanel/META-INF/manifest.xml b/odk/examples/python/toolpanel/META-INF/manifest.xml
new file mode 100644
index 0000000..950bbab
--- /dev/null
+++ b/odk/examples/python/toolpanel/META-INF/manifest.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<manifest:manifest xmlns:manifest="http://openoffice.org/2001/manifest">
+  <manifest:file-entry
+    manifest:media-type="application/vnd.sun.star.uno-components"
+    manifest:full-path="toolpanel.components"/>
+  <manifest:file-entry
+    manifest:media-type="application/vnd.sun.star.configuration-data"
+    manifest:full-path="CalcWindowState.xcu"/>
+  <manifest:file-entry
+    manifest:media-type="application/vnd.sun.star.configuration-data"
+    manifest:full-path="Factory.xcu"/>
+  <manifest:file-entry
+    manifest:full-path="toolPanelPocBasic/"
+    manifest:media-type="application/vnd.sun.star.basic-library"/>
+</manifest:manifest>
diff --git a/odk/examples/python/toolpanel/description.xml b/odk/examples/python/toolpanel/description.xml
new file mode 100755
index 0000000..a012658
--- /dev/null
+++ b/odk/examples/python/toolpanel/description.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<description xmlns="http://openoffice.org/extensions/description/2006" xmlns:xlink="http://www.w3.org/1999/xlink">
+    <version value="0.1.0"/>
+    <identifier value="org.libreoffice.example.toolpanel"/>
+</description>
diff --git a/odk/examples/python/toolpanel/toolPanelPocBasic/Module1.xba b/odk/examples/python/toolpanel/toolPanelPocBasic/Module1.xba
new file mode 100644
index 0000000..9d44f7f
--- /dev/null
+++ b/odk/examples/python/toolpanel/toolPanelPocBasic/Module1.xba
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
+<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Module1" script:language="StarBasic">
+global theDialog
+
+
+Sub dialogOnLoad(event)
+
+	theDialog = event.source
+		
+End Sub
+
+sub buttonClick(event)
+
+
+	theButton = theDialog.getControl(&quot;CommandButton1&quot;)
+	theTextField = theDialog.getControl(&quot;TextInfo&quot;)
+
+	colors = Array(rgb(255,0,0),rgb(0,255,0),rgb(0,0,255)) 
+	rank = getSystemTicks() mod 3
+
+	theDialog.Model.BackgroundColor = colors(rank)
+	theTextField.text =  cstr(Now) + chr(10)+&quot;Color &quot; + cstr(rank) + &quot; randomly applied&quot;
+	
+	theButton.label = &quot;Click Me to change color&quot;
+	
+
+end sub
+</script:module>
\ No newline at end of file
diff --git a/odk/examples/python/toolpanel/toolPanelPocBasic/dialog.xlb b/odk/examples/python/toolpanel/toolPanelPocBasic/dialog.xlb
new file mode 100644
index 0000000..a738363
--- /dev/null
+++ b/odk/examples/python/toolpanel/toolPanelPocBasic/dialog.xlb
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">
+<library:library xmlns:library="http://openoffice.org/2000/library" library:name="toolPanelPocBasic" library:readonly="false" library:passwordprotected="false"/>
\ No newline at end of file
diff --git a/odk/examples/python/toolpanel/toolPanelPocBasic/script.xlb b/odk/examples/python/toolpanel/toolPanelPocBasic/script.xlb
new file mode 100644
index 0000000..4d9cc4d
--- /dev/null
+++ b/odk/examples/python/toolpanel/toolPanelPocBasic/script.xlb
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">
+<library:library xmlns:library="http://openoffice.org/2000/library" library:name="toolPanelPocBasic" library:readonly="false" library:passwordprotected="false">
+ <library:element library:name="Module1"/>
+</library:library>
\ No newline at end of file
diff --git a/odk/examples/python/toolpanel/toolpanel.component b/odk/examples/python/toolpanel/toolpanel.component
new file mode 100644
index 0000000..0234e20
--- /dev/null
+++ b/odk/examples/python/toolpanel/toolpanel.component
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--# Version: MPL 1.1 / GPLv3+ / LGPLv3+
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License or as specified alternatively below. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# The Initial Developer of the Original Code is
+#       Laurent Godard <lgodard.libre at laposte.net>
+# Portions created by the Initial Developer are Copyright (C) 2011 the
+# Initial Developer. All Rights Reserved.
+#
+# Major Contributor(s):
+#
+# For minor contributions see the git repository.
+#
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+# instead of those above.-->
+
+<component loader="com.sun.star.loader.Python"
+    xmlns="http://openoffice.org/2010/uno-components">
+  <implementation name="org.libreoffice.example.toolpanel.pocFactory">
+    <service name="org.libreoffice.example.toolpanel.pocFactory"/>
+  </implementation>
+</component>
diff --git a/odk/examples/python/toolpanel/toolpanel.py b/odk/examples/python/toolpanel/toolpanel.py
new file mode 100644
index 0000000..31fce51
--- /dev/null
+++ b/odk/examples/python/toolpanel/toolpanel.py
@@ -0,0 +1,148 @@
+# Version: MPL 1.1 / GPLv3+ / LGPLv3+
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License or as specified alternatively below. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# The Initial Developer of the Original Code is
+#       Laurent Godard <lgodard.libre at laposte.net>
+# Portions created by the Initial Developer are Copyright (C) 2011 the
+# Initial Developer. All Rights Reserved.
+#
+# Major Contributor(s):
+#
+# For minor contributions see the git repository.
+#
+# inspired from core/testautomation/extensions/optional/input/extension_sources/TaskPaneComponent
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+# instead of those above.
+
+import uno
+import unohelper
+
+from com.sun.star.ui import XUIElementFactory
+from com.sun.star.ui import XUIElement
+from com.sun.star.ui.UIElementType import TOOLPANEL as unoTOOLPANEL
+from com.sun.star.ui import XToolPanel
+
+implementation_name = "org.libreoffice.example.toolpanel.pocFactory" # as defined in Factory.xcu
+implementation_services = ("org.libreoffice.example.toolpanel.pocFactory",)
+
+xdlPath = "toolpanels/poc.xdl" # the path inside the oxt
+extensionID = "org.libreoffice.example.toolpanel" # as defined in description.xml
+
+########################################################################
+########################################################################
+
+class pocToolPanel( unohelper.Base, XToolPanel ):
+
+        def __init__ ( self, xPanelWindow, ctx ):
+
+                self.ctx = ctx
+                self.PanelWindow = xPanelWindow
+                self.Window = xPanelWindow
+
+        def createAccessible( self, i_parentAccessible ):
+
+                return self.PanelWindow
+
+########################################################################
+########################################################################
+
+class pyPanel( unohelper.Base, XUIElement ):
+
+        def __init__ ( self, ctx, xFrame, xParentWindow, url ):
+
+                self.ctx = ctx
+                self.xParentWindow = xParentWindow
+                self.toolpanel = None
+                self.m_panelRootWindow = None
+
+                self.Frame = xFrame
+                self.ResourceURL = url
+                self.Type = unoTOOLPANEL
+
+
+        def getRealInterface( self ):
+
+                if not self.toolpanel:
+                        rootWindow = self.getOrCreatePanelRootWindow()
+                        self.toolpanel = pocToolPanel(rootWindow, self.ctx)
+
+                return self.toolpanel
+
+        def getOrCreatePanelRootWindow( self ):
+
+                pip = self.ctx.getValueByName("/singletons/com.sun.star.deployment.PackageInformationProvider" )
+                s = pip.getPackageLocation(extensionID)
+                dialogUrl = s + "/" + xdlPath
+
+                provider = self.ctx.ServiceManager.createInstanceWithContext("com.sun.star.awt.ContainerWindowProvider",self.ctx)  
+                self.m_panelRootWindow = provider.createContainerWindow(dialogUrl,"",self.xParentWindow, None)
+
+                return self.m_panelRootWindow
+
+        def postDisposing( self ):
+
+                super.postDisposing()
+
+                if self.m_panelRootWindow:
+                    self.m_panelRootWindow.dispose()
+                    self.m_panelRootWindow = None
+
+                self.toolpanel = None
+
+                return
+
+#######################################################################
+#######################################################################
+
+class pocFactory( unohelper.Base, XUIElementFactory ):
+
+        def __init__ ( self, ctx ):
+
+                self.ctx = ctx
+
+        def createUIElement( self, url, properties ):
+
+            xParentWindow = None
+            xFrame = None
+            xUIElement = None
+
+            for arg in properties:
+                if arg.Name == "Frame":
+                    xFrame = arg.Value
+                elif arg.Name == "ParentWindow":
+                    xParentWindow = arg.Value
+
+            if xFrame and xParentWindow:
+                try:
+                    xUIElement = pyPanel(self.ctx, xFrame, xParentWindow, url)
+                except Exception as e:
+                    print(e)
+
+            return xUIElement
+
+########################################################################
+########################################################################
+
+# pythonloader looks for a static g_ImplementationHelper variable
+g_ImplementationHelper = unohelper.ImplementationHelper ()
+
+# add the FormatFactory class to the implementation container,
+# which the loader uses to register/instantiate the component.
+g_ImplementationHelper.addImplementation (pocFactory,
+					implementation_name,
+					implementation_services,
+					)
+
diff --git a/odk/examples/python/toolpanel/toolpanels/poc.xdl b/odk/examples/python/toolpanel/toolpanels/poc.xdl
new file mode 100755
index 0000000..2e07cd6
--- /dev/null
+++ b/odk/examples/python/toolpanel/toolpanels/poc.xdl
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
+<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="MyDialog" dlg:left="192" dlg:top="127" dlg:width="174" dlg:height="147" dlg:closeable="true" dlg:moveable="true" dlg:help-url="customcontrol1" dlg:withtitlebar="false">
+ <script:event script:event-name="on-focus" script:macro-name="vnd.sun.star.script:toolPanelPocBasic.Module1.dialogOnLoad?language=Basic&amp;location=application" script:language="Script"/>
+ <dlg:bulletinboard>
+  <dlg:button dlg:id="CommandButton1" dlg:tab-index="0" dlg:left="6" dlg:top="8" dlg:width="80" dlg:height="30" dlg:value="The button label">
+   <script:event script:event-name="on-performaction" script:macro-name="vnd.sun.star.script:toolPanelPocBasic.Module1.buttonClick?language=Basic&amp;location=application" script:language="Script"/>
+  </dlg:button>
+  <dlg:textfield dlg:id="TextInfo" dlg:textarea-vertical-align="top" dlg:tab-index="1" dlg:left="6" dlg:top="48" dlg:width="80" dlg:height="59" dlg:value="a sample text" dlg:multiline="true"/>
+ </dlg:bulletinboard>
+</dlg:window>
-- 
1.7.1


--------------090105060102070800050708--


More information about the LibreOffice mailing list