Welcome beginner. What is your question or comment?
Please try to briefly and clearly tell us: What you want, What you tried, and What happened.
-----------------------------------------------------------------------------------------------------------
I am trying to set up a database of .svg and .jpg images I have set up all the fields save one. I want a button that opens the original images (in the default editor: Inkscape and GIMP respectively) using a text box that contains the file path. I have tried using a python macro I found on this forum from topic "[Solved] How to Open a PDF from a form". I cannot get the macro to attach to the button or form (need more explicit instructions).When running the macro through Tools>Macros>Run Macros I got an error messages stating the following:
"com.sun.star.uno.RuntimeExceptionError during invoking function file_on_record_change in module file:///C:/Program%20Files/OpenOffice.org%203/Basis/share/Scripts/python/DBForms.py (exceptions.TypeError:file_on_record_change() takes exactly 1 argument (0given) C:\Program Files\OpenOffice.org 3\Basis\program\pythonscript.py:635 in function invoked() [ret = self.func( *args)])
I am not a programmer. Can this be fixed or is there some other way to get this button to work.
[Solved] Open file from a Base form
-
- Posts: 3
- Joined: Wed Nov 19, 2008 6:51 pm
[Solved] Open file from a Base form
Last edited by confused_end_user on Fri Nov 21, 2008 1:07 am, edited 1 time in total.
OOo 3.0.X on Ms Windows XP
Re: Open file from a Base form
Python support broken in OOo 3.0, use 2.4.2 for this.
AOO 4.0 and LibO 4 on Win 8
Hungarian forum co-admin
Hungarian forum co-admin
Re: Open file from a Base form
Following my own instructions in Re: How to Open a PDF from a form the macro works for me if installed in OOo's installation directory where you obviously have it installed. The error indicates that the thing is called, but it's called in a wrong way. So I don't think it is a OOo+Python+Windows kind of problem.
-- You have a form with event "After record change" assigned to the macro mentioned in the error message ("file_on_record_change")
-- The form's data source contains a field with path-names like C:\Path\Name.pdf
-- The form has a button named "File_Button" with "Action"="Open Document/web-page" and "Additional Info"="name_of_your_url_field"
After every successful record change macro "file_on_record_change" converts the given field's value "C:\Path\Name.pdf" to "file:///C:/Path/Name.pdf" and assigns this system-independent URL to the URL-property of a button named "File_Button". When you click the button, you click the file-URL. If you navigate to a record with no URL, you get another error message because the code is very minimalistic without any error handling.
There is also a Basic version of the same macros, which is a bit more difficult to install, but meanwhile we have a [Tutorial] How to install a code snippet
-- You have a form with event "After record change" assigned to the macro mentioned in the error message ("file_on_record_change")
-- The form's data source contains a field with path-names like C:\Path\Name.pdf
-- The form has a button named "File_Button" with "Action"="Open Document/web-page" and "Additional Info"="name_of_your_url_field"
After every successful record change macro "file_on_record_change" converts the given field's value "C:\Path\Name.pdf" to "file:///C:/Path/Name.pdf" and assigns this system-independent URL to the URL-property of a button named "File_Button". When you click the button, you click the file-URL. If you navigate to a record with no URL, you get another error message because the code is very minimalistic without any error handling.
There is also a Basic version of the same macros, which is a bit more difficult to install, but meanwhile we have a [Tutorial] How to install a code snippet
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
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
-
- Posts: 3
- Joined: Wed Nov 19, 2008 6:51 pm
Re: Open file from a Base form
From your instructions I found I understood better about how this script works. It helped me to realize that that the event "After Record change" was a form event and not attached to the button itself. It has been corrected and I am now using the Baisic Script. The button still doesn't work and when run physically (same procedure and path given in initial post) I get the following message "A Scripting Framework error occurred while running the Basic script Library1.Module1.file_on_record_change. Message: wrong number of paramters! Is this a problem running the script or is it due to a bad installation by me?
OOo 3.0.X on Ms Windows XP
Re: Open file from a Base form
When you call the macro from an event, the routine gets the calling form passed as parameter. This way the macro can work with any button named "File_Button" on any form without changing a single line of code.
The whole macro with comments:
def file_on_record_change(oEv): # symbol oEv is the expected structure to be passed from the calling form
frm = oEv.Source # structure oEv has an element Source, being the calling form
cols = frm.getColumns() # every bound form has columns (of the current record)
btn = frm.getByName("File_Button") # we assume a button named "File_Button"
tag = btn.Tag # that button has a tag (the "Additional Information" in the properties dialogue)
field = cols.getByName(tag) # from the form's current record's columns get the column whose name is specified by the tag
btn.TargetURL = uno.systemPathToFileUrl(field.getString()) # convert the column's string-value to a file-URL and assign it to the hyperlink button's property "TargetURL" (the "URL" in the properties dialogue)
Now tell me what is oEv and the form oEv.Source when you call it from the macros dialog? It's simply missing.
The whole macro with comments:
def file_on_record_change(oEv): # symbol oEv is the expected structure to be passed from the calling form
frm = oEv.Source # structure oEv has an element Source, being the calling form
cols = frm.getColumns() # every bound form has columns (of the current record)
btn = frm.getByName("File_Button") # we assume a button named "File_Button"
tag = btn.Tag # that button has a tag (the "Additional Information" in the properties dialogue)
field = cols.getByName(tag) # from the form's current record's columns get the column whose name is specified by the tag
btn.TargetURL = uno.systemPathToFileUrl(field.getString()) # convert the column's string-value to a file-URL and assign it to the hyperlink button's property "TargetURL" (the "URL" in the properties dialogue)
Now tell me what is oEv and the form oEv.Source when you call it from the macros dialog? It's simply missing.
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
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
-
- Posts: 3
- Joined: Wed Nov 19, 2008 6:51 pm
Re: Open file from a Base form
The macro is now working.
I found the last things two problems hindering the macro from running properly (three if you count my own lack of understanding). One was for some reason when the macro was assigned to the "After Record Change" the form didn't save properly. Another save attempt fixed this. Secondly, I had misunderstood your original instructions of how the table field name goes in the "Additional Information" tag and not the name of the form text box field. Thank you Villeroy. Your explanations of the code and procedure were instrumental in solving this problem. Thanks for the great work.

OOo 3.0.X on Ms Windows XP