Page 1 of 1

[Solved] Problem with Python macro and BasicAddonBuilder

Posted: Sun Aug 30, 2015 2:16 pm
by MisterMillennia
Hello! I am sorry if this is in the wrong spot, I was unsure if this would count as an extensions question, or a python question, because it contains both.

I am have been having some serious trouble working my way through the documentation for Python Macros and Extensions for Open Office, and was wondering if anyone had some beginner-level resources or solutions to some problems I am having with an extension I am working on.

I am using the BasicAddonBuilder 0.5.0 to reduce the number of variables that could be causing things to fail (as it takes care of all the XML and packaging and all that, I just provide the functions and layout of the extension).

Specifically, I am having trouble with the simple act of getting a Python macro to run through the extension. I have copied the basic Hello World code from the sample scripts folder to my extension folder, and have called it in my extension. The extension fully compiles and saves to a .oxt package and can be installed into Open Office, but when I press the menu item, I always get the error:

Code: Select all

A Scripting Framework error occurred while running the Python script vnd.sun.star.script:extension.oxt|PythonFiles|HelloWorld.py$Hello?
language=Python&location=user:uno_packages.

Message: <type 'exceptions.KeyError'>: u'extension.oxt
C:\Program Files (x86)\OpenOffice4\program\pythonscript.py:380 in funtion getStorageUrlFromPersistentUrl() [package = self.mapPackageName2Pathh[ packageName]]
C:\Program Files (x86)\OpenOffice4\program\pythonscript.py:984 in function getScript()
[self.pprovCtx.uriHelper.getStorageURI(scriptUri) );]
I have searched for this error, and it seems to be caused by being unable to find the python file or function in question. I am certain, however, that the python file is in the right spot, and that it shouldn't be unable to find the function because I have defined its position to be the right one. The function itself works in the user scripts folder, so I don't believe that that is the problem, so it is either my code for importing the function into the system, or a problem with Basic Addon Builder.

My code for the extension looks like this:

Code: Select all

Sub myExtension
' ___________________________________________________________________

beginDescription("NONNAd", "1.2.1")
  setLicense("en")
  setPublisherName("en", "NONNAd", "http://www.NONNAd.com")
  setDisplayName("en", "NONNAd")
  setReleaseNotes("en", "http://www.NONNAd.com/notes/ReadMe120.txt")
  beginUpdateInformation("direct", "direct") 
	setUpdateSource("http://www.NONNAd.com/", "http://www.NONNAd.com/") ' first choice
	setUpdateSource("http://www.NONNAd.cn/",  "http://wwwNONNAd.cn/")  ' fallback on another server (optional)
  endUpdateInformation
  setHelp("en") ' should be after setDisplayName instructions
endDescription  

beginAnnexes 
endAnnexes

beginAddonUI
   beginOfficeMenuBar
      beginTitles
	    setTitle("Authors Aid", "en")
      endTitles
      beginMenuItems
        beginCommand
          beginTitles("Writer")
            setTitle("Hello World", "en")
          endTitles
          setURL("Python", "PythonFiles/HelloWorld.py", "HelloWorldPython")
        endCommand
      endMenuItems
  endOfficeMenuBar
endAddonUI 
So what am I doing wrong? I am honestly so confused as to what is happening, or what I can do to fix it...

Re: Problem with Python macro and BasicAddonBuilder extensio

Posted: Sun Aug 30, 2015 8:20 pm
by B Marcelly
Hi,
MisterMillenia wrote:I am using the BasicAddonBuilder 0.5.0 to reduce the number of variables that could be causing things to fail (as it takes care of all the XML and packaging and all that, I just provide the functions and layout of the extension).
I am not aware that BasicAddonBuilder can create extensions of Python scripts.
MisterMillenia wrote:My code for the extension looks like this:

Code: Select all

    Sub myExtension
    ' ___________________________________________________________________

    beginDescription("NONNAd", "1.2.1")
      setLicense("en")
      setPublisherName("en", "NONNAd", "http://www.NONNAd.com")
      setDisplayName("en", "NONNAd")
      setReleaseNotes("en", "http://www.NONNAd.com/notes/ReadMe120.txt")
This is a code for the tool ExtensionCompiler.
BasicAddonBuilder and ExtensionCompiler are two different tools.

You should download and look at the file ExtensionDemo.zip. As explained in the Wiki page it contains a Python script.
In your code, you should have an instruction inside beginAnnexes/endAnnexes.

Re: Problem with Python macro and BasicAddonBuilder extensio

Posted: Sun Aug 30, 2015 9:15 pm
by Villeroy
If you want to distribute Python macros, simply put the source code in an archive and tell the user where to extract the source code. Easy enough.
If your code manipulates a specific document, you can and should embed the in a document template just like document specific Basic code: https://wiki.openoffice.org/wiki/Python ... s_document

A "true Python extension" has nothing to do with macros. It is an extension to the office suite with its own classes but no callable routines in the macro menues.

Re: Problem with Python macro and BasicAddonBuilder extensio

Posted: Tue Sep 01, 2015 1:47 am
by MisterMillennia
This is a code for the tool ExtensionCompiler.
BasicAddonBuilder and ExtensionCompiler are two different tools.
Apologies about that, I honestly just confused myself as to which one I was using, and picked the wrong one.
You should download and look at the file ExtensionDemo.zip. As explained in the Wiki page it contains a Python script.
In your code, you should have an instruction inside beginAnnexes/endAnnexes.
Thanks for the link to the demo function, I didn't find it while looking myself. It took a bit of looking back and forth but I finally have something that runs!
A "true Python extension" has nothing to do with macros. It is an extension to the office suite with its own classes but no callable routines in the macro menues.
Sorry, I wasn't familiar with the meanings of the Open Office nomenclature and had no idea that they were not related. I'll try not to make the same mistake.