diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /odk/examples/python/toolpanel | |
parent | Initial commit. (diff) | |
download | libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'odk/examples/python/toolpanel')
-rw-r--r-- | odk/examples/python/toolpanel/CalcWindowState.xcu | 29 | ||||
-rw-r--r-- | odk/examples/python/toolpanel/Factory.xcu | 34 | ||||
-rw-r--r-- | odk/examples/python/toolpanel/META-INF/manifest.xml | 23 | ||||
-rw-r--r-- | odk/examples/python/toolpanel/Makefile | 29 | ||||
-rw-r--r-- | odk/examples/python/toolpanel/description.xml | 13 | ||||
-rw-r--r-- | odk/examples/python/toolpanel/readme | 13 | ||||
-rw-r--r-- | odk/examples/python/toolpanel/toolPanelPocBasic/Module1.xba | 29 | ||||
-rw-r--r-- | odk/examples/python/toolpanel/toolPanelPocBasic/dialog.xlb | 3 | ||||
-rw-r--r-- | odk/examples/python/toolpanel/toolPanelPocBasic/script.xlb | 5 | ||||
-rw-r--r-- | odk/examples/python/toolpanel/toolpanel.component | 16 | ||||
-rw-r--r-- | odk/examples/python/toolpanel/toolpanel.py | 139 | ||||
-rw-r--r-- | odk/examples/python/toolpanel/toolpanels/poc.xdl | 11 |
12 files changed, 344 insertions, 0 deletions
diff --git a/odk/examples/python/toolpanel/CalcWindowState.xcu b/odk/examples/python/toolpanel/CalcWindowState.xcu new file mode 100644 index 000000000..9abb827d8 --- /dev/null +++ b/odk/examples/python/toolpanel/CalcWindowState.xcu @@ -0,0 +1,29 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * +--> +<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 000000000..bc9b5feef --- /dev/null +++ b/odk/examples/python/toolpanel/Factory.xcu @@ -0,0 +1,34 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * +--> +<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.sdk.CustomToolPanel" 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 000000000..300501b7f --- /dev/null +++ b/odk/examples/python/toolpanel/META-INF/manifest.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * +--> +<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.component"/> + <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/Makefile b/odk/examples/python/toolpanel/Makefile new file mode 100644 index 000000000..a2e77f057 --- /dev/null +++ b/odk/examples/python/toolpanel/Makefile @@ -0,0 +1,29 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +PRJ = ../../.. +SETTINGS = $(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +FILES = \ + CalcWindowState.xcu \ + Factory.xcu \ + META-INF/manifest.xml \ + description.xml \ + toolPanelPocBasic/Module1.xba \ + toolPanelPocBasic/dialog.xlb \ + toolPanelPocBasic/script.xlb \ + toolpanel.component \ + toolpanel.py \ + toolpanels/poc.xdl + +$(OUT_BIN)/toolpanel.$(UNOOXT_EXT): $(FILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_ZIP) $@ $^ diff --git a/odk/examples/python/toolpanel/description.xml b/odk/examples/python/toolpanel/description.xml new file mode 100644 index 000000000..c448e8541 --- /dev/null +++ b/odk/examples/python/toolpanel/description.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * +--> +<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/readme b/odk/examples/python/toolpanel/readme new file mode 100644 index 000000000..5dedd9385 --- /dev/null +++ b/odk/examples/python/toolpanel/readme @@ -0,0 +1,13 @@ + +This extension is a Proof of concept on implementing Toolpanel in Python + +- make will create the oxt + - provided sdk environment is set + - alternatively zip the files and name it toolpanel.oxt +- install it +- activate Task Panes in menu (check View > Task Pane menu) +- enjoy! + +The events of the controls (Click me button) in the task panel are handled by basic macro code to illustrate that Toolpanel definition and events codes are independent. One could use any language to react on events + +Then focus only on .py and xml files for the toolpanel activation analysis diff --git a/odk/examples/python/toolpanel/toolPanelPocBasic/Module1.xba b/odk/examples/python/toolpanel/toolPanelPocBasic/Module1.xba new file mode 100644 index 000000000..9d44f7f01 --- /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("CommandButton1") + theTextField = theDialog.getControl("TextInfo") + + 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)+"Color " + cstr(rank) + " randomly applied" + + theButton.label = "Click Me to change color" + + +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 000000000..a738363ea --- /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 000000000..4d9cc4d51 --- /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 000000000..d7fde3545 --- /dev/null +++ b/odk/examples/python/toolpanel/toolpanel.component @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * +--> +<components xmlns="http://openoffice.org/2010/uno-components"> + <component loader="com.sun.star.loader.Python" uri="./toolpanel.py"> + <implementation name="org.libreoffice.example.toolpanel.pocFactory"> + <service name="org.libreoffice.example.toolpanel.pocFactory"/> + </implementation> + </component> +</components> diff --git a/odk/examples/python/toolpanel/toolpanel.py b/odk/examples/python/toolpanel/toolpanel.py new file mode 100644 index 000000000..8fcfb3f32 --- /dev/null +++ b/odk/examples/python/toolpanel/toolpanel.py @@ -0,0 +1,139 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +# inspired by core/testautomation/extensions/optional/input/extension_sources/TaskPaneComponent +# + +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 100644 index 000000000..2e07cd628 --- /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&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&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> |