Move setting of LD_LIBRARY_PATH closer to invocation of cppunittester
[LibreOffice.git] / odk / examples / python / toolpanel / toolpanel.py
bloba4b05b8ca46f179dbc769ee798ccf24e74333b4a
2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 # inspired by core/testautomation/extensions/optional/input/extension_sources/TaskPaneComponent
21 import unohelper
23 from com.sun.star.ui import XUIElementFactory
24 from com.sun.star.ui import XUIElement
25 from com.sun.star.ui.UIElementType import TOOLPANEL as unoTOOLPANEL
26 from com.sun.star.ui import XToolPanel
28 implementation_name = "org.libreoffice.example.toolpanel.pocFactory" # as defined in Factory.xcu
29 implementation_services = ("org.libreoffice.example.toolpanel.pocFactory",)
31 xdlPath = "toolpanels/poc.xdl" # the path inside the oxt
32 extensionID = "org.libreoffice.example.toolpanel" # as defined in description.xml
34 ########################################################################
35 ########################################################################
37 class pocToolPanel( unohelper.Base, XToolPanel ):
39 def __init__ ( self, xPanelWindow, ctx ):
41 self.ctx = ctx
42 self.PanelWindow = xPanelWindow
43 self.Window = xPanelWindow
45 def createAccessible( self, i_parentAccessible ):
47 return self.PanelWindow
49 ########################################################################
50 ########################################################################
52 class pyPanel( unohelper.Base, XUIElement ):
54 def __init__ ( self, ctx, xFrame, xParentWindow, url ):
56 self.ctx = ctx
57 self.xParentWindow = xParentWindow
58 self.toolpanel = None
59 self.m_panelRootWindow = None
61 self.Frame = xFrame
62 self.ResourceURL = url
63 self.Type = unoTOOLPANEL
66 def getRealInterface( self ):
68 if not self.toolpanel:
69 rootWindow = self.getOrCreatePanelRootWindow()
70 self.toolpanel = pocToolPanel(rootWindow, self.ctx)
72 return self.toolpanel
74 def getOrCreatePanelRootWindow( self ):
76 pip = self.ctx.getValueByName("/singletons/com.sun.star.deployment.PackageInformationProvider" )
77 s = pip.getPackageLocation(extensionID)
78 dialogUrl = s + "/" + xdlPath
80 provider = self.ctx.ServiceManager.createInstanceWithContext("com.sun.star.awt.ContainerWindowProvider",self.ctx)
81 self.m_panelRootWindow = provider.createContainerWindow(dialogUrl,"",self.xParentWindow, None)
83 return self.m_panelRootWindow
85 def postDisposing( self ):
87 super.postDisposing()
89 if self.m_panelRootWindow:
90 self.m_panelRootWindow.dispose()
91 self.m_panelRootWindow = None
93 self.toolpanel = None
95 return
97 #######################################################################
98 #######################################################################
100 class pocFactory( unohelper.Base, XUIElementFactory ):
102 def __init__ ( self, ctx ):
104 self.ctx = ctx
106 def createUIElement( self, url, properties ):
108 xParentWindow = None
109 xFrame = None
110 xUIElement = None
112 for arg in properties:
113 if arg.Name == "Frame":
114 xFrame = arg.Value
115 elif arg.Name == "ParentWindow":
116 xParentWindow = arg.Value
118 if xFrame and xParentWindow:
119 try:
120 xUIElement = pyPanel(self.ctx, xFrame, xParentWindow, url)
121 except Exception as e:
122 print(e)
124 return xUIElement
126 ########################################################################
127 ########################################################################
129 # pythonloader looks for a static g_ImplementationHelper variable
130 g_ImplementationHelper = unohelper.ImplementationHelper ()
132 # add the FormatFactory class to the implementation container,
133 # which the loader uses to register/instantiate the component.
134 g_ImplementationHelper.addImplementation (pocFactory,
135 implementation_name,
136 implementation_services,