Py-uno location=user versus location=application in base code macro not working

Hi-
macros with base libreoffice and pyuno.
~/.config/libreoffice/4/user/Scripts/python
DIALOG_URL = “vnd.sun.star.script:Standard.Dialog1?location=user” if i put it like that it won’t work but if i substitute =application i am good to go. Gemini insisted that i get this corrected. Do you know what could cause me to have it so that i can’t use the keyword user for a location? It was complaining something about my profile, but i reset that so i don’t know why, and i even changed file permissions and folder permissions 600 700 respectively in ubuntu with chmod.

AI and i went round and round about this, but now I am starting to get it to work other than this sticking point. I can display a custom dialog – just not the exact way it needs me to.

thanks,
j.

And… how exactly do you need it?

P.S. Don’t waste your time with AI.

elmau-

i guess the real question is does it really matter? I thought application was fine. It worked but if there is something glaring that i am missing that would make a huge diff… If you think application may suffice and that is your advice i will run with that. thanks

Just search for LOCPARAM in the following link.

https://wiki.documentfoundation.org/Documentation/DevGuide/Scripting_Framework

Usage seems to be depend on your used language…

Yes it does.
This is not a bug report site; when you post a question here, you (should) expect people to help you overcome a problem that prevents making a job done. And - well, when there may be a bug in the program, the help may be workarounds, which could depend on use case.

On the other hand, if you confused this site with a bug tracker, than the report wasn’t clear enough to allow someone else to “do this than that, and see the problem on their system” :wink: - that is a hint, how to improve your report, when you decide to properly file it on the respective site.

Hi -
I understand the report ‘wasn’t sufficient to get this one or that one to do this or that’ obviously no offense but will this report pique someones curiosity? thanks all –
this is a problem i am having and a conversation with gemini the ai. LO is not letting me use the script profile correctly. I run lo using apt package manager through Ubuntu 22.04.
My code is not letting me run this location from within libreoffice. I go to Tools->Organize Python Scripts-> Execute and it doesnt work with my user profile. It goes to location=application and searches backward in that dir first which is out of order because if I hadve a dialog in system wide it searches there first and then falls back to user. Only location=application is working with DIALOG_URL = “vnd.sun.star.script:Standard.Dialog1?location=application” If i run it in code specified like this my dialog shows – otherwise No. I will include the code i am testing a the end of this email.

Thanks so much for considering helping me resolve this because my scripts will not be portable or able to be used in a business that I am not the administrator for which is unlikely.

Have the coolest of days.

thanks again - j.

I am using Version: 24.2.7.2 (X86_64) / LibreOffice Community
Build ID: 420(Build:2)
CPU threads: 8; OS: Linux 6.14; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Ubuntu package version: 4:24.2.7-0ubuntu0.24.04.4
Calc: threaded

You are correct that the URL
DIALOG_URL = “vnd.sun.star.script:Standard.Dialog1?location=application” is strange in this context. Given the file path you provided, the location=application part of the URL is incorrect and will cause an error.
Here is an explanation of why and how to fix it:
The problem with location=application
The location=application argument in the URL tells LibreOffice to look for the script or dialog in the application’s shared directory, which is a system-wide directory. Your files, however, are in your user profile: /home/funnysys/.config/libreoffice/4/user/basic/Standard.
The correct URL needs to specify location=user so that LibreOffice looks in the correct place, which is your user profile.
Correct URL for a Python script
To call a Basic dialog (Dialog1 from the Standard library) from a Python macro, you must instantiate it from the correct location.
If your Python macro is calling a Basic macro
If your Python script is simply triggering a Basic macro that handles the dialog, the URL should point to the Basic macro itself.
python

Calls a macro named ‘Main’ inside Module1.xba

DIALOG_URL = “vnd.sun.star.script:Standard.Module1.Main?language=Basic&location=user”

Use code with caution.
If your Python macro is opening the dialog directly
If your Python macro is responsible for instantiating the dialog, the process is different. The Python script would get the dialog from the correct library and then run it. The URL would not be used in the same way.
Instead, a Python macro would use the UNO framework to get the dialog from the Standard library in the user’s profile and then execute it. The code might look something like this:
python

import uno

def run_dialog():
# Get the LibreOffice Basic libraries
basic_libraries = uno.getComponentContext().getServiceManager().createInstance(
“com.sun.star.script.provider.MasterScriptProviderFactory”
).createScriptProvider("")

# Get the user's Standard library
user_script_library = basic_libraries.getLibrary("Standard", "user")

# Load the dialog from the library
dialog_container = user_script_library.getDialogContainer()
oDialog = dialog_container.getByName("Dialog1")

# Create the dialog model
dialog_model = uno.getComponentContext().getServiceManager().createInstance("com.sun.star.awt.Dialog")
dialog_model.setModel(oDialog.createUnoModel())

# Execute the dialog
dialog_model.execute()

Use code with caution.
dialog.xlc and script.xlc
The .xlc files are cache files that LibreOffice uses for faster access to the Basic libraries. They store information about the modules (script.xlc) and dialogs (dialog.xlc) in the library. You should never edit these manually. They are automatically created and updated by LibreOffice when you use the Macro Organizer.
In summary
The URL vnd.sun.star.script:Standard.Dialog1?location=application will fail because your files are in the user profile, not the system-wide application folder. The location parameter must be changed from application to user for the call to work correctly from a Basic macro. For a Python macro, you would use UNO to access the dialog programmatically from the correct location.

-- coding: utf-8 --

from future import unicode_literals

import uno, unohelper
from com.sun.star.awt import XDialogEventHandler
from com.sun.star.lang import IllegalArgumentException

_DLG_PROVIDER = “com.sun.star.awt.DialogProvider2”
DIALOG_URL = “vnd.sun.star.script:Standard.Dialog1?location=user”

class Console(unohelper.Base, XDialogEventHandler):
“”" Access2Base Console Handler “”"

def show(self, ctx, smgr):
    """Creates and executes the dialog using the provided context."""

    # Create dialog with handler.
    dp = smgr.createInstanceWithContext(_DLG_PROVIDER, ctx)

    try:
        # Note: location=user is typically for "My Macros & Dialogs"
        dialog = dp.createDialogWithHandler(DIALOG_URL, self)
        dialog.setTitle("Konsole")

        # Execute the dialog.
        dialog.execute()

    except IllegalArgumentException as e:
        # Handle error if dialog is not found.
        self._msgbox(f"Dialog not found: {DIALOG_URL}\nError: {e.Message}", "Dialog Error")
    except uno.Exception as e:
        self._msgbox(f"UNO Exception: {e.Message}", "UNO Error")

# The method handles the dialog's events (not part of IDE testing)
# The handles method is a requirement of XDialogEventHandler
def handleEvent(self, event):
    return False

def getSupportedMethodNames(self):
    return () # Empty tuple since no custom methods are supported in this example.

def _msgbox(self, prompt, title):
    """Helper function for displaying message boxes."""
    try:
        # Get the desktop window as a parent for the message box.
        ctx = uno.getComponentContext()
        toolkit = ctx.getServiceManager().createInstance("com.sun.star.awt.Toolkit")
        parent = toolkit.getDesktopWindow()

        mb = toolkit.createMessageBox(parent, "infobox", 1, title, prompt)
        mb.execute()
    except Exception:
        # Fallback for IDE testing
        print(f"[{title}] {prompt}")

def ConsoleHandler():
“”“Main entry point for the LibreOffice macro.”""
try:
# Get the component context provided by LibreOffice.
ctx = XSCRIPTCONTEXT.getComponentContext()
smgr = ctx.getServiceManager()
Console().show(ctx, smgr)
except NameError:
# This will be caught when running outside LibreOffice.
print(“This function cannot be run outside of LibreOffice.”)

g_exportedScripts = (ConsoleHandler,)

if name == “main”:
# IDE runnable code: uses a mock LibreOffice environment.
# We explicitly avoid the graphical parts here.
from IDE_utils import Runner
with Runner():
print(“Simulating ConsoleHandler, but skipping GUI interactions.”)
# We cannot create the dialog handler correctly here, so we skip it.

Sent with Proton Mail secure email.

Bug 168550 has been successfully created

I asked them to let me know if they will look into in future, and I can just use status quo for now and down the road someday might get looked into. They will get back. It is unconfirmed. thanks

As you exchanged left and right side of the “equation” they might have a hard time to understand your report… (and for me the talk about “search path” is misleading too…)

location=application

specify application=location to get the dialog to appear. It won’t work with application=user.