Marshal858 refers to
http://user.services.openoffice.org/en/ ... 92&p=14885 and
http://user.services.openoffice.org/en/ ... 57&p=21667
I bundled 3 versions in a Python module.
The mailto-version adds protocol-prefix "mailto:" to the field's value.
The file-version converts a system path to URL with protocol-prefix "file:".
The url-version uses any URL which already includes the protocol in the field value.
The URL is assigned to a push-button. The push-button must be named "File_Button", "URL_Button" or "Mailto_Button" respectively. The tag (property "Additional Information") must specify the field name from where to get the URL. Don't mix up the field name with the name of a control. The field name is the name of one of the form's source columns.
Extract the attached zip-archive to <ooo_user_dir>/user/Scripts/python/ or save the following code without correct indendation and UNIX line feeds as <ooo_user_dir>/user/Scripts/python/DBForms.py
Assign the form's event "After Record Change" to one of the routines. Add a wrapper routine if you have to use more than one button in this manner.
Code: Select all
import uno
def mail_on_record_change(oEv):
frm = oEv.Source
cols = frm.getColumns()
btn = frm.getByName("Mailto_Button")
tag = btn.Tag
field = cols.getByName(tag)
btn.TargetURL = 'mailto:'+ field.getString()
def url_on_record_change(oEv):
frm = oEv.Source
cols = frm.getColumns()
btn = frm.getByName("URL_Button")
tag = btn.Tag
field = cols.getByName(tag)
btn.TargetURL = field.getString()
def file_on_record_change(oEv):
frm = oEv.Source
cols = frm.getColumns()
btn = frm.getByName("File_Button")
tag = btn.Tag
field = cols.getByName(tag)
btn.TargetURL = uno.systemPathToFileUrl(field.getString())
g_exportedScripts = mail_on_record_change, url_on_record_change, file_on_record_change
Edit: 2008-05-21: The installation procedure is unclear. Thanks, mobio |
Redirection from another thread: http://user.services.openoffice.org/en/ ... =13&t=5937
mobio wrote:Problem is that I try to copy in one of the folders with python scripts (where I have Hello World, ...since I can't find the script specified in hyperlinked post <oo folder>/User/Script/phyton)
The "Hello World" stuff that comes with OOo is saved in the program's installation path, such as:
C:\Program Files\OOo.2.4\share\Script\python\
[sorry, no Windows at hand, but that's roughly the path]
On a decent operating system you need administration access in order to copy anything into this folder.
If you copied the macro to the system wide location, you find the macro below
"OpenOffice.org Macros">DBForms... where "DBForms" is derived from the file name "DBFroms.py"
In case you do not have any Python macros in Menu:Tools>Macros>Organize>Python... then you installed the office without support for Python macros.
Each office user has a profile folder for all his/her individual customizations, preferences, templates and macros. This is the path for Python macros:
C:\Documents And Settings\YourLogInName\OOo.2.4\user\Script\python\
(Add the "python" folder in "Script" when you copy your first Python-macro to this place)
If you copied to your user profile, you find the macro below
"My Macros">DBForms... where "DBForms" is derived from the file name "DBFroms.py"
I recommend to install the DBFroms.py contained the attached zip archive rather than pasting the above code into a text editor. It has the correct indentation and line-feeds.
If you want to edit Python macros, then you should use a decent text editor with two facts in mind:
- Leading white space (indentation) has a meaning in Python.
- OOo requires UNIX line feeds to handle Python macros.
- When you copy the above code by using the "Select All" hyperlink, all the code gets an extra indentation of 4 spaces. Select the code manually, paste into your editor and tell it to use Unix line feeds.
Edit: 'nother edit because not every installation includes Python and Ubuntu messed up Python support for their version of OOo2.4 ... Anyway, this is the Basic version. |
Menu:Tools>Macros>Organize>OOo Basic... [Organizer...] some new module in some new library... replace module's default content with the following:
Code: Select all
REM ***** BASIC *****
sub mail_on_record_change(oEv)
frm = oEv.Source
cols = frm.getColumns()
btn = frm.getByName("Mailto_Button")
tag = btn.Tag
field = cols.getByName(tag)
btn.TargetURL = "mailto:"& field.getString()
end sub
sub url_on_record_change(oEv)
frm = oEv.Source
cols = frm.getColumns()
btn = frm.getByName("URL_Button")
tag = btn.Tag
field = cols.getByName(tag)
btn.TargetURL = field.getString()
end sub
sub file_on_record_change(oEv)
frm = oEv.Source
cols = frm.getColumns()
btn = frm.getByName("File_Button")
tag = btn.Tag
field = cols.getByName(tag)
btn.TargetURL = ConvertToURL(field.getString())
end sub