Can't create python script?

When I go to tools -> macros -> organize macros -> python I can't
create or edit scripts. The buttons are grayed out. It does have a few sample
scripts, which I can run.

I went to the extension manager and found "script provider for python"
so apparently I'm supposed to have script capability? The help page
about extension manager is blank.

I have LO 3.5.3.2 running on windows XP, PortableApps.

Thanks for any help.

Kelly

Kelly

When I go to tools -> macros -> organize macros -> python I can't
  create or edit scripts. The buttons are grayed out. It does have a few sample
  scripts, which I can run.

I went to the extension manager and found "script provider for python"
  so apparently I'm supposed to have script capability? The help page
  about extension manager is blank.

I have LO 3.5.3.2 running on windows XP, PortableApps.

Thanks for any help.

Kelly

Try Tools>Options>LibreOffice>General and make sure the "Enable Experimental (Unstable) Features" is checked to enable macros. On a new install I believe it is disabled by default.

Yes, I double-checked, it's enabled. And I can record macros, and run them.

Weird. ??

Hi :slight_smile:
Do you have to "enable experimental features?
Tools - Options - General (2nd item i think)
Then bottom of the box is "Enable experimental features".  There are a few odd things that are not really experimental that seem to be disabled without that.

There is better help in the official documentation, the 'Beginners Guide' chapter 13 at
http://wiki.documentfoundation.org/Documentation/Publications
or at the official LibreOffice page.  If you scroll down to the programming section on the wiki then you get to
http://wiki.documentfoundation.org/Documentation/Publications#Programmers
and see Andrew Pitonyak's excellent guide.  I think Andrews guide costs money but people say it is well worth it so it might be worth getting.

Often people on this list can give more specific help but i think they would probably want to know more about the macro you want to build.   
Regards from
Tom :slight_smile:

Am 17.05.2012 03:15, Kelly Holman wrote:

When I go to tools -> macros -> organize macros -> python I can't
  create or edit scripts. The buttons are grayed out. It does have a few sample
  scripts, which I can run.

I went to the extension manager and found "script provider for python"
  so apparently I'm supposed to have script capability? The help page
  about extension manager is blank.

I have LO 3.5.3.2 running on windows XP, PortableApps.

Thanks for any help.

Kelly

You edit Python in your favourite IDE.

Hi :slight_smile:
Ahhh, thanks Andreas!  Do text-editors such as Gedit, Kate, SciTe count as IDEs or are IDEs a tad more technical?
Regards from
Tom :slight_smile:

Am 17.05.2012 13:04, Tom Davies wrote:

Hi :slight_smile:
Ahhh, thanks Andreas! Do text-editors such as Gedit, Kate, SciTe count as IDEs or are IDEs a tad more technical?
Regards from
Tom :slight_smile:

The minimum Swiss knife for Python macros consists of Writer and a shell.
When I need to fix Python on a Windows system without decent editor at hand I use to use Writer. In the end it is plain text. Contrary to other scripting languages, line indents have a meaning and Python macros need to have Unix line feeds. Writer can display the white space properly and it can save Unix line feeds on Windows (filter "encoded text"). When you started the office from a command line, print commands to debug Python macros are redirected to that command line.

http://www.openoffice.org/udk/python/python-bridge.html (mandatory reading)
http://www.oooforum.org/forum/viewtopic.phtml?t=4818 (starting the Idle IDE
  with PyUNO on Windows)
http://user.services.openoffice.org/en/forum/viewtopic.php?f=45&t=22904 (typical discussion in this context)

Thank you Andreas!

I just need to do one little thing. As an alternative to figuring out
all about python, is there any way to call a perl script (already
written) from within LibreOffice? The script wouldn't need to do
anything with Office, just return a string or array.

Thanks!

Redirect the output to a file and link the file content? How can I tell
without the faintest idea about the purpose nor the exact flavour of data?
Once upon a time there used to be some Perl module for UNO.
Being a Perl programmer you may even manipulate the XML "source code" of an
ODF document.

Sorry, I didn't mean to be unclear. There are several ways I could get
the result of the perl script: an array of strings, a single string I
would parse, or writing it to a file as you suggest. That part doesn't
matter.

All I need to know is whether I can call the perl script from within
LO, using LO basic. My understanding of UNO is that it's a way for
other programs to control LO, but I need the other way around. Is
there more to UNO than I realize?

If running a perl script isn't possible, there are perl modules that
can write to a Calc file, so I could go that route. But it would be
simpler to just use that one little perl script and then do the rest
in LO.

Thanks for your help!

Am 17.05.2012 21:01, Kelly Holman wrote:

Sorry, I didn't mean to be unclear. There are several ways I could get
the result of the perl script: an array of strings, a single string I
would parse, or writing it to a file as you suggest. That part doesn't
matter.

All I need to know is whether I can call the perl script from within
LO, using LO basic. My understanding of UNO is that it's a way for
other programs to control LO, but I need the other way around. Is
there more to UNO than I realize?

If running a perl script isn't possible, there are perl modules that
can write to a Calc file, so I could go that route. But it would be
simpler to just use that one little perl script and then do the rest
in LO.

Thanks for your help!

I don't know much about Perl. But I remember that calling a Perl script under Windows is a horrible mess. If I remember correctly, you need to write some shell script because Windows can not identify the correct interpreter.

Anyhow, on my Linux system the following Basic macro ...

Sub Main
x = shell("~/bin/number2words.pl",0,"123")
End Sub

... executes number2words.pl in no visible window and with argument 123.
The output "one hundred twenty three" is dumped to the shell from where I started the office. Variable x is zero in case of no error.

Thanks Andreas. You may be right about running a perl script under
windows. I have the installation but haven't used it yet. It's a long
time since I've done any real programming.

In the meantime, I think I've found another way that would work more
seamlessly -- BeanShell can access the file system. I haven't used it
before, but I know Java.

Where would be the best place to ask questions about using BeanShell in LO?

Thanks again!

Am 17.05.2012 22:31, Andreas Säger wrote:

Anyhow, on my Linux system the following Basic macro ...

Sub Main
x = shell("~/bin/number2words.pl",0,"123")
End Sub

... executes number2words.pl in no visible window and with argument 123.
The output "one hundred twenty three" is dumped to the shell from where
I started the office. Variable x is zero in case of no error.

In Python there are much more sophisticated methods to start a subprocess and get returned values from it:
http://docs.python.org/library/os.html#
http://docs.python.org/library/subprocess.html#module-subprocess

Am 17.05.2012 23:05, Kelly Holman wrote:

Thanks Andreas. You may be right about running a perl script under
windows. I have the installation but haven't used it yet. It's a long
time since I've done any real programming.

In the meantime, I think I've found another way that would work more
seamlessly -- BeanShell can access the file system. I haven't used it
before, but I know Java.

Where would be the best place to ask questions about using BeanShell in LO?

Thanks again!

Any programming language can access the file system but that's not what you asked for. You asked how to trigger some external program, namely a Perl script (which needs to be called through a batch script, but you are the Perl coder who should know better).
I can not see any difference between Python, Java Script and BeanShell in the context of this office suite. You assign a macro to some push button and the macro calls the external program in the respective language. The details are language specific and have nothing to do with the office program. Write your Beanshell code which is able to trigger the Perl script and drop it in your user profile. Then bind a push button to it.
Why don't you simply call your Perl script from some button on your task bar, desktop, Windows menu or something. Why does it need to be this office suite?

Hi Kerry,

When I go to tools -> macros -> organize macros -> python I can't
create or edit scripts. The buttons are grayed out. It does have a few sample
scripts, which I can run.

There is no built-in python editor in LibreOffice. If you want to edit a
python script and then run it from within LO, you have to create it
outside of LO, in a text editor, or a python dedicated IDE, and then
copy the script to the correct directory within your LO application
framework, usually this in a subfolder of Scripts, e.g. on the Mac :

/Applications/LibreOffice.app/Contents/share/Scripts

or else in the user's own LO configuration folder :

/Users/alex/Library/Application Support/LibreOffice/3/user/Scripts

Alex