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
24 from com
.sun
.star
.ui
import XUIElementFactory
25 from com
.sun
.star
.ui
import XUIElement
26 from com
.sun
.star
.ui
.UIElementType
import TOOLPANEL
as unoTOOLPANEL
27 from com
.sun
.star
.ui
import XToolPanel
29 implementation_name
= "org.libreoffice.example.toolpanel.pocFactory" # as defined in Factory.xcu
30 implementation_services
= ("org.libreoffice.example.toolpanel.pocFactory",)
32 xdlPath
= "toolpanels/poc.xdl" # the path inside the oxt
33 extensionID
= "org.libreoffice.example.toolpanel" # as defined in description.xml
35 ########################################################################
36 ########################################################################
38 class pocToolPanel( unohelper
.Base
, XToolPanel
):
40 def __init__ ( self
, xPanelWindow
, ctx
):
43 self
.PanelWindow
= xPanelWindow
44 self
.Window
= xPanelWindow
46 def createAccessible( self
, i_parentAccessible
):
48 return self
.PanelWindow
50 ########################################################################
51 ########################################################################
53 class pyPanel( unohelper
.Base
, XUIElement
):
55 def __init__ ( self
, ctx
, xFrame
, xParentWindow
, url
):
58 self
.xParentWindow
= xParentWindow
60 self
.m_panelRootWindow
= None
63 self
.ResourceURL
= url
64 self
.Type
= unoTOOLPANEL
67 def getRealInterface( self
):
69 if not self
.toolpanel
:
70 rootWindow
= self
.getOrCreatePanelRootWindow()
71 self
.toolpanel
= pocToolPanel(rootWindow
, self
.ctx
)
75 def getOrCreatePanelRootWindow( self
):
77 pip
= self
.ctx
.getValueByName("/singletons/com.sun.star.deployment.PackageInformationProvider" )
78 s
= pip
.getPackageLocation(extensionID
)
79 dialogUrl
= s
+ "/" + xdlPath
81 provider
= self
.ctx
.ServiceManager
.createInstanceWithContext("com.sun.star.awt.ContainerWindowProvider",self
.ctx
)
82 self
.m_panelRootWindow
= provider
.createContainerWindow(dialogUrl
,"",self
.xParentWindow
, None)
84 return self
.m_panelRootWindow
86 def postDisposing( self
):
90 if self
.m_panelRootWindow
:
91 self
.m_panelRootWindow
.dispose()
92 self
.m_panelRootWindow
= None
98 #######################################################################
99 #######################################################################
101 class pocFactory( unohelper
.Base
, XUIElementFactory
):
103 def __init__ ( self
, ctx
):
107 def createUIElement( self
, url
, properties
):
113 for arg
in properties
:
114 if arg
.Name
== "Frame":
116 elif arg
.Name
== "ParentWindow":
117 xParentWindow
= arg
.Value
119 if xFrame
and xParentWindow
:
121 xUIElement
= pyPanel(self
.ctx
, xFrame
, xParentWindow
, url
)
122 except Exception as e
:
127 ########################################################################
128 ########################################################################
130 # pythonloader looks for a static g_ImplementationHelper variable
131 g_ImplementationHelper
= unohelper
.ImplementationHelper ()
133 # add the FormatFactory class to the implementation container,
134 # which the loader uses to register/instantiate the component.
135 g_ImplementationHelper
.addImplementation (pocFactory
,
137 implementation_services
,