The code box contains the relevant code of my
SpecialCells extension which opens the help file of that extension which is a Writer document.
Code: Select all
def getConfigurationRoot(ctx,sNodePath):
sProvider = "com.sun.star.configuration.ConfigurationProvider"
sAccess = "com.sun.star.configuration.ConfigurationAccess"
aConfigProvider = createUnoService(ctx,sProvider)
prp = uno.createUnoStruct("com.sun.star.beans.PropertyValue")
prp.Name = "nodepath"
prp.Value = sNodePath
result = aConfigProvider.createInstanceWithArguments(sAccess, (prp,))
return result
def getMacroExpander(ctx):
btx = ctx.getServiceManager().createInstanceWithContext("com.sun.star.configuration.bootstrap.BootstrapContext", ctx)
if btx:
return btx.getValueByName("/singletons/com.sun.star.util.theMacroExpander")
else:
return ctx.getValueByName("/singletons/com.sun.star.util.theMacroExpander")
class ConfigProvider(XJobExecutor,unohelper.Base):
RootNode = 'name.AndreasSaeger.SpecialCells.Localization/LocalizedStrings'
HelpDoc = 'SpecialCells.sxw'
Bookmark = '#_TOP'
def __init__(self,ctx,):
try:
self.FileAccess = createUnoService(ctx, 'com.sun.star.ucb.SimpleFileAccess')
self.Desktop = getDesktop(ctx)
self.ConfRoot = getConfigurationRoot(ctx,ConfigProvider.RootNode)
# %origin%/../help/SpecialCells.sxw
# vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE/uno_packages/SHZUe5_/SpecialCells.0.5.62.uno.zip/registry/../help/en/SpecialCells.sxw
EXP = getMacroExpander(ctx)
sMacroString = self.ConfRoot.getByName('HelpPath')
sPrefix = "vnd.sun.star.expand:"
sURL = EXP.expandMacros(sMacroString)
n = len(sPrefix)
if sURL.startswith(sPrefix):
sURL = sURL[n:]
self.HelpPath = sURL
except:
pass
def getHelpURL(self,sHelpFile):
"""return complete URL if self.HelpPath/sHelpFile exists, else ''"""
sResult = ''
try:
if self.HelpPath.endswith('/'):
sURL = self.HelpPath + sHelpFile
else:
sURL = self.HelpPath +'/'+ sHelpFile
if self.FileAccess.exists(sURL):
sResult = sURL
except:
pass
return sResult
def trigger(self,arg=''):
if self.HelpPath:
sURL = self.getHelpURL(ConfigProvider.HelpDoc)
self.loadHelpDocument(sURL + ConfigProvider.Bookmark)
def loadHelpDocument(self,sURL,):
'''Load writer document read-only'''
try:
prp = uno.createUnoStruct("com.sun.star.beans.PropertyValue")
prp.Name = "ReadOnly"
prp.Value = True
oDoc = self.Desktop.loadComponentFromURL(sURL,"_default",0,(prp,))
if oDoc:
oFrame = oDoc.getCurrentController().getFrame()
oFrame.activate()
oFrame.getContainerWindow().toFront()
except:
pass
if __name__ == "__main__":
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", localContext )
ctx = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
oConfProvider = ConfigProvider(ctx,)
p = oConfProvider.HelpPath
print p
fileURL = oConfProvider.getHelpURL('SpecialCells.sxw')
print fileURL
# open the help file at bookmark #_DialogCellFormatRanges
oConfProvider.trigger(fileURL +'#_DialogCellFormatRanges')
I used the __main__ routine for testing against a listening office instance. Class ConfigProvider gets initialized with the right component context of the listening office suite and determines the full path of the help file within the installed extension from its registered root node 'name.AndreasSaeger.SpecialCells.Localization/LocalizedStrings'