| View previous topic :: View next topic |
| Author |
Message |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Sat May 01, 2004 12:40 pm Post subject: Development of Calc Function add ons in Python |
|
|
In the Developer's Guide, you can find a section on how to develop Calc Add-Ons.
I would like to do the following....
1. Develop a trivial Calc function add on in Python.
2. To be followed by more sophisticated functions.
3. To be followed by eventually running a Poll on OOoForum asking what kind of functions shoudl be developed. (PLEASE don't post any answers to this question AT THIS TIME. This post is a ROADMAP, NOT A REQUEST for ideas.)
4. Build a canned example, posted to OOoForum that is specifically designed for easy cloning and creation of new Calc functions.
In regard to item (1), I have gotten started on this today. No success yet. The component below is intended to add the following new functions to the Calc spreadsheet.
=AddFive( x )
=AddSix( x )
Using the AddFive() function in a spreadsheet, returns the argument x with five added to it. You can guess what AddSix() does. One component that implements multiple functions. Each function will have the tooltips, descriptions, appear in the function list, etc. just like built in calc functions.
Each of the functions is localized to the English US language. Later, when I get the basic concept to work, I will add an mechanism (Item 4 on above list) so that it is easy to just clone this framework, add new functions, and localize them for a number of languages.
Has anyone ever developed a Calc function? Any insights into why my component is not working? Any experts that can help?
Here is how you install it and what happens.
WARNING! DO NOT do this unless you have fully read this post and understand the consequences. Be sure not to have any important documents open in OOo.
Copy all of the code below into a file, and name it DannyCalcAddOn.py. Place this file into your
OOo\user\uno_packages
folder. Make sure OOo is not running, including quickstarter. Run pkgchk. Check the log.txt file in the newly created
OOo\user\uno_packages\cache
folder to make sure the component installed without incident. Start OOo, but do NOT open any important documents.
At this point, you cannot create a spreadsheet. So having simply registered my component definitely had an effect. You cannot open or create a new spreadsheet. But other document types are unaffected. As long as you never attempt to open or create a spreadsheet, everything works okay. As soon as you attempt to open or create a spreadsheet it fails, and you are now unable to close any other open documents.
It is interesting that the mere registration of a component has this effect on the spreadsheet. We have not even done anything (explicitly) to invoke the component.
You can uninstall the component as follows. Quit out of OOo, including the quickstarter. Remove the DannyCalcAddOn.py file from the uno_packages folder where you placed it. Run pkgchk again.
There is an easier way to remove. If you have no *other* third party components installed, then simply just throw away both files...
DannyCalcAddOn.py
and the Cache folder. No need to run pkgchk.
The component is now uninstalled and OOo is back to normal.
It is unclear to me what I am missing or doing wrong.
Maybe some expert out there can help?
Here is my first attempt at a Calc function add on.
| Code: | import sys
import unohelper
from com.sun.star.sheet import XAddIn
from com.sun.star.sheet import XCompatibilityNames
from com.sun.star.lang import XServiceName
from com.sun.star.lang import XLocalizable
g_ImplementationHelper = unohelper.ImplementationHelper()
class DannysCalcFunctions1( unohelper.Base, XAddIn, XLocalizable, XCompatibilityNames, XServiceName ):
# The component must have a ctor with the component context as argument.
def __init__( self, oContext ):
self.oContext = oContext
self.oCoreReflection = None
self.StarDesktop = None
self.getDesktop()
#----------------------------------------
# Danny's stuff to make programming less convenient.
#----------------------------------------
def getServiceManager( self ):
"""Get the ServiceManager from the running OpenOffice.org.
"""
return self.oContext.ServiceManager
def createUnoService( self, cClass ):
"""A handy way to create a global objects within the running OOo.
"""
oServiceManager = self.getServiceManager()
oObj = oServiceManager.createInstance( cClass )
return oObj
def getDesktop( self ):
"""An easy way to obtain the Desktop object from a running OOo.
"""
if self.StarDesktop == None:
self.StarDesktop = self.createUnoService( "com.sun.star.frame.Desktop" )
return self.StarDesktop
def getCoreReflection( self ):
if self.oCoreReflection == None:
self.oCoreReflection = self.createUnoService( "com.sun.star.reflection.CoreReflection" )
return oCoreReflection
def createUnoStruct( self, cTypeName ):
"""Create a UNO struct and return it.
"""
oCoreReflection = self.getCoreReflection()
# Get the IDL class for the type name
oXIdlClass = oCoreReflection.forName( cTypeName )
# Create the struct.
oReturnValue, oStruct = oXIdlClass.createObject( None )
return oStruct
def makePropertyValue( self, cName=None, uValue=None, nHandle=None, nState=None ):
"""Create a com.sun.star.beans.PropertyValue struct and return it.
"""
oPropertyValue = self.createUnoStruct( "com.sun.star.beans.PropertyValue" )
if cName != None:
oPropertyValue.Name = cName
if uValue != None:
oPropertyValue.Value = uValue
if nHandle != None:
oPropertyValue.Handle = nHandle
if nState != None:
oPropertyValue.State = nState
return oPropertyValue
#----------------------------------------
# Inconvenience routines for working with structs needed later
#
def makeLocale( self, cLanguage="", cCountry="", cVariant="" ):
oLocale = self.createUnoStruct( "com.sun.star.lang.Locale" )
oLocale.Language = cLanguage
oLocale.Country = cCountry
oLocale.Variant = oVariant
return oLocale
def makeLocalizedName( self, stLocale, cName ):
oLocalizedName = self.createUnoStruct( "com.sun.star.sheet.LocalizedName" )
oLocalizedName.Locale = stLocale
oLocalizedName.Name = cName
return oLocalizedName
#----------------------------------------
# Interface: XAddIn
# Inherits from... XLocalizable
#----------------------------------------
# string
# getProgrammaticFuntionName( [in] string aDisplayName );
# Note: the method name spelling error is in the API!
def getProgrammaticFuntionName( self, cDisplayFnName ):
if cDisplayFnName == "AddFive":
return "nom.DannyBrewer.test.DannysCalcFunctions1.AddFive"
elif cDisplayFnName == "AddSix":
return "nom.DannyBrewer.test.DannysCalcFunctions1.AddSix"
return ""
# string
# getDisplayFunctionName( [in] string aProgrammaticName );
def getDisplayFunctioName( self, cProgrammaticFnName ):
if cProgrammaticFnName == "nom.DannyBrewer.test.DannysCalcFunctions1.AddFive":
return "AddFive"
elif cProgrammaticFnName == "nom.DannyBrewer.test.DannysCalcFunctions1.AddSix":
return "AddSix"
return ""
# string
# getFunctionDescription( [in] string aProgrammaticName );
def getFunctionDescription( self, ccProgrammaticFnName ):
if cProgrammaticFnName == "nom.DannyBrewer.test.DannysCalcFunctions1.AddFive":
return "Adds five to the argument."
elif cProgrammaticFnName == "nom.DannyBrewer.test.DannysCalcFunctions1.AddSix":
return "Add six to the argument."
return ""
# string
# getDisplayArgumentName( [in] string aProgrammaticName
# [in] long nArgument );
def getDisplayArgumentName( self, ccProgrammaticFnName, nArgNum ):
if cProgrammaticFnName == "nom.DannyBrewer.test.DannysCalcFunctions1.AddFive":
if nArgNum == 0:
return "number"
elif cProgrammaticFnName == "nom.DannyBrewer.test.DannysCalcFunctions1.AddSix":
if nArgNum == 0:
return "number"
return ""
# string
# getArgumentDescription( [in] string aProgrammaticName
# [in] long nArgument );
def getArgumentDescription( self, ccProgrammaticFnName, nArgNum ):
if cProgrammaticFnName == "nom.DannyBrewer.test.DannysCalcFunctions1.AddFive":
if nArgNum == 0:
return "A number to which five will be added."
elif cProgrammaticFnName == "nom.DannyBrewer.test.DannysCalcFunctions1.AddSix":
if nArgNum == 0:
return "A number to which six will be added."
return ""
# string
# getProgrammaticCategoryName( [in] string aProgrammaticName );
def getProgrammaticCategoryName( self, ccProgrammaticFnName ):
if cProgrammaticFnName == "nom.DannyBrewer.test.DannysCalcFunctions1.AddFive":
return "Add-In"
elif cProgrammaticFnName == "nom.DannyBrewer.test.DannysCalcFunctions1.AddSix":
return "Add-In"
return ""
# string
# getDisplayCategoryName( [in] string aProgrammaticName );
def getDisplayCategoryName( self, ccProgrammaticFnName ):
if cProgrammaticFnName == "nom.DannyBrewer.test.DannysCalcFunctions1.AddFive":
return "Add-In"
elif cProgrammaticFnName == "nom.DannyBrewer.test.DannysCalcFunctions1.AddSix":
return "Add-In"
return ""
#----------------------------------------
# Interface: XCompatibilityNames
#----------------------------------------
# sequence< LocalizedName >
# getCompatibilityNames( [in] string aProgrammaticName );
def getCompatibilityNames( self, ccProgrammaticFnName ):
if cProgrammaticFnName == "nom.DannyBrewer.test.DannysCalcFunctions1.AddFive":
return (
self.makeLocalizedName( self.makeLocale( "en", "US", "" ),
"AddFive" )
,)
elif cProgrammaticFnName == "nom.DannyBrewer.test.DannysCalcFunctions1.AddSix":
return (
self.makeLocalizedName( self.makeLocale( "en", "US", "" ),
"AddSix" )
,)
return ()
#----------------------------------------
# Interface: XLocalizable
# This is here because XAddIn inherits it.
#----------------------------------------
# void
# setLocale( [in] Locale eLocale );
def setLocale( self, stLocale ):
return
# Locale
# getLocale();
def getLocale( self ):
return self.makeLocale( "en", "US", "" )
#----------------------------------------
# Interface: XServiceName
#----------------------------------------
# string
# getServiceName();
def getServiceName( self ):
return "nom.DannyBrewer.test.DannysCalcFunctions1"
# add the class to the implementation container,
# which the loader uses to register/instantiate the component.
g_ImplementationHelper.addImplementation( \
# The class
DannysCalcFunctions1,
# The implementation name.
# Change this name for your own service.
"nom.DannyBrewer.test.DannysCalcFunctions1",
# A list of services that that are implemented.
("com.sun.star.sheet.AddIn",), )
|
It is also worth noting that I have not figured out where to actually implement the two functions AddFive() and AddSix(). All of the above is just the infrastructure for making the two functions and their descriptions and argument lists known to Calc.
I still have to finish reading the above linked section of the Developer's Guide again. Maybe I can figure out what I'm missing. Or maybe there is a fully working Calc function example somewhere else (even in a different language?) that I can examine? _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Sat May 01, 2004 2:40 pm Post subject: |
|
|
I think I figured out what is likely the problem after looking at the Java example, and scrounging around in the archives of the developer's mailing lists.
I need to implement a second service. That second service needs to implement a custom interface. Yuck. That means creating the IDL description file, compiling it, etc. I don't have any more time to spend on this today. Oh, well, next saturday.
But I think I may have it figured out. Thank goodness the python bridge implements the XTypeProvider interface.
Still, any advice appreciated. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3623 Location: Columbus, Ohio, USA
|
Posted: Sat May 01, 2004 7:27 pm Post subject: |
|
|
Hi Danny,
I am sorry for such a lame reply (given that I have never done what you are doing), but... I understand that version two will possible make this process easier. Have you investigated this at all? _________________ --
Andrew Pitonyak
http://www.pitonyak.org/oo.php |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Sun May 02, 2004 6:49 am Post subject: |
|
|
| pitonyak wrote: | | I understand that version two will possible make this process easier. Have you investigated this at all? |
Hi Andrew, long time no see.
Very interesting. Do you have any more detailed information on how/why this might be easier.
I know of an example of something else that is supposed to be easier in 2.0. Writing new help files for OOo's online help. Many other internal improvements as well. The UI configuration is supposed to be part of the configuration manager, so that just using the config mgr API you could customize the UI just like using Tools --> Configure (which will be renamed Tools --> Customize). I read various e-mail messages and specs, but I don't have links to where I read these tidbits. So I don't expect you to necessarily know where you might have seen such an interesting tidbit about Calc functions. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Wed Aug 18, 2004 11:51 am Post subject: |
|
|
I'm close to having a working Calc Add-In in Python. There is one problem.
If my python component is not first loaded by the following macro (from a Draw document), then I cannot open or create any new spreadsheet documents.
| Code: | Sub Main
' just load the service, then forget it.
oService = createUnoService( "name.dannyBrewer.test.DannysCalcFunctions1" )
End Sub
|
Once this macro is run, then everything works perfectly. My new calc functions work just great for as long as OOo is running. The new add-in functions show up propertly in calc's
Insert --> Function...
dialog, and the new functions and their parameters are described perfectly.
I have carefully re-read 8.6 Spreadsheet Add-Ins from the Developer's Guide. I also am looking carefully at the example add-in (written in java) in the SDK. (CalcAddins.java)
I am using OOo 1.1.2 on Win XP.
If a macro does not first instantiate my service, then I get the following results...
Create new calc document.... nothing, no window appears, nothing happens.
Loading a Calc document that does NOT reference my functions... Empty calc window, but no cells.
Loading a Calc document that DOES reference my functions...
Error loading document file:///C:/Danny/....path.to.document.sxc:
Read-Error.
An unknown error has occured.
Now, I know that the document can be loaded. Once I either uninstall my component from the office, or run a macro that loads my component, then this spreadsheet containing my new functions can be read in just fine.
My IDL looks like this....
| Code: | #include <com/sun/star/uno/XInterface.idl>
#include <com/sun/star/beans/XPropertySet.idl>
#include <com/sun/star/sheet/AddIn.idl>
module name {
module dannyBrewer {
module test {
interface XDannysCalcFunctions1 : com::sun::star::uno::XInterface
{
long addFive(
[in] long intDummy
);
long addSix(
[in] long intDummy
);
};
service DannysCalcFunctions1
{
interface XDannysCalcFunctions1;
};
};
};
};
|
and
| Code: | #include <com/sun/star/uno/XInterface.idl>
#include <com/sun/star/beans/PropertyValue.idl>
module name {
module dannyBrewer {
module misc {
interface XCommand : com::sun::star::uno::XInterface
{
any doCommand(
[in] string cCommand,
[in] sequence< com::sun::star::beans::PropertyValue > aParams
);
};
};
};
};
|
(Note the XCommand interface is just a private interface I use for debugging/testing. See it in the Python code below.)
My Python code looks like this.
| Code: | import uno
import unohelper
g_ImplementationHelper = unohelper.ImplementationHelper()
##################################################################
# Global initialization routines.
def globalInitialization( oComponentContext ):
"""This is called when a service is instantiated."""
global goServiceManager
if goServiceManager == False:
goServiceManager = oComponentContext.ServiceManager
# preload the StarDesktop variable.
getDesktop()
#------------------------------------------------------------
# Uno ServiceManager access
# A different version of this routine and global variable
# is needed for code running inside a component.
#------------------------------------------------------------
# The ServiceManager of the running OOo.
# It is cached in a global variable.
goServiceManager = False
def getServiceManager( cHost="localhost", cPort="8100" ):
"""Get the ServiceManager from the running OpenOffice.org.
Then retain it in the global variable goServiceManager for future use.
This is similar to the GetProcessServiceManager() in OOo Basic.
"""
global goServiceManager
# if not goServiceManager:
# # Get the uno component context from the PyUNO runtime
# oLocalContext = uno.getComponentContext()
# # Create the UnoUrlResolver on the Python side.
# oLocalResolver = oLocalContext.ServiceManager.createInstanceWithContext(
# "com.sun.star.bridge.UnoUrlResolver", oLocalContext )
# # Connect to the running OpenOffice.org and get its context.
# oContext = oLocalResolver.resolve( "uno:socket,host=" + cHost + ",port=" + cPort + ";urp;StarOffice.ComponentContext" )
# # Get the ServiceManager object
# goServiceManager = oContext.ServiceManager
return goServiceManager
#------------------------------------------------------------
# Uno convenience functions
# The stuff in this section is just to make
# python progrmaming of OOo more like using OOo Basic.
#------------------------------------------------------------
# This is the same as ServiceManager.createInstance( ... )
def createUnoService( cClass ):
"""A handy way to create a global objects within the running OOo.
Similar to the function of the same name in OOo Basic.
"""
oServiceManager = getServiceManager()
oObj = oServiceManager.createInstance( cClass )
return oObj
# The StarDesktop object. (global like in OOo Basic)
# It is cached in a global variable.
StarDesktop = None
def getDesktop():
"""An easy way to obtain the Desktop object from a running OOo.
"""
global StarDesktop
if StarDesktop == None:
StarDesktop = createUnoService( "com.sun.star.frame.Desktop" )
return StarDesktop
# The CoreReflection object.
# It is cached in a global variable.
goCoreReflection = False
def getCoreReflection():
global goCoreReflection
if not goCoreReflection:
goCoreReflection = createUnoService( "com.sun.star.reflection.CoreReflection" )
return goCoreReflection
def createUnoStruct( cTypeName ):
"""Create a UNO struct and return it.
Similar to the function of the same name in OOo Basic.
"""
oCoreReflection = getCoreReflection()
# Get the IDL class for the type name
oXIdlClass = oCoreReflection.forName( cTypeName )
# Create the struct.
oReturnValue, oStruct = oXIdlClass.createObject( None )
return oStruct
#------------------------------------------------------------
# API helpers
#------------------------------------------------------------
def hasUnoInterface( oObject, cInterfaceName ):
"""Similar to Basic's HasUnoInterfaces() function, but singular not plural."""
# Get the Introspection service.
oIntrospection = createUnoService( "com.sun.star.beans.Introspection" )
# Now inspect the object to learn about it.
oObjInfo = oIntrospection.inspect( oObject )
# Obtain an array describing all methods of the object.
oMethods = oObjInfo.getMethods( uno.getConstantByName( "com.sun.star.beans.MethodConcept.ALL" ) )
# Now look at every method.
for oMethod in oMethods:
# Check the method's interface to see if
# these aren't the droids you're looking for.
cMethodInterfaceName = oMethod.getDeclaringClass().getName()
if cMethodInterfaceName == cInterfaceName:
return True
return False
def hasUnoInterfaces( oObject, *cInterfaces ):
"""Similar to the function of the same name in OOo Basic."""
for cInterface in cInterfaces:
if not hasUnoInterface( oObject, cInterface ):
return False
return True
#------------------------------------------------------------
# High level general purpose functions
#------------------------------------------------------------
def makePropertyValue( cName=None, uValue=None, nHandle=None, nState=None ):
"""Create a com.sun.star.beans.PropertyValue struct and return it.
"""
oPropertyValue = createUnoStruct( "com.sun.star.beans.PropertyValue" )
if cName != None:
oPropertyValue.Name = cName
if uValue != None:
oPropertyValue.Value = uValue
if nHandle != None:
oPropertyValue.Handle = nHandle
if nState != None:
oPropertyValue.State = nState
return oPropertyValue
def makePoint( nX, nY ):
"""Create a com.sun.star.awt.Point struct."""
oPoint = createUnoStruct( "com.sun.star.awt.Point" )
oPoint.X = nX
oPoint.Y = nY
return oPoint
def makeSize( nWidth, nHeight ):
"""Create a com.sun.star.awt.Size struct."""
oSize = createUnoStruct( "com.sun.star.awt.Size" )
oSize.Width = nWidth
oSize.Height = nHeight
return oSize
def makeRectangle( nX, nY, nWidth, nHeight ):
"""Create a com.sun.star.awt.Rectangle struct."""
oRect = createUnoStruct( "com.sun.star.awt.Rectangle" )
oRect.X = nX
oRect.Y = nY
oRect.Width = nWidth
oRect.Height = nHeight
return oRect
def Array( *args ):
"""This is just sugar coating so that code from OOoBasic which
contains the Array() function can work perfectly in python."""
tArray = ()
for arg in args:
tArray += (arg)
return tArray
def getConfigAccess( cNodePath, bWriteAccess=False, bEnableSync=True, bLazyWrite=False ):
"""An easy way to obtain a configuration node from the configuration manager."""
oConfigProvider = getServiceManager().createInstanceWithArguments(
"com.sun.star.configuration.ConfigurationProvider",
( makePropertyValue( "enablesync", bEnableSync ), ) )
if bWriteAccess:
cServiceName = "com.sun.star.configuration.ConfigurationUpdateAccess"
else:
cServiceName = "com.sun.star.configuration.ConfigurationAccess"
oConfigAccess = oConfigProvider.createInstanceWithArguments( cServiceName,
( makePropertyValue( "nodepath", cNodePath ),
makePropertyValue( "lazywrite", bLazyWrite ), ) )
return oConfigAccess
#----------------------------------------
# Inconvenience routines for working with structs needed later
#
def makeLocale( cLanguage="", cCountry="", cVariant="" ):
oLocale = createUnoStruct( "com.sun.star.lang.Locale" )
oLocale.Language = cLanguage
oLocale.Country = cCountry
oLocale.Variant = cVariant
return oLocale
def makeLocalizedName( stLocale, cName ):
oLocalizedName = createUnoStruct( "com.sun.star.sheet.LocalizedName" )
oLocalizedName.Locale = stLocale
oLocalizedName.Name = cName
return oLocalizedName
##################################################################
class DannysUnoBaseClass:
cServiceName = ""
tServiceNames = ( cServiceName, )
tInterfaces = (
"com.sun.star.lang.XServiceName",
"com.sun.star.lang.XServiceInfo",
"com.sun.star.lang.XTypeProvider",
)
# The component must have a ctor with the component context as argument.
def __init__( self, oContext ):
self.oContext = oContext
#----------
# stuff to support the XTypeProvider interface.
#----------
# uuid is used in the getImplementationId() method of the XTypeProvider.
# The uuid should be class specific, but must be
# instance specific in order for Basic to work.
# See note: http://udk.openoffice.org/servlets/ReadMsg?list=dev&msgNo=2540
self.uuid = uno.generateUuid()
# tInterfaceTypes is used in the getTypes() method of XTypeProvider.
self.tInterfaceTypes = None
#----------
globalInitialization( oContext )
#----------------------------------------
# Interface: XServiceName
#----------------------------------------
# string
# getServiceName();
def getServiceName( self ):
return self.cServiceName
#----------------------------------------
# Interface: XServiceInfo
#----------------------------------------
# string
# getImplementationName();
def getImplementationName( self ):
return self.cServiceName
# boolean
# supportsService( [in] string ServiceName );
def supportsService( self, cServiceName ):
return cServiceName in self.getSupportedServiceNames()
# sequence< string >
# getSupportedServiceNames();
def getSupportedServiceNames( self ):
return self.tServiceNames
#----------------------------------------
# Interface: XTypeProvider
#----------------------------------------
# sequence< type >
# getTypes();
def getTypes( self ):
if self.tInterfaceTypes == None:
self.tInterfaceTypes = ()
for cTypeName in self.tInterfaces:
self.tInterfaceTypes += ( uno.getTypeByName( cTypeName ), )
return self.tInterfaceTypes
# sequence< byte >
# getImplementationId();
def getImplementationId( self ):
return self.uuid
##################################################################
class DannysCalcFunctions1( DannysUnoBaseClass ):
# The programmatic names of the functions from the interface
# name.dannyBrewer.test.XDannysCalcFunctions1
calcFnName_Prog_AddFive = "addFive"
calcFnName_Prog_AddSix = "addSix"
# The display names of the functions shown to the user.
calcFnName_Disp_AddFive = "AddFive"
calcFnName_Disp_AddSix = "AddSix"
cServiceName = "name.dannyBrewer.test.DannysCalcFunctions1"
tServiceNames = ( cServiceName,
"com.sun.star.sheet.AddIn",
)
# The component must have a ctor with the component context as argument.
def __init__( self, oContext ):
DannysUnoBaseClass.__init__( self, oContext )
self.tInterfaces += (
"name.dannyBrewer.test.XDannysCalcFunctions1",
"com.sun.star.sheet.XAddIn",
)
#--interfaces not currently associated with this service--
#"name.dannyBrewer.misc.XCommand",
self.locale = makeLocale( "en", "US", "" )
#----------------------------------------
# Interface: name.dannyBrewer.misc.XCommand
#----------------------------------------
# This interface is so that Basic macros can make private calls to
# the doCommand function for debugging and testing.
# An array of PropertyValue can be passed to doCommand as a
# group of "parameters" to the chosen command.
# any
# doCommand( [in] string cCommand,
# [in] sequence< com.sun.star.beans.PropertyValue > aParams );
def doCommand( self, cCommand, aParams ):
if cCommand == "getServiceName":
return self.cServiceName
if cCommand == "createDraw":
getDesktop().loadComponentFromURL( "private:factory/sdraw", "_blank", 0, Array() )
return None
#----------------------------------------
# Interface: com.sun.star.sheet.XAddIn
# Inherits from...
# com.sun.star.lang.XLocalizable
#----------------------------------------
# string
# getProgrammaticFuntionName( [in] string aDisplayName );
# Note: the method name spelling error is in the API!
def getProgrammaticFuntionName( self, cDisplayFnName ):
if cDisplayFnName == self.calcFnName_Disp_AddFive:
return self.calcFnName_Prog_AddFive
elif cDisplayFnName == self.calcFnName_Disp_AddSix:
return self.calcFnName_Prog_AddSix
return cDisplayFnName
# string
# getDisplayFunctionName( [in] string aProgrammaticName );
def getDisplayFunctionName( self, cProgrammaticFnName ):
if cProgrammaticFnName == self.calcFnName_Prog_AddFive:
return self.calcFnName_Disp_AddFive
elif cProgrammaticFnName == self.calcFnName_Prog_AddSix:
return self.calcFnName_Disp_AddSix
return ""
# string
# getFunctionDescription( [in] string aProgrammaticName );
def getFunctionDescription( self, cProgrammaticFnName ):
if cProgrammaticFnName == self.calcFnName_Prog_AddFive:
return "Add five to the argument."
elif cProgrammaticFnName == self.calcFnName_Prog_AddSix:
return "Add six to the argument."
return ""
# string
# getDisplayArgumentName( [in] string aProgrammaticName
# [in] long nArgument );
def getDisplayArgumentName( self, cProgrammaticFnName, nArgNum ):
if cProgrammaticFnName == self.calcFnName_Prog_AddFive:
if nArgNum == 0:
return "nNumber"
elif cProgrammaticFnName == self.calcFnName_Prog_AddSix:
if nArgNum == 0:
return "nNumber"
return ""
# string
# getArgumentDescription( [in] string aProgrammaticName
# [in] long nArgument );
def getArgumentDescription( self, cProgrammaticFnName, nArgNum ):
if cProgrammaticFnName == self.calcFnName_Prog_AddFive:
if nArgNum == 0:
return "A number to which five will be added."
elif cProgrammaticFnName == self.calcFnName_Prog_AddSix:
if nArgNum == 0:
return "A number to which six will be added."
return ""
# string
# getProgrammaticCategoryName( [in] string aProgrammaticName );
def getProgrammaticCategoryName( self, cProgrammaticFnName ):
#if cProgrammaticFnName == self.calcFnName_Prog_AddFive:
# return "Add-In"
#elif cProgrammaticFnName == self.calcFnName_Prog_AddSix:
# return "Add-In"
return "Add-in"
# string
# getDisplayCategoryName( [in] string aProgrammaticName );
def getDisplayCategoryName( self, cProgrammaticFnName ):
#if cProgrammaticFnName == self.calcFnName_Prog_AddFive:
# return "Add-In"
#elif cProgrammaticFnName == self.calcFnName_Prog_AddSix:
# return "Add-In"
return "Add-In"
#----------------------------------------
# Interface: com.sun.star.lang.XLocalizable
# Inherited by...
# com.sun.star.sheet.XAddIn
#----------------------------------------
# void
# setLocale( [in] Locale eLocale );
def setLocale( self, stLocale ):
self.locale = stLocale
# Locale
# getLocale();
def getLocale( self ):
return self.locale
#----------------------------------------
# Interface: name.dannyBrewer.test.XDannysCalcFunctions1
#----------------------------------------
def addFive( self, x ):
"Add five to the argument."
return x + 5
def addSix( self, x ):
"Add six to the argument."
return x + 6
# add the class to the implementation container,
# which the loader uses to register/instantiate the component.
g_ImplementationHelper.addImplementation(
# The class
DannysCalcFunctions1,
# The implementation name.
# Change this name for your own service.
DannysCalcFunctions1.cServiceName,
# A list of services that that are implemented.
DannysCalcFunctions1.tServiceNames,
)
|
The two IDL files must be compiled. The resulting RDB files and the Python program must be zipped up. Then the zip file put into the user\uno_components folder. Then pkgchk must be run. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|