Create APSO Toolbar Icon

After installing the APSO Extension it is configured under Tools, Customise, Keyboard: LibreOffice, Shortcut Keys - Alt+Shift+F11 service:apso.python.script.organiser.impl?execute

Under My Macros, apso.oxt, tools it only lists the console Function, not execute. How is APSO attached to a LibreOffice Toolbar icon? Preferred icon is C:/Program%20Files/LibreOffice/help/media/icon-themes/cmd/32/scriptorganizer.svg

My Basic macro does the same as Ctrl+Shift+F11.
Tthe translation into Python:

def Trigger_Apso(*args):
     s = "apso.python.script.organizer.impl"
     smgr = uno.getComponentContext().ServiceManager
     oService = smgr.createInstance(s)
     oService.trigger("execute")

No need for desktop or current document. Just let the global service manager instanciate service “apso.python.script.organizer.impl”. This works from any component including the office start screen.

btw: how can I define a code block here? [Solved]

2 Likes

You can specify a string of three characters ``` before and after the code.
It is also possible to try to specify the language in the first line of code:
```python.

1 Like

Thank you… Is this documented somewhere?

Asked at Where is the help on using Discourse, that is easily discoverable by users? :slight_smile:

1 Like

How can Trigger_Apso be pushed back into the apso.oxt file (unpacking/packing zip is understood)? [btw It needs to import uno.]

.
I tried inserting Trigger_Apso before the last line in tools.py, then adding function name to last line and removing last line. It’s basically the same code before the trigger command except it uses XSCRIPTCONTEXT instead of uno.

def console(*args, **kwargs):
...
    # we need to load apso before import statement
    ctx = XSCRIPTCONTEXT.getComponentContext()
    ctx.ServiceManager.createInstance("apso.python.script.organizer.impl")
    # now we can use apso_utils library
    from apso_utils import console
    kwargs.setdefault('loc', {})
    kwargs['loc'].setdefault('XSCRIPTCONTEXT', XSCRIPTCONTEXT)
    return console(**kwargs)


g_exportedScripts = console,

calls sources/python/pythonpath/apso_utils.py · master · Jean-Marc Zambon / apso · GitLab

APSO is an extension. It is not a macro.
You can add a toolbar to the extension package. I know, this is ridiculously difficult but searching for the URL to call the service I found “service:apso.python.script.organizer.impl?execute” in Accelerators.xcu.
In a Basic macro you can trigger that service like this:

Sub Trigger_Apso()
s="apso.python.script.organizer.impl"
oService = createUnoService(s)
oService.trigger("execute")
End Sub

I use to call APSO via Ctrl+Shift+F11 analog to Ctrl+F11 calling the Basic organizer.

2 Likes

Thank you, that works and gets me going. Until I learn more about UNO I’ll take your word for it.
.
The APSO shortcut key is Ctrl+Shift+F11 as you say but I probably won’t remember it.
.
For toolbar button:

  1. Create macro: Tools, Macro, Edit, and paste it into a module.
  2. Create toolbar button: Tools, Customise, Toolbars, Category Macros - select macro and position it, Modify, Change icon, Select icon, OK

Now, we’re not going to launch a python IDE with Basic are we? Unlike Basic the context needs to be set up (Python : Programming with Python):

# launch APSO - Alternative Python Script Organiser
import uno

def context():
    # set global variables for context
    global desktop
    global model
    global active_sheet
    
    # get the doc from the scripting context 
    desktop = XSCRIPTCONTEXT.getDesktop()
    model = desktop.getCurrentComponent()
    active_sheet = model.CurrentController.ActiveSheet
    
def trigger_apso(*args):
    # call function context()
    context()

    s = "apso.python.script.organizer.impl"
    #oService = createUnoService(s)
    ctx = uno.getComponentContext()
    smgr = ctx.getServiceManager()
    o_service = smgr.createInstanceWithContext(s, ctx)
    o_service.trigger("execute")

Comments on launcher code welcome.

the name of context is somehow ugly and misleading, the whole Function is completly unnecessary in this context, and in any case if possible you should NOT use global

2 Likes

No macro needed. Add a toolbar to the extension. I wrote the macro only because I was too lazy to write tons of tricky XML.
Adding the macro to the extension would add a similar level of complexity and the result would not include any visible GUI element.
Extension development is a nightmare (to me at least). I avoid nifty GUI elements. If you want to learn more about this, you should be very familiar with the product and read some tutorials.

Copied from another extension:

<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="Addons" oor:package="org.openoffice.Office">

  <node oor:name="AddonUI">
<-- some other UI elements here -->

        <node oor:name="OfficeToolBar">
            <node oor:name="oxygenoffice.extensions.smart.smartprotocolhandler" oor:op="replace">
                <node oor:name="m1" oor:op="replace">
                    <prop oor:name="Context" oor:type="xs:string">
                        <value>com.sun.star.drawing.DrawingDocument,com.sun.star.presentation.PresentationDocument</value>
                    </prop>
                    <prop oor:name="URL" oor:type="xs:string">
                        <value>oxygenoffice.extensions.smart.smartprotocolhandler:showSmartGallery</value>
                    </prop>
                    <prop oor:name="ImageIdentifier" oor:type="xs:string">
                        <value />
                    </prop>
                    <prop oor:name="Title" oor:type="xs:string">
                        <value xml:lang="en">SmART gallery</value>
                        <value xml:lang="hu">SmART galéria</value>
                    </prop>
                    <prop oor:name="ControlType" oor:type="xs:string">
                        <value>ImageButton</value>
                    </prop>
                    <prop oor:name="Target" oor:type="xs:string">
                        <value>_self</value>
                    </prop>
<------><------></node>
            </node>
<------></node>


        <node oor:name="Images">
            <node oor:name="oxygenoffice.extensions.smart.smartprotocolhandler.images" oor:op="replace">
                <prop oor:name="URL" oor:type="xs:string">
                    <value>oxygenoffice.extensions.smart.smartprotocolhandler:showSmartGallery</value>
                </prop>
                <node oor:name="UserDefinedImages">
                    <prop oor:name="ImageSmallURL">
                        <value>%origin%/../../../../../images/smart_16.png</value>
                    </prop>
                    <prop oor:name="ImageBigURL">
                        <value>%origin%/../../../../../images/smart_26.png</value>
                    </prop>
                </node>
            </node>
        </node>
</oor:component-data>

The XLM is a nice answer but I’m actually more interested in learning about macro programming and uno [after having tried a couple of tutorials and checking the docs] than this specific solution. It doesn’t look straightforward in the APSO example I provided above.

[Tutorial] Introduction into object inspection with MRI

P.S. I forgot to mention that the XML UI configuration belongs to file Addon.xcu of an extension package.