1#************************************************************** 2# 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance 9# with the License. You may obtain a copy of the License at 10# 11# http://www.apache.org/licenses/LICENSE-2.0 12# 13# Unless required by applicable law or agreed to in writing, 14# software distributed under the License is distributed on an 15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16# KIND, either express or implied. See the License for the 17# specific language governing permissions and limitations 18# under the License. 19# 20#************************************************************** 21 22import uno 23import unohelper 24 25from com.sun.star.awt import Rectangle 26from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK 27from com.sun.star.awt.MessageBoxType import INFOBOX 28from com.sun.star.frame import XDispatch, XDispatchProvider 29from com.sun.star.lang import XServiceInfo 30from com.sun.star.registry import InvalidRegistryException 31 32class Provider(unohelper.Base, XServiceInfo, XDispatchProvider): 33 implementationName = "com.sun.star.comp.test.deployment.active_python" 34 35 serviceNames = ("com.sun.star.test.deployment.active_python",) 36 37 def __init__(self, context): 38 self.context = context 39 40 def getImplementationName(self): 41 return self.implementationName 42 43 def supportsService(self, ServiceName): 44 return ServiceName in self.serviceNames 45 46 def getSupportedServiceNames(self): 47 return self.serviceNames 48 49 def queryDispatch(self, URL, TargetFrame, SearchFlags): 50 return self.context.getValueByName( \ 51 "/singletons/com.sun.star.test.deployment.active_python_singleton") 52 53 def queryDispatches(self, Requests): 54 tuple( \ 55 self.queryDispatch(i.FeatureURL, i.FrameName, i.SearchFlags) \ 56 for i in Requests) 57 58class Dispatch(unohelper.Base, XServiceInfo, XDispatch): 59 implementationName = \ 60 "com.sun.star.comp.test.deployment.active_python_singleton" 61 62 serviceNames = () 63 64 def __init__(self, context): 65 self.context = context 66 67 def getImplementationName(self): 68 return self.implementationName 69 70 def supportsService(self, ServiceName): 71 return ServiceName in self.serviceNames 72 73 def getSupportedServiceNames(self): 74 return self.serviceNames 75 76 def dispatch(self, URL, Arguments): 77 smgr = self.context.getServiceManager() 78 box = smgr.createInstanceWithContext( \ 79 "com.sun.star.awt.Toolkit", self.context).createMessageBox( \ 80 smgr.createInstanceWithContext( \ 81 "com.sun.star.frame.Desktop", self.context). \ 82 getCurrentFrame().getComponentWindow(), \ 83 INFOBOX, BUTTONS_OK, "active", "python") 84 box.execute(); 85 box.dispose(); 86 87 def addStatusListener(self, Control, URL): 88 pass 89 90 def removeStatusListener(self, Control, URL): 91 pass 92 93def getComponentFactory(implementationName, smgr, regKey): 94 if implementationName == Provider.implementationName: 95 return unohelper.createSingleServiceFactory( \ 96 Provider, Provider.implementationName, Provider.serviceNames) 97 elif implementationName == Dispatch.implementationName: 98 return unohelper.createSingleServiceFactory( \ 99 Dispatch, Dispatch.implementationName, Dispatch.serviceNames) 100 else: 101 return None 102 103def writeRegistryInfo(smgr, regKey): 104 try: 105 for i in (Provider, Dispatch): 106 key = regKey.createKey("/" + i.implementationName + "/UNO") 107 for j in i.serviceNames: 108 key.createKey("/SERVICES/" + j); 109 regKey.createKey( \ 110 "/" + Dispatch.implementationName + "/UNO/SINGLETONS/" \ 111 "com.sun.star.test.deployment.active_python_singleton"). \ 112 setStringValue(Dispatch.implementationName) 113 except InvalidRegistryException: 114 return False 115 return True 116