How to configure PyCharm for authoring macros

  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?

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

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.

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

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.

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.