From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- odk/examples/python/toolpanel/CalcWindowState.xcu | 29 +++++ odk/examples/python/toolpanel/Factory.xcu | 34 +++++ .../python/toolpanel/META-INF/manifest.xml | 23 ++++ odk/examples/python/toolpanel/Makefile | 29 +++++ odk/examples/python/toolpanel/description.xml | 13 ++ odk/examples/python/toolpanel/readme | 13 ++ .../python/toolpanel/toolPanelPocBasic/Module1.xba | 29 +++++ .../python/toolpanel/toolPanelPocBasic/dialog.xlb | 3 + .../python/toolpanel/toolPanelPocBasic/script.xlb | 5 + odk/examples/python/toolpanel/toolpanel.component | 16 +++ odk/examples/python/toolpanel/toolpanel.py | 139 +++++++++++++++++++++ odk/examples/python/toolpanel/toolpanels/poc.xdl | 11 ++ 12 files changed, 344 insertions(+) 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 100644 odk/examples/python/toolpanel/Makefile create mode 100644 odk/examples/python/toolpanel/description.xml create mode 100644 odk/examples/python/toolpanel/readme 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 100644 odk/examples/python/toolpanel/toolpanels/poc.xdl (limited to 'odk/examples/python/toolpanel') 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 @@ + + + + + + + + ToolPanel Proof of Concept + + + true + + + + + 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 @@ + + + + + + + + toolpanel + + + myToolPanelPoc + + + + + + org.libreoffice.example.toolpanel.pocFactory + + + + + 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 @@ + + + + + + + + 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 @@ + + + + + + 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 @@ + + + +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 + \ 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 @@ + + + \ 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 @@ + + + + + \ 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 @@ + + + + + + + + + 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 @@ + + + + + + + + + + + -- cgit v1.2.3