We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question

How to configure PyCharm for authoring macros [closed]

asked 2017-06-06 08:07:55 +0200

Max Pixel gravatar image

updated 2017-06-10 05:46:54 +0200

  1. Add LibreOffice's included Python libraries to PyCharm as an environment
  2. Open the included Python scripts folder, or a copy of it, in PyCharm
  3. Open any of the .py files

The included .py files are, obviously, error-free, however PyCharm reports the error "unresolved context XSCRIPTCONTEXT"

What steps are necessary in order to configure PyCharm to know the interface of XSCRIPTCONTEXT?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-10-23 22:45:13.347266

3 Answers

Sort by » oldest newest most voted

answered 2017-12-14 18:15:35 +0200

You may check Python Design Guide to verify that PyCharm can be used to debug LibreOffice python macro.

edit flag offensive delete link more

answered 2017-06-07 15:36:08 +0200

komma4 gravatar image

@Ratslinger is right, you only can run LO macros from command line if you connect to a listening LO instance.

XSCRIPTCONTEXT is a global variable set by the scripting framework, if a macro is started (from within or through socket). PyCharm doesn't resolve this. And all the SDK libraries (com.sun.star.*) won't resolve either. I didn't find a solution by now.

Additional note: LO only reloads python scripts in the Scripts folder, if their timestamp is newer than the one remembered after first execution. I use symlinks to an external directory (for not clustering the "Macros execute..." dialogue, having test files and version control system files in that directory, too) and wrote a script which monitors the symlink's target(s) and update the timestamp if necessary. Drop me a note if you'd like a copy.

edit flag offensive delete link more


Is it necessary for the IDE to actually connect to the framework? I would expect there to by .py files declaring the interface somewhere, unless they are embedded into a custom fork of python.exe or some other LibreOffice binary.

Max Pixel gravatar imageMax Pixel ( 2017-06-08 18:08:21 +0200 )edit

PyCharm is never "connected" to an instance of LO. You can develop scripts and execute them from within without any sockets running. Only time you need to connect is when starting a script from command line.
Get DannyB's OOoLib module ffrom Github (old, but still good, as everything by him) to see connection examples and more.
And i recommend MRI extension, as it makes object inspection and debugging extremely convenient.

komma4 gravatar imagekomma4 ( 2017-06-08 20:26:11 +0200 )edit

answered 2017-06-07 15:24:09 +0200

Ratslinger gravatar image

To my knowledge, you won't be able to directly connect with LO from a Python IDE. The only IDE available is for Basic ( I seem to recall also something for Java) and that is built in. To directly interface with LO you would have to use an open socket - click here for more info.

APSO (Alternate Python Script Organizer) is a nice tool to organize & test Python scripts - click here.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2017-06-06 08:07:55 +0200

Seen: 1,065 times

Last updated: Dec 14 '17