summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odk/CustomTarget_build-examples.mk1
-rw-r--r--odk/Package_examples.mk7
-rw-r--r--odk/examples/python/minimal-extension/Addons.xcu28
-rw-r--r--odk/examples/python/minimal-extension/META-INF/manifest.xml7
-rw-r--r--odk/examples/python/minimal-extension/Makefile25
-rw-r--r--odk/examples/python/minimal-extension/description.xml19
-rw-r--r--odk/examples/python/minimal-extension/main.py68
-rw-r--r--odk/examples/python/minimal-extension/pkg-description/pkg-description.en1
-rw-r--r--odk/examples/python/minimal-extension/registration/license.txt1
9 files changed, 157 insertions, 0 deletions
diff --git a/odk/CustomTarget_build-examples.mk b/odk/CustomTarget_build-examples.mk
index 4a725ad78846..dd5a2e58732e 100644
--- a/odk/CustomTarget_build-examples.mk
+++ b/odk/CustomTarget_build-examples.mk
@@ -28,6 +28,7 @@ my_example_dirs = \
cpp/counter \
cpp/remoteclient \
python/toolpanel \
+ python/minimal-extension \
# cpp/custompanel \
diff --git a/odk/Package_examples.mk b/odk/Package_examples.mk
index fe8d927c6d85..eb6c3563c5f5 100644
--- a/odk/Package_examples.mk
+++ b/odk/Package_examples.mk
@@ -551,6 +551,13 @@ $(eval $(call gb_Package_add_files_with_dir,odk_examples,$(SDKDIRNAME)/examples,
python/toolpanel/toolpanel.component \
python/toolpanel/toolpanel.py \
python/toolpanel/toolpanels/poc.xdl \
+ python/minimal-extension/Makefile \
+ python/minimal-extension/main.py \
+ python/minimal-extension/description.xml \
+ python/minimal-extension/Addons.xcu \
+ python/minimal-extension/registration/license.txt \
+ python/minimal-extension/pkg-description/pkg-description.en \
+ python/minimal-extension/META-INF/manifest.xml \
python/DocumentHandling/DocumentConverter.py \
python/DocumentHandling/DocumentLoader.py \
python/DocumentHandling/DocumentPrinter.py \
diff --git a/odk/examples/python/minimal-extension/Addons.xcu b/odk/examples/python/minimal-extension/Addons.xcu
new file mode 100644
index 000000000000..5d40bad39a19
--- /dev/null
+++ b/odk/examples/python/minimal-extension/Addons.xcu
@@ -0,0 +1,28 @@
+<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="Addons" oor:package="org.openoffice.Office">
+ <node oor:name="AddonUI">
+ <node oor:name="OfficeMenuBar">
+ <node oor:name="org.extension.sample.menubar" oor:op="replace">
+ <prop oor:name="Title" oor:type="xs:string">
+ <value xml:lang="en-US">Sample Extension</value>
+ </prop>
+ <prop oor:name="Context" oor:type="xs:string">
+ <value>com.sun.star.text.TextDocument</value>
+ </prop>
+ <node oor:name="Submenu">
+ <node oor:name="M1" oor:op="replace">
+ <prop oor:name="Title">
+ <value xml:lang="en-US">Example item</value>
+ </prop>
+ <prop oor:name="URL">
+ <value>service:org.extension.sample.do?FirstMenuItem</value>
+ </prop>
+ <prop oor:name="Target" oor:type="xs:string">
+ <value>_self</value>
+ </prop>
+ </node>
+ </node>
+ </node>
+ </node>
+ </node>
+</oor:component-data>
+
diff --git a/odk/examples/python/minimal-extension/META-INF/manifest.xml b/odk/examples/python/minimal-extension/META-INF/manifest.xml
new file mode 100644
index 000000000000..a3f7700875a3
--- /dev/null
+++ b/odk/examples/python/minimal-extension/META-INF/manifest.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE manifest:manifest PUBLIC "-//OpenOffice.org//DTD Manifest 1.0//EN" "Manifest.dtd">
+<manifest:manifest xmlns:manifest="http://openoffice.org/2001/manifest">
+ <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-component;type=Python" manifest:full-path="main.py" />
+ <manifest:file-entry manifest:full-path="pkg-desc/pkg-description.en" manifest:media-type="application/vnd.sun.star.package-bundle-description;locale=en"/>
+ <manifest:file-entry manifest:full-path="Addons.xcu" manifest:media-type="application/vnd.sun.star.configuration-data"/>
+</manifest:manifest>
diff --git a/odk/examples/python/minimal-extension/Makefile b/odk/examples/python/minimal-extension/Makefile
new file mode 100644
index 000000000000..0cd40a43c1b3
--- /dev/null
+++ b/odk/examples/python/minimal-extension/Makefile
@@ -0,0 +1,25 @@
+#
+# 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 = \
+ Addons.xcu \
+ META-INF/manifest.xml \
+ description.xml \
+ pkg-description/pkg-description.en \
+ registration/license.txt \
+ main.py
+
+$(OUT_BIN)/minimal-python.$(UNOOXT_EXT): $(FILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_ZIP) $@ $^
diff --git a/odk/examples/python/minimal-extension/description.xml b/odk/examples/python/minimal-extension/description.xml
new file mode 100644
index 000000000000..ccbba2566dc1
--- /dev/null
+++ b/odk/examples/python/minimal-extension/description.xml
@@ -0,0 +1,19 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<description
+ xmlns="http://openoffice.org/extensions/description/2006"
+ xmlns:dep="http://openoffice.org/extensions/description/2006"
+ xmlns:xlink="http://www.w3.org/1999/xlink">
+ <identifier value="org.extension.sample"/>
+ <version value="1.0"/>
+ <registration>
+ <simple-license accept-by="admin" default-license-id="ID0" suppress-on-update="true" >
+ <license-text xlink:href="registration/license.txt" lang="en" license-id="ID0" />
+ </simple-license>
+ </registration>
+ <publisher>
+ <name xlink:href="mailto:developer@mywebsite.org">Developer</name>
+ </publisher>
+ <display-name>
+ <name>Minimal Python extension</name>
+ </display-name>
+</description>
diff --git a/odk/examples/python/minimal-extension/main.py b/odk/examples/python/minimal-extension/main.py
new file mode 100644
index 000000000000..225d5bbfa942
--- /dev/null
+++ b/odk/examples/python/minimal-extension/main.py
@@ -0,0 +1,68 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# 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/.
+#
+
+import sys
+import unohelper
+import officehelper
+
+from com.sun.star.task import XJobExecutor
+
+
+# The MainJob is a UNO component derived from unohelper.Base class
+# and also the XJobExecutor, the implemented interface
+class MainJob(unohelper.Base, XJobExecutor):
+ def __init__(self, ctx):
+ self.ctx = ctx
+ # handling different situations (inside LibreOffice or other process)
+ try:
+ self.sm = ctx.getServiceManager()
+ self.desktop = XSCRIPTCONTEXT.getDesktop()
+ except NameError:
+ self.sm = ctx.ServiceManager
+ self.desktop = self.ctx.getServiceManager().createInstanceWithContext(
+ "com.sun.star.frame.Desktop", self.ctx)
+
+ def trigger(self, args):
+ desktop = self.ctx.ServiceManager.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", self.ctx)
+ model = desktop.getCurrentComponent()
+ if not hasattr(model, "Text"):
+ model = self.desktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, ())
+ text = model.Text
+ cursor = text.createTextCursor()
+ text.insertString(cursor, "Hello Extension argument -> " + args + "\n", 0)
+
+
+# Starting from Python IDE
+def main():
+ try:
+ ctx = XSCRIPTCONTEXT
+ except NameError:
+ ctx = officehelper.bootstrap()
+ if ctx is None:
+ print("ERROR: Could not bootstrap default Office.")
+ sys.exit(1)
+ job = MainJob(ctx)
+ job.trigger("hello")
+
+
+# Starting from command line
+if __name__ == "__main__":
+ main()
+
+
+# pythonloader loads a static g_ImplementationHelper variable
+g_ImplementationHelper = unohelper.ImplementationHelper()
+
+g_ImplementationHelper.addImplementation(
+ MainJob, # UNO object class
+ "org.extension.sample.do", # implementation name (customize for yourself)
+ ("com.sun.star.task.Job",), ) # implemented services (only 1)
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/odk/examples/python/minimal-extension/pkg-description/pkg-description.en b/odk/examples/python/minimal-extension/pkg-description/pkg-description.en
new file mode 100644
index 000000000000..81c8f8c90102
--- /dev/null
+++ b/odk/examples/python/minimal-extension/pkg-description/pkg-description.en
@@ -0,0 +1 @@
+Example LibreOffice extension. Copyright (c) Developer 2023.
diff --git a/odk/examples/python/minimal-extension/registration/license.txt b/odk/examples/python/minimal-extension/registration/license.txt
new file mode 100644
index 000000000000..4bf8bc8df55c
--- /dev/null
+++ b/odk/examples/python/minimal-extension/registration/license.txt
@@ -0,0 +1 @@
+A very short license.