APSO - Alternative Script Organizer for Python

56 9

Based on an original script from Hanya, APSO will install a macro organizer dedicated to python scripts.

Project Description

APSO is compatible with OpenOffice

Based on an original script from Hanya, APSO is an extension that will install a macro organizer dedicated to python scripts.

Features

  • localisation (by now EN, DE, FR, IT, HU thanks to Tibor Kovács and NL thanks to Dick Groskamp)
  • embedding scripts in or extracting them from documents
  • binding the extension with one's favorite code editor (thanks to another script from Hanya, see Options below)
  • quick edition of embedded scripts (but only in the context of the APSO extension*)
  • integrated gui debugger
  • interactive python interpreter
  • automatic update once installed

(* Changes will only be kept if APSO is either opened or closed after last save.)

How it works

APSO adds a new element Organize python scripts under menu Tools/Macros with default shortcut Alt+Shift+F11:

 

This new item or shortcut opens a dialog box that lists all python scripts and provides various actions:

 

The Execute  button launches the selected macro. Actions available under Menu button change according to the selection:

  • create module or library if selection is a container (My Macros, Office Macros or document)
  • Edit, rename, delete a module or library
  • Embed module from application (My Macros or Office Macros) into current document
  • Substitute an embedded module with an external file
  • Export an embedded module

Helpers

APSO comes with a small library apso_utils that contains some helpers for debugging purpose during macro writing. These helpers are four functions named msgbox, xray, mri and console and can be imported by a classic import statement like from apso_utils import msgbox

function description
msgbox

Like the oobasic build-in function msgbox, but simplified as only intended for quick debugging.

Signature: msgbox(message, title='Message', boxtype='message', buttons=1, frame=None)

xray

Launches the introspection tool Xray by Bernard Marcelly (must be installed first)

Signature: xray(obj)

mri

Launches the introspection tool MRI by Hanya (must be installed first)

Signature: mri(target)

console

Emulates, as close as possible, the python interactive shell. What one can do with such a tool:
- interact directly with a document and test "live" the methods of the uno api (maybe also useful for other languages, such basic);
- quickly verify python expressions in the context of the embedded interpreter;
- display the output of a script running in parallel or started from the shell (all modules visible from the office program can be imported);
- debug a script using pdb's runcall function (will not work with scripts embedded in documents);
- get quick info on any function using the builtin help() command;
- explore living uno objects with introspection tools such as MRI or Xray (if installed);
- ...

Signature: console(**kwargs), where optional kwargs are intended to overwrite default gui values (BACKGROUND, FOREGROUND...) or to pass caller's locales and/or globals to the console context.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


Example

from apso_utils import console, msgbox, mri, xray
def testhelpers():
    # console()
    # console(BACKGROUND=0x0, FOREGROUND=0xFFFFFF)
    loc = locals()
    loc.update(globals())
    console(loc=loc)

    doc = XSCRIPTCONTEXT.getDocument()
    # xray(doc)
    msgbox(doc.Title)
    mri(doc)

apso_console

 

 

 

 

 

 

 

 

 

 

Only the console macro is accessible outside an APSO instance. If someone wants to import the module apso_utils independently of APSO, he has to force that instanciation:
def entryfunc(event=None):
    ctx = XSCRIPTCONTEXT.getComponentContext()
    ctx.ServiceManager.createInstance("apso.python.script.organizer.impl")
    # now we can import apso_utils library
    from apso_utils import console
    console()

Integreted debugger

The debugger can be launched from the Apso "Menu" button when a function is selected in the main window.

Once the debugger opened, one can execute the code step by step, enter any called function, return to the caller, etc.

Break points are not supported, but you can jump ahead by double clicking any line below the current one within the same function.

You can check any caller state and scope by double clicking it in the "Stack" window (bottom left). If you have MRI or Xray installed, you can inspect any UNO variables by double clicking it in the "Scope" window (bottom right).

When you open a console window from the tool bar, the global and local scope will be automatically loaded.

If you edit the script while the debugger is running, changes will be taken in account after clicking "Restart".

The debugger uses the font name and height defined for the Basic IDE.

The debugger is still not fully localised

Apso debugger screenshot

APSO Options

The extension option page is available under Tools -> Extension Manager -> APSO -> Options.
By default, APSO uses the system defined editor. To edit scripts with a specific editor, provide the executable full path in the "Editor" field.
To allow the opening at a given line and column offset when relevant, enter in the "Options" field the command line syntax corresponding to the choosen editor, using the placeholders {FILENAME}, {ROW} and {COL} (they will be replaced in due time).
Example for Emacs: +{ROW}:{COL} {FILENAME}.
Example for Sublime Text: {FILENAME}:{ROW}:{COL}.

Category/Categories

All modules, Macro

Homepage of the Project

https://gitlab.com/jmzambon/apso

Logo

Current Release

APSO - Alternative Script Organizer for Python - 1.2.2

Released Mar 10, 2019 — tested with:

LibreOffice 3.4, LibreOffice 3.5, LibreOffice 3.6, LibreOffice 4.0, LibreOffice 4.1, LibreOffice 4.2, LibreOffice 4.3, LibreOffice 4.4, LibreOffice 5.0, LibreOffice 5.1, LibreOffice 5.2, LibreOffice 5.3, LibreOffice 5.4, LibreOffice 6.0, LibreOffice 6.1, LibreOffice 6.2,

Minor bug fixes.
More about this release…

All platforms

All Releases

Version

Released

Platform(s)

Compatibility

Description

License(s)

Status

1.2.2

Mar 10, 2019
  • All platforms
  • LibreOffice 3.4
  • LibreOffice 3.5
  • LibreOffice 3.6
  • LibreOffice 4.0
  • LibreOffice 4.1
  • LibreOffice 4.2
  • LibreOffice 4.3
  • LibreOffice 4.4
  • LibreOffice 5.0
  • LibreOffice 5.1
  • LibreOffice 5.2
  • LibreOffice 5.3
  • LibreOffice 5.4
  • LibreOffice 6.0
  • LibreOffice 6.1
  • LibreOffice 6.2
Minor bug fixes.
  • AL-v2 (Apache License Version 2.0)
final

1.2.1

Jan 06, 2019
  • All platforms
  • LibreOffice 3.4
  • LibreOffice 3.5
  • LibreOffice 3.6
  • LibreOffice 4.0
  • LibreOffice 4.1
  • LibreOffice 4.2
  • LibreOffice 4.3
  • LibreOffice 4.4
  • LibreOffice 5.0
  • LibreOffice 5.1
  • LibreOffice 5.2
  • LibreOffice 5.3
  • LibreOffice 5.4
  • LibreOffice 6.0
  • LibreOffice 6.1
  • LibreOffice 6.2
New integrated debugger tool and minor bug fixes in module and library naming.
  • AL-v2 (Apache License Version 2.0)
final

1.2.0

  • All platforms
  • LibreOffice 3.4
  • LibreOffice 3.5
  • LibreOffice 3.6
  • LibreOffice 4.0
  • LibreOffice 4.1
  • LibreOffice 4.2
  • LibreOffice 4.3
  • LibreOffice 4.4
  • LibreOffice 5.0
  • LibreOffice 5.1
  • LibreOffice 5.2
  • LibreOffice 5.3
  • LibreOffice 5.4
  • LibreOffice 6.0
  • LibreOffice 6.1
New integrated debugger tool and minor bug fixes in module and library naming.
  • AL-v2 (Apache License Version 2.0)
beta

1.1.4

Jun 05, 2018
  • All platforms
  • LibreOffice 3.4
  • LibreOffice 3.5
  • LibreOffice 3.6
  • LibreOffice 4.0
  • LibreOffice 4.1
  • LibreOffice 4.2
  • LibreOffice 4.3
  • LibreOffice 4.4
  • LibreOffice 5.0
  • LibreOffice 5.1
  • LibreOffice 5.2
  • LibreOffice 5.3
  • LibreOffice 5.4
  • LibreOffice 6.0
  • LibreOffice 6.1
Code fixing and cleaning
  • AL-v2 (Apache License Version 2.0)
final

1.1.2

Oct 25, 2017
  • All platforms
  • LibreOffice 4.0
  • LibreOffice 4.1
  • LibreOffice 4.2
  • LibreOffice 4.3
  • LibreOffice 4.4
  • LibreOffice 5.0
  • LibreOffice 5.1
  • LibreOffice 5.2
  • LibreOffice 5.3
  • LibreOffice 5.4
  • LibreOffice 6.0
New console tool (see Menu button). Code clean up.
  • AL-v2 (Apache License Version 2.0)
final

1.0.2

Sep 19, 2017
  • All platforms
  • LibreOffice 4.0
  • LibreOffice 4.1
  • LibreOffice 4.2
  • LibreOffice 4.3
  • LibreOffice 4.4
  • LibreOffice 5.0
  • LibreOffice 5.1
  • LibreOffice 5.2
  • LibreOffice 5.3
  • LibreOffice 5.4
Bug fixes
  • AL-v2 (Apache License Version 2.0)
final

1.0.0

Jun 18, 2017
  • All platforms
  • LibreOffice 5.0
  • LibreOffice 5.1
  • LibreOffice 5.2
  • LibreOffice 5.3
First official release
  • AL-v2 (Apache License Version 2.0)
final

Legal Disclaimer and Limitations for Downloads

The Document Foundation has not reviewed, and cannot review, all of the material, including computer software, available on or by means of The Document Foundation's
websites, and cannot therefore be responsible for that material's content, use or effects. By operating its websites, The Document Foundation does not represent or imply that it endorses the material there available, or that it believes such material to be accurate, useful or nonharmful. You are responsible for taking precautions as necessary to protect yourself and your computer systems from viruses, worms, Trojan horses and other harmful or destructive content. The Document Foundation's websites may contain content that is offensive, indecent or otherwise objectionable, as well as content containing technical inaccuracies, typographical mistakes and other errors. The Document Foundation's websites may also contain material that violates the privacy or publicity rights, or infringes the proprietary rights, of third parties, or the downloading, copying or use of which is subject to additional terms and conditions, stated or unstated. The Document Foundation disclaims any responsibility for any harm resulting from the use by The Document Foundation's visitors of The Document Foundation's websites, or from any downloading by those visitors of content available on or by means of The Document Foundation's websites.

Changes

Content contained on The Document Foundation's websites, including these Legal Disclaimers and Limitations, may be changed at the sole discretion of The Document Foundation and without notice. You are bound by any such updates or changes, and so should periodically review these Legal Disclaimers and Limitations.

If you believe any file is present on the site contrary to any TDF rule or applicable law, please supply full details to info@documentfoundation.org for impartial consideration.