| View previous topic :: View next topic |
| Author |
Message |
hillerd General User

Joined: 02 Jul 2005 Posts: 22
|
Posted: Sat Feb 24, 2007 1:23 pm Post subject: Changing images in dialog interactively |
|
|
I want to interactively change the image of an "ImageControl" of a dialog.
Since the corresponding macro is installed with the extension manager, I cannot use absolute paths in the URL.
So I need to find out, where the images have been placed with the extension manager and manipulate the graphURL value accordingly.
Is there an example somewhere? Programming language is BASIC.
Thanks |
|
| Back to top |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 7649 Location: Germany
|
Posted: Sat Feb 24, 2007 2:18 pm Post subject: |
|
|
Browse the directory <user-dir>/.openoffice.org2/user/uno_packages/cache/uno_packages/
Under Windows something like: Docs and settings\name\Application Data\OOo\user\uno_packages\cache\uno_packages\ _________________ XUbuntu 9.04, OOo 3.1.1(Sun), Sun Java 1.5.0_06 |
|
| Back to top |
|
 |
hillerd General User

Joined: 02 Jul 2005 Posts: 22
|
Posted: Sun Feb 25, 2007 2:36 am Post subject: |
|
|
I have found the add-on, but I need to tell in the dialog editor the URL where the image is located. Since I want to install the add-on via the extension manager I cannot use the direct URL but have to take a general term. I found the %origin% but have no idea of how to make use of it.
Do you have any suggestions? |
|
| Back to top |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 7649 Location: Germany
|
Posted: Sun Feb 25, 2007 3:51 am Post subject: |
|
|
If your add-on is registered as "name/your_name/myAddon" and one of your configuration entries in mySetup.xcu looks like
"%origin%/pictures/mypic.png"
the registered add-on will store this info in a file ~/.openoffice.org2/user/uno_packages/cache/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/registry/data/name/your_name/myAddon/mySetup.xcu
The corresponding line reads like:
vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE/uno_packages/SHZUe5_/myAddon.uno.zip/pictures/myPic.png
You have to read that entry from a config-node, instanciate a macro-expander, use it's method expand(str) in order to get a url like:
vnd.sun.star.expand:file:///<real/path/to/your/installed/package>/uno_packages/SHZUe5_/....
Strip "vnd.sun.star.expand:" and you have the url of the picture file.
One example in python, but almost usable as Basic code:
http://www.oooforum.org/forum/viewtopic.phtml?t=14552&highlight=themacroexpander
The first link in my signature provides a working add-on in python.
The relevant stuff is in "registry/Localization.xcu|xcs" and python/SpecialCells.py, class ConfigProvider.
Sorry, I can't find a StarBasic example yet. _________________ XUbuntu 9.04, OOo 3.1.1(Sun), Sun Java 1.5.0_06 |
|
| Back to top |
|
 |
hillerd General User

Joined: 02 Jul 2005 Posts: 22
|
Posted: Sun Feb 25, 2007 4:06 am Post subject: |
|
|
Thanks, that looks very promising. It will take some time to get this done (I am just preparing for a paragliding exam and thus do not have too much time), but be sure that I will let you know.
Dietmar |
|
| Back to top |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 7649 Location: Germany
|
Posted: Sun Feb 25, 2007 5:45 am Post subject: |
|
|
*g* Of course I have a working example in StarBasic.
Install my add-on "SpecialCells" and run this:
| Code: |
Sub print_SpecialCellsHelpPath
'calls getRootElement, getExpander
Const sNode = "name.AndreasSaeger.SpecialCells.Localization/LocalizedStrings"
Const sEntry = "HelpPath"
Const sPrefix = "vnd.sun.star.expand:"
oRoot = getRootElement(sNode)
sMacroString = oRoot.getbyName("HelpPath")
print "sMacroString: "& sMacroString
expander = getMacroExpander()
sExpandURL = expander.expandMacros(sMacroString)
print "sExpandURL: "& sExpandURL
sFileURL = mid(sExpandURL,len(sPrefix) +1)
print "sFileURL: "& sFileURL
End Sub
Function getRootElement(sNodePath$)
Dim sProvider$,sAccess$,aSettings
Dim aConfigProvider, aParams2(0) as new com.sun.star.beans.PropertyValue
sProvider = "com.sun.star.configuration.ConfigurationProvider"
sAccess = "com.sun.star.configuration.ConfigurationAccess"
aConfigProvider = createUnoService(sProvider)
aParams2(0).Name = "nodepath"
aParams2(0).Value = sNodePath
aSettings = aConfigProvider.createInstanceWithArguments(sAccess, aParams2())
getRootElement = aSettings
End Function
Function getMacroExpander():
Dim PSM, ctx,btx
PSM = getProcessServiceManager()
ctx = PSM.DefaultContext
btx = PSM.createInstanceWithContext("com.sun.star.configuration.bootstrap.BootstrapContext", ctx)
getMacroExpander= btx.getValueByName("/singletons/com.sun.star.util.theMacroExpander")
End FUnction
|
If you run a german version the last print shows a path "file:///.../de", otherwise it is "file:///.../en". _________________ XUbuntu 9.04, OOo 3.1.1(Sun), Sun Java 1.5.0_06 |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3208 Location: Troyes France
|
|
| Back to top |
|
 |
hillerd General User

Joined: 02 Jul 2005 Posts: 22
|
Posted: Mon Feb 26, 2007 10:09 am Post subject: |
|
|
Thank you all, I understand the way to go.
While I am working through your documents, another question arose:
Do I actually have to do the same for static images, so images installed with the extention manager that are not controlled from the code? Or is there a trick to tell the dialog editior to look in the %origin% directory? |
|
| Back to top |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 7649 Location: Germany
|
Posted: Mon Feb 26, 2007 2:28 pm Post subject: |
|
|
| hillerd wrote: | Thank you all, I understand the way to go.
While I am working through your documents, another question arose:
Do I actually have to do the same for static images, so images installed with the extention manager that are not controlled from the code? Or is there a trick to tell the dialog editior to look in the %origin% directory? |
No, I don't think there is such a trick. I created a dialog with an image control.
The image path is absolute.
| Code: |
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="Dialog2" dlg:left="10" dlg:top="76" dlg:width="152" dlg:height="122" dlg:closeable="true" dlg:moveable="true">
<dlg:bulletinboard>
<dlg:img dlg:id="ImageControl1" dlg:tab-index="0" dlg:left="34" dlg:top="37" dlg:width="82" dlg:height="54" dlg:src="file:///home/andreas/Documents/Bilder/airbag.jpg"/>
</dlg:bulletinboard>
|
This changes the picture:
| Code: |
Sub test_Dialog2
globalscope.dialoglibraries.loadlibrary("Library1")
oObj = DialogLibraries.Library1.Dialog2
oDlg = createUnoDialog(oObj)
oDlg.Model.getByName("ImageControl1").ImageURL = "file:///home/andreas/Documents/Bilder/Bremse.jpg"
oDlg.execute()
end sub
|
_________________ XUbuntu 9.04, OOo 3.1.1(Sun), Sun Java 1.5.0_06 |
|
| Back to top |
|
 |
hillerd General User

Joined: 02 Jul 2005 Posts: 22
|
|
| Back to top |
|
 |
|