Hi folks here
I'm quite new with python and Openoffice base and trying to find solution
how to connect the OpenOffice Base with Python macro *inside* OpenOffice
base user interface i.e calling python macro .py from there.
I've been trying several times without success. I just like to know
if anyone here has ever been successful doing this kind of thing.
There are a few example scripts I've been trying with and making some
modifications to them but seems to not work. F. ex. biblio_access.py
Is it ment to be used outside or inside the OpenOffice to retrieve the BIBLIO
database.
I'm using OpenOffice 3.3.0 on Windows XP
Best Regards
Jarmo Kangas
(user JKPythOob)
Python connect to OOo Base inside OOo
Python connect to OOo Base inside OOo
OpenOffice 3.3 on Windows XP
-
- Volunteer
- Posts: 283
- Joined: Tue Dec 04, 2007 6:38 pm
- Location: Houston, TX
Re: Python connect to OpenOffice base inside OpenOffice
What kind of problems are you having? Where are your scripts stored? These need to be stored in ..\${OO_DIR}\Basis\share\Scripts\python\, where {$OO_DIR} is the directory where you have OpenOffice.org installed OR ${USE_DIR}\Application Data\OpenOffice.org\3\user\Scripts\python, where ${USER_DIR} refers to the logged user's directory (e.g. C:\Users\tux\..., C:\Documents and Settings\tux\...., /home/tux/...)
When you place a script there, it appears in the macro selector when binding a macro to a UI Element ,such as menu item, button i form, etc.
When you place a script there, it appears in the macro selector when binding a macro to a UI Element ,such as menu item, button i form, etc.
Re: Python connect to OpenOffice base inside OpenOffice
If you installed OpenOffice with PythonUno support you will have two or three sample macros (Capitalize.py and HelloWorld.py). These macros are located in the installation folder of OpenOffice in the place that was mentioned by QuazzieEvil in his post. If you have read the initial comment there, you will know that they need a active Writer Document to work properly. I any circumstances if you can start these sample macros via "Run Macro" or "Organize Macros -> Python" you should also be able to start Python macros that are accessing Base's UNO objects when you store them in your User Profile at the location given by QuazzieEvil.
There is no extra magic coming with Base compared to Writer or Calc, you just need to know the UNO objects. Typically the only thing that you get from the database related UNO objects are result sets. There is no easy way to tell Base via macros to run parameterized query XY and display the results in the nice grid that you know from working directly with queries in Base. Visualizing the result set would be another task that your macro would need to do. If you don't want to use a writer document or a calc sheet for this, this is not an easy task. (And I guess this is why the common opinion in the Base forum is to work without macros as long as possible).
There is no extra magic coming with Base compared to Writer or Calc, you just need to know the UNO objects. Typically the only thing that you get from the database related UNO objects are result sets. There is no easy way to tell Base via macros to run parameterized query XY and display the results in the nice grid that you know from working directly with queries in Base. Visualizing the result set would be another task that your macro would need to do. If you don't want to use a writer document or a calc sheet for this, this is not an easy task. (And I guess this is why the common opinion in the Base forum is to work without macros as long as possible).
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
Re: Python connect to OpenOffice base inside OpenOffice
Thanks for your replies...
That biblioaccess.py i got from http://udk.openoffice.org/python/python-bridge.html
the same site as the other example scripts that rudolfo mentioned.
It really stands there that it's a command line script thus it would not work from inside
Oob. I just though it would otherwise suit with my needs (database handling with
SQL commands). My scripts should be in the right folder
${USE_DIR}\Application Data\OpenOffice.org\3\user\Scripts\python and I see them
from OoBase user interface (and can run) with execute macro function.
That biblioaccess.py just doesn't do anything as it should do something into the
biblio database (but maybe it just doesn't work inside OoBase..)
Sometimes it gives an error message from pythonscript.py 'WSAECONNREFUSED
winsock connection refused' and I tried to disable the firewall a few times but
still doesn't work.
A couple of other scripts (rowset.py and connect.py) have i also tested.
Would you have any advice how to get something on the screen while executing
python macros inside the OoBase (like print does with command level).
Br. JK
That biblioaccess.py i got from http://udk.openoffice.org/python/python-bridge.html
the same site as the other example scripts that rudolfo mentioned.
It really stands there that it's a command line script thus it would not work from inside
Oob. I just though it would otherwise suit with my needs (database handling with
SQL commands). My scripts should be in the right folder
${USE_DIR}\Application Data\OpenOffice.org\3\user\Scripts\python and I see them
from OoBase user interface (and can run) with execute macro function.
That biblioaccess.py just doesn't do anything as it should do something into the
biblio database (but maybe it just doesn't work inside OoBase..)
Sometimes it gives an error message from pythonscript.py 'WSAECONNREFUSED
winsock connection refused' and I tried to disable the firewall a few times but
still doesn't work.
A couple of other scripts (rowset.py and connect.py) have i also tested.
Would you have any advice how to get something on the screen while executing
python macros inside the OoBase (like print does with command level).
Br. JK
OpenOffice 3.3 on Windows XP
Re: Python connect to OpenOffice base inside OpenOffice
"winsock connection refused" sounds a bit like the script tries to connect to a running OpenOffice instance in headless or server mode. Anyway I guess you need to inspect the behaviour of the script more closely. Maybe the following module from Code Snippet section of the other forum can help you.
But if you say you are new to Python and OpenOffice I see a problem: Though Python is one of the best choices for writing macros, if you find a problem you will always have to dig in both areas. There will be quite a lot of problems with OOo in the beginning (simply because it has its own way of doing things and it takes some time to get used to it) and if you are not sure that your python part is without errors you will be searching here and searching there, scratching your head. You have mentioned quite a lot of python code. If you are sure that you understood that code without making your own modifications it would be a good/better point to start making changes.
Also if you work with OOo the MRI extension (an object inspection tool) will be helpful. It is written in Python.
But if you say you are new to Python and OpenOffice I see a problem: Though Python is one of the best choices for writing macros, if you find a problem you will always have to dig in both areas. There will be quite a lot of problems with OOo in the beginning (simply because it has its own way of doing things and it takes some time to get used to it) and if you are not sure that your python part is without errors you will be searching here and searching there, scratching your head. You have mentioned quite a lot of python code. If you are sure that you understood that code without making your own modifications it would be a good/better point to start making changes.
Also if you work with OOo the MRI extension (an object inspection tool) will be helpful. It is written in Python.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
Re: Python connect to OOo Base inside OOo
Thanks again for your replies rudolfo.
I'll try that what you suggested maybe it gets going better that way.
I have many other things also under work but trying this still anyway.
Br. JK
I'll try that what you suggested maybe it gets going better that way.
I have many other things also under work but trying this still anyway.
Br. JK
OpenOffice 3.3 on Windows XP