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

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 close merge delete

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.

( 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.

( 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.

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

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

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

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

( 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.

( 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?

( 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

( 2017-05-17 05:29:05 +0200 )edit

Sort by » oldest newest most voted

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

more

+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 !

( 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.

( 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 ?

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

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

( 2017-05-19 04:03:25 +0200 )edit