Ask Your Question
2

Can I embed python script and integrate with basic? (solved)

asked 2017-05-16 17:45:21 +0200

Pansmanser gravatar image

updated 2017-05-16 23:35:36 +0200

There is a very useful python script by @librebel to detect the current os: https://ask.libreoffice.org/en/questi...

To make it portable it can be embedded in the document. This is beautifully explained by Christopher Bourez here: http://christopher5106.github.io/offi...

Now the question: how can I call the embedded python script from basic?

edit retag flag offensive close merge delete

Comments

Thank you @Pansmanser, only by this very good idea of yours, to embed the get_OS() python script into a document, does it become useful. Btw it was i who wrote it.

librebel gravatar imagelibrebel ( 2017-05-16 18:13:51 +0200 )edit

@librebel Appreciated your article (read a while back) but you may want to check out APSO in the document I attached in my answer.

Ratslinger gravatar imageRatslinger ( 2017-05-16 18:28:07 +0200 )edit

sorry i might have missed that part ( i have installed APSO ) .. i meant to say that the python script to detect the current os was not written by karolus and EasyTrieve, but by me.

librebel gravatar imagelibrebel ( 2017-05-16 19:18:51 +0200 )edit

Got it. It was still a good article and your script was OK too.

Ratslinger gravatar imageRatslinger ( 2017-05-16 19:25:43 +0200 )edit

Sorry if I've misunderstood. I think I attributed it to you in my question, @librebel.

Pansmanser gravatar imagePansmanser ( 2017-05-16 23:38:25 +0200 )edit

No problemo amigos, thanks for the credits:) .. i'll search if there is a way to embed the Python script in the user's document by code. However for that macro to work, the user should also have the libreoffice-script-provider-python installed.

librebel gravatar imagelibrebel ( 2017-05-17 03:38:04 +0200 )edit

@librebel Not clear on your purpose to 'embed the Python script in the user's document by code.' What is that vs what is already done in APSO?

Ratslinger gravatar imageRatslinger ( 2017-05-17 03:46:38 +0200 )edit
1

@Ratslinger, i thought it would be nice if the method that depends on the python script "get_OS" would automatically install that python script for the user. Be it inside their document, or in the user or share location. ... having connection difficulties, 1 of my comments was lost after posting it

librebel gravatar imagelibrebel ( 2017-05-17 05:29:05 +0200 )edit

1 Answer

Sort by » oldest newest most voted
3

answered 2017-05-16 17:54:35 +0200

Ratslinger gravatar image

updated 2017-05-16 19:37:17 +0200

Some of my recent searching reveals embedding Python scripts in a LO document can done by manipulating the data in files within the zipped document. However effective this is, it is prone to error.

I have found much simpler way to do this. As the images I have used take considerable space, I have attached a document with all the necessary information. It is a very simple procedure.

As for the call in basic, change the basic script from:

oScript = oScriptProvider.getScript( "vnd.sun.star.script:get_os.py$get_OS?language=Python&location=user" )

To:

oScript = oScriptProvider.getScript( "vnd.sun.star.script:get_os.py$get_OS?language=Python&location=document" )

Note: The only thing changing is at the end of the line: ‘user’ to ‘document’. Test the script.

Attachment: EmbedPythonScriptInDocument.odt

If this answers your question please click on the ✔ (upper left area of answer).

edit flag offensive delete link more

Comments

+1 @Ratslinger that is awesome! i hadn't noticed the "Embed in Document" menu before... Thanks for your handy manual, and thank you @Hanya for APSO !

librebel gravatar imagelibrebel ( 2017-05-19 03:33:09 +0200 )edit

@librebel I can't believe you didn't see that even after the comment I made previously about the duplicating effort in a macro. BTW there were two people involved. Hubert Lambert was the other beside Hanya. Props to both.

Ratslinger gravatar imageRatslinger ( 2017-05-19 03:49:17 +0200 )edit

yes sorry Ratslinger, ma bad, i was commenting too quickly while i had not yet taken the time to read all notifications... Thanks indeed at Hubert Lambert too for APSO! ... Have they ever appeared in this forum ?

librebel gravatar imagelibrebel ( 2017-05-19 04:01:34 +0200 )edit

Never know. Have not seen, at least with those names.

Ratslinger gravatar imageRatslinger ( 2017-05-19 04:03:25 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-05-16 17:45:21 +0200

Seen: 910 times

Last updated: May 16 '17