[Solved] OptionsDialog not showing up for Python Extension

Creating a macro - Writing a Script - Using the API

[Solved] OptionsDialog not showing up for Python Extension

Postby jmarch » Wed Jan 09, 2019 6:24 am

I am trying to add an options dialog to my python extension for LibreOffice. My problem is that the dialog only displays if I remove the service name from the EventHandlerService property in my OptionsDialog.xcu file. I see someone had a similar problem in this thread:

viewtopic.php?f=20&t=19784

The poster's solution was: "Found the problem with my EventHandlerService: it was not registered as a RegistrationClass. I had to edit the nbproject/project-uno.properties so the registration.classname property also contained my DialogEventHandler."

But I'm not sure what this means or how to do this in Python.

Is there more to do besides this:

g_ImplementationHelper.addImplementation(
create_option_handler, "OptionsPageHandler", ("mytools.search.IncrementalSearch.OptionsPageHandler",),)

Thanks for any help you can provide!
Last edited by jmarch on Fri Jan 11, 2019 4:27 pm, edited 1 time in total.
LibreOffice 6.0.5.2 on Mac Mojave.
jmarch
 
Posts: 5
Joined: Mon Dec 24, 2018 12:36 am

Re: OptionsDialog not showing up for Python Extension

Postby hubert lambert » Wed Jan 09, 2019 11:49 am

Hi,

The "addImplementation" method should return : the handler class, the implementation name and a tuple of supported services. Something like, in your case:
Code: Select all   Expand viewCollapse view

g_ImplementationHelper
.addImplementation(
create_option_handler, "mytools.search.IncrementalSearch.OptionsPageHandler", ("mytools.search.IncrementalSearch.OptionsPageHandler",),)


In your "OptionsDialog.xcu" config file, the value of the "EventHandlerService" property should be the same implementation name :
Code: Select all   Expand viewCollapse view
[...]
<
prop oor:name="EventHandlerService">
   <value>mytools.search.IncrementalSearch.OptionsPageHandler</value>
</
prop>
[...] 

Regards.
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
hubert lambert
 
Posts: 135
Joined: Mon Jun 13, 2016 10:50 am

Re: OptionsDialog not showing up for Python Extension

Postby jmarch » Wed Jan 09, 2019 5:52 pm

Thanks for your reply. I reduced my extension to the bare minimum to narrow things down. Maybe I need to be doing something more in my Event Handler? This is what I have:
Code: Select all   Expand viewCollapse view
import uno
import unohelper

from com.sun.star.awt import XActionListener, XContainerWindowEventHandler
from com.sun.star.lang import Locale, XServiceInfo, XInitialization

IMPLEMENTATION_NAME = "abc.OptionsPageHandler"

class OptionsPageHandler(unohelper.Base,
        XContainerWindowEventHandler, XServiceInfo):
    """ Option page implementation for incremental search. """
   
    def __init__(self, ctx, args):
        self.ctx = ctx

    # XContainerWindowEventHandler
    def getSupportedMethodNames(self):
        return ("external_event", )

# XServiceInfo
    def supportsService(self, name):
        return (name == IMPLEMENTATION_NAME)

    def getImplementationName(self):
        return IMPLEMENTATION_NAME

    def getSupportedServiceNames(self):
        return (IMPLEMENTATION_NAME,)

    def getServiceNames(self):
        return (IMPLEMENTATION_NAME,)       
   
    def callHandlerMethod(self, window, ev, name):
        # if name == "external_event":
        #     self.handle(window, ev)
        #     return True
        # else:
        #     return False
        return True
   
g_ImplementationHelper = unohelper.ImplementationHelper()
g_ImplementationHelper.addImplementation(
    OptionsPageHandler, IMPLEMENTATION_NAME, (IMPLEMENTATION_NAME,),)


In OptionsDialog.xcu I have this:
Code: Select all   Expand viewCollapse view
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE oor:component-data SYSTEM "../../../../component-update.dtd">
<oor:component-data
    xmlns:oor="http://openoffice.org/2001/registry"    
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    oor:package="org.openoffice.Office"
    oor:name="OptionsDialog">
    <node oor:name="Nodes">
        <node oor:name="Writer" oor:op="fuse">
            <node oor:name="Leaves">
                <node oor:name="abc.OptionsPageHandler.nodes.Writer.ASTLeaf" oor:op="fuse">
                    <prop oor:name="Id">
                        <value>abc.OptionsPageHandler</value>
                    </prop>                   
                    <prop oor:name="Label">
                        <value xml:lang="en-US">ABC Settings</value>
                    </prop>                   
                    <prop oor:name="OptionsPage">
                        <value>%origin%/dialogs/ASTLeaf.xdl</value>
                    </prop>                   
                    <prop oor:name="EventHandlerService">
                        <value>abc.OptionsPageHandler</value>
                    </prop>
                </node>
            </node>
        </node>
    </node>
</oor:component-data>


The dialog will display if I remove abc.OptionsPageHander here:

Code: Select all   Expand viewCollapse view
                    <prop oor:name="EventHandlerService">
                        <value></value>
                    </prop>


Thanks for any help.
LibreOffice 6.0.5.2 on Mac Mojave.
jmarch
 
Posts: 5
Joined: Mon Dec 24, 2018 12:36 am

Re: OptionsDialog not showing up for Python Extension

Postby hubert lambert » Wed Jan 09, 2019 7:33 pm

As written in the Developper's Guide, "the value of the property Id must be same as the extension identifier".
In your file, that value is the name of the dialog handler class. Is it actually the same as the extension identifier? If so, try renaming it...
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
hubert lambert
 
Posts: 135
Joined: Mon Jun 13, 2016 10:50 am

Re: OptionsDialog not showing up for Python Extension

Postby jmarch » Fri Jan 11, 2019 4:27 pm

Thanks so much for your help. I'm still not sure precisely what the problem was, but it's working now. For others with this problem I found this example very helpful:

https://github.com/p--q/OptionsDialog
LibreOffice 6.0.5.2 on Mac Mojave.
jmarch
 
Posts: 5
Joined: Mon Dec 24, 2018 12:36 am

Re: [Solved] OptionsDialog not showing up for Python Extensi

Postby hubert lambert » Fri Jan 11, 2019 5:25 pm

Thanks for the link !
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
hubert lambert
 
Posts: 135
Joined: Mon Jun 13, 2016 10:50 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 7 guests