[Solved] Python LO Base Gateway

Discuss the database features

[Solved] Python LO Base Gateway

Postby El Catala » Mon Dec 07, 2020 6:44 pm

Hello,

I am French and speak English very poorly. I apologize in advance. My problem is this: After writing a python script, I would start from a basic HSQL in LibreOffice.I have read the LO documentation, look at many examples but I am peddling.You have to import UNO but how do you activate the connection with
Code: Select all   Expand viewCollapse view
ctx = XSCRIPTCONTEXT.getComponentContext()

Could you help me in solving this problem

cordially
Last edited by El Catala on Tue Dec 08, 2020 6:37 pm, edited 1 time in total.
LibreOffice 7.0.4 Xubuntu 20.4
El Catala
 
Posts: 17
Joined: Mon Dec 07, 2020 6:29 pm

Re: Python LO Base Gateway

Postby Villeroy » Mon Dec 07, 2020 7:48 pm

Most of my Base related macros are triggered by a form event or by a form control event.
Two entry points for script events bound to forms or form controls respectively:
Code: Select all   Expand viewCollapse view
def Control_Action(ev):
    ctrl = ev.Source
    frm = ev.Source.Model.Parent
    subform = frm.getByName("MySubform")

def Form_Action(ev):
    frm = ev.Source
    ctrl = frm.getByName("MyButton")
    subform = frm.getByName("MySubform")


This branch of the API is the most complicated of the whole office suite and the API of this office suite is a nightmare. You can not really do anything without certain extensions.
MRI: viewtopic.php?f=74&t=49294
APSO: https://extensions.libreoffice.org/en/e ... for-python

Most request for macros on this forum are pointless. Before you even think of any macros, you should become very familiar with the application itself.
Base tutorial: http://user.services.openoffice.org/en/ ... 74#p201074
Complex database (embedded HSQL) with no macro: viewtopic.php?f=100&t=70259
More tutorials and examples on this forum: viewforum.php?f=83

The Base component is a tiny addition to this office suite. Base itself is not a database development sute within this office suite. It is far, far behind MS Access.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
 
Posts: 29718
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Python LO Base Gateway

Postby El Catala » Tue Dec 08, 2020 2:45 pm

Hello,
Thank you very much for your detailed response.I am a little surprised because I thought that it was necessary to go through uno to be able to establish the communication between the script and libreoffice base.
I will test your method and give you the test result.
Completely agree with your judgment on the Base module.
If I use it, it is for fear of attacking a database under SQLite.
For now, I am new to and testing Python.

Thank you again and have a nice day.
LibreOffice 7.0.4 Xubuntu 20.4
El Catala
 
Posts: 17
Joined: Mon Dec 07, 2020 6:29 pm

Re: Python LO Base Gateway

Postby Villeroy » Tue Dec 08, 2020 3:29 pm

All this is about UNO events. The event passes an UNO event struct with at least one element "Source" pointing to the calling object. In 90% of all cases (form related macros) this is all you need.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
 
Posts: 29718
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Python LO Base Gateway

Postby El Catala » Tue Dec 08, 2020 6:36 pm

Good evening,

Indeed, it seems to work according to the scripts transmitted.
Unfortunately, I need the "requests" Python module, and this one is not recognized by LO Base.
Pity.
I will close this topic. I have to find another solution.

Thank you for your help
LibreOffice 7.0.4 Xubuntu 20.4
El Catala
 
Posts: 17
Joined: Mon Dec 07, 2020 6:29 pm


Return to Base

Who is online

Users browsing this forum: No registered users and 5 guests