Create a doc under LibreOffice with python

The issue of this python macro will need to take one .txt with questions and answers file and then to save it into a fillable PDF.

My problem come when I try to create the .doc under LibreOffice ( not WriteDocument – LibreOficeWriter) with python macro.

This python macro will be add to new toolbar + new macro to LibreOffice default window.

I try with this source code:

import os
import uno
import sys
import traceback


# a UNO struct later needed to create a document
from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
from com.sun.star.text.TextContentAnchorType import AS_CHARACTER
from com.sun.star.awt import Size
from com.sun.star.lang import XMain
# try to open and save 
from com.sun.star.ui.dialogs.TemplateDescription import FILEOPEN_SIMPLE
from com.sun.star.ui.dialogs.TemplateDescription import FILESAVE_SIMPLE

def file_dialog_open():
    try:
        oCtx = uno.getComponentContext()
        oServiceManager = ctx.getServiceManager()

        oFilePicker = oServiceManager.createInstanceWithArgumentsAndContext(
                'com.sun.star.ui.dialogs.OfficeFilePicker',
                (FILEOPEN_SIMPLE,),
                oCtx
            )

        oFilePicker.Title = 'Open as'

        #oDisp = oFilePicker.Text

        oFilePicker.execute()

    except:
        pass
        #oDisp = traceback.format_exc(sys.exc_info()[2])

file_dialog_open

but I got this error:

com.sun.star.uno.RuntimeExceptionError during invoking function file_dialog_open in module file:///C:/Program%20Files/LibreOffice%205/share/Scripts/python/pythonSamples/TesteRomana.py (<class 'TypeError'>: file_dialog_open() takes 0 positional arguments but 1 was given
  C:\Program Files\LibreOffice 5\program\pythonscript.py:870 in function invoke() [ret = self.func( *args )]
)

Hallo

the Traceback is clear enough!

LO calls any function, which is called via some button, some Event or some Menu-Entry (except Menu: →Tools→Macros…), with some usefull Calling-Context as Argument.
To resolve the Error you should change the Signatur of your Function to something like:

def file_dialog_open(context):
# or only optional:
#def file_dialog_open(*context):

[1] by the way, your Function does nothing more than: →File→Open…
[2] its bad, to hide any usefull Errormessages behind blanc:

    except:
        pass

I used python with C:\Program Files\LibreOffice 5\share\Scripts\python\pythonSamples\test001.py to try open dialog under LibreOffice interface.Not working with your idea.
[1] yes I used this function to open write or calc file if into the file I open need to be parsed for write or calc and thar will depend by file I open with my script.
[2] I don’t have anything to do with except now because the open dialog for LibreOffice interface not working.
…something like File-Wizards under LibreOffice.